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

Fix Package[sensu] on windows #699

Merged
merged 18 commits into from
Jun 30, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
c032808
(Maint) Ignore direnv and rbenv dotfiles
jeffmccune Jun 29, 2017
10a781b
(Maint) Change windows user management warning to a notice
jeffmccune Jun 29, 2017
c8a2475
(GH-646) Add failing test case
jeffmccune Jun 28, 2017
148666c
(GH-646) Add tests/sensu-client-windows.pp
jeffmccune Jun 28, 2017
2324425
(GH-681) Add Vagrant provisioning for Win2012r2
jeffmccune Jun 28, 2017
ff8d2aa
(GH-646) Bump windows VM from 512 to 1024 ram
jeffmccune Jun 29, 2017
0fa31e4
(GH-646) Bump Win VM memory to 2048 to fix ruby hanging
jeffmccune Jun 29, 2017
abadfa2
Use $sensu::dir_mode in RabbitMQ configuration.
jmkeyes Apr 11, 2017
1a1b52a
Use $pkg_title for all Sensu package resource references.
jmkeyes Apr 11, 2017
d42f79c
(GH-646) Use Package[sensu], not Package[Sensu] on Windows
jeffmccune Jun 29, 2017
8f3a15b
(GH-646) Default sensu package version to installed
jeffmccune Jun 29, 2017
08d6c27
(GH-646) Allow package source URL override using windows_pkg_url
jeffmccune Jun 29, 2017
634bf10
(GH-646) Fix Exec[install-sensu-client] powershell error
jeffmccune Jun 29, 2017
28e57bc
(GH-646) Make Vagrant Win puppet.msi install more robust
jeffmccune Jun 29, 2017
18cfc7c
(GH-646) Switch Exec[install-sensu-client] to Powershell
jeffmccune Jun 29, 2017
dc57895
(GH-646) Make win msi install idempotent
jeffmccune Jun 29, 2017
98513d0
(GH-646) Map windows MSI file versions to OS versions
jeffmccune Jun 29, 2017
16ef568
(GH-646) Fix vagrant win 1vcpu, port 3389, puppet-agent.log
jeffmccune Jun 29, 2017
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
3 changes: 3 additions & 0 deletions .fixtures.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,8 @@ fixtures:
remote_file:
repo: git://github.com/lwf/puppet-remote_file.git
ref: v1.1.3
powershell:
repo: git://github.com/puppetlabs/puppetlabs-powershell.git
ref: 2.1.0
symlinks:
sensu: "#{source_dir}"
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,7 @@ log/
vendor/
sensu.komodoproject
doc/**

# direnv & rbenv
/.envrc
/.ruby-version
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ Sensu-Puppet module.
- puppetlabs/apt
- puppetlabs/stdlib
- lwf/puppet-remote_file
- puppetlabs/powershell

See `metadata.json` for details.

Expand Down
21 changes: 21 additions & 0 deletions Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,25 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
client.vm.provision :shell, :path => "tests/provision_basic_ubuntu.sh"
client.vm.provision :shell, :path => "tests/provision_client_ubuntu1404.sh"
end

config.vm.define "win2012r2-client", autostart: false do |client|
client.vm.box = "opentable/win-2012r2-standard-amd64-nocm"
client.vm.provider :virtualbox do |vb|
vb.customize ["modifyvm", :id, "--memory", "2048"]
vb.customize ["modifyvm", :id, "--cpus", "1"]
end
client.vm.hostname = 'win2012r2-client'
client.vm.network :private_network, ip: "192.168.56.15"
client.vm.network "forwarded_port", host: 3389, guest: 3389, auto_correct: true
# There are two basic power shell scripts. The first installs Puppet, but
# puppet is not in the PATH. The second invokes a new shell which will have
# Puppet in the PATH.
#
## Install Puppet
client.vm.provision :shell, :path => "tests/provision_basic_win.ps1"
## Symlink module into place, run puppet module install for puppet apply
client.vm.provision :shell, :path => "tests/provision_basic_win.2.ps1"
## Run puppet apply
client.vm.provision :shell, :path => "tests/provision_client_win.ps1"
end
end
10 changes: 5 additions & 5 deletions manifests/client/service.pp
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@
}

exec { 'install-sensu-client':
command => "powershell.exe -ExecutionPolicy RemoteSigned -Command \"New-Service -Name sensu-client -BinaryPathName c:\\opt\\sensu\\bin\\sensu-client.exe -DisplayName 'Sensu Client' -StartupType Automatic\"",
unless => 'powershell.exe -ExecutionPolicy RemoteSigned -Command "Get-Service sensu-client"',
path => 'C:/Windows/System32/WindowsPowerShell/v1.0:C:/Windows/SysWOW64/WindowsPowerShell/v1.0',
before => Service['sensu-client'],
require => File['C:/opt/sensu/bin/sensu-client.xml'],
provider => 'powershell',
command => "New-Service -Name sensu-client -BinaryPathName c:\\opt\\sensu\\bin\\sensu-client.exe -DisplayName 'Sensu Client' -StartupType Automatic",
unless => 'if (Get-Service sensu-client -ErrorAction SilentlyContinue) { exit 0 } else { exit 1 }',
before => Service['sensu-client'],
require => File['C:/opt/sensu/bin/sensu-client.xml'],
}
}

Expand Down
26 changes: 19 additions & 7 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
# == Parameters
#
# [*version*]
# String. Version of sensu to install
# Default: latest
# String. Version of sensu to install. Defaults to `installed` to support
# Windows MSI packaging and to avoid surprising upgrades.
# Default: installed
# Valid values: absent, installed, latest, present, [\d\.\-el]+
#
# [*sensu_plugin_name*]
Expand All @@ -16,7 +17,8 @@
#
# [*sensu_plugin_provider*]
# String. Provider used to install the sensu-plugin package. Refers to the
# sensu-plugin rubygem, not the sensu-plugins community scripts
# sensu-plugin rubygem, not the sensu-plugins community scripts. On windows,
# defaults to `gem`, all other platforms defaults to `undef`
# Default: undef
# Valid values: sensu_gem, apt, aptitude, yum
#
Expand Down Expand Up @@ -352,12 +354,21 @@
# String. used to set package_checksum for windows installs
# Default: undef
#

# [*windows_pkg_url*]
# String. If specified, override the behavior of computing the package source
# URL from windows_repo_prefix and os major release fact. This parameter is
# intended to allow the end user to override the source URL used to install
# the Windows package. For example:
# `"https://repositories.sensuapp.org/msi/2012r2/sensu-0.29.0-11-x64.msi"`
# Default: undef

class sensu (
$version = 'latest',
$version = 'installed',
$sensu_plugin_name = 'sensu-plugin',
$sensu_plugin_provider = undef,
$sensu_plugin_provider = $::osfamily ? {
'windows' => 'gem',
default => undef,
},
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This avoids Provider sensu_gem is not functional on windows. Considered moving the behavior to package.pp, put it here to make it clear.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it not embedded on windows?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gem is embedded on windows, e.g. https://github.com/sensu/sensu-puppet/blob/30fe995/lib/puppet/provider/package/sensu_gem.rb#L16

It seems the parent gem provider in puppet has a confinement preventing it from working on Windows. My guess is sensu_gem is inheriting this. I'll see if I can override and sensu_gem works.

$sensu_plugin_version = 'installed',
$install_repo = true,
$enterprise = false,
Expand Down Expand Up @@ -444,7 +455,8 @@
$deregister_on_stop = false,
$deregister_handler = undef,
$package_checksum = undef,
$windows_repo_prefix = 'http://repositories.sensuapp.org/msi/sensu',
$windows_pkg_url = undef,
$windows_repo_prefix = 'https://repositories.sensuapp.org/msi',
$windows_logrotate = false,
$windows_log_number = '10',
$windows_log_size = '10240',
Expand Down
51 changes: 38 additions & 13 deletions manifests/package.pp
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,40 @@
'windows': {
$repo_require = undef

$pkg_version = inline_template("<%= scope.lookupvar('sensu::version').sub(/(.*)\\-/, '\\1.') %>")
$pkg_title = 'Sensu'
# $pkg_version is passed to Package[sensu] { ensure }. The Windows MSI
# provider translates hyphens to dots, e.g. '0.29.0-11' maps to
# '0.29.0.11' on the system. This mapping is necessary to converge.
$pkg_version = template('sensu/sensu-windows-package-version.erb')
# The version used to construct the download URL.
$pkg_url_version = $::sensu::version ? {
'installed' => 'latest',
default => $::sensu::version,
}
# The title used for consistent relationships in the Puppet catalog
$pkg_title = 'sensu'
# The name used by the provider to compare to Windows Add/Remove programs.
$pkg_name = 'Sensu'
$pkg_source = "C:\\Windows\\Temp\\sensu-${sensu::version}.msi"
$pkg_require = "Remote_file[${pkg_source}]"
# Where the MSI is downloaded to and installed from.
$pkg_source = "C:\\Windows\\Temp\\sensu-${pkg_url_version}.msi"
$pkg_require = "Remote_file[${pkg_title}]"

# The user can override the computation of the source URL.
if $::sensu::windows_pkg_url {
$pkg_url = $::sensu::windows_pkg_url
} else {
# The OS Release specific sub-folder
$os_release = $facts['os']['release']['major']
# e.g. '2012 R2' => '2012r2'
$pkg_url_dir = template('sensu/sensu-version.erb')
$pkg_arch = $facts['os']['architecture']
$pkg_url = "${sensu::windows_repo_prefix}/${pkg_url_dir}/sensu-${pkg_url_version}-${pkg_arch}.msi"
}

remote_file { $pkg_source:
# path matches Package[sensu] { source => $pkg_source }
remote_file { $pkg_title:
ensure => present,
source => "${sensu::windows_repo_prefix}-${sensu::version}.msi",
path => $pkg_source,
source => $pkg_url,
checksum => $::sensu::package_checksum,
}
}
Expand Down Expand Up @@ -97,7 +122,7 @@
owner => '0',
group => '0',
mode => '0444',
require => Package['sensu'],
require => Package[$pkg_title],
}
}

Expand All @@ -109,7 +134,7 @@
purge => $::sensu::_purge_config,
recurse => true,
force => true,
require => Package[$pkg_name],
require => Package[$pkg_title],
}

if $::sensu::manage_handlers_dir {
Expand All @@ -121,7 +146,7 @@
purge => $::sensu::_purge_handlers,
recurse => true,
force => true,
require => Package[$pkg_name],
require => Package[$pkg_title],
}
}

Expand All @@ -133,7 +158,7 @@
purge => $::sensu::_purge_extensions,
recurse => true,
force => true,
require => Package[$pkg_name],
require => Package[$pkg_title],
}

if $::sensu::manage_mutators_dir {
Expand All @@ -145,7 +170,7 @@
purge => $::sensu::_purge_mutators,
recurse => true,
force => true,
require => Package[$pkg_name],
require => Package[$pkg_title],
}
}

Expand All @@ -158,7 +183,7 @@
purge => $::sensu::_purge_plugins,
recurse => true,
force => true,
require => Package[$pkg_name],
require => Package[$pkg_title],
}
}

Expand All @@ -177,7 +202,7 @@
system => true,
}
} elsif $::sensu::manage_user and $::osfamily == 'windows' {
warning('Managing a local windows user is not supported')
notice('Managing a local windows user is not implemented on windows')
}

file { "${sensu::etc_dir}/config.json": ensure => absent }
Expand Down
2 changes: 1 addition & 1 deletion manifests/plugin.pp
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@
recurse => $recurse,
purge => $purge,
force => $force,
require => Package['sensu'],
require => Package[$sensu::package::pkg_title],
}
}
'package': {
Expand Down
2 changes: 1 addition & 1 deletion manifests/plugins_dir.pp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
recurse => $recurse,
purge => $purge,
force => $force,
require => Package['sensu'],
require => Package[$sensu::package::pkg_title],
}
}
}
4 changes: 2 additions & 2 deletions manifests/rabbitmq/config.pp
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
ensure => directory,
owner => $::sensu::user,
group => $::sensu::group,
mode => '0755',
require => Package['sensu'],
mode => $::sensu::dir_mode,
require => Package[$::sensu::package::pkg_title],
}

# if provided a cert chain, and its a puppet:// URI, source file form the
Expand Down
2 changes: 1 addition & 1 deletion manifests/repo/apt.pp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
'id' => $::sensu::repo_key_id,
'source' => $::sensu::repo_key_source,
},
before => Package['sensu'],
before => Package[$sensu::package::pkg_title],
notify => Exec['apt-update'],
}

Expand Down
2 changes: 1 addition & 1 deletion manifests/repo/yum.pp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
gpgcheck => 0,
name => 'sensu',
descr => 'sensu',
before => Package['sensu'],
before => Package[$sensu::package::pkg_title],
}

# prep for Enterprise repos
Expand Down
4 changes: 4 additions & 0 deletions metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@
{
"name": "puppetlabs/stdlib",
"version_requirement": ">=4.16.0 <5.0.0"
},
{
"name": "puppetlabs/powershell",
"version_requirement": ">=2.1.0 <3.0.0"
}
]
}
28 changes: 15 additions & 13 deletions spec/classes/sensu_init_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,29 @@
it 'should compile' do should create_class('sensu') end
it { should contain_user('sensu') }

context 'osfamily windows with manage_user => true' do
context 'osfamily windows' do
let(:facts) do
{
:osfamily => 'windows',
:kernel => 'windows',
:operatingsystem => 'Windows',
:os => {
:architecture => 'x64',
:release => {
:major => '2012 R2',
},
},
}
end

it { should_not contain_user('sensu') }
end
describe 'with manage_user => true' do
it { should_not contain_user('sensu') }
end

context 'osfamily windows with manage_user => false' do
let(:facts) do
{
:osfamily => 'windows',
:kernel => 'windows',
}
describe 'with manage_user => false' do
let(:params) { {:manage_user => false} }
it { should_not contain_user('sensu') }
end
end
let(:params) { {:manage_user => false} }

it { should_not contain_user('sensu') }
end

context 'with manage_user => false' do
Expand Down
Loading