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