diff options
author | Bryan McLellan <btm@opscode.com> | 2011-05-20 16:03:40 -0700 |
---|---|---|
committer | Bryan McLellan <btm@opscode.com> | 2011-05-20 16:03:40 -0700 |
commit | 65e8717bc86740b5f43dead2a4dea8f7e664bb2a (patch) | |
tree | a80f5aebc21b47e2918fcc56d6962e1b2f173c45 | |
parent | 5347eadc4a8f16bc0fae0efc1c914c5648e83faf (diff) | |
parent | beaa38c7ce78d89e30fe1ac9d0695b096e070f7c (diff) | |
download | chef-65e8717bc86740b5f43dead2a4dea8f7e664bb2a.tar.gz |
Merge branch 'CHEF-2129'
-rw-r--r-- | chef/lib/chef/provider/package/zypper.rb | 23 | ||||
-rw-r--r-- | chef/spec/unit/provider/package/zypper_spec.rb | 36 |
2 files changed, 54 insertions, 5 deletions
diff --git a/chef/lib/chef/provider/package/zypper.rb b/chef/lib/chef/provider/package/zypper.rb index e309abf1e3..43727466e2 100644 --- a/chef/lib/chef/provider/package/zypper.rb +++ b/chef/lib/chef/provider/package/zypper.rb @@ -78,9 +78,18 @@ class Chef @current_resource end + + #Gets the zypper Version from command output (Returns Floating Point number) + def zypper_version() + `zypper -V 2>&1`.scan(/\d+/).join(".").to_f + end def install_package(name, version) - if version + if zypper_version < 1.0 + run_command( + :command => "zypper install -y #{name}" + ) + elsif version run_command( :command => "zypper -n --no-gpg-checks install -l #{name}=#{version}" ) @@ -92,7 +101,11 @@ class Chef end def upgrade_package(name, version) - if version + if zypper_version < 1.0 + run_command( + :command => "zypper install -y #{name}" + ) + elsif version run_command( :command => "zypper -n --no-gpg-checks install -l #{name}=#{version}" ) @@ -104,7 +117,11 @@ class Chef end def remove_package(name, version) - if version + if zypper_version < 1.0 + run_command( + :command => "zypper remove -y #{name}" + ) + elsif version run_command( :command => "zypper -n --no-gpg-checks remove #{name}=#{version}" ) diff --git a/chef/spec/unit/provider/package/zypper_spec.rb b/chef/spec/unit/provider/package/zypper_spec.rb index 5b6e9f93b5..03207343f9 100644 --- a/chef/spec/unit/provider/package/zypper_spec.rb +++ b/chef/spec/unit/provider/package/zypper_spec.rb @@ -34,6 +34,7 @@ describe Chef::Provider::Package::Zypper do @stderr = StringIO.new @stdout = StringIO.new @pid = mock("PID") + @provider.stub!(:`).and_return("2.0") end describe "when loading the current package state" do @@ -89,14 +90,12 @@ describe Chef::Provider::Package::Zypper do end describe "install_package" do - it "should run zypper install with the package name and version" do @provider.should_receive(:run_command).with({ :command => "zypper -n --no-gpg-checks install -l emacs=1.0", }) @provider.install_package("emacs", "1.0") end - end describe "upgrade_package" do @@ -123,4 +122,37 @@ describe Chef::Provider::Package::Zypper do @provider.purge_package("emacs", "1.0") end end + + describe "on an older zypper" do + before(:each) do + @provider.stub!(:`).and_return("0.11.6") + end + + describe "install_package" do + it "should run zypper install with the package name and version" do + @provider.should_receive(:run_command).with({ + :command => "zypper install -y emacs" + }) + @provider.install_package("emacs", "1.0") + end + end + + describe "upgrade_package" do + it "should run zypper update with the package name and version" do + @provider.should_receive(:run_command).with({ + :command => "zypper install -y emacs" + }) + @provider.upgrade_package("emacs", "1.0") + end + end + + describe "remove_package" do + it "should run zypper remove with the package name" do + @provider.should_receive(:run_command).with({ + :command => "zypper remove -y emacs" + }) + @provider.remove_package("emacs", "1.0") + end + end + end end |