Skip to content

Commit 744d24b

Browse files
test code for migration
1 parent 2aaacfc commit 744d24b

File tree

5 files changed

+89
-3
lines changed

5 files changed

+89
-3
lines changed

functions/migration_opts_default.pp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ function peadm::migration_opts_default () {
77
'config' => false,
88
'orchestrator' => true,
99
'puppetdb' => true,
10-
'rbac' => true,
10+
'rbac' => false,
1111
}
1212
}

plans/backup.pp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
Peadm::SingleTargetSpec $targets,
1313

1414
# backup type determines the backup options
15-
Enum['recovery', 'custom'] $backup_type = 'recovery',
15+
Enum['recovery', 'custom', 'migration'] $backup_type = 'recovery',
1616

1717
# Which data to backup
1818
Peadm::Recovery_opts $backup = {},

plans/check_config.pp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
plan peadm::check_config(
2+
TargetSpec $targets
3+
) {
4+
get_targets($targets).each |$target| {
5+
$peadm_config = run_task('peadm::get_peadm_config', $target).first.value
6+
out::message("${target} - peadm_config:${$peadm_config}.")
7+
$postgresql_a_host = $peadm_config['role-letter']['postgresql']['A']
8+
$postgresql_b_host = $peadm_config['role-letter']['postgresql']['B']
9+
$pe_status = run_task('service', $target, 'action' => 'status', 'name' => 'puppet.service')
10+
$pdb_status = run_task('service', $target, 'action' => 'status', 'name' => 'pe-puppetdb.service')
11+
$agent_status = run_task('package', $target,
12+
action => 'status',
13+
name => 'puppet-agent').first['status']
14+
out::message("${target} - postgresql_a_host:${$postgresql_a_host}.")
15+
out::message("${target} - postgresql_b_host:${$postgresql_b_host}.")
16+
out::message("${target} - pe_status:${$pe_status}.")
17+
out::message("${target} - pdb_status:${$pdb_status}.")
18+
out::message("${target} - agent_status:${$agent_status}.")
19+
}
20+
}

plans/restore.pp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
Peadm::SingleTargetSpec $targets,
1313

1414
# restore type determines the restore options
15-
Enum['recovery', 'recovery-db', 'custom'] $restore_type = 'recovery',
15+
Enum['recovery', 'recovery-db', 'custom', 'migration'] $restore_type = 'recovery',
1616

1717
# Which data to restore
1818
Peadm::Recovery_opts $restore = {},

plans/test_restore.pp

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
plan peadm::test_restore (
2+
# This plan should be run on the primary server
3+
Peadm::SingleTargetSpec $target,
4+
5+
# Path to the recovery tarball
6+
Pattern[/.*\.tar\.gz$/] $input_file,
7+
8+
# boolean flag to indicate clean target before restore
9+
Boolean $clean_target = false,
10+
) {
11+
peadm::assert_supported_bolt_version()
12+
13+
# prior to running this plan the user will have something like this:
14+
# perform a backup on the source PE server:
15+
# bolt plan run peadm::backup backup_type=migration -t festive-gantlet.delivery.puppetlabs.net --no-host-key-check
16+
#
17+
# download the backup file locally:
18+
# bolt file download /tmp/pe-backup-2025-01-30T091722Z.tar.gz /tmp --targets festive-gantlet.delivery.puppetlabs.net --no-host-key-check
19+
#
20+
# upload the backup file to the target PE server:
21+
# bolt file upload /tmp/festive-gantlet.delivery.puppetlabs.net/pe-backup-2025-01-30T091722Z.tar.gz /tmp --targets inspiring-reign.delivery.puppetlabs.net --no-host-key-check
22+
#
23+
# install PE on the target server (using the "code_manager_auto_configure": true parameter)
24+
# bolt plan run peadm::install primary_host=inspiring-reign.delivery.puppetlabs.net replica_host=inspiring-reign.delivery.puppetlabs.net code_manager_auto_configure=true --no-host-key-check
25+
#
26+
# run this plan to restore the backup on the target PE server:
27+
# bolt plan run peadm::test_restore clean_target=false input_file=/tmp/festive-gantlet.delivery.puppetlabs.net/pe-backup-2025-01-30T135004Z.tar.gz target=inspiring-reign.delivery.puppetlabs.net --no-host-key-check
28+
#
29+
30+
$params = loadjson('params.json')
31+
$primary_host = $params['primary_host']
32+
out::message("params: ${params}")
33+
out::message("primary_host:${primary_host}.")
34+
35+
# check param to see if we need to do an uninstall/install on the target
36+
if $clean_target {
37+
out::message('Cleaning target before restore')
38+
run_plan('peadm::uninstall', $target)
39+
run_plan('peadm::install', $params)
40+
#run_plan('peadm::install', $target, { 'params' => '@params.json' })
41+
} else {
42+
out::message('Skipping clean target before restore')
43+
}
44+
45+
# delete the file on the target first in case it is there
46+
$file_name = basename($input_file)
47+
$dir_name = $file_name[0,-8]
48+
out::message("Deleting /tmp/${file_name} and /tmp/${dir_name} on ${target}")
49+
run_command("rm -rf /tmp/${file_name}", $target)
50+
run_command("rm -rf /tmp/${dir_name}", $target)
51+
52+
# copy the file over from the bolt controller to the target
53+
out::message("Copying ${input_file} to /tmp/${file_name} on ${target}")
54+
upload_file($input_file, "/tmp/${file_name}", $target)
55+
56+
# kick off the restore plan on the target
57+
out::message("Running peadm::restore on ${target}")
58+
run_plan('peadm::restore', $target, { 'input_file' => "/tmp/${file_name}", 'restore_type' => 'migration' })
59+
60+
# # add replica back
61+
# run_plan('peadm::add_replica',
62+
# primary_host => $primary_host,
63+
# replica_host => $replica_host,
64+
# replica_postgresql_host => undef,
65+
# )
66+
}

0 commit comments

Comments
 (0)