Skip to content

Commit 2d98e57

Browse files
authored
Merge pull request #49 from jpartlow/openvox-gha-acceptance-7.x
(gh-21) Openvox gha acceptance for the 7.x branch
2 parents af1929f + a9483b4 commit 2d98e57

9 files changed

Lines changed: 221 additions & 29 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
# Acceptance tests
88
/junit/
99
/log/
10+
/.beaker
1011

1112
# Emacs
1213
*#

Gemfile

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,11 @@ group :test do
3636

3737
case puppet_ref
3838
when "latest"
39-
gem 'puppet', ">= #{oldest_supported_puppet}", :require => false
39+
gem 'openvox', ">= #{oldest_supported_puppet}", :require => false
4040
when "oldest"
41-
gem 'puppet', oldest_supported_puppet, :require => false
41+
gem 'openvox', oldest_supported_puppet, :require => false
4242
else
43-
gem 'puppet', :git => 'https://github.com/puppetlabs/puppet.git',
43+
gem 'openvox', :git => 'https://github.com/openvoxproject/openvox.git',
4444
:ref => puppet_ref, :require => false
4545
end
4646

@@ -61,12 +61,9 @@ if ENV['NO_ACCEPTANCE'] != 'true'
6161
gem 'beaker', *location_for(beaker_version)
6262
else
6363
# use the pinned version
64-
gem 'beaker', '~> 4.1'
64+
gem 'beaker', '~> 6.0'
6565
end
6666
gem 'beaker-hostgenerator', '~> 2.4'
67-
gem 'beaker-abs', *location_for(ENV['BEAKER_ABS_VERSION'] || '~> 0.2')
68-
gem 'beaker-vmpooler', *location_for(ENV['BEAKER_VMPOOLER_VERSION'] || "~> 1.3")
69-
gem 'beaker-puppet', '~> 1.0'
70-
gem 'faraday', '~> 1.8.0'
67+
gem 'beaker-puppet', '~> 4.0'
7168
end
7269
end

acceptance/helper.rb

Lines changed: 156 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
require 'test/unit/assertions'
99
require 'json'
1010
require 'inifile'
11+
require 'mkmf' # provides find_executable()
1112

1213
module PuppetDBExtensions
1314
include Test::Unit::Assertions
@@ -63,6 +64,12 @@ def self.initialize_test_config(options, os_families)
6364
"'purge packages and perform exhaustive cleanup after run'",
6465
"PUPPETDB_PURGE_AFTER_RUN", :false)
6566

67+
skip_openvox_package_installation =
68+
get_option_value(options[:puppetdb_skip_openvox_package_installation],
69+
[:true, :false],
70+
"'skip installation of openvox packages, since the test suite does not know how'",
71+
"PUPPETDB_SKIP_OPENVOX_PACKAGE_INSTALLATION", :true)
72+
6673
skip_presuite_provisioning =
6774
get_option_value(options[:puppetdb_skip_presuite_provisioning],
6875
[:true, :false],
@@ -130,6 +137,7 @@ def self.initialize_test_config(options, os_families)
130137
:repo_hiera => puppetdb_repo_hiera,
131138
:repo_facter => puppetdb_repo_facter,
132139
:git_ref => puppetdb_git_ref,
140+
:skip_openvox_package_installation => skip_openvox_package_installation == :true,
133141
:skip_presuite_provisioning => skip_presuite_provisioning == :true,
134142
:nightly => nightly == :true
135143
}
@@ -195,7 +203,7 @@ def populate_facts
195203
end
196204

197205
def get_os_family(host)
198-
on(host, "which yum", :silent => true)
206+
result = on(host, "which yum", :silent => true)
199207
if result.exit_code == 0
200208
:redhat
201209
else
@@ -235,7 +243,7 @@ def puppetdb_pids(host)
235243

236244
def start_puppetdb(host)
237245
step "Starting PuppetDB" do
238-
on host, "service puppetdb start"
246+
on(host, puppet_resource('service', 'puppetdb', 'ensure=running'))
239247
sleep_until_started(host)
240248
end
241249
end
@@ -462,6 +470,70 @@ def install_puppetdb_module(hosts, puppet_platform)
462470
on(hosts, 'puppet module install puppetlabs-puppetdb --version 7.14.0')
463471
end
464472

473+
def setup_openvoxdb_certs(database)
474+
step 'Ensure PuppetDB certificates are setup' do
475+
# Normally the openvoxdb package automagically post-install runs
476+
# 'puppetdb ssl-setup', but this relies on the openvox-agent
477+
# already having certs generated at the time that the openvoxdb
478+
# package was installed. If we installed openvoxdb before
479+
# running the suite and before agent certs were generated, then
480+
# we need this step to ensure that openvoxdb now gets its certs.
481+
# (If they are already in place, the command should be
482+
# idempotent.)
483+
apply_manifest_on(database, <<~EOM)
484+
exec { 'puppetdb-prepare-certs':
485+
command => '/opt/puppetlabs/bin/puppetdb ssl-setup',
486+
path => '/bin:/sbin:/usr/bin',
487+
onlyif => 'test -f /opt/puppetlabs/bin/puppetdb',
488+
}
489+
EOM
490+
end
491+
end
492+
493+
# Use the puppetdb module to configure pre-installed openvoxdb
494+
# and packages.
495+
def configure_openvoxdb(host)
496+
manifest = <<~EOS
497+
class { 'puppetdb':
498+
puppetdb_package => 'openvoxdb',
499+
manage_firewall => false,
500+
manage_package_repo => true,
501+
disable_update_checking => true,
502+
database_listen_address => 'localhost',
503+
postgres_version => '14',
504+
database_name => 'puppetdb',
505+
database_username => 'puppetdb',
506+
database_password => 'puppetdb',
507+
read_database_username => 'puppetdb-read',
508+
read_database_password => 'puppetdb-read',
509+
}
510+
EOS
511+
apply_manifest_on(host, manifest)
512+
print_ini_files(host)
513+
sleep_until_started(host)
514+
end
515+
516+
def configure_openvoxdb_termini(host, databases)
517+
server_urls = databases.map {|db| "https://#{db.node_name}:8081"}.join(',')
518+
manifest = <<~EOS
519+
class { 'puppetdb::master::config':
520+
terminus_package => 'openvoxdb-termini',
521+
puppetdb_startup_timeout => 120,
522+
manage_report_processor => true,
523+
enable_reports => true,
524+
strict_validation => true,
525+
}
526+
ini_setting {'server_urls':
527+
ensure => present,
528+
section => 'main',
529+
path => "${puppetdb::params::puppet_confdir}/puppetdb.conf",
530+
setting => 'server_urls',
531+
value => '#{server_urls}',
532+
}
533+
EOS
534+
apply_manifest_on(host, manifest)
535+
end
536+
465537
def install_puppetdb(host, version=nil)
466538
manifest = <<-EOS
467539
class { 'puppetdb::globals':
@@ -554,23 +626,37 @@ def enable_https_apt_sources(host)
554626
apply_manifest_on(host, manifest)
555627
end
556628

629+
# Work around for testing on rhel and the repos on the image
630+
# not finding the pg packages it needs.
631+
# TODO: figure out why puppetdb module isn't managing this?
632+
def configure_postgresql_repos_on_el(host)
633+
if host.platform =~ /el-/
634+
step 'Update EL postgresql repos' do
635+
major_version = host.platform.split('-')[1]
636+
637+
on(host, "dnf install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-#{major_version}-x86_64/pgdg-redhat-repo-latest.noarch.rpm")
638+
on(host, "dnf -qy module disable postgresql")
639+
end
640+
end
641+
end
642+
557643
def postgres_manifest
558644
# bionic and buster are EOL, so the pgdg repos were removed.
559645
# For RedHat, the versions of the module that support upgrade_oldest
560646
# tests from Puppet 6 configure the wrong GPG key
561647
manage_package_repo = ! ( is_bionic || is_buster || is_el )
562648

563-
manifest = <<-EOS
649+
manifest = <<~EOS
564650
# create the puppetdb database
565651
class { '::puppetdb::database::postgresql':
566-
listen_addresses => 'localhost',
567-
manage_package_repo => #{manage_package_repo},
568-
postgres_version => '14',
569-
database_name => 'puppetdb',
570-
database_username => 'puppetdb',
571-
database_password => 'puppetdb',
572-
read_database_username => 'puppetdb-read',
573-
read_database_password => 'puppetdb-read',
652+
listen_addresses => 'localhost',
653+
manage_package_repo => #{manage_package_repo},
654+
postgres_version => '14',
655+
database_name => 'puppetdb',
656+
database_username => 'puppetdb',
657+
database_password => 'puppetdb',
658+
read_database_username => 'puppetdb-read',
659+
read_database_password => 'puppetdb-read',
574660
}
575661
EOS
576662
manifest
@@ -653,11 +739,11 @@ class { 'puppetdb::master::report_processor':
653739
end
654740

655741
def stop_puppetdb(host)
656-
pids = puppetdb_pids(host)
657-
658-
on host, "service puppetdb stop"
659-
660-
sleep_until_stopped(host, pids)
742+
step 'Stopping PuppetDB' do
743+
pids = puppetdb_pids(host)
744+
on(host, puppet_resource('service', 'puppetdb', 'ensure=stopped'))
745+
sleep_until_stopped(host, pids)
746+
end
661747
end
662748

663749
def sleep_until_stopped(host, pids)
@@ -758,7 +844,7 @@ def curl_with_retries(desc, host, curl_args, desired_exit_codes, max_retries = 6
758844
desired_exit_codes = [desired_exit_codes].flatten
759845
result = on host, command, :acceptable_exit_codes => (0...127), :silent => true
760846
num_retries = 0
761-
until desired_exit_codes.include?(exit_code) and (result.stdout =~ expected_output)
847+
until desired_exit_codes.include?(result.exit_code) and (result.stdout =~ expected_output)
762848
sleep retry_interval
763849
result = on host, command, :acceptable_exit_codes => (0...127), :silent => true
764850
num_retries += 1
@@ -1035,5 +1121,58 @@ def database
10351121
end
10361122
end
10371123

1124+
module Beaker
1125+
module DSL
1126+
module Helpers
1127+
module PuppetServerAcceptance
1128+
# A sad little abstraction around service/systemctl to handle
1129+
# os differences for edge cases not suited to puppet resource
1130+
# service calls.
1131+
def service(host, action, service_name, acceptable_exit_codes: [0])
1132+
if find_executable('systemctl')
1133+
command = Command.new("systemctl #{action} #{service_name}")
1134+
elsif find_executable('service')
1135+
command = Command.new("service #{service_name} #{action}")
1136+
else
1137+
raise "Neither systemctl nor service found on #{host.name}"
1138+
end
1139+
1140+
host.exec(command, acceptable_exit_codes: acceptable_exit_codes)
1141+
end
1142+
1143+
# Override beaker-puppet BeakerPuppet::Helpers::PuppetHelpers#bounce_service
1144+
# to allow for systems that only have systemctl now (el9+, etc.)
1145+
#
1146+
# Ostensibly we should fork beaker-puppet...I'm just not quite
1147+
# ready to touch that yet...
1148+
#
1149+
# Restarts the named puppet service
1150+
#
1151+
# @param [Host] host Host the service runs on
1152+
# @param [String] service Name of the service to restart
1153+
# @param [Fixnum] curl_retries Number of seconds to wait for the restart to complete before failing
1154+
# @param [Fixnum] port Port to check status at
1155+
#
1156+
# @return [Result] Result of last status check
1157+
# @!visibility private
1158+
def bounce_service(host, service, curl_retries = nil, port = nil)
1159+
curl_retries = 120 if curl_retries.nil?
1160+
port = options[:puppetserver_port] if port.nil?
1161+
result = service(host, :reload, service, acceptable_exit_codes: [0, 1, 3])
1162+
return result if result.exit_code == 0
1163+
1164+
host.exec puppet_resource('service', service, 'ensure=stopped')
1165+
host.exec puppet_resource('service', service, 'ensure=running')
1166+
1167+
curl_with_retries(" #{service} ", host, "https://localhost:#{port}", [35, 60], curl_retries)
1168+
end
1169+
end
1170+
end
1171+
end
1172+
end
1173+
1174+
# Register the DSL extension
1175+
Beaker::DSL.register(Beaker::DSL::Helpers::PuppetServerAcceptance)
1176+
10381177
# oh dear.
10391178
Beaker::TestCase.send(:include, PuppetDBExtensions)

acceptance/options/openvox.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Set the option vars provided by acceptance/options/postgres.rb
2+
# without tying in the hardcoded pre-suite and test paths set
3+
# in acceptance/options/common.rb
4+
{
5+
:is_puppetserver => 'true',
6+
:'use-service' => 'true',
7+
:'puppetserver-confdir' => '/etc/puppetlabs/puppetserver/conf.d',
8+
:puppetservice => 'puppetserver',
9+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# This mirrors the structure of
2+
# setup/pre_suite/90_install_devel_puppetdb.rb, but just
3+
# configures rather than trying to install openvox packages.
4+
test_name('configure openvoxdb using the puppetdb module') do
5+
databases.each do
6+
setup_openvoxdb_certs(database)
7+
configure_postgresql_repos_on_el(database)
8+
configure_openvoxdb(database)
9+
10+
# The package should automatically start the service on debian.
11+
# On redhat, it doesn't. However, during test runs where we're
12+
# doing package upgrades, the redhat package *should* detect that
13+
# the service was running before the upgrade, and it should restart
14+
# it automatically.
15+
#
16+
# That leaves the case where we're on a redhat box and we're
17+
# running the tests as :install only (as opposed to :upgrade).
18+
# In that case we need to start the service ourselves here.
19+
os = test_config[:os_families][database.name]
20+
if test_config[:install_mode] == :install and [:redhat].include?(os)
21+
start_puppetdb(database)
22+
else
23+
# make sure it got started by the package install/upgrade
24+
sleep_until_started(database)
25+
end
26+
end
27+
28+
configure_openvoxdb_termini(master, databases)
29+
end
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Ensures that the /root/.ssh/environment file is
2+
# set up with a path that includes /opt/puppetlabs/bin.
3+
# Normally this would be called as part of beaker-puppet
4+
# install steps, but we are installing openvox packages outside
5+
# of beaker-puppet, since it doesn't handle openvox.
6+
test_name('configure root ssh environment path') do
7+
configure_type_defaults_on(agents)
8+
end
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
test_name 'Ensure en_US.UTF-8 locale is present on Debian for openvoxdb migrations' do
2+
confine :to, :platform => /^debian/
3+
on(master, puppet_resource('package', 'locales-all', 'ensure=present'))
4+
end

acceptance/setup/pre_suite/20_install_puppet.rb

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,14 @@
44
on(hosts, 'update-crypto-policies --set LEGACY')
55
end
66

7-
step "Install Puppet" do
8-
install_puppet(puppet_repo_version(test_config[:platform_version],
9-
test_config[:install_mode],
10-
test_config[:nightly]))
7+
if (test_config[:skip_openvox_package_installation])
8+
install_puppet_conf
9+
else
10+
step "Install Puppet" do
11+
install_puppet(puppet_repo_version(test_config[:platform_version],
12+
test_config[:install_mode],
13+
test_config[:nightly]))
14+
end
1115
end
1216
end
1317

acceptance/setup/pre_suite/90_install_devel_puppetdb.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
when :package
1515
Log.notify("Installing puppetdb from package; install mode: '#{test_config[:install_mode].inspect}'")
1616

17+
configure_postgresql_repos_on_el(database)
1718
enable_https_apt_sources(database)
1819
install_puppetdb(database)
1920

0 commit comments

Comments
 (0)