Skip to content

Commit

Permalink
(PUP-7095) Enable portage install and uninstall options
Browse files Browse the repository at this point in the history
Allow the portage package provider to accept install and uninstall
options.  This is useful if you do not want to use the default global
EMERGE_DEFAULT_OPTS paramaters setable in make.conf.
  • Loading branch information
prometheanfire committed Jan 13, 2017
1 parent f9bffba commit d5dd81c
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 7 deletions.
28 changes: 23 additions & 5 deletions lib/puppet/provider/package/portage.rb
Expand Up @@ -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",
Expand Down Expand Up @@ -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.
Expand All @@ -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
Expand Down Expand Up @@ -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
26 changes: 24 additions & 2 deletions spec/unit/provider/package/portage_spec.rb
Expand Up @@ -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"})

Expand Down

0 comments on commit d5dd81c

Please sign in to comment.