diff --git a/lib/puppet/provider/package/portage.rb b/lib/puppet/provider/package/portage.rb index 374667c3523..bfa0fd2bcc5 100644 --- a/lib/puppet/provider/package/portage.rb +++ b/lib/puppet/provider/package/portage.rb @@ -2,9 +2,13 @@ require 'fileutils' Puppet::Type.type(:package).provide :portage, :parent => Puppet::Provider::Package do - desc "Provides packaging support for Gentoo's portage system." + desc "Provides packaging support for Gentoo's portage system. - has_features :versionable, :reinstallable + This provider supports the `install_options` and `uninstall_options` attributes, which allows command-line + flags to be passed to apt-get. These options should be specified as a string (e.g. '--flag'), a hash + (e.g. {'--flag' => 'value'}), or an array where each element is either a string or a hash." + + has_features :versionable, :reinstallable, :install_options, :uninstall_options { :emerge => "/usr/bin/emerge", @@ -57,12 +61,15 @@ def self.instances def install should = @resource.should(:ensure) + cmd = %w{} name = package_name - unless should == :present or should == :latest + if [:latest, :present].include?(should) # We must install a specific version name = package_atom_with_version(should) end - emerge name + cmd += install_options if @resource[:install_options] + cmd << name + emerge *cmd end # The common package name format. @@ -89,7 +96,10 @@ def package_atom_with_version(version) end def uninstall - emerge "--unmerge", package_name + cmd = %w{--unmerge} + cmd += uninstall_options if @resource[:uninstall_options] + cmd << package_name + emerge *cmd end def reinstall @@ -190,4 +200,12 @@ def self.eix_slot_versions_format def self.eix_search_arguments ["--nocolor", "--pure-packages", "--format",self.eix_search_format] end + + def install_options + join_options(@resource[:install_options]) + end + + def uninstall_options + join_options(@resource[:uninstall_options]) + end end diff --git a/spec/unit/provider/package/portage_spec.rb b/spec/unit/provider/package/portage_spec.rb index 00f2ebe6fc3..ce91397ecfa 100644 --- a/spec/unit/provider/package/portage_spec.rb +++ b/spec/unit/provider/package/portage_spec.rb @@ -41,12 +41,34 @@ expect(provider).to be_reinstallable end - it "uses :emerge to install packages" do - @provider.expects(:emerge) + it 'should support string install options' do + @resource.stubs(:[]).with(:install_options).returns(['--foo', '--bar']) + @provider.expects(:emerge).with('--foo', '--bar', @resource[:name]) @provider.install end + it 'should support hash install options' do + @resource.stubs(:[]).with(:install_options).returns(['--foo', { '--bar' => 'baz', '--baz' => 'foo' }]) + @provider.expects(:emerge).with('--foo', '--bar=baz', '--baz=foo', @resource[:name]) + + @provider.install + end + + it 'should support string uninstall options' do + @resource.stubs(:[]).with(:uninstall_options).returns(['--foo', '--bar']) + @provider.expects(:emerge).with('--unmerge', '--foo', '--bar', @resource[:name]) + + @provider.uninstall + end + + it 'should support hash uninstall options' do + @resource.stubs(:[]).with(:uninstall_options).returns(['--foo', { '--bar' => 'baz', '--baz' => 'foo' }]) + @provider.expects(:emerge).with('--unmerge', '--foo', '--bar=baz', '--baz=foo', @resource[:name]) + + @provider.uninstall + end + it "uses query to find the latest package" do @provider.expects(:query).returns({:versions_available => "myversion"})