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

« back to all changes in this revision

Viewing changes to job-parts/juju1_deploy_ok.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:
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.
4
4
#
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.
6
7
 
7
 
clear_tmps() {
8
 
  rm -f $instances
9
 
  rm -f $jstat
 
8
clear_tmp_files() {
 
9
  rm -f $instances_tmp_file
 
10
  rm -f $jstat_tmp_file
10
11
}
11
12
 
12
13
# Handle manual runs.
26
27
echo "Juju env name:  ${JENV_NAME}"
27
28
 
28
29
# Check for bad agent/machine states in juju status yaml output
29
 
jstat=$(mktemp)
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' ||:)"
32
33
 
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 ||:)"
38
39
else
39
40
  # juju deployment (not openstack-installer)
40
 
  jenv_files="$(ls ${HOME}/.juju/environments/*jenv -alh 2> /dev/null || true)"
41
 
fi
42
 
 
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 ||:)"
 
42
fi
 
43
 
 
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}."
 
47
  echo $bad_states
 
48
  clear_tmp_files
 
49
  echo "ERROR 6 - ${msg}"
 
50
  exit 6
 
51
fi
 
52
 
 
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..."
47
 
  instances=$(mktemp)
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 ||:)
51
61
 
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?"
56
 
      clear_tmps
 
66
      clear_tmp_files
57
67
      exit 1
58
68
    fi
59
69
  fi
64
74
       "active/STARTED, and Juju jenv file(s) exist for enviro: ${JENV_NAME}."
65
75
  echo $bad_states
66
76
  echo $jenv_files
67
 
  cp $jstat $WORKSPACE/juju-stat-bad-states.$BUILD_NUMBER || true
68
 
  clear_tmps
 
77
  cp $jstat_tmp_file $WORKSPACE/juju-stat-bad-states.$BUILD_NUMBER ||:
 
78
  clear_tmp_files
69
79
  exit 2
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}."
72
82
  echo $bad_states
73
 
  clear_tmps
74
 
  while true; do echo "ERROR 3 - Manual intervention required.  Undercloud issue?  ${msg}"; sleep 120; done
75
 
#  exit 3
 
83
  clear_tmp_files
 
84
  echo "ERROR 3 - Manual intervention required.  Undercloud issue?  ${msg}"
 
85
  exit 3
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}."
79
 
  clear_tmps
 
89
  clear_tmp_files
80
90
  exit 0
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}."
84
 
  clear_tmps
 
94
  clear_tmp_files
85
95
  exit 0
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}."
89
 
  clear_tmps
 
99
  clear_tmp_files
90
100
  exit 0
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}"
94
 
  clear_tmps
95
 
  while true; do echo "ERROR 4 - Manual intervention required.  Undercloud issue?  ${msg}"; sleep 120; done
96
 
#  exit 4
 
104
  clear_tmp_files
 
105
  echo "ERROR 4 - Manual intervention required.  Undercloud issue?  ${msg}"
 
106
  exit 4
97
107
else
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}"
104
 
  clear_tmps
105
 
  while true; do echo "ERROR 5 - Manual intervention required.  Undercloud issue?  ${msg}"; sleep 120; done
106
 
#  exit 5
 
114
  clear_tmp_files
 
115
  echo "ERROR 5 - Manual intervention required.  Undercloud issue?  ${msg}"
 
116
  exit 5
107
117
fi