-
Notifications
You must be signed in to change notification settings - Fork 136
Commit
Expose a custom fact about Chocolatey's version. Do not attempt to do configuration in versions of choco less than 0.9.9. This does mean a second convergence will be required to apply the configuration settings.
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
Facter.add('chocolateyversion') do | ||
setcode do | ||
value = nil | ||
|
||
choco_path = "#{Facter.value(:choco_install_path)}\\bin\\choco.exe" | ||
if Puppet::Util::Platform.windows? && File.exist?(choco_path) | ||
begin | ||
old_choco_message = 'Please run chocolatey /? or chocolatey help - chocolatey v' | ||
#Facter::Core::Execution.exec is 2.0.1 forward | ||
value = Facter::Util::Resolution.exec("#{choco_path} -v").gsub(old_choco_message,'').strip | ||
rescue StandardError => e | ||
value = '0' | ||
end | ||
end | ||
|
||
value || '0' | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,20 +2,24 @@ | |
class chocolatey::config { | ||
assert_private() | ||
|
||
#todo: check choco version from custom choco_version fact | ||
#if versioncmp("#{::choco_version}", '0.9.9.0') >= 0 { | ||
# | ||
$_choco_exe_path = "${chocolatey::choco_install_location}\\bin\\choco.exe" | ||
# this will require a second converge when choco is not | ||
# installed the first time through. This is on purpose | ||
# as we don't want to try to set these values for a | ||
# version less than 0.9.9 and we don't know what the | ||
# user may link to - it could be an older version of | ||
# Chocolatey | ||
if versioncmp($::chocolateyversion, '0.9.9.0') >= 0 { | ||
$_choco_exe_path = "${chocolatey::choco_install_location}\\bin\\choco.exe" | ||
|
||
$_enable_autouninstaller = $chocolatey::enable_autouninstaller ? { | ||
false => 'disable', | ||
default => 'enable' | ||
} | ||
$_enable_autouninstaller = $chocolatey::enable_autouninstaller ? { | ||
false => 'disable', | ||
default => 'enable' | ||
} | ||
|
||
exec { "chocolatey_autouninstaller_${_enable_autouninstaller}": | ||
path => $::path, | ||
command => "${_choco_exe_path} feature -r ${_enable_autouninstaller} -n autoUninstaller", | ||
unless => "cmd.exe /c ${_choco_exe_path} feature list -r | findstr /X /I /C:\"autoUninstaller - [${_enable_autouninstaller}d]\"", | ||
exec { "chocolatey_autouninstaller_${_enable_autouninstaller}": | ||
path => $::path, | ||
command => "${_choco_exe_path} feature -r ${_enable_autouninstaller} -n autoUninstaller", | ||
unless => "cmd.exe /c ${_choco_exe_path} feature list -r | findstr /X /I /C:\"autoUninstaller - [${_enable_autouninstaller}d]\"", | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
ferventcoder
Author
Contributor
|
||
} | ||
} | ||
#} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
require 'facter' | ||
require 'rspec/its' | ||
|
||
describe 'chocolateyversion fact' do | ||
subject(:fact) { Facter.fact(:chocolateyversion) } | ||
|
||
context 'on Windows', :if => Puppet::Util::Platform.windows? do | ||
it "should return the value from running choco -v" do | ||
expected_value = '1.2.3' | ||
Facter::Util::Resolution.expects(:exec).returns(expected_value) | ||
|
||
subject.value.must == expected_value | ||
end | ||
|
||
it "should handle cleaning up spaces" do | ||
expected_value = '1.2.3' | ||
Facter::Util::Resolution.expects(:exec).returns(' ' + expected_value + ' ') | ||
|
||
subject.value.must == expected_value | ||
end | ||
|
||
it "should handle older versions of choco" do | ||
expected_value = '1.2.3' | ||
Facter::Util::Resolution.expects(:exec).returns('Please run chocolatey /? or chocolatey help - chocolatey v' + expected_value) | ||
|
||
subject.value.must == expected_value | ||
end | ||
end | ||
|
||
context 'on Linux', :if => Puppet.features.posix? do | ||
its(:value) { should eql('0') } | ||
end | ||
|
||
after :each do | ||
Facter.clear | ||
Facter.clear_messages | ||
end | ||
end |
this line works for you @ferventcoder ?