Skip to content

Commit

Permalink
Merge pull request juju#12160 from benhoyt/tests-backup-28
Browse files Browse the repository at this point in the history
juju#12160

I landed the backup and `juju-restore` tests to develop, but Jenkins is trying to run them on 2.8 as well (where they don't exist). They should work on 2.8 so there's no reason not to add them. This PR cherry-picks them to 2.8 -- commits from two PRs juju#12137 and juju#12153.
  • Loading branch information
jujubot authored Oct 20, 2020
2 parents 9333e82 + 3a9b638 commit f120f4c
Show file tree
Hide file tree
Showing 4 changed files with 117 additions and 8 deletions.
6 changes: 3 additions & 3 deletions tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ Tests are structured into test suites. Each suite contains a root task (akin
to a package test) that will setup and run each individual test.

To help break tests down, each test can have a number of subtests. Subtests
are meant for indivdual units of work, without having to bootstrap a controller
for every test. Each subtest will just `ensure` that it does have one, failure
are meant for individual units of work, without having to bootstrap a controller
for every test. Each subtest will just `ensure` that it does have one; failing
to find a suitable controller, it will create one for you.

### Example of a test suite
Expand All @@ -33,7 +33,7 @@ test_deploy_bundles() { # Test
## Exit codes / Success

All tests will run through until the end of a test/subtest, unless it encounters
a none zero exit code. In otherwards if you want to assert something passes,
a non-zero exit code. In other words, if you want to assert something passes,
ensure that the command returns `exit 0`. Failure can then be detected of the
inverse.

Expand Down
15 changes: 10 additions & 5 deletions tests/main.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,26 @@ import_subdir_files() {

import_subdir_files includes

# If adding a test suite, then ensure to add it here to be picked up!
TEST_NAMES="static_analysis \
# If adding a test suite, then ensure to add it here to be picked up! (Please
# keep these in alphabetic order.)
TEST_NAMES="agents \
appdata \
backup \
branches \
caasadmission \
cli \
controller \
deploy \
hooks \
hook_tools \
hooktools \
machine \
manual \
model \
network \
relations \
smoke \
model"
spaces_ec2 \
static_analysis"

# Show test suites, can be used to test if a test suite is available or not.
show_test_suites() {
Expand All @@ -54,7 +59,7 @@ show_test_suites() {
# shellcheck disable=SC2086
output="${output}\n${test}"
done
echo "${output}" | column -t -s "|"
echo -e "${output}" | column -t -s "|"
exit 0
}

Expand Down
85 changes: 85 additions & 0 deletions tests/suites/backup/backup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
run_basic_backup_create() {
echo

file="${TEST_DIR}/test-basic-backup-create.log"

ensure "test-basic-backup-create" "${file}"

juju switch controller
juju create-backup --filename "${TEST_DIR}/basic_backup.tar.gz"

# Do some basic sanity checks on what's inside the backup
tar xf "${TEST_DIR}/basic_backup.tar.gz" -C "${TEST_DIR}"
echo "checking metadata.json is present"
test -s "${TEST_DIR}/juju-backup/metadata.json"
echo "checking root.tar is present"
test -s "${TEST_DIR}/juju-backup/root.tar"
echo "checking oplog.bson is present"
test -s "${TEST_DIR}/juju-backup/dump/oplog.bson"

destroy_model "test-basic-backup-create"
}

run_basic_backup_restore() {
echo

wget -O "${TEST_DIR}/juju-restore" https://github.com/juju/juju-restore/releases/latest/download/juju-restore
chmod +x "${TEST_DIR}/juju-restore"

file="${TEST_DIR}/test-basic-backup-restore.log"

ensure "test-basic-backup-restore" "${file}"

echo "Deploy a workload (1 machine)"
juju deploy cs:~jameinel/ubuntu-lite-7
wait_for "ubuntu-lite" "$(idle_condition "ubuntu-lite")"
juju status --format json | jq '.machines | length' | check 1
id0=$(juju status --format json | jq -r '.machines["0"]["instance-id"]')

echo "Create a backup"
juju switch controller # create-backup only works from controller model
juju create-backup --filename "${TEST_DIR}/basic_backup.tar.gz"

echo "Add another machine (after the backup)"
juju switch test-basic-backup-restore
juju add-unit ubuntu-lite
wait_for_machine_agent_status "1" "started"
juju status --format json | jq '.machines | length' | check 2
id1=$(juju status --format json | jq -r '.machines["1"]["instance-id"]')

echo "Restore the backup"
juju switch controller
juju scp "${TEST_DIR}/juju-restore" 0:
juju scp "${TEST_DIR}/basic_backup.tar.gz" 0:
juju ssh 0 ./juju-restore --yes basic_backup.tar.gz

echo "Ensure there's only one machine (state before the backup)"
juju switch test-basic-backup-restore
wait_for "ubuntu-lite" "$(idle_condition "ubuntu-lite")"
juju status --format json | jq '.machines | length' | check 1

# Only do this check if provider is LXD (too hard to do for all providers)
if [ "${BOOTSTRAP_PROVIDER}" == "lxd" ] || [ "${BOOTSTRAP_PROVIDER}" == "localhost" ]; then
echo "Ensure that both instances are running (restore shouldn't terminate machines)"
lxc info "${id0}" | grep Status | check Running
lxc info "${id1}" | grep Status | check Running
fi

destroy_model "test-basic-backup-restore"
}

test_basic_backup() {
if [ "$(skip 'test_basic_backup')" ]; then
echo "==> TEST SKIPPED: basic backup"
return
fi

(
set_verbosity

cd .. || exit

run "run_basic_backup_create"
run "run_basic_backup_restore"
)
}
19 changes: 19 additions & 0 deletions tests/suites/backup/task.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
test_backup() {
if [ "$(skip 'test_backup')" ]; then
echo "==> TEST SKIPPED: Backup and Restore tests"
return
fi

set_verbosity

echo "==> Checking for dependencies"
check_dependencies juju

file="${TEST_DIR}/test-backup-restore.log"

bootstrap "test-cli" "${file}"

test_basic_backup

destroy_controller "test-cli"
}

0 comments on commit f120f4c

Please sign in to comment.