~andrewjbeach/juju-ci-tools/make-local-patcher

« back to all changes in this revision

Viewing changes to test-restricted-network

  • Committer: Aaron Bentley
  • Date: 2014-02-28 16:40:22 UTC
  • mto: This revision was merged to the branch mainline in revision 257.
  • Revision ID: aaron.bentley@canonical.com-20140228164022-kfip2tphn9m9invi
Add juju-backup script.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/bin/bash
2
 
set -eu
3
 
JUJU_HOME="$HOME/.juju"
4
 
AMI_IMAGE=""
5
 
SERIES=""
6
 
REVISION_BUILD="lastSuccessfulBuild"
7
 
while [[ "${1-}" != "" && $1 =~ ^-.*  ]]; do
8
 
    case $1 in
9
 
        --juju-home)
10
 
            shift
11
 
            JUJU_HOME=$(cd $1; pwd)
12
 
            ;;
13
 
        --ami-image)
14
 
            shift
15
 
            AMI_IMAGE=$1
16
 
            ;;
17
 
        --series)
18
 
            shift
19
 
            SERIES=$1
20
 
            ;;
21
 
        --revision-build)
22
 
            shift
23
 
            REVISION_BUILD=$1
24
 
            ;;
25
 
    esac
26
 
    shift
27
 
done
28
 
 
29
 
if [[ -z $AMI_IMAGE || -z $SERIES ]]; then
30
 
    echo "--ami-image and --series are required"
31
 
    exit 2
32
 
fi
33
 
 
34
 
export JUJU_HOME
35
 
export AMI_IMAGE
36
 
export SERIES
37
 
 
38
 
SCRIPTS=$(readlink -f $(dirname $0))
39
 
: ${JOB_NAME="testy"}
40
 
export JOB_NAME
41
 
export PATH="$SCRIPTS:$PATH"
42
 
source $JUJU_HOME/ec2rc
43
 
mkdir -p bash
44
 
$SCRIPTS/jujuci.py get -a -b $REVISION_BUILD build-revision buildvars.bash bash
45
 
source bash/buildvars.bash
46
 
ec2-terminate-job-instances
47
 
set -x
48
 
export INSTANCE_TYPE=m1.large
49
 
instance_id=$(ec2-run-instance-get-id)
50
 
instance_name=$(ec2-get-name $instance_id)
51
 
ec2-tag-job-instances $instance_id
52
 
wait-for-port $instance_name 22
53
 
 
54
 
RELEASE=$(ssh -o 'StrictHostKeyChecking no' -o 'UserKnownHostsFile /dev/null' \
55
 
    ubuntu@$instance_name lsb_release -sr)
56
 
ARCH=$(ssh -o 'StrictHostKeyChecking no' -o 'UserKnownHostsFile /dev/null' \
57
 
    ubuntu@$instance_name dpkg --print-architecture)
58
 
 
59
 
if [ -e debs ]; then
60
 
  rm -R debs
61
 
fi
62
 
mkdir -p debs
63
 
$SCRIPTS/s3ci.py get \
64
 
    $revision_build build-binary-trusty-$ARCH 'juju.*\.deb' debs
65
 
 
66
 
scp -o 'StrictHostKeyChecking no' -o 'UserKnownHostsFile /dev/null' \
67
 
  debs/*.deb ubuntu@$instance_name:
68
 
 
69
 
set +e
70
 
ssh -o "StrictHostKeyChecking no" -o "UserKnownHostsFile /dev/null" \
71
 
    ubuntu@$instance_name "SERIES=$SERIES bash"<<"EOT"
72
 
set -eux
73
 
for attempt in $(seq 10); do
74
 
  if grep ec2.archive.ubuntu.com /etc/apt/sources.list > /dev/null; then
75
 
    break
76
 
  elif [ "$attempt" == "10" ]; then
77
 
    exit 1
78
 
  fi
79
 
  sleep 10
80
 
done
81
 
sudo sed s,//.*ec2.archive.ubuntu.com,//archive.ubuntu.com, \
82
 
    /etc/apt/sources.list -i
83
 
if [[ $SERIES == "precise" ]]; then
84
 
    sudo add-apt-repository cloud-archive:tools
85
 
fi
86
 
sudo apt-get update
87
 
sudo DEBIAN_FRONTEND=noninteractive apt-get upgrade -y
88
 
sudo DEBIAN_FRONTEND=noninteractive apt-get install -y bzr
89
 
 
90
 
# prevent spurious failure on success
91
 
rm .bash_logout
92
 
afact=lastSuccessfulBuild/artifact
93
 
sudo dpkg -i *.deb || true
94
 
sudo apt-get install -y -f
95
 
export JUJU_REPOSITORY="$HOME/repo"
96
 
mkdir -p $JUJU_REPOSITORY/$SERIES
97
 
bzr branch lp:charms/ubuntu $JUJU_REPOSITORY/$SERIES/ubuntu
98
 
mkdir ~/.juju
99
 
cat > ~/.juju/environments.yaml <<EOT2
100
 
default: local
101
 
environments:
102
 
  local:
103
 
    type: local
104
 
    tools-metadata-url: http://juju-dist.s3.amazonaws.com/testing/tools
105
 
    enable-os-refresh-update: true
106
 
    default-series: trusty
107
 
EOT2
108
 
ssh-keygen -t rsa -b 2048 -N "" -f ~/.ssh/id_rsa
109
 
 
110
 
report_network() {
111
 
    echo
112
 
    echo $1
113
 
    ip link
114
 
    ip route
115
 
    ip addr
116
 
    sudo iptables-save
117
 
}
118
 
 
119
 
report_network "The starting network conditions:"
120
 
echo "Restricting the network:"
121
 
login_ip=$(netstat --tcp -n|sed -nr 's/.*:22 *([^ ]*):.* .*/\1/p')
122
 
gateway=$(route -n | sed -rn 's/^0.0.0.0 *([0-7.]*) .*/\1/p')
123
 
nameservers="$(sed /etc/resolv.conf -nr -e 's/nameserver (.*)/\1/p')"
124
 
for ns in $nameservers; do
125
 
  sudo route add $ns gw $gateway
126
 
done
127
 
sudo route add $login_ip gw $gateway
128
 
for ip in $(dig archive.ubuntu.com ubuntu-cloud.archive.canonical.com\
129
 
    security.ubuntu.com cloud-images.ubuntu.com +short |sort|uniq); do
130
 
  sudo route add $ip gw $gateway
131
 
done
132
 
sudo route add -net 172.16.0.0 netmask 255.240.0.0 gw $gateway
133
 
sudo route del default gw $gateway
134
 
report_network "The final network conditions:"
135
 
juju bootstrap --show-log
136
 
for x in $(seq 6); do
137
 
  if juju deploy --show-log local:$SERIES/ubuntu; then
138
 
    break
139
 
  elif [ "$x" == "6" ]; then
140
 
    exit 0;
141
 
  fi
142
 
done
143
 
for x in $(seq 30); do
144
 
  # relying on the indentation of ubuntu/0's agent-state here...
145
 
  # but current: idle matches only the unit of the ubuntu service.
146
 
  if juju status  --format yaml | grep -E ' {8}agent-state: started|current: idle'; then
147
 
    exit 0;
148
 
  fi
149
 
  sleep 10
150
 
done
151
 
juju status --format yaml
152
 
report_network "The failing network conditions:"
153
 
# Restore some routing so that staff can do an autopsy
154
 
sudo route add default gw $gateway eth0
155
 
exit 1
156
 
EOT
157
 
result=$?
158
 
set -e
159
 
ec2-terminate-job-instances
160
 
exit $result