2
2
# Check current juju environment for all good agent and instance states,
3
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 is nova/juju sane.
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
12
13
# Handle manual runs.
26
27
echo "Juju env name: ${JENV_NAME}"
28
29
# Check for bad agent/machine states in juju status yaml output
30
juju stat --format=yaml &> $jstat || true
31
bad_states="$(cat $jstat | grep 'agent\-state:' | egrep -v 'started' || true)"
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' ||:)"
33
34
# Check for juju environment files
34
35
echo "Checking for jenv files..."
35
36
if [[ -n "$OSI_JUJU_HOME" ]]; then
36
37
# openstack-installer is in play
37
jenv_files="$(ls ${HOME}/.juju/environments/*jenv ${OSI_JUJU_HOME}/environments/*jenv -alh 2> /dev/null || true)"
38
jenv_files="$(ls ${HOME}/.juju/environments/*jenv ${OSI_JUJU_HOME}/environments/*jenv -alh 2> /dev/null ||:)"
39
40
# juju deployment (not openstack-installer)
40
jenv_files="$(ls ${HOME}/.juju/environments/*jenv -alh 2> /dev/null || true)"
43
# Check for good and bad nova instances where instance name
44
# contains the juju environment name.
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.
45
55
if [[ "${JENV_NAME^^}" != *MAAS* ]]; then
46
56
echo "Checking for nova instances..."
48
nova list | grep "\-${JENV_NAME}\-machine" > $instances || true
49
good_instances=$(grep 'ACTIVE' $instances || true)
50
bad_instances=$(grep -v 'ACTIVE' $instances || true)
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 ||:)
52
62
if [[ -n $good_instances ]]; then
53
63
if [[ -n $bad_instances ]]; then
54
64
echo "NON-ACTIVE: Nova list found non-ACTIVE instances for ${JENV_NAME}." \
55
65
"Perhaps a build is in progress or incomplete?"
64
74
"active/STARTED, and Juju jenv file(s) exist for enviro: ${JENV_NAME}."
67
cp $jstat $WORKSPACE/juju-stat-bad-states.$BUILD_NUMBER || true
77
cp $jstat_tmp_file $WORKSPACE/juju-stat-bad-states.$BUILD_NUMBER ||:
70
80
elif [[ -n $bad_states ]] && [[ -z "$jenv_files" ]]; then
71
81
msg="! TEARDOWN-NEEDED: Juju environment, agent and/or instance states are bad, and Juju jenv file(s) do not exist for ${JENV_NAME}."
74
while true; do echo "ERROR 3 - Manual intervention required. Undercloud issue? ${msg}"; sleep 120; done
84
echo "ERROR 3 - Manual intervention required. Undercloud issue? ${msg}"
76
86
elif [[ -z $bad_states ]] && [[ -n "$jenv_files" ]] && [[ -z $bad_instances ]] && [[ -n $good_instances ]]; then
77
87
echo " . DEPLOYED: Juju environment, agent and instance states are good," \
78
88
"and Juju jenv file(s) exist for ${JENV_NAME}."
81
91
elif [[ -z $bad_states ]] && [[ -n "$jenv_files" ]] && [[ "${JENV_NAME^^}" == *MAAS* ]]; then
82
echo " . DEPLOYED: Juju environment (maas substrate), agent states are good," \
92
echo " . DEPLOYED: Juju environment (maas provider), agent states are good," \
83
93
"and Juju jenv file(s) exist for ${JENV_NAME}."
86
96
elif [[ -z $bad_states ]] && [[ -z "$jenv_files" ]] && [[ -z $bad_instances ]] && [[ -z $good_instances ]]; then
87
97
echo " . CLEAR: Juju environment, agent and instance states not found," \
88
98
"and Juju jenv file(s) do not exist for ${JENV_NAME}."
91
101
elif [[ -z $good_instances ]] && [[ -z $bad_instances ]] && [[ -n "$jenv_files" ]] && [[ "${JENV_NAME^^}" != *MAAS* ]]; then
92
msg=" ! TEARDOWN-NEEDED: Funky state! Juju jenv file(s) exist, but there are no nova instances for: ${JENV_NAME}."
102
msg=" ! TEARDOWN-NEEDED: Juju jenv file(s) exist, but there are no nova instances for: ${JENV_NAME}."
93
103
echo "jenv_files: ${jenv_files}"
95
while true; do echo "ERROR 4 - Manual intervention required. Undercloud issue? ${msg}"; sleep 120; done
105
echo "ERROR 4 - Manual intervention required. Undercloud issue? ${msg}"
98
msg=" ! FAIL: Unknown state, need to debug or troubleshoot this node. Env name: ${JENV_NAME}. Possibly a non-default juju environment deployed?"
108
msg=" ! FAIL: Unknown state, need to debug or troubleshoot this node. Env name: ${JENV_NAME}."
99
109
echo "1: ${JENV_NAME}"
100
110
echo "2: ${bad_instances}"
101
111
echo "3: ${good_instances}"
102
112
echo "4: ${bad_states}"
103
113
echo "5: ${jenv_files}"
105
while true; do echo "ERROR 5 - Manual intervention required. Undercloud issue? ${msg}"; sleep 120; done
115
echo "ERROR 5 - Manual intervention required. Undercloud issue? ${msg}"