New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add default release option for apt package provider. Fixes #CHEF-1547 #165

Closed
wants to merge 1 commit into
base: master
from
Jump to file or symbol
Failed to load files and symbols.
+29 −2
Diff settings

Always

Just for now

@@ -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
@@ -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
@@ -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
@@ -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
ProTip! Use n and p to navigate between commits in a pull request.