Skip to content

Commit

Permalink
Merge pull request #639 from mhashizume/MODULES-11392/main/puppet8-test
Browse files Browse the repository at this point in the history
(MODULES-11392) Add Puppet 7 to 8 upgrade test
  • Loading branch information
mhashizume authored Mar 9, 2023
2 parents 0974891 + 77830dc commit 8c36ace
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 25 deletions.
4 changes: 2 additions & 2 deletions acceptance/Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ task :ci do
begin
Rake.application['prepare'].invoke
case ENV['MASTER_COLLECTION']
when /puppet6/
beaker('exec ./tests/test_upgrade_puppet5_to_puppet6.rb')
when /puppet7/
beaker('exec ./tests/test_upgrade_puppet6_to_puppet7.rb')
when /puppet8/
beaker('exec ./tests/test_upgrade_puppet7_to_puppet8.rb')
end
ensure
beaker('destroy')
Expand Down
25 changes: 8 additions & 17 deletions acceptance/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,9 @@ def require_master_collection(args)
if args.is_a?(Symbol)
collection = args.to_s

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

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

install_dev_puppet_module_on(host,
source: File.join(File.dirname(__FILE__), '..'),
Expand Down Expand Up @@ -251,8 +252,6 @@ def set_up_initial_agent_on(host, initial_package_version_or_collection)
on(host, puppet('resource', 'service', 'puppet', 'ensure=stopped'))
end

server_version = puppetserver_version_on(master)

step '(Agent) configure server setting on agent' do
on(host, puppet("config set server #{master}"))
end
Expand All @@ -263,11 +262,7 @@ def set_up_initial_agent_on(host, initial_package_version_or_collection)

agent_certname = fact_on(host, 'fqdn')
step '(Master) Sign certs' do
if version_is_less('5.99.99', server_version)
on(master, "puppetserver ca sign --certname #{agent_certname}")
else
on(master, puppet("cert sign #{agent_certname}"))
end
on(master, "puppetserver ca sign --certname #{agent_certname}")
end

teardowns << -> do
Expand Down Expand Up @@ -400,11 +395,7 @@ def remove_installed_agent(host)
# @param [String] agent_certname The name of the cert to remove from the master
def clean_agent_certificate(agent_certname)
step "Teardown: (Master) Clean agent #{agent_certname} cert" do
if version_is_less('5.99.99', puppetserver_version_on(master))
on(master, "puppetserver ca clean --certname #{agent_certname}")
else
on(master, puppet("cert clean #{agent_certname}"))
end
on(master, "puppetserver ca clean --certname #{agent_certname}")
end
end
end
Expand Down
10 changes: 5 additions & 5 deletions acceptance/pre_suite/00_master_setup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@

step 'Install puppetserver' do
# puppetserver is distributed in "release streams" instead of collections.
opts = if %r{^pc1$}i.match?(install_options[:puppet_collection])
# There is no release stream that's equivalent to the PC1 (puppet-agent
# 1.y.z/puppet 4) collection; This version is fine.
{ version: '2.8.1' }

# Dirty, temporary workaround for when we have puppet8 agent nightlies but not server nightlies
# Once we have puppet8 server releases, pare down to just what's in the else statement
opts = if install_options[:puppet_collection].include?('nightly')
{ release_stream: 'puppet7' }
else
# puppet collections _do_ match with server release streams from puppet 5 onward.
{ release_stream: install_options[:puppet_collection] }
end

Expand Down
69 changes: 69 additions & 0 deletions acceptance/tests/test_upgrade_puppet7_to_puppet8.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
require 'beaker-puppet'
require_relative '../helpers'

# Tests FOSS upgrades from the latest Puppet 7 (the puppet7-nightly collection)
# to the latest puppet8-nightly build.
test_name 'puppet_agent class: Upgrade agents from puppet7 to puppet8' do
require_master_collection 'puppet8-nightly'
exclude_pe_upgrade_platforms
latest_version = `curl https://builds.delivery.puppetlabs.net/passing-agent-SHAs/puppet-agent-main-version`

puppet_testing_environment = new_puppet_testing_environment

step 'Create new site.pp with upgrade manifest' do
# In previous versions of this manifest, Windows and macOS downloaded the package with the latest SHA
# Due to issues with versioning Puppet 8 in its prerelease stage, we'll use auto for now.
manifest = <<-PP
node default {
if $facts['os']['family'] in ['solaris', 'aix'] {
$_package_version = '#{latest_version}'
} elsif $facts['os']['family'] in ['darwin', 'windows'] {
$_package_version = 'auto'
} else {
$_package_version = 'latest'
}
class { puppet_agent:
package_version => $_package_version,
apt_source => 'https://nightlies.puppet.com/apt',
yum_source => 'https://nightlies.puppet.com/yum',
mac_source => 'https://nightlies.puppet.com/downloads',
windows_source => 'https://nightlies.puppet.com/downloads',
collection => 'puppet8-nightly',
service_names => []
}
}
PP
site_pp_path = File.join(environment_location(puppet_testing_environment), 'manifests', 'site.pp')
create_remote_file(master, site_pp_path, manifest)
on(master, %(chown #{puppet_user(master)} "#{site_pp_path}"))
on(master, %(chmod 755 "#{site_pp_path}"))
end

agents_only.each do |agent|
set_up_initial_agent_on(agent, 'puppet7-nightly') do
step '(Agent) Change agent environment to testing environment' do
on(agent, puppet("config --section agent set environment #{puppet_testing_environment}"))
on(agent, puppet('config --section user set environment production'))
end
end
end

step 'Upgrade the agents from Puppet 7 to Puppet 8...' do
agents_only.each do |agent|
on(agent, puppet('agent -t --debug'), acceptable_exit_codes: 2)
wait_for_installation_pid(agent)
# The aio_agent_version fact reports the wrong version for puppet8 prerelease nightlies
# Use this statement instead after the Puppet 8.0.0 release
# assert(puppet_agent_version_on(agent) =~ %r{^8\.\d+\.\d+.*})
puppet_version = on(agent, puppet('--version')).output
assert(puppet_version.start_with?('8.'))
end
end

step 'Run again for idempotency' do
agents_only.each do |agent|
on(agent, puppet('agent -t --debug'), acceptable_exit_codes: 0)
end
end
end
2 changes: 1 addition & 1 deletion spec/spec_helper_acceptance.rb
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ def teardown_puppet_on(host)
# the machine after each run.
case host['platform']
when %r{debian|ubuntu}
on host, '/opt/puppetlabs/bin/puppet module install puppetlabs-apt --version 7.7.1', { acceptable_exit_codes: [0, 1] }
on host, '/opt/puppetlabs/bin/puppet module install puppetlabs-apt --version 9.0.0', { acceptable_exit_codes: [0, 1] }
clean_repo = "include apt\napt::source { 'pc_repo': ensure => absent, notify => Package['puppet-agent'] }"
when %r{fedora|el|centos}
clean_repo = "yumrepo { 'pc_repo': ensure => absent, notify => Package['puppet-agent'] }"
Expand Down

0 comments on commit 8c36ace

Please sign in to comment.