|
8 | 8 | require 'test/unit/assertions' |
9 | 9 | require 'json' |
10 | 10 | require 'inifile' |
| 11 | +require 'mkmf' # provides find_executable() |
11 | 12 |
|
12 | 13 | module PuppetDBExtensions |
13 | 14 | include Test::Unit::Assertions |
@@ -63,6 +64,12 @@ def self.initialize_test_config(options, os_families) |
63 | 64 | "'purge packages and perform exhaustive cleanup after run'", |
64 | 65 | "PUPPETDB_PURGE_AFTER_RUN", :false) |
65 | 66 |
|
| 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 | + |
66 | 73 | skip_presuite_provisioning = |
67 | 74 | get_option_value(options[:puppetdb_skip_presuite_provisioning], |
68 | 75 | [:true, :false], |
@@ -130,6 +137,7 @@ def self.initialize_test_config(options, os_families) |
130 | 137 | :repo_hiera => puppetdb_repo_hiera, |
131 | 138 | :repo_facter => puppetdb_repo_facter, |
132 | 139 | :git_ref => puppetdb_git_ref, |
| 140 | + :skip_openvox_package_installation => skip_openvox_package_installation == :true, |
133 | 141 | :skip_presuite_provisioning => skip_presuite_provisioning == :true, |
134 | 142 | :nightly => nightly == :true |
135 | 143 | } |
@@ -195,7 +203,7 @@ def populate_facts |
195 | 203 | end |
196 | 204 |
|
197 | 205 | def get_os_family(host) |
198 | | - on(host, "which yum", :silent => true) |
| 206 | + result = on(host, "which yum", :silent => true) |
199 | 207 | if result.exit_code == 0 |
200 | 208 | :redhat |
201 | 209 | else |
@@ -235,7 +243,7 @@ def puppetdb_pids(host) |
235 | 243 |
|
236 | 244 | def start_puppetdb(host) |
237 | 245 | step "Starting PuppetDB" do |
238 | | - on host, "service puppetdb start" |
| 246 | + on(host, puppet_resource('service', 'puppetdb', 'ensure=running')) |
239 | 247 | sleep_until_started(host) |
240 | 248 | end |
241 | 249 | end |
@@ -462,6 +470,70 @@ def install_puppetdb_module(hosts, puppet_platform) |
462 | 470 | on(hosts, 'puppet module install puppetlabs-puppetdb --version 7.14.0') |
463 | 471 | end |
464 | 472 |
|
| 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 | + |
465 | 537 | def install_puppetdb(host, version=nil) |
466 | 538 | manifest = <<-EOS |
467 | 539 | class { 'puppetdb::globals': |
@@ -554,23 +626,37 @@ def enable_https_apt_sources(host) |
554 | 626 | apply_manifest_on(host, manifest) |
555 | 627 | end |
556 | 628 |
|
| 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 | + |
557 | 643 | def postgres_manifest |
558 | 644 | # bionic and buster are EOL, so the pgdg repos were removed. |
559 | 645 | # For RedHat, the versions of the module that support upgrade_oldest |
560 | 646 | # tests from Puppet 6 configure the wrong GPG key |
561 | 647 | manage_package_repo = ! ( is_bionic || is_buster || is_el ) |
562 | 648 |
|
563 | | - manifest = <<-EOS |
| 649 | + manifest = <<~EOS |
564 | 650 | # create the puppetdb database |
565 | 651 | 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', |
574 | 660 | } |
575 | 661 | EOS |
576 | 662 | manifest |
@@ -653,11 +739,11 @@ class { 'puppetdb::master::report_processor': |
653 | 739 | end |
654 | 740 |
|
655 | 741 | 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 |
661 | 747 | end |
662 | 748 |
|
663 | 749 | def sleep_until_stopped(host, pids) |
@@ -758,7 +844,7 @@ def curl_with_retries(desc, host, curl_args, desired_exit_codes, max_retries = 6 |
758 | 844 | desired_exit_codes = [desired_exit_codes].flatten |
759 | 845 | result = on host, command, :acceptable_exit_codes => (0...127), :silent => true |
760 | 846 | 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) |
762 | 848 | sleep retry_interval |
763 | 849 | result = on host, command, :acceptable_exit_codes => (0...127), :silent => true |
764 | 850 | num_retries += 1 |
@@ -1035,5 +1121,58 @@ def database |
1035 | 1121 | end |
1036 | 1122 | end |
1037 | 1123 |
|
| 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 | + |
1038 | 1177 | # oh dear. |
1039 | 1178 | Beaker::TestCase.send(:include, PuppetDBExtensions) |
0 commit comments