forked from rcbops/jenkins-build
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjenkins-deb-exercise
executable file
·184 lines (142 loc) · 4.12 KB
/
jenkins-deb-exercise
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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
#!/bin/bash
#
# $1 = test repo number
#
# force a local default so this can be run on command line
DISTRELEASE=${DISTRELEASE-ubuntu-natty}
PACKAGE_REPO=${PACKAGE_REPO-proposed-packages}
[ -e $(dirname $0)/jenkins-deb-common ] || exit 1
. $(dirname $0)/jenkins-deb-common
jenkins_init
jenkins_set_vars
function err_cleanup_exercise() {
# $1 - name
if [ -e "${tmpdir}" ]; then
rm -rf "${tmpdir}"
fi
if [ "${NOCLEAN-0}" == "1" ]; then
exit 0
fi
sudo virsh destroy ${1}
sleep 5
sudo lvremove -f ${LVM_ROOT}/${1}
exit 1
}
kvm_instance_name=${BINARY_BUILD_RELEASE}-${NOVA_RELEASE}-${MILESTONE}-exercise
# this sets IP as a side-effect
get_ip $kvm_instance_name
MEMORY=2048000
maybe_make_kvm_instance $kvm_instance_name
start_kvm_instance $kvm_instance_name ${IP} http://192.168.1.1/${PACKAGE_REPO} ${BINARY_BUILD_RELEASE} ${NOVA_RELEASE}-${MILESTONE}
tmpdir=$(mktemp -d)
trap "err_cleanup_exercise ${kvm_instance_name}" SIGINT SIGTERM EXIT ERR
declare -a ip_octets
ip_octets=(${IP//./ })
cat > ${tmpdir}/dna.json <<EOF
{
"public": {
"label": "public",
"num_networks": "1",
"network_size": "255",
"bridge": "br100",
"bridge_dev": "eth0.100",
"dns1": "8.8.8.8",
"dns2": "8.8.4.4",
"ipv4_cidr": "10.2.${ip_octets[3]}.0/24"
},
"private": {
"label": "private",
"num_networks": "1",
"network_size": "255",
"bridge": "br101",
"bridge_dev": "eth0.101",
"dns1": "8.8.8.8",
"dns2": "8.8.4.4",
"ipv4_cidr": "10.3.${ip_octets[3]}.0/24"
},
"floating": {
"ipv4_cidr": "10.1.${ip_octets[3]}.0/24"
},
"package_url": "http://192.168.1.1/${PACKAGE_REPO}",
"package_release": "${BINARY_BUILD_RELEASE}",
"package_component": "${NOVA_RELEASE}-${MILESTONE}",
"virt_type": "qemu",
"run_list": [ "recipe[apt]", "recipe[openstack::allinone]", "recipe[kong]" ]
}
EOF
ssh root@${IP} apt-get install vlan -y --force-yes
ssh root@${IP} vconfig add eth0 100
ssh root@${IP} vconfig add eth0 101
run_chef_solo ${IP} "https://raw.github.com/rcbops/chef-cookbooks/diablo/cookbooks.tgz" ${tmpdir}/dna.json
sleep 20
echo "export HOST_IP=${IP}" > ${tmpdir}/localrc
cat >> ${tmpdir}/localrc <<"EOF"
export TENANT=openstack
export USERNAME=admin
export ADMIN_PASSWORD=secrete
export ACTIVE_TIMEOUT=120
export BOOT_TIMEOUT=120
export ASSOCIATE_TIMEOUT=120
export NOVA_URL=http://${HOST_IP}:5000/v2.0/
export NOVA_REGION_NAME=RegionOne
export NOVA_VERSION=1.1
export NOVA_PROJECT_ID=${TENANT}
export NOVA_API_KEY=${ADMIN_PASSWORD}
export NOVA_USERNAME=${USERNAME}
function do_cleanup() {
EXITSTAT=$?
if [ $EXITSTAT -eq 0 ] && [[ ! $(basename ${BASH_SOURCE[0]}) =~ ".sh" ]]; then
return 0
fi
set +e
trap - SIGINT SIGTERM ERR
if [ ${EXITSTAT} -ne 0 ]; then
echo " == STARTING CLEANUP == "
fi
SECGROUP=test_secgroup
if ( nova secgroup-list | grep ${SECGROUP}); then
nova secgroup-delete ${SECGROUP}
fi
NAME=myserver
for id in $(nova list | grep "${NAME}" | cut -d'|' -f2); do
echo "Deleting ${id}"
nova delete ${id}
if ! timeout ${ACTIVE_TIMEOUT} sh -c "while nova show ${id}; do sleep 1; done"; then
echo "Server ${id} would not shut down"
exit 1
fi
done
# propogate SIGINT so timeouts aren't stupid
if [ $EXITSTAT -eq 130 ]; then
echo "Bailing on SIGINT"
kill -s SIGINT $$
exit 130
fi
exit 1
}
function grep() {
if [ "${1:-}" == "private network" ]; then
shift
/bin/grep "public network" "$@"
else
/bin/grep "$@"
fi
}
if [ $(basename ${BASH_SOURCE[$(( ${#BASH_SOURCE[@]} - 1))]}) == "exercise.sh" ]; then
echo "== INSTALLING TRAP HANDLER =="
trap do_cleanup SIGINT SIGTERM ERR
do_cleanup
else
echo "Not installing trap handler."
fi
EOF
# box should be configured now....
ssh root@${IP} -- apt-get install -y git-core euca2ools
ssh root@${IP} -- "cd /opt; git clone http://github.com/rpedde/devstack"
scp ${tmpdir}/localrc root@${IP}:/opt/devstack
ssh root@${IP} -- "cd /opt/devstack; SKIP_EXERCISES=swift,euca ./exercise.sh"
trap - SIGINT SIGTERM EXIT ERR
rm -rf ${tmpdir}
sudo virsh destroy ${kvm_instance_name}
sleep 5
sudo lvremove -f ${LVM_ROOT}/${kvm_instance_name}