Skip to content

Commit 8c36ace

Browse files
authored
Merge pull request #639 from mhashizume/MODULES-11392/main/puppet8-test
(MODULES-11392) Add Puppet 7 to 8 upgrade test
2 parents 0974891 + 77830dc commit 8c36ace

File tree

5 files changed

+85
-25
lines changed

5 files changed

+85
-25
lines changed

acceptance/Rakefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,10 @@ task :ci do
5454
begin
5555
Rake.application['prepare'].invoke
5656
case ENV['MASTER_COLLECTION']
57-
when /puppet6/
58-
beaker('exec ./tests/test_upgrade_puppet5_to_puppet6.rb')
5957
when /puppet7/
6058
beaker('exec ./tests/test_upgrade_puppet6_to_puppet7.rb')
59+
when /puppet8/
60+
beaker('exec ./tests/test_upgrade_puppet7_to_puppet8.rb')
6161
end
6262
ensure
6363
beaker('destroy')

acceptance/helpers.rb

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,9 @@ def require_master_collection(args)
8787
if args.is_a?(Symbol)
8888
collection = args.to_s
8989

90-
# puppet_collection_for doesn't know about nightly collections
91-
unless collection.include?(server_collection)
90+
# Dirty, temporary workaround for when we have puppet8 agent nightlies but not server nightlies
91+
# Once we have puppet8 server releases, remove the second conditional
92+
unless collection.include?(server_collection) || collection == 'puppet8-nightly'
9293
skip_test(msg_prefix + "\nThis test requires a puppetserver from the #{collection} collection. Skipping the test ...")
9394
end
9495

@@ -178,9 +179,9 @@ def new_puppet_testing_environment
178179
# @param [String] environment The puppet environment to install the modules to, this must
179180
# be a valid environment in the puppet install on the host.
180181
def install_puppet_agent_module_on(host, environment)
181-
on(host, puppet('module', 'install', 'puppetlabs-stdlib', '--version', '5.1.0', '--environment', environment), { acceptable_exit_codes: [0] })
182-
on(host, puppet('module', 'install', 'puppetlabs-inifile', '--version', '2.4.0', '--environment', environment), { acceptable_exit_codes: [0] })
183-
on(host, puppet('module', 'install', 'puppetlabs-apt', '--version', '7.7.1', '--environment', environment), { acceptable_exit_codes: [0] })
182+
on(host, puppet('module', 'install', 'puppetlabs-stdlib', '--version', '8.4.0', '--environment', environment), { acceptable_exit_codes: [0] })
183+
on(host, puppet('module', 'install', 'puppetlabs-inifile', '--version', '5.3.0', '--environment', environment), { acceptable_exit_codes: [0] })
184+
on(host, puppet('module', 'install', 'puppetlabs-apt', '--version', '9.0.0', '--environment', environment), { acceptable_exit_codes: [0] })
184185

185186
install_dev_puppet_module_on(host,
186187
source: File.join(File.dirname(__FILE__), '..'),
@@ -251,8 +252,6 @@ def set_up_initial_agent_on(host, initial_package_version_or_collection)
251252
on(host, puppet('resource', 'service', 'puppet', 'ensure=stopped'))
252253
end
253254

254-
server_version = puppetserver_version_on(master)
255-
256255
step '(Agent) configure server setting on agent' do
257256
on(host, puppet("config set server #{master}"))
258257
end
@@ -263,11 +262,7 @@ def set_up_initial_agent_on(host, initial_package_version_or_collection)
263262

264263
agent_certname = fact_on(host, 'fqdn')
265264
step '(Master) Sign certs' do
266-
if version_is_less('5.99.99', server_version)
267-
on(master, "puppetserver ca sign --certname #{agent_certname}")
268-
else
269-
on(master, puppet("cert sign #{agent_certname}"))
270-
end
265+
on(master, "puppetserver ca sign --certname #{agent_certname}")
271266
end
272267

273268
teardowns << -> do
@@ -400,11 +395,7 @@ def remove_installed_agent(host)
400395
# @param [String] agent_certname The name of the cert to remove from the master
401396
def clean_agent_certificate(agent_certname)
402397
step "Teardown: (Master) Clean agent #{agent_certname} cert" do
403-
if version_is_less('5.99.99', puppetserver_version_on(master))
404-
on(master, "puppetserver ca clean --certname #{agent_certname}")
405-
else
406-
on(master, puppet("cert clean #{agent_certname}"))
407-
end
398+
on(master, "puppetserver ca clean --certname #{agent_certname}")
408399
end
409400
end
410401
end

acceptance/pre_suite/00_master_setup.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@
3030

3131
step 'Install puppetserver' do
3232
# puppetserver is distributed in "release streams" instead of collections.
33-
opts = if %r{^pc1$}i.match?(install_options[:puppet_collection])
34-
# There is no release stream that's equivalent to the PC1 (puppet-agent
35-
# 1.y.z/puppet 4) collection; This version is fine.
36-
{ version: '2.8.1' }
33+
34+
# Dirty, temporary workaround for when we have puppet8 agent nightlies but not server nightlies
35+
# Once we have puppet8 server releases, pare down to just what's in the else statement
36+
opts = if install_options[:puppet_collection].include?('nightly')
37+
{ release_stream: 'puppet7' }
3738
else
38-
# puppet collections _do_ match with server release streams from puppet 5 onward.
3939
{ release_stream: install_options[:puppet_collection] }
4040
end
4141

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
require 'beaker-puppet'
2+
require_relative '../helpers'
3+
4+
# Tests FOSS upgrades from the latest Puppet 7 (the puppet7-nightly collection)
5+
# to the latest puppet8-nightly build.
6+
test_name 'puppet_agent class: Upgrade agents from puppet7 to puppet8' do
7+
require_master_collection 'puppet8-nightly'
8+
exclude_pe_upgrade_platforms
9+
latest_version = `curl https://builds.delivery.puppetlabs.net/passing-agent-SHAs/puppet-agent-main-version`
10+
11+
puppet_testing_environment = new_puppet_testing_environment
12+
13+
step 'Create new site.pp with upgrade manifest' do
14+
# In previous versions of this manifest, Windows and macOS downloaded the package with the latest SHA
15+
# Due to issues with versioning Puppet 8 in its prerelease stage, we'll use auto for now.
16+
manifest = <<-PP
17+
node default {
18+
if $facts['os']['family'] in ['solaris', 'aix'] {
19+
$_package_version = '#{latest_version}'
20+
} elsif $facts['os']['family'] in ['darwin', 'windows'] {
21+
$_package_version = 'auto'
22+
} else {
23+
$_package_version = 'latest'
24+
}
25+
26+
class { puppet_agent:
27+
package_version => $_package_version,
28+
apt_source => 'https://nightlies.puppet.com/apt',
29+
yum_source => 'https://nightlies.puppet.com/yum',
30+
mac_source => 'https://nightlies.puppet.com/downloads',
31+
windows_source => 'https://nightlies.puppet.com/downloads',
32+
collection => 'puppet8-nightly',
33+
service_names => []
34+
}
35+
}
36+
PP
37+
site_pp_path = File.join(environment_location(puppet_testing_environment), 'manifests', 'site.pp')
38+
create_remote_file(master, site_pp_path, manifest)
39+
on(master, %(chown #{puppet_user(master)} "#{site_pp_path}"))
40+
on(master, %(chmod 755 "#{site_pp_path}"))
41+
end
42+
43+
agents_only.each do |agent|
44+
set_up_initial_agent_on(agent, 'puppet7-nightly') do
45+
step '(Agent) Change agent environment to testing environment' do
46+
on(agent, puppet("config --section agent set environment #{puppet_testing_environment}"))
47+
on(agent, puppet('config --section user set environment production'))
48+
end
49+
end
50+
end
51+
52+
step 'Upgrade the agents from Puppet 7 to Puppet 8...' do
53+
agents_only.each do |agent|
54+
on(agent, puppet('agent -t --debug'), acceptable_exit_codes: 2)
55+
wait_for_installation_pid(agent)
56+
# The aio_agent_version fact reports the wrong version for puppet8 prerelease nightlies
57+
# Use this statement instead after the Puppet 8.0.0 release
58+
# assert(puppet_agent_version_on(agent) =~ %r{^8\.\d+\.\d+.*})
59+
puppet_version = on(agent, puppet('--version')).output
60+
assert(puppet_version.start_with?('8.'))
61+
end
62+
end
63+
64+
step 'Run again for idempotency' do
65+
agents_only.each do |agent|
66+
on(agent, puppet('agent -t --debug'), acceptable_exit_codes: 0)
67+
end
68+
end
69+
end

spec/spec_helper_acceptance.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ def teardown_puppet_on(host)
199199
# the machine after each run.
200200
case host['platform']
201201
when %r{debian|ubuntu}
202-
on host, '/opt/puppetlabs/bin/puppet module install puppetlabs-apt --version 7.7.1', { acceptable_exit_codes: [0, 1] }
202+
on host, '/opt/puppetlabs/bin/puppet module install puppetlabs-apt --version 9.0.0', { acceptable_exit_codes: [0, 1] }
203203
clean_repo = "include apt\napt::source { 'pc_repo': ensure => absent, notify => Package['puppet-agent'] }"
204204
when %r{fedora|el|centos}
205205
clean_repo = "yumrepo { 'pc_repo': ensure => absent, notify => Package['puppet-agent'] }"

0 commit comments

Comments
 (0)