Greetings!
Please review the pull request #107: Make pacman-the-package-provider able to install package from source opened by (5long)
Some more information about the pull request:
- Opened: Mon Sep 12 14:14:46 UTC 2011
- Based on: puppetlabs:master (2ba3c446f818f1b3d2d2334e354f4197b3cbb7fc)
- Requested merge: 5long:pacman-source (74cdf4570449f3d31f8a2c2a58d4e47fa2bc1eb9)
Description:
pacman -U could be used to install package from a local file or a URL and here it goes.
CLA signed as: https://projects.puppetlabs.com/users/3462
Thanks!
The Pull Request Bot
Diff follows:
diff --git a/lib/puppet/provider/package/pacman.rb b/lib/puppet/provider/package/pacman.rb
index 5e05d14..7ee2e88 100644
--- a/lib/puppet/provider/package/pacman.rb
+++ b/lib/puppet/provider/package/pacman.rb
@@ -1,4 +1,5 @@
require 'puppet/provider/package'
+require 'uri'
Puppet::Type.type(:package).provide :pacman, :parent => Puppet::Provider::Package do
desc "Support for the Package Manager Utility (pacman) used in Archlinux."
@@ -12,13 +13,45 @@ Puppet::Type.type(:package).provide :pacman, :parent => Puppet::Provider::Packag
# Installs quietly, without confirmation or progressbar, updates package
# list from servers defined in pacman.conf.
def install
- pacman "--noconfirm", "--noprogressbar", "-Sy", @resource[:name]
+ if @resource[:source]
+ install_from_file
+ else
+ install_from_repo
+ end
unless self.query
raise Puppet::ExecutionFailure.new("Could not find package %s" % self.name)
end
end
+ def install_from_repo
+ pacman "--noconfirm", "--noprogressbar", "-Sy", @resource[:name]
+ end
+ private :install_from_repo
+
+ def install_from_file
+ source = @resource[:source]
+ begin
+ source_uri = URI.parse source
+ rescue => detail
+ fail "Invalid source '#{source}': #{detail}"
+ end
+
+ source = case source_uri.scheme
+ when nil then source
+ when /https?/i then source
+ when /ftp/i then source
+ when /file/i then source_uri.path
+ when /puppet/i
+ fail "puppet:// URL is not supported by pacman"
+ else
+ fail "Source #{source} is not supported by pacman"
+ end
+ pacman "--noconfirm", "--noprogressbar", "-Sy"
+ pacman "--noconfirm", "--noprogressbar", "-U", source
+ end
+ private :install_from_file
+
def self.listcmd
[command(:pacman), " -Q"]
end
diff --git a/spec/unit/provider/package/pacman_spec.rb b/spec/unit/provider/package/pacman_spec.rb
index 6791726..88a5ffa 100644
--- a/spec/unit/provider/package/pacman_spec.rb
+++ b/spec/unit/provider/package/pacman_spec.rb
@@ -7,7 +7,8 @@ describe provider do
before do
provider.stubs(:command).with(:pacman).returns('/usr/bin/pacman')
@resource = stub 'resource'
- @resource.stubs(:[]).returns("package")
+ @resource.stubs(:[]).with(:name).returns("package")
+ @resource.stubs(:[]).with(:source).returns(nil)
@resource.stubs(:name).returns("name")
@provider = provider.new(@resource)
end
@@ -46,7 +47,7 @@ describe provider do
provider.
expects(:execute).
with { |args|
- args[3,4] == ["-Sy", @resource[0]]
+ args[3,4] == ["-Sy", @resource[:name]]
}.
returns("")
@@ -59,6 +60,78 @@ describe provider do
lambda { @provider.install }.should raise_exception(Puppet::ExecutionFailure)
end
+
+ context "when :source is specified" do
+ context "reconizable by pacman" do
+ %w{
+ /some/package/file
+ http://some.package.in/the/air
+ ftp://some.package.in/the/air
+ }.each do |source|
+ it "should install #{source} directly" do
+ @resource.stubs(:[]).with(:source).returns source
+ db = states("db").starts_as(:not_synced)
+
+ provider.expects(:execute).
+ with(all_of(includes("-Sy"), includes("--noprogressbar"))).
+ then(db.is(:synced)).
+ returns("")
+
+ provider.expects(:execute).
+ with(all_of(includes("-U"), includes(source))).
+ when(db.is(:synced)).
+ returns("")
+
+ @provider.install
+ end
+ end
+ end
+
+ context "as an file:// URL" do
+ before do
+ @package_file = "file:///some/package/file"
+ @actual_file_path = "/some/package/file"
+ @resource.stubs(:[]).with(:source).returns @package_file
+ end
+
+ it "should install from the path segment of the URL" do
+ db = states("db").starts_as(:not_synced)
+
+ provider.expects(:execute).
+ with(all_of(includes("-Sy"), includes("--noprogressbar"),
+ includes("--noconfirm"))).
+ then(db.is(:synced)).
+ returns("")
+
+ provider.expects(:execute).
+ with(all_of(includes("-U"), includes(@actual_file_path))).
+ when(db.is(:synced)).
+ returns("")
+
+ @provider.install
+ end
+ end
+
+ context "as a puppet URL" do
+ before do
+ @resource.stubs(:[]).with(:source).returns "puppet://server/whatever"
+ end
+
+ it "should fail" do
+ lambda { @provider.install }.should raise_error(Puppet::Error)
+ end
+ end
+
+ context "as a malformed URL" do
+ before do
+ @resource.stubs(:[]).with(:source).returns "blah://"
+ end
+
+ it "shoudl fail" do
+ lambda { @provider.install }.should raise_error(Puppet::Error)
+ end
+ end
+ end
end
describe "when updating" do
@@ -95,7 +168,7 @@ describe provider do
provider.
expects(:execute).
with { |args|
- args[3,4] == ["-R", @resource[0]]
+ args[3,4] == ["-R", @resource[:name]]
}.
returns("")
@@ -107,7 +180,7 @@ describe provider do
it "should query pacman" do
provider.
expects(:execute).
- with(["/usr/bin/pacman", "-Qi", @resource[0]])
+ with(["/usr/bin/pacman", "-Qi", @resource[:name]])
@provider.query
end
@@ -149,7 +222,7 @@ EOF
@provider.query.should == {
:ensure => :purged,
:status => 'missing',
- :name => @resource[0],
+ :name => @resource[:name],
:error => 'ok',
}
end
@@ -219,7 +292,7 @@ EOF
provider.
expects(:execute).
when(refreshed.is('refreshed')).
- with(['/usr/bin/pacman', '-Sp', '--print-format', '%v', @resource[0]]).
+ with(['/usr/bin/pacman', '-Sp', '--print-format', '%v', @resource[:name]]).
returns("")
@provider.latest
-- You received this message because you are subscribed to the Google Groups "Puppet Developers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to [email protected].
For more options, visit this group at http://groups.google.com/group/puppet-dev?hl=en.
