Merge "Get HA test case results on failure"
[yardstick.git] / tests / ci / load_images.sh
1 #!/bin/bash
2 ##############################################################################
3 # Copyright (c) 2015 Ericsson AB, Huawei Technologies Co.,Ltd and others.
4 #
5 # All rights reserved. This program and the accompanying materials
6 # are made available under the terms of the Apache License, Version 2.0
7 # which accompanies this distribution, and is available at
8 # http://www.apache.org/licenses/LICENSE-2.0
9 ##############################################################################
10
11 # Set up the environment to run yardstick test suites.
12
13 set -e
14
15 YARD_IMG_ARCH=amd64
16
17 if ! grep -q "Defaults env_keep += \"YARD_IMG_ARCH\"" "/etc/sudoers"; then
18     echo "Defaults env_keep += \"YARD_IMG_ARCH YARDSTICK_REPO_DIR\"" | sudo tee -a /etc/sudoers
19 fi
20
21 # Look for a compute node, that is online, and check if it is aarch64
22 if [ "${INSTALLER_TYPE}" == 'fuel' ]; then
23     ssh_options="-o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no"
24     COMPUTE_ARCH=$(ssh -l ubuntu ${INSTALLER_IP} -i ${SSH_KEY} ${ssh_options} \
25         "sudo salt 'cmp*' grains.get cpuarch --out yaml | awk '{print \$2; exit}'")
26     if [ "${COMPUTE_ARCH}" == 'aarch64' ]; then
27         YARD_IMG_ARCH=arm64
28     fi
29 fi
30 export YARD_IMG_ARCH
31
32 HW_FW_TYPE=""
33 if [ "${YARD_IMG_ARCH}" == "arm64" ]; then
34     HW_FW_TYPE=uefi
35 fi
36 export HW_FW_TYPE
37
38 UCA_HOST="cloud-images.ubuntu.com"
39 if [ "${YARD_IMG_ARCH}" == "arm64" ]; then
40     export CLOUD_IMG_URL="http://${UCA_HOST}/${release}/current/${release}-server-cloudimg-${YARD_IMG_ARCH}.tar.gz"
41     if ! grep -q "Defaults env_keep += \"CLOUD_IMG_URL\"" "/etc/sudoers"; then
42         echo "Defaults env_keep += \"CLOUD_IMG_URL\"" | sudo tee -a /etc/sudoers
43     fi
44 fi
45
46 cleanup_loopbacks() {
47     # try again to cleanup loopbacks in case of error
48     losetup -a
49     losetup -O NAME,BACK-FILE | awk '/yardstick/ { print $1 }' | xargs -l1 losetup -v -d || true
50 }
51
52 build_yardstick_image()
53 {
54     echo
55     echo "========== Build yardstick cloud image =========="
56
57     if [[ "$DEPLOY_SCENARIO" == *"-lxd-"* ]]; then
58         if [ ! -f "${RAW_IMAGE}" ];then
59             local cmd
60             cmd="sudo $(which yardstick-img-lxd-modify) $(pwd)/tools/ubuntu-server-cloudimg-modify.sh"
61
62             # Build the image. Retry once if the build fails
63             $cmd || $cmd
64
65             cleanup_loopbacks
66             if [ ! -f "${RAW_IMAGE}" ]; then
67                 echo "Failed building RAW image"
68                 exit 1
69             fi
70         fi
71     else
72         if [ ! -f "${QCOW_IMAGE}" ];then
73             ANSIBLE_SCRIPTS="${0%/*}/../../ansible"
74             cd ${ANSIBLE_SCRIPTS} &&\
75             ansible-playbook \
76                      -e img_property="normal" \
77                      -e YARD_IMG_ARCH=${YARD_IMG_ARCH} \
78                      -vvv -i inventory.ini build_yardstick_image.yml
79
80             cleanup_loopbacks
81             if [ ! -f "${QCOW_IMAGE}" ]; then
82                 echo "Failed building QCOW image"
83                 exit 1
84             fi
85         fi
86         # DPDK compile is not enabled for arm64 yet so disable for now
87         # JIRA: YARSTICK-1124
88         if [[ ! -f "${QCOW_NSB_IMAGE}"  && ${DEPLOY_SCENARIO} == *[_-]ovs_dpdk[_-]* && "${YARD_IMG_ARCH}" != "arm64" ]]; then
89             ansible-playbook \
90                      -e img_property="nsb" \
91                      -e YARD_IMG_ARCH=${YARD_IMG_ARCH} \
92                      -vvv -i inventory.ini build_yardstick_image.yml
93             cleanup_loopbacks
94             if [ ! -f "${QCOW_NSB_IMAGE}" ]; then
95                 echo "Failed building QCOW NSB image"
96                 exit 1
97             fi
98         fi
99     fi
100 }
101
102 load_yardstick_image()
103 {
104     echo
105     echo "========== Loading yardstick cloud image =========="
106     EXTRA_PARAMS=""
107     if [[ "${YARD_IMG_ARCH}" == "arm64" ]]; then
108         EXTRA_PARAMS="--property hw_video_model=vga"
109     fi
110
111     # VPP requires guest memory to be backed by large pages
112     if [[ "$DEPLOY_SCENARIO" == *"-fdio-"* ]]; then
113         EXTRA_PARAMS=$EXTRA_PARAMS" --property hw_mem_page_size=large"
114     fi
115
116     if [[ -n "${HW_FW_TYPE}" ]]; then
117         EXTRA_PARAMS=$EXTRA_PARAMS" --property hw_firmware_type=${HW_FW_TYPE}"
118     fi
119
120     if [[ "$DEPLOY_SCENARIO" == *"-lxd-"* ]]; then
121         output=$(eval openstack ${SECURE} image create \
122             --public \
123             --disk-format raw \
124             --container-format bare \
125             ${EXTRA_PARAMS} \
126             --file ${RAW_IMAGE} \
127             yardstick-image)
128     else
129         output=$(eval openstack ${SECURE} image create \
130             --public \
131             --disk-format qcow2 \
132             --container-format bare \
133             ${EXTRA_PARAMS} \
134             --file ${QCOW_IMAGE} \
135             yardstick-image)
136         # DPDK compile is not enabled for arm64 yet so disable NSB images for now
137         # JIRA: YARSTICK-1124
138         if [[ $DEPLOY_SCENARIO == *[_-]ovs_dpdk[_-]* && "${YARD_IMG_ARCH}" != "arm64" ]]; then
139             nsb_output=$(eval openstack ${SECURE} image create \
140                 --public \
141                 --disk-format qcow2 \
142                 --container-format bare \
143                 ${EXTRA_PARAMS} \
144                 --file ${QCOW_NSB_IMAGE} \
145                 yardstick-samplevnfs)
146             echo "$nsb_output"
147         fi
148     fi
149
150     echo "$output"
151
152     GLANCE_IMAGE_ID=$(echo "$output" | grep " id " | awk '{print $(NF-1)}')
153
154     if [ -z "$GLANCE_IMAGE_ID" ]; then
155         echo 'Failed uploading image to cloud'.
156         exit 1
157     fi
158
159     echo "Glance image id: $GLANCE_IMAGE_ID"
160 }
161
162 load_cirros_image()
163 {
164     EXTRA_PARAMS=""
165     if [[ "${YARD_IMG_ARCH}" == "arm64" ]]; then
166         CIRROS_IMAGE_VERSION="cirros-d161201"
167         CIRROS_IMAGE_PATH="/home/opnfv/images/cirros-d161201-aarch64-disk.img"
168         EXTRA_PARAMS="--property hw_video_model=vga --property short_id=ubuntu16.04"
169     else
170         CIRROS_IMAGE_VERSION="cirros-0.3.5"
171         CIRROS_IMAGE_PATH="/home/opnfv/images/cirros-0.3.5-x86_64-disk.img"
172     fi
173
174     if [[ -n $(openstack ${SECURE} image list | grep -e "${CIRROS_IMAGE_VERSION}") ]]; then
175         echo "${CIRROS_IMAGE_VERSION} image already exist, skip loading cirros image"
176     else
177         echo
178         echo "========== Loading cirros cloud image =========="
179
180         local image_file="${CIRROS_IMAGE_PATH}"
181
182         # VPP requires guest memory to be backed by large pages
183         if [[ "$DEPLOY_SCENARIO" == *"-fdio-"* ]]; then
184             EXTRA_PARAMS=$EXTRA_PARAMS" --property hw_mem_page_size=large"
185         fi
186
187         if [[ -n "${HW_FW_TYPE}" ]]; then
188             EXTRA_PARAMS=$EXTRA_PARAMS" --property hw_firmware_type=${HW_FW_TYPE}"
189         fi
190
191         output=$(openstack ${SECURE} image create \
192             --disk-format qcow2 \
193             --container-format bare \
194             ${EXTRA_PARAMS} \
195             --file ${image_file} \
196             cirros-0.3.5)
197         echo "$output"
198
199         CIRROS_IMAGE_ID=$(echo "$output" | grep " id " | awk '{print $(NF-1)}')
200         if [ -z "$CIRROS_IMAGE_ID" ]; then
201             echo 'Failed uploading cirros image to cloud'.
202             exit 1
203         fi
204
205         echo "Cirros image id: $CIRROS_IMAGE_ID"
206     fi
207 }
208
209 load_ubuntu_image()
210 {
211     echo
212     echo "========== Loading ubuntu cloud image =========="
213
214     local ubuntu_image_file=/home/opnfv/images/xenial-server-cloudimg-amd64-disk1.img
215
216     EXTRA_PARAMS=""
217     # VPP requires guest memory to be backed by large pages
218     if [[ "$DEPLOY_SCENARIO" == *"-fdio-"* ]]; then
219         EXTRA_PARAMS=$EXTRA_PARAMS" --property hw_mem_page_size=large"
220     fi
221
222     output=$(openstack ${SECURE} image create \
223         --disk-format qcow2 \
224         --container-format bare \
225         $EXTRA_PARAMS \
226         --file $ubuntu_image_file \
227         Ubuntu-16.04)
228     echo "$output"
229
230     UBUNTU_IMAGE_ID=$(echo "$output" | grep " id " | awk '{print $(NF-1)}')
231
232     if [ -z "$UBUNTU_IMAGE_ID" ]; then
233         echo 'Failed uploading UBUNTU image to cloud'.
234         exit 1
235     fi
236
237     echo "Ubuntu image id: $UBUNTU_IMAGE_ID"
238 }
239
240 create_nova_flavor()
241 {
242     if ! openstack ${SECURE} flavor list | grep -q yardstick-flavor; then
243         echo
244         echo "========== Creating yardstick-flavor =========="
245         # Create the nova flavor used by some sample test cases
246         openstack ${SECURE} flavor create --id 100 --ram 1024 --disk 10 --vcpus 1 yardstick-flavor
247         # DPDK-enabled OVS requires guest memory to be backed by large pages
248         if [[ $DEPLOY_SCENARIO == *[_-]ovs[_-]* ]]; then
249             openstack ${SECURE} flavor set --property hw:mem_page_size=large yardstick-flavor
250         fi
251         # VPP requires guest memory to be backed by large pages
252         if [[ "$DEPLOY_SCENARIO" == *"-fdio-"* ]]; then
253             openstack ${SECURE} flavor set --property hw:mem_page_size=large yardstick-flavor
254         fi
255     fi
256
257     if ! openstack ${SECURE} flavor list | grep -q storperf; then
258         echo
259         echo "========== Creating storperf flavor =========="
260         # Create the nova flavor used by storperf test case
261         openstack ${SECURE} flavor create --id auto --ram 8192 --disk 4 --vcpus 2 storperf
262     fi
263 }
264
265 main()
266 {
267     QCOW_IMAGE="/tmp/workspace/yardstick/yardstick-image.img"
268     QCOW_NSB_IMAGE="/tmp/workspace/yardstick/yardstick-nsb-image.img"
269     RAW_IMAGE="/tmp/workspace/yardstick/yardstick-image.tar.gz"
270
271     if [ -f /home/opnfv/images/yardstick-image.img ];then
272         QCOW_IMAGE='/home/opnfv/images/yardstick-image.img'
273     fi
274     if [ -f /home/opnfv/images/yardstick-image.tar.gz ];then
275         RAW_IMAGE='/home/opnfv/images/yardstick-image.tar.gz'
276     fi
277
278     if [ $OS_INSECURE ] && [ "$(echo $OS_INSECURE | tr '[:upper:]' '[:lower:]')" = "true" ]; then
279         SECURE="--insecure"
280     else
281         SECURE=""
282     fi
283
284     build_yardstick_image
285     load_yardstick_image
286     if [ "${YARD_IMG_ARCH}" == "arm64" ]; then
287         #We have overlapping IP with the real network
288         for filename in ${YARDSTICK_REPO_DIR}/tests/opnfv/test_cases/*; do
289             sed -i "s/cidr: '10.0.1.0\/24'/cidr: '10.3.1.0\/24'/g" "${filename}"
290         done
291     else
292         load_ubuntu_image
293     fi
294     load_cirros_image
295     create_nova_flavor
296 }
297
298 main