From 781e80697a9bac4efe798e00a6b18ea4612e497d Mon Sep 17 00:00:00 2001 From: Trey Dockendorf Date: Sat, 11 May 2019 09:32:17 -0400 Subject: [PATCH] Simplify package_source for Windows --- README.md | 12 ++++++++-- REFERENCE.md | 27 ++++++++++++++++++++++ manifests/agent.pp | 27 +++++++++++++--------- spec/acceptance/windows_spec.rb | 6 ++--- spec/classes/agent_spec.rb | 40 ++++++++++++++++++++++++++++----- tests/sensu-agent.pp | 8 +++---- 6 files changed, 96 insertions(+), 24 deletions(-) diff --git a/README.md b/README.md index 8b2596b3db..c951271618 100644 --- a/README.md +++ b/README.md @@ -124,13 +124,21 @@ associated to `linux` and `apache-servers` subscriptions. ### Manage Windows Agent -The Windows package source must either be specified as a URL via `package_source_url` parameter or set to a filesystem location using `package_source` parameter. +The Windows package source must be specified as either a URL, a Puppet source or a filesystem path. Install sensu-go-agent on Windows from URL: ```puppet class { 'sensu::agent': - package_source_url => 'https://s3-us-west-2.amazonaws.com/sensu.io/sensu-go/5.7.0/sensu-go-agent_5.7.0.2380_en-US.x64.msi', + package_source => 'https://s3-us-west-2.amazonaws.com/sensu.io/sensu-go/5.7.0/sensu-go-agent_5.7.0.2380_en-US.x64.msi', +} +``` + +Install sensu-ago-agent on Windows from Puppet source: + +```puppet +class { 'sensu::agent': + package_source => 'puppet:///modules/profile/sensu/sensu-go-agent.msi', } ``` diff --git a/REFERENCE.md b/REFERENCE.md index 022b5ed479..f86880be77 100644 --- a/REFERENCE.md +++ b/REFERENCE.md @@ -170,6 +170,24 @@ Windows MSI packaging and to avoid surprising upgrades. Default value: `undef` +##### `package_source` + +Data type: `Optional[String[1]]` + +Source of package for installing Windows. +Paths with http:// or https:// will be downloaded +Paths with puppet:// or absolute filesystem paths will also be installed. + +Default value: `undef` + +##### `package_download_path` + +Data type: `Optional[Stdlib::Absolutepath]` + +Where to download the MSI for Windows. Defaults to `C:`. + +Default value: `undef` + ##### `package_name` Data type: `String` @@ -229,6 +247,15 @@ Sets show_diff parameter for agent.yml configuration file Default value: `true` +##### `log_file` + +Data type: `Optional[Stdlib::Absolutepath]` + +Path to agent log file, only for Windows. +Defaults to `C:\ProgramData\sensu\log\sensu-agent.log` + +Default value: `undef` + ### sensu::backend Class to manage the Sensu backend. diff --git a/manifests/agent.pp b/manifests/agent.pp index 123966ac58..578b225ba7 100644 --- a/manifests/agent.pp +++ b/manifests/agent.pp @@ -13,11 +13,10 @@ # @param version # Version of sensu agent to install. Defaults to `installed` to support # Windows MSI packaging and to avoid surprising upgrades. -# @param package_source_url -# URL of package source for installing on Windows # @param package_source -# Alternative to package_source_url in order to install Windows package -# Use if the MSI installer already exists on local filesystem +# Source of package for installing Windows. +# Paths with http:// or https:// will be downloaded +# Paths with puppet:// or absolute filesystem paths will also be installed. # @param package_download_path # Where to download the MSI for Windows. Defaults to `C:`. # @param package_name @@ -43,8 +42,7 @@ # class sensu::agent ( Optional[String] $version = undef, - Optional[Variant[Stdlib::HTTPSUrl,Stdlib::HTTPUrl]] $package_source_url = undef, - Optional[Stdlib::Absolutepath] $package_source = undef, + Optional[String[1]] $package_source = undef, Optional[Stdlib::Absolutepath] $package_download_path = undef, String $package_name = 'sensu-go-agent', String $service_name = 'sensu-agent', @@ -98,16 +96,25 @@ File['sensu_agent_config'], ], } - if $package_source_url { - $package_source_basename = basename($package_source_url) - $_package_source = pick($package_source, "${package_download_path}\\${package_source_basename}") + if $package_source and ($package_source =~ Stdlib::HTTPSUrl or $package_source =~ Stdlib::HTTPUrl) { + $package_source_basename = basename($package_source) + $_package_source = "${package_download_path}\\${package_source_basename}" archive { 'sensu-go-agent.msi': - source => $package_source_url, + source => $package_source, path => $_package_source, extract => false, cleanup => false, before => Package['sensu-go-agent'], } + } elsif $package_source and $package_source =~ /^puppet:/ { + $package_source_basename = basename($package_source) + $_package_source = "${package_download_path}\\${package_source_basename}" + file { 'sensu-go-agent.msi': + ensure => 'file', + path => $_package_source, + source => $package_source, + before => Package['sensu-go-agent'], + } } else { $_package_source = $package_source } diff --git a/spec/acceptance/windows_spec.rb b/spec/acceptance/windows_spec.rb index 953c5ac159..f8afd57229 100644 --- a/spec/acceptance/windows_spec.rb +++ b/spec/acceptance/windows_spec.rb @@ -5,9 +5,9 @@ pp = <<-EOS class { '::sensu': } class { '::sensu::agent': - package_source_url => 'https://s3-us-west-2.amazonaws.com/sensu.io/sensu-go/5.7.0/sensu-go-agent_5.7.0.2380_en-US.x64.msi', - backends => ['sensu_backend:8081'], - config_hash => { + package_source => 'https://s3-us-west-2.amazonaws.com/sensu.io/sensu-go/5.7.0/sensu-go-agent_5.7.0.2380_en-US.x64.msi', + backends => ['sensu_backend:8081'], + config_hash => { 'name' => 'sensu_agent', } } diff --git a/spec/classes/agent_spec.rb b/spec/classes/agent_spec.rb index aadfbde856..90cf749979 100644 --- a/spec/classes/agent_spec.rb +++ b/spec/classes/agent_spec.rb @@ -72,20 +72,50 @@ } end - context 'when package_source_url defined' do - let(:params) {{ package_source_url: 'https://foo/sensu-go-agent.msi' }} + context 'when package_source defined as URL' do + let(:params) {{ package_source: 'https://foo/sensu-go-agent.msi' }} if facts[:os]['family'] == 'windows' it { should contain_archive('sensu-go-agent.msi').with({ 'source' => 'https://foo/sensu-go-agent.msi', 'path' => 'C:\\\\sensu-go-agent.msi', - 'extract' => 'false', - 'cleanup' => 'false', - 'before' => 'Package[sensu-go-agent]', + 'extract'=> 'false', + 'cleanup'=> 'false', + 'before' => 'Package[sensu-go-agent]', }) } + it { should contain_package('sensu-go-agent').with_source('C:\\\\sensu-go-agent.msi') } else it { should_not contain_archive('sensu-go-agent.msi') } + it { should contain_package('sensu-go-agent').without_source } + end + end + + context 'when package_source defined as puppet' do + let(:params) {{ package_source: 'puppet:///modules/profile/sensu-go-agent.msi' }} + if facts[:os]['family'] == 'windows' + it { + should contain_file('sensu-go-agent.msi').with({ + 'ensure' => 'file', + 'source' => 'puppet:///modules/profile/sensu-go-agent.msi', + 'path' => 'C:\\\\sensu-go-agent.msi', + 'before' => 'Package[sensu-go-agent]', + }) + } + it { should contain_package('sensu-go-agent').with_source('C:\\\\sensu-go-agent.msi') } + else + it { should_not contain_archive('sensu-go-agent.msi') } + it { should contain_package('sensu-go-agent').without_source } + end + end + + context 'when package_source is local' do + let(:params) {{ package_source: 'C:\\sensu-go-agent.msi' }} + it { should_not contain_archive('sensu-go-agent.msi') } + if facts[:os]['family'] == 'windows' + it { should contain_package('sensu-go-agent').with_source('C:\\sensu-go-agent.msi') } + else + it { should contain_package('sensu-go-agent').without_source } end end diff --git a/tests/sensu-agent.pp b/tests/sensu-agent.pp index d53f8206f5..fbc2463d78 100644 --- a/tests/sensu-agent.pp +++ b/tests/sensu-agent.pp @@ -1,10 +1,10 @@ if $facts['os']['family'] == 'windows' { - $package_source_url = 'https://s3-us-west-2.amazonaws.com/sensu.io/sensu-go/5.7.0/sensu-go-agent_5.7.0.2380_en-US.x64.msi' + $package_source = 'https://s3-us-west-2.amazonaws.com/sensu.io/sensu-go/5.7.0/sensu-go-agent_5.7.0.2380_en-US.x64.msi' } else { - $package_source_url = undef + $package_source = undef } class { '::sensu::agent': - backends => ['sensu-backend.example.com:8081'], - package_source_url => $package_source_url, + backends => ['sensu-backend.example.com:8081'], + package_source => $package_source, }