33
33
. ${OSCI_ROOT}/job-parts/osci_job_common.sh
34
34
f_novarc_undercloud
36
# Extra safety measure, as nova delete might be called.
37
if [[ $OS_USERNAME != osci ]] && [[ "${JENV_NAME^^}" != *MAAS* ]]; then
38
echo " ! novarc env vars do not look like OSCI, halting here."
36
42
env_names="$(juju switch -l)"
37
43
j_env_dir="${HOME}/.juju/environments"
40
46
if [[ ! -d "$j_env_dir" ]]; then
41
echo " ! Never bootstrapped here before? Juju environment dir not found: ${j_env_dir}"
47
echo " ! Juju environment dir not found: ${j_env_dir}"
44
50
# Always attempt a destroy on all enviros/models if ANY are found
69
75
# Delete nova instances if matches are found
71
77
f_get_my_nova_instances
72
79
if [[ -n "$my_instances" ]]; then
73
80
echo " ! Nova instances unexpectedly remain after juju destroy. This is likely an undercloud issue."
74
echo "_:destroy.failed"
76
# XXX: nova instance cleanup is disabled, as it should not be necessary.
77
# If it becomes necessary, either the undercloud is failing to destroy
78
# instances, or the juju tooling has a bug.
80
# echo -e " - These nova instances will now be deleted:"
82
echo -e " - These nova instances will be deleted:"
81
83
# Use filter on my_instances for added safety
82
# my_instances_filtered=$(echo "$my_instances" | grep "$nova_instance_safety_substring")
83
# echo "$my_instances_filtered"
84
my_instances_filtered=$(echo "$my_instances" | egrep "$nova_instance_safety_substring")
85
echo "$my_instances_filtered"
85
# while read -r line; do
86
# instance_id=$(echo $line | awk '{ print $2 }')
87
# echo " - Deleting nova instance: ${instance_id}"
88
# timeout 120 nova delete $instance_id
89
# done <<< "$my_instances_filtered"
87
while read -r line; do
88
instance_id=$(echo $line | awk '{ print $2 }')
89
echo " - Deleting nova instance: ${instance_id}"
90
timeout 120 openstack server delete --wait $instance_id ||:
91
done <<< "$my_instances_filtered"
92
93
# Re-check nova instances
93
# f_get_my_nova_instances
94
# if [[ -n "$my_instances" ]]; then
95
# echo "$my_instances"
96
# echo " ! Nova instance cleanup failed. One or more still exist. Manual intervention required."
99
# echo " . Nova instances appear to be adequately cleaned up."
94
f_get_my_nova_instances
95
if [[ -n "$my_instances" ]]; then
97
echo " ! Nova instance cleanup failed. One or more still exist. Manual intervention required."
98
echo "_:destroy.failed"
99
# Never return if destroy failed; block to require human intervention.
102
echo " . Nova instances appear to be adequately cleaned up."
103
106
# Delete juju .env files if they remain, after backing them up
104
107
if [[ -n "$env_files" ]]; then
105
echo " ! Juju environment file(s) remain after juju destroy:"
108
echo " ! Juju1 env file(s) remain after juju destroy:"
106
109
echo "$env_files"
107
110
d_str=$(date +"%Y%m%d%H%M%S%N")
108
111
loc_dir="${HOME}/tmp.juju-env-files"
125
128
for env_name in $env_names; do
126
129
export JENV_NAME="${env_name}"
127
juju_ok="$(timeout 30 ${OSCI_ROOT}/job-parts/juju_deploy_ok.sh || true)"
130
juju_ok="$(timeout 30 ${OSCI_ROOT}/job-parts/juju1_deploy_ok.sh ||:)"
129
132
if [[ "$juju_ok" != *CLEAR:* ]]; then
130
133
echo " ! ${JENV_NAME} on ${NODE_NAME} is not clear."