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

« back to all changes in this revision

Viewing changes to run/job-parts/deprecated/juju1_deploy_ok.sh

  • Committer: Ryan Beisner
  • Date: 2018-12-13 22:12:48 UTC
  • mfrom: (402.2.9 uosci-func-test-update)
  • Revision ID: ryan.beisner@canonical.com-20181213221248-by9gaj688y9911cw
[1chb1n, r=thedac] Make functional test naming generic and deprecate unused legacy bits

The functional tests may run amulet or zaza based on each
repo's tox definitions.

Leave symlink shims in for legacy amulet jobs until the
corresponding jobs are all updated to point to the new
generic runner file.

Remove several unused legacy amulet helpers.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/bin/bash -e
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.
4
 
#
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.
7
 
 
8
 
clear_tmp_files() {
9
 
  rm -f $instances_tmp_file
10
 
  rm -f $jstat_tmp_file
11
 
}
12
 
 
13
 
# Handle manual runs.
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"
22
 
 
23
 
. ~/novarc
24
 
 
25
 
# Always use current juju environment name
26
 
JENV_NAME=$(juju switch | xargs)
27
 
echo "Juju env name:  ${JENV_NAME}"
28
 
 
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' ||:)"
33
 
 
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 ||:)"
39
 
else
40
 
  # juju deployment (not openstack-installer)
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.
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 ||:)
61
 
 
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?"
66
 
      clear_tmp_files
67
 
      exit 1
68
 
    fi
69
 
  fi
70
 
fi
71
 
 
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}."
75
 
  echo $bad_states
76
 
  echo $jenv_files
77
 
  cp $jstat_tmp_file $WORKSPACE/juju-stat-bad-states.$BUILD_NUMBER ||:
78
 
  clear_tmp_files
79
 
  exit 2
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}."
82
 
  echo $bad_states
83
 
  clear_tmp_files
84
 
  echo "ERROR 3 - Manual intervention required.  Undercloud issue?  ${msg}"
85
 
  exit 3
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}."
89
 
  clear_tmp_files
90
 
  exit 0
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}."
94
 
  clear_tmp_files
95
 
  exit 0
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}."
99
 
  clear_tmp_files
100
 
  exit 0
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}"
104
 
  clear_tmp_files
105
 
  echo "ERROR 4 - Manual intervention required.  Undercloud issue?  ${msg}"
106
 
  exit 4
107
 
else
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}"
114
 
  clear_tmp_files
115
 
  echo "ERROR 5 - Manual intervention required.  Undercloud issue?  ${msg}"
116
 
  exit 5
117
 
fi