~abentley/juju-ci-tools/parallel-compatibility

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
#!/bin/bash
set -eu
JUJU_HOME="$HOME/.juju"
AMI_IMAGE=""
SERIES=""
while [[ "${1-}" != "" && $1 =~ ^-.*  ]]; do
    case $1 in
        --juju-home)
            shift
            JUJU_HOME=$(cd $1; pwd)
            ;;
        --ami-image)
            shift
            AMI_IMAGE=$1
            ;;
        --series)
            shift
            SERIES=$1
            ;;
    esac
    shift
done

if [[ -z $AMI_IMAGE || -z $SERIES ]]; then
    echo "--ami-image and --series are required"
    exit 2
fi

export JUJU_HOME
export AMI_IMAGE
export SERIES

SCRIPTS=$(readlink -f $(dirname $0))
: ${JOB_NAME="testy"}
export JOB_NAME
export PATH="$SCRIPTS:$PATH"
source $JUJU_HOME/ec2rc
mkdir -p bash
$SCRIPTS/jujuci.py get -a build-revision buildvars.bash bash
source bash/buildvars.bash
ec2-terminate-job-instances
set -x
export INSTANCE_TYPE=m1.large
instance_id=$(ec2-run-instance-get-id)
instance_name=$(ec2-get-name $instance_id)
ec2-tag-job-instances $instance_id
wait-for-port $instance_name 22

RELEASE=$(ssh -o 'StrictHostKeyChecking no' -o 'UserKnownHostsFile /dev/null' \
    ubuntu@$instance_name lsb_release -sr)
ARCH=$(ssh -o 'StrictHostKeyChecking no' -o 'UserKnownHostsFile /dev/null' \
    ubuntu@$instance_name dpkg --print-architecture)

juju_local_deb="juju-local_$VERSION-0ubuntu1~$RELEASE.1~juju1_all.deb"
juju_core_deb="juju-core_$VERSION-0ubuntu1~$RELEASE.1~juju1_$ARCH.deb"

if [ -e debs ]; then
  rm -R debs
fi
mkdir -p debs
$SCRIPTS/jujuci.py get assemble-streams $juju_local_deb debs
$SCRIPTS/jujuci.py get assemble-streams $juju_core_deb debs

scp -o 'StrictHostKeyChecking no' -o 'UserKnownHostsFile /dev/null' \
  debs/$juju_local_deb debs/$juju_core_deb ubuntu@$instance_name:

set +e
ssh -o "StrictHostKeyChecking no" -o "UserKnownHostsFile /dev/null" \
    ubuntu@$instance_name "SERIES=$SERIES juju_local_deb=$juju_local_deb\
    juju_core_deb=$juju_core_deb bash"<<"EOT"
set -eux
for attempt in $(seq 10); do
  if grep ec2.archive.ubuntu.com /etc/apt/sources.list > /dev/null; then
    break
  elif [ "$attempt" == "10" ]; then
    exit 1
  fi
  sleep 10
done
sudo sed s,//.*ec2.archive.ubuntu.com,//archive.ubuntu.com, \
    /etc/apt/sources.list -i
if [[ $SERIES == "precise" ]]; then
    sudo add-apt-repository cloud-archive:tools
fi
sudo apt-get update
sudo DEBIAN_FRONTEND=noninteractive apt-get upgrade -y
sudo DEBIAN_FRONTEND=noninteractive apt-get install -y bzr

# prevent spurious failure on success
rm .bash_logout
afact=lastSuccessfulBuild/artifact
sudo dpkg -i $juju_core_deb $juju_local_deb || true
sudo apt-get install -y -f
export JUJU_REPOSITORY="$HOME/repo"
mkdir -p $JUJU_REPOSITORY/$SERIES
bzr branch lp:charms/ubuntu $JUJU_REPOSITORY/$SERIES/ubuntu
mkdir ~/.juju
cat > ~/.juju/environments.yaml <<EOT2
default: local
environments:
  local:
    type: local
    tools-metadata-url: http://juju-dist.s3.amazonaws.com/testing/tools
    enable-os-refresh-update: true
    default-series: trusty
EOT2
ssh-keygen -t rsa -b 2048 -N "" -f ~/.ssh/id_rsa

report_network() {
    echo
    echo $1
    ip link
    ip route
    ip addr
    sudo iptables-save
}

report_network "The starting network conditions:"
echo "Restricting the network:"
login_ip=$(netstat --tcp -n|sed -nr 's/.*:22 *([^ ]*):.* .*/\1/p')
gateway=$(route -n | sed -rn 's/^0.0.0.0 *([0-7.]*) .*/\1/p')
nameservers="$(sed /etc/resolv.conf -nr -e 's/nameserver (.*)/\1/p')"
for ns in $nameservers; do
  sudo route add $ns gw $gateway
done
sudo route add $login_ip gw $gateway
for ip in $(dig archive.ubuntu.com ubuntu-cloud.archive.canonical.com\
    security.ubuntu.com cloud-images.ubuntu.com +short |sort|uniq); do
  sudo route add $ip gw $gateway
done
sudo route add -net 172.16.0.0 netmask 255.240.0.0 gw $gateway
sudo route del default gw $gateway
report_network "The final network conditions:"
juju bootstrap --show-log
for x in $(seq 6); do
  if juju deploy --show-log local:$SERIES/ubuntu; then
    break
  elif [ "$x" == "6" ]; then
    exit 0;
  fi
done
for x in $(seq 30); do
  # relying on the indentation of ubuntu/0's agent-state here...
  if juju status | grep -E ' {8}agent-state: started'; then
    exit 0;
  fi
  sleep 10
done
juju status
report_network "The failing network conditions:"
# Restore some routing so that staff can do an autopsy
sudo route add default gw $gateway eth0
exit 1
EOT
result=$?
set -e
ec2-terminate-job-instances
exit $result