Skip to content

Commit

Permalink
Simplify package_source for Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
treydock committed May 11, 2019
1 parent 6b7b032 commit 781e806
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 24 deletions.
12 changes: 10 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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',
}
```

Expand Down
27 changes: 27 additions & 0 deletions REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down Expand Up @@ -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.
Expand Down
27 changes: 17 additions & 10 deletions manifests/agent.pp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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',
Expand Down Expand Up @@ -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
}
Expand Down
6 changes: 3 additions & 3 deletions spec/acceptance/windows_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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',
}
}
Expand Down
40 changes: 35 additions & 5 deletions spec/classes/agent_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
8 changes: 4 additions & 4 deletions tests/sensu-agent.pp
Original file line number Diff line number Diff line change
@@ -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,
}

0 comments on commit 781e806

Please sign in to comment.