~james-page/ubuntu-openstack-ci/drop-tox-from-slave-config

« back to all changes in this revision

Viewing changes to job-parts/juju1_bighammer_destroy.sh

[1chb1n, r=admcleod] Update cleanup; use mojo from a venv; add ocata mapping

 - Use port-cleanup tool to delete neutron ext-ports left over from mojo runs. [Bug 1656306]
 - Update and re-enable undercloud instance reaping when error conditions are known. [Bug 1668778]
 - Block forever when destroy fails and cleanup fails, where human intervention is required anyway. [Bug 1668778]
 - Use mojo from a python virtualenv. [Bug 1666746]
 - Use python virtualenv for juju_status_health_check to work around paramiki/crypto IV CTR issues upstream. [Bug 1665598]

Show diffs side-by-side

added added

removed removed

Lines of Context:
33
33
. ${OSCI_ROOT}/job-parts/osci_job_common.sh
34
34
f_novarc_undercloud
35
35
 
 
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."
 
39
  exit 1
 
40
fi
 
41
 
36
42
env_names="$(juju switch -l)"
37
43
j_env_dir="${HOME}/.juju/environments"
38
44
f_get_env_files
39
45
 
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}"
42
48
fi
43
49
 
44
50
# Always attempt a destroy on all enviros/models if ANY are found
69
75
# Delete nova instances if matches are found
70
76
f_get_env_files
71
77
f_get_my_nova_instances
 
78
 
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"
75
81
 
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.
79
 
#
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"
84
86
 
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"
90
 
#  sleep 30
 
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"
91
92
 
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."
97
 
#    exit 1
98
 
#  else
99
 
#    echo " . Nova instances appear to be adequately cleaned up."
100
 
#  fi
 
94
  f_get_my_nova_instances
 
95
  if [[ -n "$my_instances" ]]; then
 
96
    echo "$my_instances"
 
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.
 
100
    sleep infinity
 
101
  else
 
102
    echo " . Nova instances appear to be adequately cleaned up."
 
103
  fi
101
104
fi
102
105
 
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"
124
127
 
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 ||:)"
128
131
 
129
132
  if [[ "$juju_ok" != *CLEAR:* ]]; then
130
133
    echo " ! ${JENV_NAME} on ${NODE_NAME} is not clear."
143
146
  echo "$env_files"
144
147
  echo " ! Instances:"
145
148
  echo "$my_instances"
146
 
  echo " ! Juju destroy failed.  Manual intervention required."
 
149
  echo " ! juju1_bighammer_destroy failed.  Manual intervention required."
147
150
  echo "_:destroy.failed"
148
 
  exit 1
 
151
 
 
152
  # Never return if destroy failed; block to require human intervention.
 
153
  sleep infinity
149
154
fi