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

[windows] Add option to support EXE Agent installer #410

Merged
merged 6 commits into from
Mar 23, 2017
Merged
Changes from 1 commit
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
Prev Previous commit
[windows] Fix pkg removal issue on Chef >= 12.6 and windows >= 1.39
Tested the change on Chef 12.2 and 12.18, works well on clean installs
and upgrades.

Updated the spec tests assuming they run on Chef >= 12.6.

This should be removed (and the whole recipe should be cleaned up)
when we stop supporting Chef < 12.6 on Windows.
olivielpeau committed Mar 22, 2017
commit ebfcb899c36e13425b6e2412bea86340de97493d
24 changes: 20 additions & 4 deletions recipes/_install-windows.rb
Original file line number Diff line number Diff line change
@@ -44,9 +44,21 @@

# Use a separate resource without a `source` so that it looks in the Registry to find the MSI to use
# for the package removal
windows_package 'Datadog Agent removal' do
package_name 'Datadog Agent'
action :nothing
# On Chef >= 12.6, we have to use the `package` resource instead of `windows_package` to allow not specifying a source
# (this is related to the way the windows cookbook changes the provider of `windows_package` depending on the
# version of Chef, and to improvements on the `package` resource made in Chef 12.6)
# FIXME: when we remove Chef < 12.6 support on Windows, which should allow using core resources only
use_windows_package_resource = Gem::Version.new(Chef::VERSION) < Gem::Version.new('12.6.0')
if use_windows_package_resource
windows_package 'Datadog Agent removal' do
package_name 'Datadog Agent'
action :nothing
end
else
package 'Datadog Agent removal' do
package_name 'Datadog Agent'
action :nothing
end
end

package_retries = node['datadog']['agent_package_retries']
@@ -60,7 +72,11 @@
retry_delay package_retry_delay unless package_retry_delay.nil?
# As of v1.37, the windows cookbook doesn't upgrade the package if a newer version is downloaded
# As a workaround uninstall the package first if a new MSI is downloaded
notifies :remove, 'windows_package[Datadog Agent removal]', :immediately
if use_windows_package_resource
notifies :remove, 'windows_package[Datadog Agent removal]', :immediately
else
notifies :remove, 'package[Datadog Agent removal]', :immediately
end
end

# Install the package
4 changes: 2 additions & 2 deletions spec/shared_examples.rb
Original file line number Diff line number Diff line change
@@ -82,11 +82,11 @@
end

it 'doesn\'t remove existing version of the Datadog Agent by default' do
expect(chef_run.windows_package('Datadog Agent removal')).to do_nothing
expect(chef_run.package('Datadog Agent removal')).to do_nothing
end

it 'notifies the removal of the Datadog Agent when a remote file is downloaded' do
expect(chef_run.remote_file(agent_installer)).to notify('windows_package[Datadog Agent removal]').to(:remove)
expect(chef_run.remote_file(agent_installer)).to notify('package[Datadog Agent removal]').to(:remove)
end

it 'installs Datadog Agent' do