summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLamont Granquist <lamont@opscode.com>2011-06-09 11:04:49 -0700
committerBryan McLellan <btm@opscode.com>2011-07-19 08:56:33 -0700
commitb146d4becc84b4a189cde4652031b27cb8383c90 (patch)
tree7b5269dd8d00c2d8be3b298fdf3d0a45be5b81fe
parente8554e82a6f48b5b23848eb47569546c5865e2f4 (diff)
downloadchef-b146d4becc84b4a189cde4652031b27cb8383c90.tar.gz
CHEF-2041: adding support for gem_package "/path/to/file.gem" along with dpkg/rpm/etc
-rw-r--r--chef/lib/chef/mixin/get_source_from_package.rb42
-rw-r--r--chef/lib/chef/provider/package/dpkg.rb5
-rw-r--r--chef/lib/chef/provider/package/freebsd.rb3
-rw-r--r--chef/lib/chef/provider/package/rpm.rb5
-rw-r--r--chef/lib/chef/provider/package/rubygems.rb3
-rw-r--r--chef/lib/chef/provider/package/solaris.rb3
-rw-r--r--chef/lib/chef/provider/package/yum.rb4
-rw-r--r--chef/spec/unit/provider/package/dpkg_spec.rb24
-rw-r--r--chef/spec/unit/provider/package/rpm_spec.rb25
-rw-r--r--chef/spec/unit/provider/package/rubygems_spec.rb17
-rw-r--r--chef/spec/unit/provider/package/solaris_spec.rb10
-rw-r--r--chef/spec/unit/provider/package/yum_spec.rb12
12 files changed, 151 insertions, 2 deletions
diff --git a/chef/lib/chef/mixin/get_source_from_package.rb b/chef/lib/chef/mixin/get_source_from_package.rb
new file mode 100644
index 0000000000..6d5cb56a27
--- /dev/null
+++ b/chef/lib/chef/mixin/get_source_from_package.rb
@@ -0,0 +1,42 @@
+# Author:: Lamont Granquist (<lamont@opscode.com>)
+# Copyright:: Copyright (c) 2008 Opscode, Inc.
+# License:: Apache License, Version 2.0
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+
+#
+# mixin to make this syntax work without specifying a source:
+#
+# gem_pacakge "/tmp/foo-x.y.z.gem"
+# rpm_package "/tmp/foo-x.y-z.rpm"
+# dpkg_package "/tmp/foo-x.y.z.deb"
+#
+
+class Chef
+ module Mixin
+ module GetSourceFromPackage
+ def initialize(new_resource, run_context)
+ super
+ # if we're passed something that looks like a filesystem path, with no source, use it
+ # - require at least one '/' in the path to avoid gem_package "foo" breaking if a file named 'foo' exists in the cwd
+ if new_resource.source.nil? && new_resource.package_name.match(/#{::File::SEPARATOR}/) && ::File.exists?(new_resource.package_name)
+ Chef::Log.debug("No package source specified, but #{new_resource.package_name} exists on the filesystem, copying to package source")
+ new_resource.source(@new_resource.package_name)
+ end
+ end
+ end
+ end
+end
+
diff --git a/chef/lib/chef/provider/package/dpkg.rb b/chef/lib/chef/provider/package/dpkg.rb
index 8ef0ead9f8..5893c58596 100644
--- a/chef/lib/chef/provider/package/dpkg.rb
+++ b/chef/lib/chef/provider/package/dpkg.rb
@@ -19,6 +19,7 @@
require 'chef/provider/package'
require 'chef/mixin/command'
require 'chef/resource/package'
+require 'chef/mixin/get_source_from_package'
class Chef
class Provider
@@ -27,7 +28,9 @@ class Chef
DPKG_INFO = /([a-z\d\-\+]+)\t([\w\d.~-]+)/
DPKG_INSTALLED = /^Status: install ok installed/
DPKG_VERSION = /^Version: (.+)$/
-
+
+ include Chef::Mixin::GetSourceFromPackage
+
def load_current_resource
@current_resource = Chef::Resource::Package.new(@new_resource.name)
@current_resource.package_name(@new_resource.package_name)
diff --git a/chef/lib/chef/provider/package/freebsd.rb b/chef/lib/chef/provider/package/freebsd.rb
index 139bbe02d7..2de2596844 100644
--- a/chef/lib/chef/provider/package/freebsd.rb
+++ b/chef/lib/chef/provider/package/freebsd.rb
@@ -20,6 +20,7 @@
require 'chef/provider/package'
require 'chef/mixin/shell_out'
require 'chef/resource/package'
+require 'chef/mixin/get_source_from_package'
class Chef
class Provider
@@ -27,6 +28,8 @@ class Chef
class Freebsd < Chef::Provider::Package
include Chef::Mixin::ShellOut
+ include Chef::Mixin::GetSourceFromPackage
+
def initialize(*args)
super
@current_resource = Chef::Resource::Package.new(@new_resource.name)
diff --git a/chef/lib/chef/provider/package/rpm.rb b/chef/lib/chef/provider/package/rpm.rb
index 0de3fd138d..5654db309b 100644
--- a/chef/lib/chef/provider/package/rpm.rb
+++ b/chef/lib/chef/provider/package/rpm.rb
@@ -18,12 +18,15 @@
require 'chef/provider/package'
require 'chef/mixin/command'
require 'chef/resource/package'
+require 'chef/mixin/get_source_from_package'
class Chef
class Provider
class Package
class Rpm < Chef::Provider::Package
-
+
+ include Chef::Mixin::GetSourceFromPackage
+
def load_current_resource
@current_resource = Chef::Resource::Package.new(@new_resource.name)
@current_resource.package_name(@new_resource.package_name)
diff --git a/chef/lib/chef/provider/package/rubygems.rb b/chef/lib/chef/provider/package/rubygems.rb
index 1a9c700aba..091dea4ab0 100644
--- a/chef/lib/chef/provider/package/rubygems.rb
+++ b/chef/lib/chef/provider/package/rubygems.rb
@@ -20,6 +20,7 @@
require 'chef/provider/package'
require 'chef/mixin/command'
require 'chef/resource/package'
+require 'chef/mixin/get_source_from_package'
# Class methods on Gem are defined in rubygems
require 'rubygems'
@@ -299,6 +300,8 @@ class Chef
Chef::Log.logger
end
+ include Chef::Mixin::GetSourceFromPackage
+
def initialize(new_resource, run_context=nil)
super
if new_resource.gem_binary
diff --git a/chef/lib/chef/provider/package/solaris.rb b/chef/lib/chef/provider/package/solaris.rb
index 20b813f844..f87c30df1e 100644
--- a/chef/lib/chef/provider/package/solaris.rb
+++ b/chef/lib/chef/provider/package/solaris.rb
@@ -18,12 +18,15 @@
require 'chef/provider/package'
require 'chef/mixin/command'
require 'chef/resource/package'
+require 'chef/mixin/get_source_from_package'
class Chef
class Provider
class Package
class Solaris < Chef::Provider::Package
+ include Chef::Mixin::GetSourceFromPackage
+
# def initialize(*args)
# super
# @current_resource = Chef::Resource::Package.new(@new_resource.name)
diff --git a/chef/lib/chef/provider/package/yum.rb b/chef/lib/chef/provider/package/yum.rb
index 59247b3066..cff8a12b88 100644
--- a/chef/lib/chef/provider/package/yum.rb
+++ b/chef/lib/chef/provider/package/yum.rb
@@ -20,6 +20,8 @@ require 'chef/provider/package'
require 'chef/mixin/command'
require 'chef/resource/package'
require 'singleton'
+require 'chef/mixin/get_source_from_package'
+
class Chef
class Provider
@@ -866,6 +868,8 @@ class Chef
end # YumCache
+ include Chef::Mixin::GetSourceFromPackage
+
def initialize(new_resource, run_context)
super
diff --git a/chef/spec/unit/provider/package/dpkg_spec.rb b/chef/spec/unit/provider/package/dpkg_spec.rb
index 7c1f84f758..81f8455eb9 100644
--- a/chef/spec/unit/provider/package/dpkg_spec.rb
+++ b/chef/spec/unit/provider/package/dpkg_spec.rb
@@ -122,6 +122,30 @@ DPKG_S
@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.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.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",
diff --git a/chef/spec/unit/provider/package/rpm_spec.rb b/chef/spec/unit/provider/package/rpm_spec.rb
index 5d96a7b7c0..cfa60b2402 100644
--- a/chef/spec/unit/provider/package/rpm_spec.rb
+++ b/chef/spec/unit/provider/package/rpm_spec.rb
@@ -103,6 +103,31 @@ describe Chef::Provider::Package::Rpm do
@provider.upgrade_package("emacs", "21.4-20.el5")
end
+ it "should install from a path when the package is a path and the source is nil" do
+ @new_resource = Chef::Resource::Package.new("/tmp/emacs-21.4-20.el5.i386.rpm")
+ @provider = Chef::Provider::Package::Rpm.new(@new_resource, @run_context)
+ @new_resource.source.should == "/tmp/emacs-21.4-20.el5.i386.rpm"
+ @current_resource = Chef::Resource::Package.new("emacs")
+ @provider.current_resource = @current_resource
+ @provider.should_receive(:run_command_with_systems_locale).with({
+ :command => "rpm -i /tmp/emacs-21.4-20.el5.i386.rpm"
+ })
+ @provider.install_package("/tmp/emacs-21.4-20.el5.i386.rpm", "21.4-20.el5")
+ end
+
+ it "should uprgrade from a path when the package is a path and the source is nil" do
+ @new_resource = Chef::Resource::Package.new("/tmp/emacs-21.4-20.el5.i386.rpm")
+ @provider = Chef::Provider::Package::Rpm.new(@new_resource, @run_context)
+ @new_resource.source.should == "/tmp/emacs-21.4-20.el5.i386.rpm"
+ @current_resource = Chef::Resource::Package.new("emacs")
+ @current_resource.version("21.4-19.el5")
+ @provider.current_resource = @current_resource
+ @provider.should_receive(:run_command_with_systems_locale).with({
+ :command => "rpm -U /tmp/emacs-21.4-20.el5.i386.rpm"
+ })
+ @provider.upgrade_package("/tmp/emacs-21.4-20.el5.i386.rpm", "21.4-20.el5")
+ end
+
it "installs with custom options specified in the resource" do
@provider.candidate_version = '11'
@new_resource.options("--dbpath /var/lib/rpm")
diff --git a/chef/spec/unit/provider/package/rubygems_spec.rb b/chef/spec/unit/provider/package/rubygems_spec.rb
index a5c7e88c82..77e31b010a 100644
--- a/chef/spec/unit/provider/package/rubygems_spec.rb
+++ b/chef/spec/unit/provider/package/rubygems_spec.rb
@@ -405,6 +405,23 @@ describe Chef::Provider::Package::Rubygems do
@provider.action_install.should be_true
end
+ it "installs the gem from file via the gems api when the package is a path and the source is nil" do
+ @new_resource = Chef::Resource::GemPackage.new(CHEF_SPEC_DATA + '/gems/chef-integration-test-0.1.0.gem')
+ @provider = Chef::Provider::Package::Rubygems.new(@new_resource, @run_context)
+ @provider.current_resource = @current_resource
+ @new_resource.source.should == CHEF_SPEC_DATA + '/gems/chef-integration-test-0.1.0.gem'
+ @provider.gem_env.should_receive(:install).with(CHEF_SPEC_DATA + '/gems/chef-integration-test-0.1.0.gem')
+ @provider.action_install.should be_true
+ end
+
+ # this catches 'gem_package "foo"' when "./foo" is a file in the cwd, and instead of installing './foo' it fetches the remote gem
+ it "installs the gem via the gems api, when the package has no file separator characters in it, but a matching file exists in cwd" do
+ ::File.stub!(:exists?).and_return(true)
+ @new_resource.package_name('rspec-core')
+ @provider.gem_env.should_receive(:install).with(@gem_dep, :sources => nil)
+ @provider.action_install.should be_true
+ end
+
it "installs the gem by shelling out when options are provided as a String" do
@new_resource.options('-i /alt/install/location')
expected ="gem install rspec-core -q --no-rdoc --no-ri -v \"#{@spec_version}\" -i /alt/install/location"
diff --git a/chef/spec/unit/provider/package/solaris_spec.rb b/chef/spec/unit/provider/package/solaris_spec.rb
index c3795cdf0f..bbb2751d94 100644
--- a/chef/spec/unit/provider/package/solaris_spec.rb
+++ b/chef/spec/unit/provider/package/solaris_spec.rb
@@ -139,6 +139,16 @@ PKGINFO
@provider.install_package("SUNWbash", "11.10.0,REV=2005.01.08.05.16")
end
+ it "should run pkgadd -n -d when the package is a path to install" do
+ @new_resource = Chef::Resource::Package.new("/tmp/bash.pkg")
+ @provider = Chef::Provider::Package::Solaris.new(@new_resource, @run_context)
+ @new_resource.source.should == "/tmp/bash.pkg"
+ @provider.should_receive(:run_command_with_systems_locale).with({
+ :command => "pkgadd -n -d /tmp/bash.pkg all"
+ })
+ @provider.install_package("/tmp/bash.pkg", "11.10.0,REV=2005.01.08.05.16")
+ end
+
it "should run pkgadd -n -a /tmp/myadmin -d with the package options -a /tmp/myadmin" do
@new_resource.stub!(:options).and_return("-a /tmp/myadmin")
@provider.should_receive(:run_command_with_systems_locale).with({
diff --git a/chef/spec/unit/provider/package/yum_spec.rb b/chef/spec/unit/provider/package/yum_spec.rb
index 4f43a7f5cb..595339d67d 100644
--- a/chef/spec/unit/provider/package/yum_spec.rb
+++ b/chef/spec/unit/provider/package/yum_spec.rb
@@ -321,6 +321,18 @@ describe Chef::Provider::Package::Yum do
@provider.install_package("emacs", "21.4-20.el5")
end
+ it "should run yum localinstall if given a path to an rpm as the package" do
+ @new_resource = Chef::Resource::Package.new("/tmp/emacs-21.4-20.el5.i386.rpm")
+ ::File.stub!(:exists?).and_return(true)
+ @provider = Chef::Provider::Package::Yum.new(@new_resource, @run_context)
+ @provider.load_current_resource
+ @new_resource.source.should == "/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("/tmp/emacs-21.4-20.el5.i386.rpm", "21.4-20.el5")
+ end
+
it "should run yum install with the package name, version and arch" do
@provider.load_current_resource
@new_resource.stub!(:arch).and_return("i386")