Skip to content

Commit

Permalink
Merge pull request #699 from jeffmccune/646_fix_error_on_win2012r2
Browse files Browse the repository at this point in the history
Fix Package[sensu] on windows
  • Loading branch information
ghoneycutt authored Jun 30, 2017
2 parents 8969b40 + 16ef568 commit 366bc4f
Show file tree
Hide file tree
Showing 26 changed files with 343 additions and 45 deletions.
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,
},
$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

0 comments on commit 366bc4f

Please sign in to comment.