summaryrefslogtreecommitdiff
path: root/chef
diff options
context:
space:
mode:
authorCaleb Tennis <caleb.tennis@gmail.com>2011-12-21 12:37:46 -0500
committerBryan McLellan <btm@opscode.com>2012-10-05 15:20:25 -0700
commit132b8d20d3d78ce90a11360b6aefd75c14f94eda (patch)
treec79af90e401ec1e895fbcc6e3cd722403e6d74cf /chef
parent8ec6d971f6ae20b80137fcf89aa74345635863bc (diff)
downloadchef-132b8d20d3d78ce90a11360b6aefd75c14f94eda.tar.gz
[CHEF-2826] - Add support for custom arch repos
Diffstat (limited to 'chef')
-rw-r--r--chef/lib/chef/provider/package/pacman.rb11
-rw-r--r--chef/spec/unit/provider/package/pacman_spec.rb29
2 files changed, 39 insertions, 1 deletions
diff --git a/chef/lib/chef/provider/package/pacman.rb b/chef/lib/chef/provider/package/pacman.rb
index 0df909a092..82cd083225 100644
--- a/chef/lib/chef/provider/package/pacman.rb
+++ b/chef/lib/chef/provider/package/pacman.rb
@@ -53,10 +53,19 @@ class Chef
def candidate_version
return @candidate_version if @candidate_version
+ repos = ["extra","core","community"]
+
+ if(::File.exists?("/etc/pacman.conf"))
+ pacman = ::File.read("/etc/pacman.conf")
+ repos = pacman.scan(/\[(.+)\]/).flatten
+ end
+
+ package_repos = repos.join("|")
+
status = popen4("pacman -Ss #{@new_resource.package_name}") do |pid, stdin, stdout, stderr|
stdout.each do |line|
case line
- when /^(extra|core|community)\/#{Regexp.escape(@new_resource.package_name)} (.+)$/
+ when /^(#{package_repos})\/#{Regexp.escape(@new_resource.package_name)} (.+)$/
# $2 contains a string like "4.4.0-1 (kde kdenetwork)" or "3.10-4 (base)"
# simply split by space and use first token
@candidate_version = $2.split(" ").first
diff --git a/chef/spec/unit/provider/package/pacman_spec.rb b/chef/spec/unit/provider/package/pacman_spec.rb
index fbdf4aecbe..7e4abcb6d5 100644
--- a/chef/spec/unit/provider/package/pacman_spec.rb
+++ b/chef/spec/unit/provider/package/pacman_spec.rb
@@ -103,6 +103,35 @@ PACMAN
@provider.candidate_version.should eql("2.2.3-1")
end
+ it "should use pacman.conf to determine valid repo names for package versions" do
+ @pacman_conf = <<-PACMAN_CONF
+[options]
+HoldPkg = pacman glibc
+Architecture = auto
+
+[customrepo]
+Server = https://my.custom.repo
+
+[core]
+Include = /etc/pacman.d/mirrorlist
+
+[extra]
+Include = /etc/pacman.d/mirrorlist
+
+[community]
+Include = /etc/pacman.d/mirrorlist
+PACMAN_CONF
+
+ ::File.stub!(:exists?).with("/etc/pacman.conf").and_return(true)
+ ::File.stub!(:read).with("/etc/pacman.conf").and_return(@pacman_conf)
+ @stdout.stub!(:each).and_yield("customrepo/nano 1.2.3-4").
+ and_yield(" My custom package")
+ @provider.stub!(:popen4).and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status)
+
+ @provider.load_current_resource
+ @provider.candidate_version.should eql("1.2.3-4")
+ end
+
it "should raise an exception if pacman fails" do
@status.should_receive(:exitstatus).and_return(2)
lambda { @provider.load_current_resource }.should raise_error(Chef::Exceptions::Package)