diff options
author | Serdar Sutay <serdar@opscode.com> | 2014-07-02 09:59:40 -0700 |
---|---|---|
committer | Serdar Sutay <serdar@opscode.com> | 2014-07-02 09:59:40 -0700 |
commit | ded6da6048c6900d7816f3074d24f3a02f8155e9 (patch) | |
tree | d59fe78d39cb90470f113332830e05c6eb8ffa1a | |
parent | a06bc951fc9ac04200988f596c04cdf5c686e04e (diff) | |
parent | a962f9bcb68b98c0cf19ab29155af04a99c3ff12 (diff) | |
download | chef-ded6da6048c6900d7816f3074d24f3a02f8155e9.tar.gz |
Merge pull request #1589 from opscode/lcg/lolinheritance
remove inheritance from apt_package
-rw-r--r-- | lib/chef/provider/package/dpkg.rb | 51 | ||||
-rw-r--r-- | spec/unit/provider/package/dpkg_spec.rb | 72 |
2 files changed, 59 insertions, 64 deletions
diff --git a/lib/chef/provider/package/dpkg.rb b/lib/chef/provider/package/dpkg.rb index fb366fb6eb..a1f1c797b1 100644 --- a/lib/chef/provider/package/dpkg.rb +++ b/lib/chef/provider/package/dpkg.rb @@ -24,13 +24,14 @@ require 'chef/mixin/get_source_from_package' class Chef class Provider class Package - class Dpkg < Chef::Provider::Package::Apt + class Dpkg < Chef::Provider::Package # http://www.debian.org/doc/debian-policy/ch-controlfields.html#s-f-Version DPKG_INFO = /([a-z\d\-\+\.]+)\t([\w\d.~:-]+)/ DPKG_INSTALLED = /^Status: install ok installed/ DPKG_VERSION = /^Version: (.+)$/ include Chef::Mixin::GetSourceFromPackage + def define_resource_requirements super requirements.assert(:install) do |a| @@ -98,31 +99,49 @@ class Chef end def install_package(name, version) - run_command_with_systems_locale( - :command => "dpkg -i#{expand_options(@new_resource.options)} #{@new_resource.source}", - :environment => { - "DEBIAN_FRONTEND" => "noninteractive" - } + Chef::Log.info("#{@new_resource} installing #{@new_resource.source}") + run_noninteractive( + "dpkg -i#{expand_options(@new_resource.options)} #{@new_resource.source}" ) end def remove_package(name, version) - run_command_with_systems_locale( - :command => "dpkg -r#{expand_options(@new_resource.options)} #{@new_resource.package_name}", - :environment => { - "DEBIAN_FRONTEND" => "noninteractive" - } + Chef::Log.info("#{@new_resource} removing #{@new_resource.package_name}") + run_noninteractive( + "dpkg -r#{expand_options(@new_resource.options)} #{@new_resource.package_name}" ) end def purge_package(name, version) - run_command_with_systems_locale( - :command => "dpkg -P#{expand_options(@new_resource.options)} #{@new_resource.package_name}", - :environment => { - "DEBIAN_FRONTEND" => "noninteractive" - } + Chef::Log.info("#{@new_resource} purging #{@new_resource.package_name}") + run_noninteractive( + "dpkg -P#{expand_options(@new_resource.options)} #{@new_resource.package_name}" ) end + + def upgrade_package(name, version) + install_package(name, version) + end + + def preseed_package(preseed_file) + Chef::Log.info("#{@new_resource} pre-seeding package installation instructions") + run_noninteractive("debconf-set-selections #{preseed_file}") + end + + def reconfig_package(name, version) + Chef::Log.info("#{@new_resource} reconfiguring") + run_noninteractive("dpkg-reconfigure #{name}") + end + + # Runs command via shell_out with magic environment to disable + # interactive prompts. Command is run with default localization rather + # than forcing locale to "C", so command output may not be stable. + # + # FIXME: This should be "LC_ALL" => "en_US.UTF-8" in order to stabilize the output and get UTF-8 + def run_noninteractive(command) + shell_out!(command, :env => { "DEBIAN_FRONTEND" => "noninteractive", "LC_ALL" => nil }) + end + end end end diff --git a/spec/unit/provider/package/dpkg_spec.rb b/spec/unit/provider/package/dpkg_spec.rb index 22edeb7b9b..439a42daa3 100644 --- a/spec/unit/provider/package/dpkg_spec.rb +++ b/spec/unit/provider/package/dpkg_spec.rb @@ -122,46 +122,34 @@ DPKG_S describe Chef::Provider::Package::Dpkg, "install and upgrade" do it "should run dpkg -i with the package source" do - @provider.should_receive(:run_command_with_systems_locale).with({ - :command => "dpkg -i /tmp/wget_1.11.4-1ubuntu1_amd64.deb", - :environment => { - "DEBIAN_FRONTEND" => "noninteractive" - } - }) + @provider.should_receive(:run_noninteractive).with( + "dpkg -i /tmp/wget_1.11.4-1ubuntu1_amd64.deb" + ) @provider.install_package("wget", "1.11.4-1ubuntu1") end it "should run dpkg -i if the package is a path and the source is nil" do @new_resource = Chef::Resource::Package.new("/tmp/wget_1.11.4-1ubuntu1_amd64.deb") @provider = Chef::Provider::Package::Dpkg.new(@new_resource, @run_context) - @provider.should_receive(:run_command_with_systems_locale).with({ - :command => "dpkg -i /tmp/wget_1.11.4-1ubuntu1_amd64.deb", - :environment => { - "DEBIAN_FRONTEND" => "noninteractive" - } - }) + @provider.should_receive(:run_noninteractive).with( + "dpkg -i /tmp/wget_1.11.4-1ubuntu1_amd64.deb" + ) @provider.install_package("/tmp/wget_1.11.4-1ubuntu1_amd64.deb", "1.11.4-1ubuntu1") end it "should run dpkg -i if the package is a path and the source is nil for an upgrade" do @new_resource = Chef::Resource::Package.new("/tmp/wget_1.11.4-1ubuntu1_amd64.deb") @provider = Chef::Provider::Package::Dpkg.new(@new_resource, @run_context) - @provider.should_receive(:run_command_with_systems_locale).with({ - :command => "dpkg -i /tmp/wget_1.11.4-1ubuntu1_amd64.deb", - :environment => { - "DEBIAN_FRONTEND" => "noninteractive" - } - }) + @provider.should_receive(:run_noninteractive).with( + "dpkg -i /tmp/wget_1.11.4-1ubuntu1_amd64.deb" + ) @provider.upgrade_package("/tmp/wget_1.11.4-1ubuntu1_amd64.deb", "1.11.4-1ubuntu1") end it "should run dpkg -i with the package source and options if specified" do - @provider.should_receive(:run_command_with_systems_locale).with({ - :command => "dpkg -i --force-yes /tmp/wget_1.11.4-1ubuntu1_amd64.deb", - :environment => { - "DEBIAN_FRONTEND" => "noninteractive" - } - }) + @provider.should_receive(:run_noninteractive).with( + "dpkg -i --force-yes /tmp/wget_1.11.4-1ubuntu1_amd64.deb" + ) @new_resource.stub(:options).and_return("--force-yes") @provider.install_package("wget", "1.11.4-1ubuntu1") @@ -174,44 +162,32 @@ DPKG_S describe Chef::Provider::Package::Dpkg, "remove and purge" do it "should run dpkg -r to remove the package" do - @provider.should_receive(:run_command_with_systems_locale).with({ - :command => "dpkg -r wget", - :environment => { - "DEBIAN_FRONTEND" => "noninteractive" - } - }) + @provider.should_receive(:run_noninteractive).with( + "dpkg -r wget" + ) @provider.remove_package("wget", "1.11.4-1ubuntu1") end it "should run dpkg -r to remove the package with options if specified" do - @provider.should_receive(:run_command_with_systems_locale).with({ - :command => "dpkg -r --force-yes wget", - :environment => { - "DEBIAN_FRONTEND" => "noninteractive" - } - }) + @provider.should_receive(:run_noninteractive).with( + "dpkg -r --force-yes wget" + ) @new_resource.stub(:options).and_return("--force-yes") @provider.remove_package("wget", "1.11.4-1ubuntu1") end it "should run dpkg -P to purge the package" do - @provider.should_receive(:run_command_with_systems_locale).with({ - :command => "dpkg -P wget", - :environment => { - "DEBIAN_FRONTEND" => "noninteractive" - } - }) + @provider.should_receive(:run_noninteractive).with( + "dpkg -P wget" + ) @provider.purge_package("wget", "1.11.4-1ubuntu1") end it "should run dpkg -P to purge the package with options if specified" do - @provider.should_receive(:run_command_with_systems_locale).with({ - :command => "dpkg -P --force-yes wget", - :environment => { - "DEBIAN_FRONTEND" => "noninteractive" - } - }) + @provider.should_receive(:run_noninteractive).with( + "dpkg -P --force-yes wget" + ) @new_resource.stub(:options).and_return("--force-yes") @provider.purge_package("wget", "1.11.4-1ubuntu1") |