|
| 1 | +plan peadm_spec::test_migration( |
| 2 | + String $primary_host, |
| 3 | + String $new_primary_host, |
| 4 | + Optional[String] $new_replica_host = undef, |
| 5 | + Optional[String] $new_primary_postgresql_host = undef, |
| 6 | + Optional[String] $new_replica_postgresql_host = undef, |
| 7 | + Optional[String] $upgrade_version = undef, |
| 8 | +) { |
| 9 | + # Convert String values to targets if they are not blank |
| 10 | + $primary_target = $primary_host ? { '' => undef, default => peadm::get_targets($primary_host, 1) } |
| 11 | + $new_primary_target = $new_primary_host ? { '' => undef, default => peadm::get_targets($new_primary_host, 1) } |
| 12 | + $new_replica_target = $new_replica_host ? { '' => undef, default => peadm::get_targets($new_replica_host, 1) } |
| 13 | + $new_primary_postgresql_target = $new_primary_postgresql_host ? { '' => undef, default => peadm::get_targets($new_primary_postgresql_host, 1) } |
| 14 | + $new_replica_postgresql_target = $new_replica_postgresql_host ? { '' => undef, default => peadm::get_targets($new_replica_postgresql_host, 1) } |
| 15 | + |
| 16 | + # run infra status on the primary |
| 17 | + out::message("Running peadm::status on primary host ${primary_target}") |
| 18 | + $primary_status = run_plan('peadm::status', $primary_target, { 'format' => 'json' }) |
| 19 | + out::message($primary_status) |
| 20 | + |
| 21 | + if empty($primary_status['failed']) { |
| 22 | + out::message('Cluster is healthy, continuing') |
| 23 | + } else { |
| 24 | + fail_plan('Cluster is not healthy, aborting') |
| 25 | + } |
| 26 | + |
| 27 | + # perform the migration |
| 28 | + run_plan('peadm::migrate', |
| 29 | + old_primary_host => $primary_target, |
| 30 | + new_primary_host => $new_primary_target, |
| 31 | + upgrade_version => $upgrade_version, |
| 32 | + replica_host => $new_replica_target, |
| 33 | + ) |
| 34 | + |
| 35 | + # run infra status on the new primary |
| 36 | + peadm::wait_until_service_ready('all', $new_primary_target) |
| 37 | + out::message("Running peadm::status on new primary host ${new_primary_target}") |
| 38 | + $new_primary_status = run_plan('peadm::status', $new_primary_target, { 'format' => 'json' }) |
| 39 | + if empty($new_primary_status['failed']) { |
| 40 | + out::message('Migrated cluster is healthy, continuing') |
| 41 | + } else { |
| 42 | + out::message('Migrated cluster is not healthy, verify status of services') |
| 43 | + } |
| 44 | + |
| 45 | + # get the config from new_primary_target and verify config looks as expected |
| 46 | + $peadm_config = run_task('peadm::get_peadm_config', $new_primary_target).first.value |
| 47 | + out::message("peadm_config:${peadm_config}.") |
| 48 | + # if new_replica_target is supplied then check that is in the expected place in the config |
| 49 | + if $new_replica_target { |
| 50 | + if $peadm_config['params']['replica_host'] == $new_replica_target.peadm::certname() { |
| 51 | + out::message("New replica host ${new_replica_target.peadm::certname()} set up correctly") |
| 52 | + } else { |
| 53 | + fail_plan("New replica host ${new_replica_target.peadm::certname()} was not set up correctly") |
| 54 | + } |
| 55 | + } |
| 56 | + |
| 57 | + # if new_primary_postgresql_target is supplied then check that is in the expected place in the config |
| 58 | + if $new_primary_postgresql_target { |
| 59 | + if $peadm_config['params']['primary_postgresql_host'] == $new_primary_postgresql_target.peadm::certname() { |
| 60 | + out::message("New primary postgres host ${new_primary_postgresql_target.peadm::certname()} set up correctly") |
| 61 | + } else { |
| 62 | + fail_plan("New primary postgres host ${new_primary_postgresql_target.peadm::certname()} was not set up correctly") |
| 63 | + } |
| 64 | + } |
| 65 | + |
| 66 | + # if new_replica_postgresql_target is supplied then check that is in the expected place in the config |
| 67 | + if $new_replica_postgresql_target { |
| 68 | + if $peadm_config['params']['replica_postgresql_host'] == $new_replica_postgresql_target.peadm::certname() { |
| 69 | + out::message("New primary postgres host ${new_replica_postgresql_target.peadm::certname()} set up correctly") |
| 70 | + } else { |
| 71 | + fail_plan("New primary postgres host ${new_replica_postgresql_target.peadm::certname()} was not set up correctly") |
| 72 | + } |
| 73 | + } |
| 74 | + |
| 75 | + # if a new PE version was specified then check it has been upgraded |
| 76 | + if $upgrade_version and $upgrade_version != '' and !empty($upgrade_version) { |
| 77 | + if $peadm_config['pe_version'] == $upgrade_version { |
| 78 | + out::message("Upgraded to new PE version ${upgrade_version} correctly") |
| 79 | + } else { |
| 80 | + fail_plan("Failed to upgrade to new PE version ${upgrade_version} correctly") |
| 81 | + } |
| 82 | + } |
| 83 | +} |
0 commit comments