Skip to content

Commit

Permalink
Clean up offers
Browse files Browse the repository at this point in the history
During the cleaning up of integration tests, where the test "framework"
destroys the controllers, if there are any outstanding offers in the
controller then the destroying of the controller will hang for ever!

The fix is quite simple, before the actual destruction of a model, walk
over all the controllers and remove all the offers. It's quite a slow
process esp. with AWS, but it does mean that we don't have any orphaned
controllers.

In fact this is how a normal operator is supposed to handle a controller
destruction.
  • Loading branch information
SimonRichardson authored and mitechie committed Feb 10, 2020
1 parent 65e6ac8 commit b6e8191
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions tests/includes/juju.sh
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,18 @@ destroy_controller() {

echo "====> Introspection gathered"

# Unfortunately having any offers on a model, leads to failure to clean
# up a controller.
# See discussion under https://bugs.launchpad.net/juju/+bug/1830292.
echo "====> Removing offers"

set +e
remove_controller_offers "${name}"
set_verbosity

echo "====> Removed offers"


output="${TEST_DIR}/${name}-destroy-controller.txt"

echo "====> Destroying juju ($(green "${name}"))"
Expand Down Expand Up @@ -268,3 +280,22 @@ introspect_controller() {
echo "${idents}" | xargs -I % juju ssh -m "${name}:controller" % bash -lc "juju_engine_report" > "${TEST_DIR}/${name}-juju_engine_reports.txt"
echo "${idents}" | xargs -I % juju ssh -m "${name}:controller" % bash -lc "juju_goroutines" > "${TEST_DIR}/${name}-juju_goroutines.txt"
}

remove_controller_offers() {
local name

name=${1}

OUT=$(juju models -c ${name} --format=json | jq -r ".[\"models\"] | .[] | select(.[\"is-controller\"] == false) | .name" || true)
if [ -n "${OUT}" ]; then
echo "${OUT}" | while read -r model; do
OUT=$(juju offers -m "${name}:${model}" --format=json | jq -r ".[] | .[\"offer-url\"]" || true)
echo "${OUT}" | while read -r offer; do
if [ -n "${offer}" ]; then
juju remove-offer -c "${name}" "${offer}"
echo "${offer}" >> "${TEST_DIR}/${name}-juju_removed_offers.txt"
fi
done
done
fi
}

0 comments on commit b6e8191

Please sign in to comment.