diff options
author | Thom May <thom.may@betfair.com> | 2010-02-26 18:37:04 +0000 |
---|---|---|
committer | Thom May <thom.may@betfair.com> | 2010-02-26 18:37:04 +0000 |
commit | f3196a615e4c12e809a9e572549efebdbb24c289 (patch) | |
tree | 7fe52772376797579216fbf6886781a43419aefa | |
parent | 92d7de9e9efbf5838af2f2aec6533248f37d1293 (diff) | |
download | chef-f3196a615e4c12e809a9e572549efebdbb24c289.tar.gz |
CHEF-987: allow yum to do localinstalls
-rw-r--r-- | chef/lib/chef/provider/package/yum.rb | 29 | ||||
-rw-r--r-- | chef/spec/unit/provider/package/yum_spec.rb | 24 |
2 files changed, 45 insertions, 8 deletions
diff --git a/chef/lib/chef/provider/package/yum.rb b/chef/lib/chef/provider/package/yum.rb index eb7ed422dd..26bf046593 100644 --- a/chef/lib/chef/provider/package/yum.rb +++ b/chef/lib/chef/provider/package/yum.rb @@ -115,6 +115,23 @@ class Chef @current_resource = Chef::Resource::Package.new(@new_resource.name) @current_resource.package_name(@new_resource.package_name) + if @new_resource.source + unless ::File.exists?(@new_resource.source) + raise Chef::Exceptions::Package, "Package #{@new_resource.name} not found: #{@new_resource.source}" + end + + Chef::Log.debug("Checking rpm status for #{@new_resource.package_name}") + status = popen4("rpm -qp --queryformat '%{NAME} %{VERSION}-%{RELEASE}\n' #{@new_resource.source}") do |pid, stdin, stdout, stderr| + stdout.each do |line| + case line + when /([\w\d_.-]+)\s([\w\d_.-]+)/ + @current_resource.package_name($1) + @new_resource.version($2) + end + end + end + end + Chef::Log.debug("Checking yum info for #{@new_resource.package_name}") @yum.refresh @@ -133,9 +150,15 @@ class Chef end def install_package(name, version) - run_command_with_systems_locale( - :command => "yum -d0 -e0 -y install #{name}-#{version}" - ) + if @new_resource.source + run_command_with_systems_locale( + :command => "yum -d0 -e0 -y localinstall #{@new_resource.source}" + ) + else + run_command_with_systems_locale( + :command => "yum -d0 -e0 -y install #{name}-#{version}" + ) + end @yum.flush end diff --git a/chef/spec/unit/provider/package/yum_spec.rb b/chef/spec/unit/provider/package/yum_spec.rb index 37e52639be..4a8370e4a0 100644 --- a/chef/spec/unit/provider/package/yum_spec.rb +++ b/chef/spec/unit/provider/package/yum_spec.rb @@ -26,7 +26,8 @@ describe Chef::Provider::Package::Yum, "load_current_resource" do :name => "cups", :version => nil, :package_name => "cups", - :updated => nil + :updated => nil, + :source => nil ) @current_resource = mock("Chef::Resource::Package", :null_object => true, @@ -90,7 +91,8 @@ describe Chef::Provider::Package::Yum, "install_package" do :name => "emacs", :version => nil, :package_name => "emacs", - :updated => nil + :updated => nil, + :source => nil ) @yum_cache = mock( 'Chef::Provider::Yum::YumCache', @@ -109,6 +111,15 @@ describe Chef::Provider::Package::Yum, "install_package" do }) @provider.install_package("emacs", "1.0") end + + it "should run yum localinstall if given a path to an rpm" do + @new_resource.stub!(:source).and_return("/tmp/emacs-21.4-20.el5.i386.rpm") + @provider.should_receive(:run_command_with_systems_locale).with({ + :command => "yum -d0 -e0 -y localinstall /tmp/emacs-21.4-20.el5.i386.rpm" + }) + @provider.install_package("emacs", "21.4-20.el5") + end + end describe Chef::Provider::Package::Yum, "upgrade_package" do @@ -120,7 +131,8 @@ describe Chef::Provider::Package::Yum, "upgrade_package" do :name => "emacs", :version => nil, :package_name => "emacs", - :updated => nil + :updated => nil, + :source => nil ) @yum_cache = mock( 'Chef::Provider::Yum::YumCache', @@ -166,7 +178,8 @@ describe Chef::Provider::Package::Yum, "remove_package" do :name => "emacs", :version => nil, :package_name => "emacs", - :updated => nil + :updated => nil, + :source => nil ) @yum_cache = mock( 'Chef::Provider::Yum::YumCache', @@ -195,7 +208,8 @@ describe Chef::Provider::Package::Yum, "purge_package" do :name => "emacs", :version => "10", :package_name => "emacs", - :updated => nil + :updated => nil, + :source => nil ) @yum_cache = mock( 'Chef::Provider::Yum::YumCache', |