Skip to content

Commit

Permalink
Merge pull request #14573 from anvial/JUJU-1307-rewrite-to-bash-based…
Browse files Browse the repository at this point in the history
…-nw-resolve

#14573

This PR added a bash-based version of the `nw-resolve` test to the deploy suite. To implement the test, the `simple-resolve` charm was copied to the `testcharms` subfolder.

## Checklist

- [ ] Code style: imports ordered, good names, simple structure, etc
- [ ] Comments saying why design decisions were made

## QA steps

```sh
cd tests
./main.sh -v -p lxd deploy run_resolve_charm
```
  • Loading branch information
jujubot committed Sep 6, 2022
2 parents 109086c + 1579a8e commit 0c289c1
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 0 deletions.
3 changes: 3 additions & 0 deletions testcharms/charms/simple-resolve/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Simple charm that errors once on the install hook, but works the next time run.

Used to test juju resolve command.
1 change: 1 addition & 0 deletions testcharms/charms/simple-resolve/copyright
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Copyright 2018 Canonical Ltd.
26 changes: 26 additions & 0 deletions testcharms/charms/simple-resolve/hooks/install
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/bash

# Simple install hook that errors the first time it is run, on any subsequent
# run the hook will succeed (unless the canary file is removed).

canary_file=/tmp/resolver.canary
success_file=/tmp/resolver.success

function exit_error() {
status-set blocked "Install hook failed on: $1 attempts." || true
exit 1
}

if [ ! -e ${canary_file} ]; then
echo "No canary file, exiting error."
echo 1 > ${canary_file}
exit_error 1
fi

# Need to error for x amount of times before juju stops trying automatically.
run_count=$(cat ${canary_file})

# For now juju is always re-trying. Need to just exit regardless.
echo $((${run_count}+1)) > ${canary_file}
exit_error ${run_count}

11 changes: 11 additions & 0 deletions testcharms/charms/simple-resolve/hooks/start
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash

install_success_file=/tmp/resolver.success

status_message="No install hook"
if [ -e ${install_success_file} ]; then
status_message="Install hook succeeded"
fi

echo "${status_message}"
status-set active "${status_message}" || true
11 changes: 11 additions & 0 deletions testcharms/charms/simple-resolve/metadata.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: simple-resolve
maintainer: Christopher Lee <chris.mclachlan-lee@canonical.com>
summary: Purposfully error on install hook for testing resolve command.
description: |
A testing charm that errors once on install hook then succeeds on the next run.
categories:
- misc
series:
- jammy
- focal
- bionic
24 changes: 24 additions & 0 deletions tests/suites/deploy/deploy_charms.sh
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,28 @@ run_deploy_lxd_to_container() {
destroy_model "${model_name}"
}

# Checks the install hook resolving with --no-retry flag
run_resolve_charm() {
echo

model_name="test-resolve-charm"
file="${TEST_DIR}/${model_name}.log"

ensure "${model_name}" "${file}"

charm=./testcharms/charms/simple-resolve
juju deploy "${charm}"

wait_for "error" '.applications["simple-resolve"] | ."application-status".current'

juju resolve --no-retry simple-resolve/0

wait_for "No install hook" '.applications["simple-resolve"] | ."application-status".message'
wait_for "active" '.applications["simple-resolve"] | ."application-status".current'

destroy_model "${model_name}"
}

test_deploy_charms() {
if [ "$(skip 'test_deploy_charms')" ]; then
echo "==> TEST SKIPPED: deploy charms"
Expand All @@ -243,11 +265,13 @@ test_deploy_charms() {
run "run_deploy_lxd_to_machine"
run "run_deploy_lxd_profile_charm"
run "run_deploy_local_lxd_profile_charm"
run "run_resolve_charm"
;;
*)
echo "==> TEST SKIPPED: deploy_lxd_to_machine - tests for LXD only"
echo "==> TEST SKIPPED: deploy_lxd_profile_charm - tests for LXD only"
echo "==> TEST SKIPPED: deploy_local_lxd_profile_charm - tests for LXD only"
echo "==> TEST SKIPPED: resolve_charm - tests for LXD only"
;;
esac
)
Expand Down

0 comments on commit 0c289c1

Please sign in to comment.