Skip to content

Commit

Permalink
(GH-646) Allow package source URL override using windows_pkg_url
Browse files Browse the repository at this point in the history
Without this patch the computation of the package source URL will
inevitably be incorrect for some users.  To avoid support issues, this
patch adds an override as an escape hatch.  The user may specific the
specific package source URL which will override the computation.
  • Loading branch information
jeffmccune committed Jun 29, 2017
1 parent b5611c1 commit 987d04e
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 13 deletions.
9 changes: 8 additions & 1 deletion manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,13 @@
# 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 = 'installed',
Expand Down Expand Up @@ -449,6 +455,7 @@
$deregister_on_stop = false,
$deregister_handler = undef,
$package_checksum = undef,
$windows_pkg_url = undef,
$windows_repo_prefix = 'https://repositories.sensuapp.org/msi',
$windows_logrotate = false,
$windows_log_number = '10',
Expand Down
25 changes: 14 additions & 11 deletions manifests/package.pp
Original file line number Diff line number Diff line change
Expand Up @@ -45,29 +45,32 @@
$repo_require = undef

$pkg_version = $::sensu::version
# Download the latest published version
$pkg_url_version = $pkg_version ? {
'installed' => 'latest',
default => $pkg_version,
default => $pkg_version,
}
$pkg_title = 'sensu'
$pkg_name = 'sensu'
$pkg_source = "C:\\Windows\\Temp\\sensu-${pkg_url_version}.msi"
$pkg_require = "Remote_file[${pkg_name}]"
# The OS Release specific sub-folder
$os_release = $facts['os']['release']['major']
$pkg_url_dir = $os_release ? {
'2008 R2' => '2008r2',
'2012 R2' => '2012r2',
'2016 R2' => '2016r2',
default => $os_release,

# 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 = inline_template("<%= @os_release.sub(/^(\\d+)\s*[rR](\\d+)/, '\\1r\\2') %>")
$pkg_arch = $facts['os']['architecture']
$pkg_url = "${sensu::windows_repo_prefix}/${pkg_url_dir}/sensu-${pkg_url_version}-${pkg_arch}.msi"
}
$pkg_arch = $facts['os']['architecture']

# path matches Package[sensu] { source => $pkg_source }
remote_file { $pkg_name:
ensure => present,
path => $pkg_source,
source => "${sensu::windows_repo_prefix}/${pkg_url_dir}/sensu-${pkg_url_version}-${pkg_arch}.msi",
source => $pkg_url,
checksum => $::sensu::package_checksum,
}
}
Expand Down
12 changes: 12 additions & 0 deletions spec/classes/sensu_package_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,18 @@
source: 'https://repositories.sensuapp.org/msi/2012r2/sensu-0.29.0-11-x64.msi',
) }
end

context 'with windows_pkg_url specified' do
let(:params) do
{ windows_pkg_url: 'https://repositories.sensuapp.org/msi/2012r2/sensu-0.29.0-11-x64.msi' }
end

it 'overrides computation using windows_repo_prefix' do
should contain_remote_file('sensu').with(
source: 'https://repositories.sensuapp.org/msi/2012r2/sensu-0.29.0-11-x64.msi'
)
end
end
end
end
end
3 changes: 2 additions & 1 deletion tests/sensu-client-windows.pp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Note: Check http://repositories.sensuapp.org/msi/ for the latest version.
$pkg_repo = 'https://repositories.sensuapp.org/msi'
class { '::sensu':
version => '0.29.0-11',
windows_pkg_url => "${pkg_repo}/2012r2/sensu-0.29.0-11-x64.msi",
rabbitmq_password => 'correct-horse-battery-staple',
rabbitmq_host => '192.168.56.10',
rabbitmq_vhost => '/sensu',
Expand Down

0 comments on commit 987d04e

Please sign in to comment.