Skip to content

Commit

Permalink
Fix a reassigned variable
Browse files Browse the repository at this point in the history
This occurred when $ensure was set to 'absent'. Then the variable used
for the title of the exec resource was assigned twice, resulting in an
error.
  • Loading branch information
SaschaDoering committed Nov 26, 2019
1 parent 461a8fa commit 19848a5
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
11 changes: 7 additions & 4 deletions manifests/pip.pp
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,6 @@
$pip_install = "${pip_env} --log ${log}/pip.log install"
$pip_common_args = "${pypi_index} ${proxy_flag} ${install_args} ${install_editable} ${source}"

$pip_exec_name = "pip_install_${name}"

# Explicit version out of VCS when PIP supported URL is provided
if $source =~ /^'(git\+|hg\+|bzr\+|svn\+)(http|https|ssh|svn|sftp|ftp|lp|git)(:\/\/).+'$/ {
if $_ensure != present and $_ensure != latest {
Expand Down Expand Up @@ -221,14 +219,19 @@

default: {
# Anti-action, uninstall.
$pip_exec_name = "pip_uninstall_${name}"
$uninstall = true
$command = "echo y | ${pip_env} uninstall ${uninstall_args} ${proxy_flag} ${name}"
$unless_command = "! ${pip_env} list | grep -i -e '${grep_regex}'"
}
}
}

exec { $pip_exec_name:
$pip_installer = (defined('$uninstall')) ? {
true => "pip_uninstall_${name}",
false => "pip_install_${name}",
}

exec { $pip_installer:
command => $command,
unless => $unless_command,
user => $owner,
Expand Down
10 changes: 10 additions & 0 deletions spec/defines/pip_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,16 @@
it { is_expected.to contain_exec('pip_install_rpyc').with_unless(%r{wordpress-json}) }
end
end

describe 'uninstall' do
context 'adds correct title' do
let(:params) { { ensure: 'absent' } }

it { is_expected.not_to contain_exec('pip_install_rpyc') }

it { is_expected.to contain_exec('pip_uninstall_rpyc').with_command(%r{uninstall.*rpyc$}) }
end
end
end
end

Expand Down

0 comments on commit 19848a5

Please sign in to comment.