2
# Check current juju environment for all good agent and instance states,
3
# or for an environment which is clean and ready to deploy to.
5
# Return 0 if enviro is clear to deploy to, or if deployment appears to be
6
# sane from a nova undercloud and juju perspective.
9
rm -f $instances_tmp_file
14
[[ -z "$WORKSPACE" ]] &&\
15
export WORKSPACE="$(mktemp -d)"
16
[[ -z "$BUILD_NUMBER" ]] &&\
17
export BUILD_NUMBER="unknown"
18
[[ -z "$OSCI_ROOT" ]] &&\
19
export OSCI_ROOT="${HOME}/tools/ubuntu-openstack-ci"
20
[[ -z "$OPENSTACK_CHARM_TESTING_ROOT" ]] &&\
21
export OPENSTACK_CHARM_TESTING_ROOT="${HOME}/tools/openstack-charm-testing"
25
# Always use current juju environment name
26
JENV_NAME=$(juju switch | xargs)
27
echo "Juju env name: ${JENV_NAME}"
29
# Check for bad agent/machine states in juju status yaml output
30
jstat_tmp_file=$(mktemp)
31
timeout 120 juju stat --format=yaml &> $jstat_tmp_file ||:
32
bad_states="$(cat $jstat_tmp_file | grep 'agent\-state:' | egrep -v 'started' ||:)"
34
# Check for juju environment files
35
echo "Checking for jenv files..."
36
if [[ -n "$OSI_JUJU_HOME" ]]; then
37
# openstack-installer is in play
38
jenv_files="$(ls ${HOME}/.juju/environments/*jenv ${OSI_JUJU_HOME}/environments/*jenv -alh 2> /dev/null ||:)"
40
# juju deployment (not openstack-installer)
41
jenv_files="$(ls ${HOME}/.juju/environments/*jenv -alh 2> /dev/null ||:)"
44
# Check that juju status output looks like juju status output if env file exists
45
if ! grep "environment:" $jstat_tmp_file && [[ -n "$jenv_files" ]]; then
46
msg="! MODEL-ERROR: Juju1 env file(s) exist but juju status not OK for ${JENV_NAME}."
49
echo "ERROR 6 - ${msg}"
53
# Check for good and bad nova instances where instance name contains the
54
# juju model/environment name.
55
if [[ "${JENV_NAME^^}" != *MAAS* ]]; then
56
echo "Checking for nova instances..."
57
instances_tmp_file=$(mktemp)
58
openstack server list | grep "\-${JENV_NAME}\-machine" > $instances_tmp_file ||:
59
good_instances=$(grep 'ACTIVE' $instances_tmp_file ||:)
60
bad_instances=$(grep -v 'ACTIVE' $instances_tmp_file ||:)
62
if [[ -n $good_instances ]]; then
63
if [[ -n $bad_instances ]]; then
64
echo "NON-ACTIVE: Nova list found non-ACTIVE instances for ${JENV_NAME}." \
65
"Perhaps a build is in progress or incomplete?"
72
if [[ -n $bad_states ]] && [[ -n "$jenv_files" ]]; then
73
echo "! NOT-READY: Juju environment, agent and/or instance states are not" \
74
"active/STARTED, and Juju jenv file(s) exist for enviro: ${JENV_NAME}."
77
cp $jstat_tmp_file $WORKSPACE/juju-stat-bad-states.$BUILD_NUMBER ||:
80
elif [[ -n $bad_states ]] && [[ -z "$jenv_files" ]]; then
81
msg="! TEARDOWN-NEEDED: Juju environment, agent and/or instance states are bad, and Juju jenv file(s) do not exist for ${JENV_NAME}."
84
echo "ERROR 3 - Manual intervention required. Undercloud issue? ${msg}"
86
elif [[ -z $bad_states ]] && [[ -n "$jenv_files" ]] && [[ -z $bad_instances ]] && [[ -n $good_instances ]]; then
87
echo " . DEPLOYED: Juju environment, agent and instance states are good," \
88
"and Juju jenv file(s) exist for ${JENV_NAME}."
91
elif [[ -z $bad_states ]] && [[ -n "$jenv_files" ]] && [[ "${JENV_NAME^^}" == *MAAS* ]]; then
92
echo " . DEPLOYED: Juju environment (maas provider), agent states are good," \
93
"and Juju jenv file(s) exist for ${JENV_NAME}."
96
elif [[ -z $bad_states ]] && [[ -z "$jenv_files" ]] && [[ -z $bad_instances ]] && [[ -z $good_instances ]]; then
97
echo " . CLEAR: Juju environment, agent and instance states not found," \
98
"and Juju jenv file(s) do not exist for ${JENV_NAME}."
101
elif [[ -z $good_instances ]] && [[ -z $bad_instances ]] && [[ -n "$jenv_files" ]] && [[ "${JENV_NAME^^}" != *MAAS* ]]; then
102
msg=" ! TEARDOWN-NEEDED: Juju jenv file(s) exist, but there are no nova instances for: ${JENV_NAME}."
103
echo "jenv_files: ${jenv_files}"
105
echo "ERROR 4 - Manual intervention required. Undercloud issue? ${msg}"
108
msg=" ! FAIL: Unknown state, need to debug or troubleshoot this node. Env name: ${JENV_NAME}."
109
echo "1: ${JENV_NAME}"
110
echo "2: ${bad_instances}"
111
echo "3: ${good_instances}"
112
echo "4: ${bad_states}"
113
echo "5: ${jenv_files}"
115
echo "ERROR 5 - Manual intervention required. Undercloud issue? ${msg}"