Skip to content

Commit

Permalink
Add default release option for apt package provider. Fixes #CHEF-1547
Browse files Browse the repository at this point in the history
  • Loading branch information
Vlk authored and aglarond committed Apr 11, 2012
1 parent 83dd8d9 commit 25fd12a
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 2 deletions.
4 changes: 3 additions & 1 deletion chef/lib/chef/provider/package/apt.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,10 @@ def load_current_resource
def check_package_state(package)
Chef::Log.debug("#{@new_resource} checking package status for #{package}")
installed = false
# Use apt cache release option only if provider was explicitly defined
aptcache_options = "-o APT::Default-Release=#{@new_resource.default_release}" if @new_resource.provider && @new_resource.default_release

shell_out!("apt-cache policy #{package}").stdout.each_line do |line|
shell_out!("apt-cache#{expand_options(aptcache_options)} policy #{package}").stdout.each_line do |line|
case line
when /^\s{2}Installed: (.+)$/
installed_version = $1
Expand Down
11 changes: 10 additions & 1 deletion chef/lib/chef/resource/apt_package.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,17 @@ def initialize(name, run_context=nil)
super
@resource_name = :apt_package
@provider = Chef::Provider::Package::Apt
@default_release = nil
end


def default_release(arg=nil)
set_or_return(
:default_release,
arg,
:kind_of => [ String ]
)
end

end
end
end
11 changes: 11 additions & 0 deletions chef/spec/unit/provider/package/apt_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,17 @@
@provider.should_receive(:shell_out!).with("apt-cache showpkg mp3-decoder").and_return(showpkg)
lambda { @provider.load_current_resource }.should raise_error(Chef::Exceptions::Package)
end

it "should run apt-cache policy with the default_release option, if there is one and provider is explicitly defined" do
@new_resource = Chef::Resource::AptPackage.new("irssi", @run_context)
@provider = Chef::Provider::Package::Apt.new(@new_resource, @run_context)

@new_resource.stub!(:default_release).and_return("lenny-backports")
@new_resource.stub!(:provider).and_return("Chef::Provider::Package::Apt")
@provider.should_receive(:shell_out!).with("apt-cache -o APT::Default-Release=lenny-backports policy irssi").and_return(@shell_out)
@provider.load_current_resource
end

end

describe "install_package" do
Expand Down
5 changes: 5 additions & 0 deletions chef/spec/unit/resource/apt_package_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,9 @@
it "should set the provider to Chef::Provider::Package::Apt" do
@resource.provider.should eql(Chef::Provider::Package::Apt)
end

it "should support default_release" do
@resource.default_release = "lenny-backports"
@resource.default_release.should eql("lenny-backports")
end
end

0 comments on commit 25fd12a

Please sign in to comment.