Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(MODULES-9224) Add no progress flag #154

Merged
merged 1 commit into from
Jun 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a

## [Unreleased]

### Added

- When Chocolatey is version `0.10.4` or later and the `package_setting` option `Verbose` is not specified Chocolatey will be run with the `--no-progress` parameter, limiting the erroneous output of download information to the logs ([MODULES-9224](https://tickets.puppetlabs.com/browse/MODULES-9224)).

## [3.3.0] - 2019-03-19

### Added
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,7 @@ might want to do this in a default:
*about* to do; this is because some things, in particular "ensure => latest",
are pretty slow, which can lead to long periods where Puppet appears to be
doing nothing.
* When Chocolatey is version `0.10.4` or later and "Verbose" is not specified as `true` Chocolatey will be run with the `--no-progress` parameter, limiting the erroneous output of download information to the logs.
* "log_output" causes the output of chocolatey upgrades and installs to be
shown.

Expand Down
6 changes: 5 additions & 1 deletion lib/puppet/provider/package/chocolatey.rb
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ def install
@resource[:package_settings] ||= {}
if @resource[:package_settings]['verbose']
Puppet.info "Calling chocolatey with arguments: " + args.join(' ')
elsif Gem::Version.new(PuppetX::Chocolatey::ChocolateyCommon.choco_version) >= Gem::Version.new(PuppetX::Chocolatey::ChocolateyCommon::MINIMUM_SUPPORTED_CHOCO_VERSION_NO_PROGRESS)
args << '--no-progress'
end
output = chocolatey(*args)
if @resource[:package_settings]['log_output']
Expand Down Expand Up @@ -212,9 +214,11 @@ def update
end

if self.query
@resource[:package_settings] ||= {}
@resource[:package_settings] ||= {}
if @resource[:package_settings]['verbose']
Puppet.info "Calling chocolatey with arguments: " + args.join(' ')
elsif Gem::Version.new(PuppetX::Chocolatey::ChocolateyCommon.choco_version) >= Gem::Version.new(PuppetX::Chocolatey::ChocolateyCommon::MINIMUM_SUPPORTED_CHOCO_VERSION_NO_PROGRESS)
args << '--no-progress'
end
output = chocolatey(*args)
if @resource[:package_settings]['log_output']
Expand Down
1 change: 1 addition & 0 deletions lib/puppet_x/chocolatey/chocolatey_common.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ module ChocolateyCommon
FIRST_COMPILED_CHOCO_VERSION = '0.9.9.0' unless defined? FIRST_COMPILED_CHOCO_VERSION
MINIMUM_SUPPORTED_CHOCO_VERSION_EXIT_CODES = '0.9.10.0' unless defined? MINIMUM_SUPPORTED_CHOCO_VERSION_EXIT_CODES
MINIMUM_SUPPORTED_CHOCO_UNINSTALL_SOURCE = '0.9.10.0' unless defined? MINIMUM_SUPPORTED_CHOCO_UNINSTALL_SOURCE
MINIMUM_SUPPORTED_CHOCO_VERSION_NO_PROGRESS = '0.10.4.0' unless defined? MINIMUM_SUPPORTED_CHOCO_VERSION_NO_PROGRESS

def file_exists?(path)
File.exist?(path)
Expand Down
81 changes: 80 additions & 1 deletion spec/unit/puppet/provider/package/chocolatey_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@
provider = Puppet::Type.type(:package).provider(:chocolatey)

describe provider do
let (:resource) { Puppet::Type.type(:package).new(:provider => :chocolatey, :name => "chocolatey") }
let (:resource) { Puppet::Type.type(:package).new(:provider => :chocolatey, :name => "chocolatey", :package_settings => {}) }
let (:first_compiled_choco_version) {'0.9.9.0'}
let (:newer_choco_version) {'0.9.10.0'}
let (:last_posh_choco_version) {'0.9.8.33'}
let (:minimum_supported_choco_uninstall_source) {'0.9.10.0'}
let (:minimum_supported_choco_exit_codes) {'0.9.10.0'}
let (:minimum_supported_choco_no_progress) {'0.10.4.0'}
let (:choco_zero_ten_zero) {'0.10.0'}
let (:choco_zero_eleven_zero) {'0.11.0'}
let (:choco_config) { 'c:\choco.config' }
let (:choco_install_path) { 'c:\dude\bin\choco.exe' }
let (:choco_config_contents) { <<-'EOT'
Expand Down Expand Up @@ -259,6 +261,43 @@
@provider.install
end

it "should call no progress when = 0.10.4 and not using verbose package options" do
PuppetX::Chocolatey::ChocolateyCommon.expects(:set_env_chocolateyinstall)
PuppetX::Chocolatey::ChocolateyCommon.expects(:choco_config_file).returns(choco_config)
PuppetX::Chocolatey::ChocolateyCommon.expects(:file_exists?).with(choco_config).returns(true)
File.expects(:read).with(choco_config).returns choco_config_contents
PuppetX::Chocolatey::ChocolateyCommon.expects(:choco_version).returns(minimum_supported_choco_no_progress).at_least_once
resource[:ensure] = :present
@provider.expects(:chocolatey).with('install', 'chocolatey','-y', nil, '--ignore-package-exit-codes', '--no-progress')

@provider.install
end

it "should call no progress when > 0.10.4 and not using verbose package options" do
PuppetX::Chocolatey::ChocolateyCommon.expects(:set_env_chocolateyinstall)
PuppetX::Chocolatey::ChocolateyCommon.expects(:choco_config_file).returns(choco_config)
PuppetX::Chocolatey::ChocolateyCommon.expects(:file_exists?).with(choco_config).returns(true)
File.expects(:read).with(choco_config).returns choco_config_contents
PuppetX::Chocolatey::ChocolateyCommon.expects(:choco_version).returns(choco_zero_eleven_zero).at_least_once
resource[:ensure] = :present
@provider.expects(:chocolatey).with('install', 'chocolatey','-y', nil, '--ignore-package-exit-codes', '--no-progress')

@provider.install
end

it "should call no progress when = 0.10.4 and verbose package option specified" do
PuppetX::Chocolatey::ChocolateyCommon.expects(:set_env_chocolateyinstall)
PuppetX::Chocolatey::ChocolateyCommon.expects(:choco_config_file).returns(choco_config)
PuppetX::Chocolatey::ChocolateyCommon.expects(:file_exists?).with(choco_config).returns(true)
File.expects(:read).with(choco_config).returns choco_config_contents
PuppetX::Chocolatey::ChocolateyCommon.expects(:choco_version).returns(minimum_supported_choco_no_progress).at_least_once
resource[:ensure] = :present
resource[:package_settings] = {'verbose' => true}
@provider.expects(:chocolatey).with('install', 'chocolatey','-y', nil, '--ignore-package-exit-codes')

@provider.install
end

it "should use upgrade command with versioned package" do
resource[:ensure] = '1.2.3'
@provider.expects(:chocolatey).with('upgrade', 'chocolatey', '--version', '1.2.3', '-y', nil)
Expand Down Expand Up @@ -468,6 +507,46 @@
@provider.update
end

it "should call with no-progress when = 0.10.4 and package_settings: verbose is not true" do
provider.stubs(:instances).returns [provider.new({
:ensure => "1.2.3",
:name => "chocolatey",
:provider => :chocolatey,
})]
PuppetX::Chocolatey::ChocolateyCommon.expects(:choco_version).returns(minimum_supported_choco_no_progress).at_least_once
resource[:ensure] = :present
@provider.expects(:chocolatey).with('upgrade', 'chocolatey','-y', nil, '--ignore-package-exit-codes', '--no-progress')

@provider.update
end

it "should call with no-progress when > 0.10.4 and package_settings: verbose is not true" do
provider.stubs(:instances).returns [provider.new({
:ensure => "1.2.3",
:name => "chocolatey",
:provider => :chocolatey,
})]
PuppetX::Chocolatey::ChocolateyCommon.expects(:choco_version).returns(choco_zero_eleven_zero).at_least_once
resource[:ensure] = :present
@provider.expects(:chocolatey).with('upgrade', 'chocolatey','-y', nil, '--ignore-package-exit-codes', '--no-progress')

@provider.update
end

it "should not call with no-progress when = 0.10.4 and package_settings: verbose is true" do
provider.stubs(:instances).returns [provider.new({
:ensure => "1.2.3",
:name => "chocolatey",
:provider => :chocolatey,
})]
PuppetX::Chocolatey::ChocolateyCommon.expects(:choco_version).returns(minimum_supported_choco_no_progress).at_least_once
resource[:package_settings] = { 'verbose' => true }
resource[:ensure] = :present
@provider.expects(:chocolatey).with('upgrade', 'chocolatey','-y', nil, '--ignore-package-exit-codes')

@provider.update
end

it "should use `chocolatey install` when ensure latest and package absent" do
provider.stubs(:instances).returns []
@provider.expects(:chocolatey).with('install', 'chocolatey', '-y', nil)
Expand Down