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

[rebased] Update windows support to be much better #334

Merged
merged 1 commit into from
Aug 5, 2016
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
5 changes: 4 additions & 1 deletion .kitchen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,11 @@ platforms:
<% end

windows_platform = 'windows-2012r2'
windows_chef_versions = %w(
12.2.1
)

chef_versions.each do |chef_version|
windows_chef_versions.each do |chef_version|
%>

- name: <%= windows_platform %>-<%= chef_version %>
Expand Down
4 changes: 4 additions & 0 deletions attributes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@
default['datadog']['yumrepo_proxy_password'] = nil
default['datadog']['windows_agent_url'] = 'https://s3.amazonaws.com/ddagent-windows-stable/'

# Agent installer checksum
# Expected checksum to validate correct agent installer is downloaded (Windows only)
default['datadog']['windows_agent_checksum'] = nil

# Values that differ on Windows
# The location of the config folder (containing conf.d)
# The name of the dd agent service
Expand Down
4 changes: 2 additions & 2 deletions metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@

depends 'apt' # We recommend '>= 2.1.0'. See CHANGELOG.md for details
depends 'chef_handler', '~> 1.1'
depends 'windows'
depends 'windows' # We recommend '< 1.39.0' if running Chef >= 12.6. See README.md for details
depends 'yum'

suggests 'sudo'
suggests 'sudo' # ~FC052

recipe 'datadog::default', 'Default'
recipe 'datadog::dd-agent', 'Installs the Datadog Agent'
Expand Down
10 changes: 6 additions & 4 deletions recipes/_install-windows.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,19 @@
temp_file = ::File.join(Chef::Config[:file_cache_path], 'ddagent-cli.msi')

# Download the installer to a temp location
remote_file 'MSI installer' do
path temp_file
remote_file temp_file do
source node['datadog']['windows_agent_url'] + dd_agent_msi
checksum node['datadog']['windows_agent_checksum'] if node['datadog']['windows_agent_checksum']
# 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]', :immediately
end

# Install the package
windows_package 'Datadog Agent' do
windows_package 'Datadog Agent' do # ~FC009
source temp_file
options %(APIKEY="#{node['datadog']['api_key']}" HOSTNAME="#{node['hostname']}" TAGS="#{node['tags'].join(',') if node['tags']}")
installer_type :msi
options '/norestart ALLUSERS=1'
action :install
success_codes [0, 3010]
end
12 changes: 7 additions & 5 deletions recipes/dd-agent.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@
# limitations under the License.
#

is_windows = node['platform_family'] == 'windows'

# Install the agent
if node['platform_family'] == 'windows'
if is_windows
include_recipe 'datadog::_install-windows'
else
include_recipe 'datadog::_install-linux'
Expand All @@ -33,7 +35,7 @@

# Make sure the config directory exists
directory node['datadog']['config_dir'] do
if node['platform_family'] == 'windows'
if is_windows
owner 'Administrators'
rights :full_control, 'Administrators'
inherits false
Expand All @@ -52,7 +54,7 @@
raise "Add a ['datadog']['api_key'] attribute to configure this node's Datadog Agent." if node['datadog'] && node['datadog']['api_key'].nil?

template agent_config_file do
if node['platform_family'] == 'windows'
if is_windows
owner 'Administrators'
rights :full_control, 'Administrators'
inherits false
Expand All @@ -72,7 +74,7 @@
service 'datadog-agent' do
service_name node['datadog']['agent_name']
action [agent_enable, agent_start]
if node['platform_family'] == 'windows'
if is_windows
supports :restart => true, :start => true, :stop => true
else
supports :restart => true, :status => true, :start => true, :stop => true
Expand All @@ -81,4 +83,4 @@
end

# Install integration packages
include_recipe 'datadog::integrations' if node['platform_family'] != 'windows'
include_recipe 'datadog::integrations' unless is_windows
3 changes: 2 additions & 1 deletion spec/dd-agent_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,8 @@ def set_env_var(name, value)
set_env_var('ProgramData', 'C:\ProgramData')
ChefSpec::SoloRunner.new(
:platform => 'windows',
:version => '2012R2'
:version => '2012R2',
:file_cache_path => 'C:/chef/cache'
) do |node|
node.set['datadog'] = { 'api_key' => 'somethingnotnil' }
end.converge described_recipe
Expand Down
6 changes: 4 additions & 2 deletions spec/shared_examples.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,14 @@
shared_examples_for 'windows Datadog Agent' do
it_behaves_like 'common windows resources'

agent_installer = 'C:/chef/cache/ddagent-cli.msi'

it 'downloads the remote file only if it\'s changed' do
expect(chef_run).to create_remote_file('MSI installer')
expect(chef_run).to create_remote_file(agent_installer)
end

it 'notifies the removal of the Datadog Agent' do
expect(chef_run.remote_file('MSI installer')).to notify('windows_package[Datadog Agent]').to(:remove)
expect(chef_run.remote_file(agent_installer)).to notify('windows_package[Datadog Agent]').to(:remove)
end

it 'installs Datadog Agent' do
Expand Down