Skip to content

Commit

Permalink
Merge pull request #642 from mhashizume/MODULES-11364/main/install-pu…
Browse files Browse the repository at this point in the history
…ppet8

(PA-5242) Updates install tasks for puppet8
  • Loading branch information
mhashizume committed Mar 16, 2023
2 parents 24a3836 + 94112f8 commit 023a1b2
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 82 deletions.
5 changes: 2 additions & 3 deletions rakelib/commits.rake
Expand Up @@ -7,12 +7,11 @@ task(:commits) do
%x{git log --no-merges --pretty=%s #{commit_range}}.each_line do |commit_summary|
# This regex tests for the currently supported commit summary tokens.
# The exception tries to explain it in more full.
if /^\((maint|packaging|doc|docs|fm-\d+|modules-\d+)\)|revert/i.match(commit_summary).nil?
if /^\((maint|packaging|doc|docs|pa-\d+)\)|revert/i.match(commit_summary).nil?
raise "\n\n\n\tThis commit summary didn't match CONTRIBUTING.md guidelines:\n" \
"\n\t\t#{commit_summary}\n" \
"\tThe commit summary (i.e. the first line of the commit message) should start with one of:\n" \
"\t\t(MODULES-<digits>) # this is most common and should be a ticket at tickets.puppet.com\n" \
"\t\t(FM-<digits>)\n" \
"\t\t(PA-<digits>) # this is most common and should be a ticket at tickets.puppet.com\n" \
"\t\t(docs)\n" \
"\t\t(docs)(DOCUMENT-<digits>)\n" \
"\t\t(packaging)\n"
Expand Down
143 changes: 74 additions & 69 deletions task_spec/spec/acceptance/init_spec.rb
Expand Up @@ -43,55 +43,44 @@ def log_output_errors(result)
# OS, you'll typically want to specify 'latest' to install from nightlies, since
# official packages won't be released until later. During the N+1 release, you'll
# want to change `target_platform` to be the first version (N) that added the OS.
puppet_6_version = case target_platform
puppet_7_version = case target_platform
when %r{debian-11}
'6.24.0'
'7.9.0'
when %r{el-9}
'6.26.0'
when %r{fedora-30}
'6.19.1'
when %r{fedora-31}
'6.20.0'
when %r{osx-10.14}
'6.18.0'
when %r{osx-10.15}
'6.15.0'
when %r{osx-11}
'6.23.0'
when %r{osx-12-x86_64}
'6.27.1'
when %r{osx-12-arm}, %r{ubuntu-22.04}
'6.28.0'
'7.14.0'
when %r{fedora-36}
'latest'
'7.19.0'
when %r{osx-11}
'7.7.0'
when %r{osx-12}, %r{ubuntu-22.04}
'7.18.0'
else
'6.17.0'
'7.18.0'
end

# platforms that only have nightly builds available. Once a platform
# Platforms that only have nightly builds available. Once a platform
# is released, it should be removed from this list.
case target_platform
when %r{fedora-36}
puppet_6_collection = 'puppet6-nightly'
puppet_7_collection = 'puppet7-nightly'
else
puppet_6_collection = 'puppet6'
puppet_7_collection = 'puppet7'
end

# we can only tests puppet 6.x -> 6.y upgrades if there multiple versions
# Once there a platform has been released more than once, it can be removed
# from this list.
multiple_puppet6_versions = case target_platform
when %r{osx-12-arm}
false
when %r{ubuntu-22.04}
false
when %r{fedora-36}
false
else
true
end
# case target_platform
# when %r{fedora-36}
# puppet_7_collection = 'puppet7-nightly'
# puppet_8_collection = 'puppet8-nightly'
# else
puppet_7_collection = 'puppet7'
# We currently only have nightly builds of puppet8 available. Update
# this to the normal collection once we have a release.
puppet_8_collection = 'puppet8-nightly'
# end

# We can only test puppet 7 -> 7 upgrades if multiple Puppet releases
# have supported a given platform. Once a platform has been supported
# by multiple Puppet releases, it can be removed from this list.
# multiple_puppet7_versions = case target_platform
# when %r{osx-12-arm}
# false
# else
# true
# end
multiple_puppet7_versions = true

# extra request is needed on windows hosts
# this will fail with "execution expired"
Expand All @@ -104,9 +93,9 @@ def log_output_errors(result)
expect(res['value']['version']).to eq(nil)
end

# Try to install an older puppet6 version
results = run_task('puppet_agent::install', 'target', { 'collection' => puppet_6_collection,
'version' => puppet_6_version,
# Try to install an older puppet7 version
results = run_task('puppet_agent::install', 'target', { 'collection' => puppet_7_collection,
'version' => puppet_7_version,
'stop_service' => true })

results.each do |result|
Expand All @@ -116,14 +105,14 @@ def log_output_errors(result)

expect(results).to all(include('status' => 'success'))

# It installed a version older than latest puppet6
# It installed a version older than latest puppet7
results = run_task('puppet_agent::version', 'target', {})
results.each do |res|
expect(res).to include('status' => 'success')
if puppet_6_version == 'latest'
expect(res['value']['version']).to match(%r{^6\.\d+\.\d+})
if puppet_7_version == 'latest'
expect(res['value']['version']).to match(%r{^7\.\d+\.\d+})
else
expect(res['value']['version']).to eq(puppet_6_version)
expect(res['value']['version']).to eq(puppet_7_version)
end
expect(res['value']['source']).to be
end
Expand All @@ -139,7 +128,7 @@ def log_output_errors(result)

# Try to upgrade with no specific version given in parameter
# Expect nothing to happen and receive a message regarding this
results = run_task('puppet_agent::install', 'target', { 'collection' => puppet_6_collection })
results = run_task('puppet_agent::install', 'target', { 'collection' => puppet_7_collection })

results.each do |result|
logger.info("Ensuring installed puppet-agent on #{result['target']}: #{result['status']}")
Expand All @@ -155,23 +144,23 @@ def log_output_errors(result)
results = run_task('puppet_agent::version', 'target', {})
results.each do |res|
expect(res).to include('status' => 'success')
if puppet_6_version == 'latest'
expect(res['value']['version']).to match(%r{^6\.\d+\.\d+})
if puppet_7_version == 'latest'
expect(res['value']['version']).to match(%r{^7\.\d+\.\d+})
else
expect(res['value']['version']).to eq(puppet_6_version)
expect(res['value']['version']).to eq(puppet_7_version)
end
expect(res['value']['source']).to be
end

# An OS needs to be supported for more than one 6.x release to test the
# upgrade from puppet_6_version to latest
if multiple_puppet6_versions
# An OS needs to be supported for more than one 7.x release to test the
# upgrade from puppet_7_version to latest
if multiple_puppet7_versions

# Upgrade to latest puppet6 version
results = run_task('puppet_agent::install', 'target', { 'collection' => 'puppet6', 'version' => 'latest' })
# Upgrade to latest puppet7 version
results = run_task('puppet_agent::install', 'target', { 'collection' => 'puppet7', 'version' => 'latest' })

results.each do |result|
logger.info("Upgraded puppet-agent to latest puppet6 on #{result['target']}: #{result['status']}")
logger.info("Upgraded puppet-agent to latest puppet7 on #{result['target']}: #{result['status']}")
log_output_errors(result)
end

Expand All @@ -181,8 +170,8 @@ def log_output_errors(result)
results = run_task('puppet_agent::version', 'target', {})
results.each do |res|
expect(res).to include('status' => 'success')
expect(res['value']['version']).not_to eq(puppet_6_version)
expect(res['value']['version']).to match(%r{^6\.\d+\.\d+})
expect(res['value']['version']).not_to eq(puppet_7_version)
expect(res['value']['version']).to match(%r{^7\.\d+\.\d+})
expect(res['value']['source']).to be
end
end
Expand All @@ -202,30 +191,46 @@ def log_output_errors(result)
expect(output).to match(%r{ensure\s+=> 'stopped'})
end

# Succesfully upgrade from puppet6 to puppet7
results = run_task('puppet_agent::install', 'target', { 'collection' => puppet_7_collection, 'version' => 'latest' })
# Succesfully upgrade from puppet7 to puppet8
results = run_task('puppet_agent::install', 'target', { 'collection' => puppet_8_collection, 'version' => 'latest' })

results.each do |result|
logger.info("Upgraded puppet-agent to puppet7 on #{result['target']}: #{result['status']}")
logger.info("Upgraded puppet-agent to puppet8 on #{result['target']}: #{result['status']}")
log_output_errors(result)
end

expect(results).to all(include('status' => 'success'))

# Verify that it upgraded
installed_version = nil
results = run_task('puppet_agent::version', 'target', {})
# With prerelease puppet8, the puppet_agent::version task returns the wrong
# output. To temporarily work around this, we'll run puppet --version.
# Revert this change once Puppet 8.0.0 has been released.
# results = run_task('puppet_agent::version', 'target', {})
results = if %r{win}.match?(target_platform)
run_command('c:/"program files"/"puppet labs"/puppet/bin/puppet --version', 'target')
else
run_command('/opt/puppetlabs/bin/puppet --version', 'target')
end
results.each do |res|
expect(res).to include('status' => 'success')
installed_version = res['value']['stdout']
expect(installed_version).not_to match(%r{^7\.\d+\.\d+})
expect(installed_version).to match(%r{^8\.\d+\.\d+})
# We don't get the expected output with prerelease puppet8
# expect(res['value']['source']).to be
end

# More prerelease puppet8 workarounds, this block can also be deleted
# once Puppet 8.0.0 has been released.
results = run_task('puppet_agent::version', 'target', {})
results.each do |res|
installed_version = res['value']['version']
expect(installed_version).not_to match(%r{^6\.\d+\.\d+})
expect(installed_version).to match(%r{^7\.\d+\.\d+})
expect(res['value']['source']).to be
end

# Try installing the same version again
# Expect nothing to happen and receive a message regarding this
results = run_task('puppet_agent::install', 'target', { 'collection' => puppet_7_collection, 'version' => installed_version })
results = run_task('puppet_agent::install', 'target', { 'collection' => puppet_8_collection, 'version' => installed_version })

results.each do |res|
expect(res).to include('status' => 'success')
Expand Down
2 changes: 1 addition & 1 deletion tasks/install.json
Expand Up @@ -7,7 +7,7 @@
},
"collection": {
"description": "The Puppet collection to install from (defaults to puppet, which maps to the latest collection released)",
"type": "Optional[Enum[puppet6, puppet7, puppet, puppet6-nightly, puppet7-nightly, puppet-nightly]]"
"type": "Optional[Enum[puppet7, puppet, puppet7-nightly, puppet8-nightly, puppet-nightly]]"
},
"absolute_source": {
"description": "The absolute source location to find the Puppet agent package",
Expand Down
2 changes: 1 addition & 1 deletion tasks/install_powershell.json
Expand Up @@ -8,7 +8,7 @@
},
"collection": {
"description": "The Puppet collection to install from (defaults to puppet, which maps to the latest collection released)",
"type": "Optional[Enum[puppet6, puppet7, puppet, puppet6-nightly, puppet7-nightly, puppet-nightly]]"
"type": "Optional[Enum[puppet7, puppet, puppet7-nightly, puppet8-nightly, puppet-nightly]]"
},
"absolute_source": {
"description": "The absolute source location to find the Puppet agent package",
Expand Down
2 changes: 1 addition & 1 deletion tasks/install_shell.json
Expand Up @@ -9,7 +9,7 @@
},
"collection": {
"description": "The Puppet collection to install from (defaults to puppet, which maps to the latest collection released)",
"type": "Optional[Enum[puppet6, puppet7, puppet, puppet6-nightly, puppet7-nightly, puppet-nightly]]"
"type": "Optional[Enum[puppet7, puppet, puppet7-nightly, puppet8-nightly, puppet-nightly]]"
},
"absolute_source": {
"description": "The absolute source location to find the Puppet agent package",
Expand Down
14 changes: 7 additions & 7 deletions tasks/install_shell.sh
Expand Up @@ -40,15 +40,15 @@ exists() {
# Check whether the apt config file has been modified, warning and exiting early if it has
assert_unmodified_apt_config() {
puppet_list=/etc/apt/sources.list.d/puppet.list
puppet6_list=/etc/apt/sources.list.d/puppet6.list
puppet7_list=/etc/apt/sources.list.d/puppet7.list
puppet8_list=/etc/apt/sources.list.d/puppet8.list

if [[ -f $puppet_list ]]; then
list_file=puppet_list
elif [[ -f $puppet6_list ]]; then
list_file=puppet6_list
elif [[ -f $puppet7_list ]]; then
list_file=puppet7_list
elif [[ -f $puppet8_list ]]; then
list_file=puppet8_list
fi

# If puppet.list exists, get its md5sum on disk and its md5sum from the puppet-release package
Expand Down Expand Up @@ -219,15 +219,15 @@ if [ -f "$PT__installdir/facts/tasks/bash.sh" ]; then
platform_version=`sed 's/^.\+ release \([.0-9]\+\).*/\1/' /etc/redhat-release`
fi

# Handle OSX
# Handle macOS
elif test "x$platform" = "xDarwin"; then
platform="mac_os_x"
# Matching the tab-space with sed is error-prone
platform_version=`sw_vers | awk '/^ProductVersion:/ { print $2 }'`

major_version=`echo $platform_version | cut -d. -f1,2`

# Excepting MacOS 10.x, the major version is the first number only
# Excepting macOS 10.x, the major version is the first number only
if ! echo "${major_version}" | grep -q '^10\.'; then
major_version=$(echo "${major_version}" | cut -d '.' -f 1);
fi
Expand Down Expand Up @@ -305,7 +305,7 @@ if test "x$TMPDIR" = "x"; then
tmp="/tmp"
else
tmp=${TMPDIR}
# TMPDIR has trailing file sep for OSX test box
# TMPDIR has trailing file sep for macOS test box
penultimate=$((${#tmp}-1))
if test "${tmp:$penultimate:1}" = "/"; then
tmp="${tmp:0:$penultimate}"
Expand Down Expand Up @@ -654,7 +654,7 @@ case $platform in
download_url="${apt_source}/${filename}"
;;
"mac_os_x")
info "OSX platform! Lets get you a DMG..."
info "Mac platform! Lets get you a DMG..."
filetype="dmg"
if test "$version" = "latest"; then
filename="puppet-agent-latest.dmg"
Expand Down

0 comments on commit 023a1b2

Please sign in to comment.