Skip to content

Commit

Permalink
Add Windows acceptance tests
Browse files Browse the repository at this point in the history
Support Windows 2016
Handle absence of os.architecture fact for Windows
  • Loading branch information
treydock committed Mar 23, 2019
1 parent 353ac3b commit 808e05a
Show file tree
Hide file tree
Showing 7 changed files with 173 additions and 48 deletions.
8 changes: 8 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,11 @@ desc 'Generate REFERENCE.md'
task :reference do
sh 'puppet strings generate --format markdown'
end

namespace :acceptance do
desc 'Run acceptance tests against current code'
RSpec::Core::RakeTask.new(:local) do |t|
t.rspec_opts = '--format documentation'
t.pattern = 'spec/acceptance/**.rb'
end
end
56 changes: 56 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
version: '{build}-{branch}'
platform:
- x64
build: off
max_jobs: 2
cache:
- C:\downloads
- C:\vendor\bundle
init:
- ps: $env:GEM_SOURCE = "http://rubygems.org"
install:
- set PATH=C:\Ruby%RUBY_VERSION%\bin;%PATH%
- ps: |
if (!(Test-Path C:\downloads)) { mkdir C:\downloads | Out-Null }
$log = "C:/puppet-agent.log"
$agent_url = "https://downloads.puppetlabs.com/windows/${ENV:PUPPET_REPO}/puppet-agent-${ENV:PUPPET_VERSION}-x64.msi"
Write-Output "Installing Puppet from $agent_url"
Write-Output "Log will be written to $log"
if ( Test-Path $log ) { Remove-Item $log }
cd C:\downloads
if (!(Test-Path "puppet-agent-${ENV:PUPPET_VERSION}-x64.msi")) { Start-FileDownload $agent_url }
Start-Process msiexec.exe -Wait -NoNewWindow -ArgumentList @("/i", "C:\downloads\puppet-agent-${ENV:PUPPET_VERSION}-x64.msi", "/qn", "/l*", "$log")
cd $ENV:APPVEYOR_BUILD_FOLDER
- ps: Copy-Item -Path $ENV:APPVEYOR_BUILD_FOLDER -Destination C:/ProgramData/PuppetLabs/code/environments/production/modules/sensuclassic -Recurse
- set PATH=C:\Program Files\Puppet Labs\Puppet\bin;%PATH%
- puppet --version
- puppet module install puppetlabs-stdlib
- puppet module install lwf-remote_file
- puppet module install puppetlabs-dsc
- puppet module install puppetlabs-acl
- puppet module install puppetlabs-powershell
- facter
- ruby -v
- gem update --system 2.7.9
- gem -v
- bundle -v
- bundle install --jobs 4 --retry 2 --path C:\vendor\bundle
test_script:
- bundle exec rake acceptance:local
image:
# Windows 2012 R2
- Visual Studio 2015
# Windows 2016
- Visual Studio 2017
environment:
matrix:
- PUPPET_GEM_VERSION: '~>5.x'
PUPPET_REPO: puppet5
PUPPET_VERSION: 5.5.8
RUBY_VERSION: 24-x64
- PUPPET_GEM_VERSION: '~>6.x'
PUPPET_REPO: puppet6
PUPPET_VERSION: 6.1.0
RUBY_VERSION: 25-x64
matrix:
fast_finish: false
6 changes: 5 additions & 1 deletion manifests/package.pp
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,11 @@
$os_release = $facts['os']['release']['major']
# e.g. '2012 R2' => '2012r2'
$pkg_url_dir = regsubst($os_release, '^(\d+)\s*[rR](\d+)', '\\1r\\2')
$pkg_arch = $facts['os']['architecture']
if $facts['os']['architecture'] {
$pkg_arch = $facts['os']['architecture']
} else {
$pkg_arch = $facts['architecture']
}
$pkg_url = "${sensuclassic::windows_repo_prefix}/${pkg_url_dir}/sensu-${pkg_url_version}-${pkg_arch}.msi"
}

Expand Down
3 changes: 2 additions & 1 deletion metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
"operatingsystem": "Windows",
"operatingsystemrelease": [
"Server 2008 R2",
"Server 2012 R2"
"Server 2012 R2",
"Server 2016"
]
},
{
Expand Down
55 changes: 34 additions & 21 deletions spec/acceptance/class_spec.rb
Original file line number Diff line number Diff line change
@@ -1,17 +1,26 @@
require 'spec_helper_acceptance'

describe 'sensuclassic class', :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do
describe 'sensuclassic class' do

context 'sensuclassic' do
context 'default' do
it 'should work with no errors' do
pp = <<-EOS
class { 'sensuclassic':}
EOS
pp = <<-EOS
class { 'sensuclassic':}
EOS

# Run it twice and test for idempotency
apply_manifest(pp, :catch_failures => true)
apply_manifest(pp, :catch_changes => true)
if ! Gem.win_platform?
it 'should work with no errors' do
# Run it twice and test for idempotency
apply_manifest(pp, :catch_failures => true)
apply_manifest(pp, :catch_changes => true)
end
else
File.open('C:\manifest-client.pp', 'w') { |f| f.write(pp) }
puts "C:\manifest-client.pp"
puts File.read('C:\manifest-client.pp')
describe command('puppet apply --debug C:\manifest-client.pp') do
its(:exit_status) { is_expected.to eq 0 }
end
end

describe service('sensu-client') do
Expand Down Expand Up @@ -124,21 +133,25 @@ class { 'sensuclassic':
end

context 'client => false' do
it 'should work with no errors' do
pp = <<-EOS
class { 'sensuclassic':
client => false
}
EOS
pp = <<-EOS
class { 'sensuclassic':
client => false
}
EOS

# Run it twice and test for idempotency
apply_manifest(pp, :catch_failures => true)
if fact('osfamily') == 'windows'
shell('waitfor SomethingThatIsNeverHappening /t 5 2>NUL', :acceptable_exit_codes => [0,1])
else
shell('sleep 5') # Give services time to stop
if ! Gem.win_platform?
it 'should work with no errors' do
# Run it twice and test for idempotency
apply_manifest(pp, :catch_failures => true)
apply_manifest(pp, :catch_changes => true)
end
else
File.open('C:\manifest-client-false.pp', 'w') { |f| f.write(pp) }
puts "C:\manifest-client-false.pp"
puts File.read('C:\manifest-client-false.pp')
describe command('puppet apply C:\manifest-client-false.pp') do
its(:exit_status) { is_expected.to eq 0 }
end
apply_manifest(pp, :catch_changes => true)
end

describe service('sensu-client') do
Expand Down
27 changes: 27 additions & 0 deletions spec/classes/sensuclassic_package_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,33 @@
end
end
end

context 'on Windows 2016' do
let(:facts) do
{
:fqdn => 'testhost.domain.com',
:operatingsystem => 'Windows',
:kernel => 'windows',
:osfamily => 'windows',
:os => {
:architecture => 'x64',
:release => {
:major => '2016',
},
},
}
end
it { should_not contain_package('Sensu') }
it { should contain_package('sensu').with(
ensure: 'installed',
source: 'C:\\Windows\\Temp\\sensu-latest.msi',
) }

it { should contain_remote_file('sensu').with(
source: 'https://repositories.sensuapp.org/msi/2016/sensu-latest-x64.msi',
path: 'C:\\Windows\\Temp\\sensu-latest.msi',
) }
end
end

context 'with use_embedded_ruby => false' do
Expand Down
66 changes: 41 additions & 25 deletions spec/spec_helper_acceptance.rb
Original file line number Diff line number Diff line change
@@ -1,37 +1,53 @@
require 'beaker-rspec'
require 'beaker-puppet'
require 'beaker/puppet_install_helper'
require 'beaker/module_install_helper'
require 'serverspec'
if ! Gem.win_platform?
require 'beaker-rspec'
require 'beaker-puppet'
require 'beaker/puppet_install_helper'
require 'beaker/module_install_helper'

run_puppet_install_helper
install_module_dependencies
install_module
collection = ENV['BEAKER_PUPPET_COLLECTION'] || 'puppet5'
run_puppet_install_helper
install_module_dependencies
install_module
collection = ENV['BEAKER_PUPPET_COLLECTION'] || 'puppet5'
end

UNSUPPORTED_PLATFORMS = ['Suse','AIX','Solaris']
if Gem.win_platform?
set :backend, :cmd
end

if Gem.win_platform?
# Normally provided by beaker but can't load beaker for Windows run tests
# that run locally in appveyor.
def fact(v)
if v == 'osfamily'
'windows'
end
end
end

RSpec.configure do |c|
# Readable test descriptions
c.formatter = :documentation

# Configure all nodes in nodeset
c.before :suite do
# Install module and dependencies
hosts.each do |host|
if fact('osfamily') == 'RedHat' && fact('operatingsystem') != 'Amazon'
# CentOS has epel-release package in Extras, enabled by default
shell('yum -y install epel-release')
end
# Install sensu to ensure no conflicts
on host, puppet('module', 'install', 'sensu-sensu'), { :acceptable_exit_codes => [0,1] }
on host, puppet('module', 'install', 'puppet-rabbitmq'), { :acceptable_exit_codes => [0,1] }
on host, puppet('module', 'install', 'fsalum-redis'), { :acceptable_exit_codes => [0,1] }
on host, puppet('module', 'install', 'puppetlabs-apt'), { :acceptable_exit_codes => [0,1] }
on host, puppet('module', 'install', 'puppetlabs-dsc'), { :acceptable_exit_codes => [0,1] }
on host, puppet('module', 'install', 'puppetlabs-acl'), { :acceptable_exit_codes => [0,1] }
on host, puppet('module', 'install', 'puppetlabs-powershell'), { :acceptable_exit_codes => [0,1] }
if collection == 'puppet6'
on hosts, puppet('module', 'install', 'puppetlabs-yumrepo_core', '--version', '">= 1.0.1 < 2.0.0"'), { :acceptable_exit_codes => [0,1] }
if ! Gem.win_platform?
# Install module and dependencies
hosts.each do |host|
if fact('osfamily') == 'RedHat' && fact('operatingsystem') != 'Amazon'
# CentOS has epel-release package in Extras, enabled by default
shell('yum -y install epel-release')
end
on host, puppet('module', 'install', 'sensu-sensu'), { :acceptable_exit_codes => [0,1] }
on host, puppet('module', 'install', 'puppet-rabbitmq'), { :acceptable_exit_codes => [0,1] }
on host, puppet('module', 'install', 'fsalum-redis'), { :acceptable_exit_codes => [0,1] }
on host, puppet('module', 'install', 'puppetlabs-apt'), { :acceptable_exit_codes => [0,1] }
on host, puppet('module', 'install', 'puppetlabs-dsc'), { :acceptable_exit_codes => [0,1] }
on host, puppet('module', 'install', 'puppetlabs-acl'), { :acceptable_exit_codes => [0,1] }
on host, puppet('module', 'install', 'puppetlabs-powershell'), { :acceptable_exit_codes => [0,1] }
if collection == 'puppet6'
on hosts, puppet('module', 'install', 'puppetlabs-yumrepo_core', '--version', '">= 1.0.1 < 2.0.0"'), { :acceptable_exit_codes => [0,1] }
end
end
end
end
Expand Down

0 comments on commit 808e05a

Please sign in to comment.