2525040f410f015b1a870eae1265697890e5ebb4
[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 export YARD_IMG_ARCH
17
18 if ! grep -q "Defaults env_keep += \"YARD_IMG_ARCH\"" "/etc/sudoers"; then
19     echo "Defaults env_keep += \"YARD_IMG_ARCH YARDSTICK_REPO_DIR\"" | sudo tee -a /etc/sudoers
20 fi
21
22 # Look for a compute node, that is online, and check if it is aarch64
23 ARCH_SCRIPT="ssh \$(fuel2 node list | awk -F'|' '\$6 ~ /compute/ && \$11 ~ /rue/ {print \$7; exit;}') uname -m 2>/dev/null | grep -q aarch64"
24 if [ "$INSTALLER_TYPE" == "fuel" ]; then
25     sshpass -p r00tme ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -l root "${INSTALLER_IP}" "${ARCH_SCRIPT}" && YARD_IMG_ARCH=arm64
26 fi
27
28 HW_FW_TYPE=""
29 if [ "${YARD_IMG_ARCH}" == "arm64" ]; then
30     HW_FW_TYPE=uefi
31 fi
32 export HW_FW_TYPE
33
34 UCA_HOST="cloud-images.ubuntu.com"
35 if [ "${YARD_IMG_ARCH}" == "arm64" ]; then
36     export CLOUD_IMG_URL="http://${UCA_HOST}/${release}/current/${release}-server-cloudimg-${YARD_IMG_ARCH}.tar.gz"
37     if ! grep -q "Defaults env_keep += \"CLOUD_IMG_URL\"" "/etc/sudoers"; then
38         echo "Defaults env_keep += \"CLOUD_IMG_URL\"" | sudo tee -a /etc/sudoers
39     fi
40 fi
41
42 build_yardstick_image()
43 {
44     echo
45     echo "========== Build yardstick cloud image =========="
46
47     if [[ "$DEPLOY_SCENARIO" == *"-lxd-"* ]]; then
48         local cmd
49         cmd="sudo $(which yardstick-img-lxd-modify) $(pwd)/tools/ubuntu-server-cloudimg-modify.sh"
50
51         # Build the image. Retry once if the build fails
52         $cmd || $cmd
53
54         if [ ! -f "${RAW_IMAGE}" ]; then
55             echo "Failed building RAW image"
56             exit 1
57         fi
58     else
59         local cmd
60         cmd="sudo $(which yardstick-img-modify) $(pwd)/tools/ubuntu-server-cloudimg-modify.sh"
61
62         # Build the image. Retry once if the build fails
63         $cmd || $cmd
64
65         if [ ! -f "${QCOW_IMAGE}" ]; then
66             echo "Failed building QCOW image"
67             exit 1
68         fi
69     fi
70 }
71
72 load_yardstick_image()
73 {
74     echo
75     echo "========== Loading yardstick cloud image =========="
76     EXTRA_PARAMS=""
77     if [[ "${YARD_IMG_ARCH}" == "arm64" && "${YARD_IMG_AKI}" == "true" ]]; then
78         CLOUD_IMAGE="/tmp/${release}-server-cloudimg-${YARD_IMG_ARCH}.tar.gz"
79         CLOUD_KERNEL="/tmp/${release}-server-cloudimg-${YARD_IMG_ARCH}-vmlinuz-generic"
80         cd /tmp
81         if [ ! -f "${CLOUD_IMAGE}" ]; then
82             wget "${CLOUD_IMG_URL}"
83         fi
84         if [ ! -f "${CLOUD_KERNEL}" ]; then
85             tar xf "${CLOUD_IMAGE}" "${CLOUD_KERNEL##**/}"
86         fi
87         create_kernel=$(openstack image create \
88                 --public \
89                 --disk-format qcow2 \
90                 --container-format bare \
91                 --file ${CLOUD_KERNEL} \
92                 yardstick-${release}-kernel)
93
94         GLANCE_KERNEL_ID=$(echo "$create_kernel" | awk '/ id / {print $(NF-1)}')
95         if [ -z "$GLANCE_KERNEL_ID" ]; then
96             echo 'Failed uploading kernel to cloud'.
97             exit 1
98         fi
99
100         command_line="root=/dev/vdb1 console=tty0 console=ttyS0 console=ttyAMA0 rw"
101
102         EXTRA_PARAMS="--property kernel_id=$GLANCE_KERNEL_ID --property os_command_line=\"$command_line\""
103
104         rm -f -- "${CLOUD_KERNEL}" "${CLOUD_IMAGE}"
105         cd "${YARDSTICK_REPO_DIR}"
106     fi
107
108     # VPP requires guest memory to be backed by large pages
109     if [[ "$DEPLOY_SCENARIO" == *"-fdio-"* ]]; then
110         EXTRA_PARAMS=$EXTRA_PARAMS" --property hw_mem_page_size=large"
111     fi
112
113     if [[ -n "${HW_FW_TYPE}" ]]; then
114         EXTRA_PARAMS=$EXTRA_PARAMS" --property hw_firmware_type=${HW_FW_TYPE}"
115     fi
116
117     if [[ "$DEPLOY_SCENARIO" == *"-lxd-"* ]]; then
118         output=$(eval openstack image create \
119             --public \
120             --disk-format raw \
121             --container-format bare \
122             ${EXTRA_PARAMS} \
123             --file ${RAW_IMAGE} \
124             yardstick-image)
125     else
126         output=$(eval openstack image create \
127             --public \
128             --disk-format qcow2 \
129             --container-format bare \
130             ${EXTRA_PARAMS} \
131             --file ${QCOW_IMAGE} \
132             yardstick-image)
133     fi
134
135     echo "$output"
136
137     GLANCE_IMAGE_ID=$(echo "$output" | grep " id " | awk '{print $(NF-1)}')
138
139     if [ -z "$GLANCE_IMAGE_ID" ]; then
140         echo 'Failed uploading image to cloud'.
141         exit 1
142     fi
143
144     if [[ "$DEPLOY_SCENARIO" == *"-lxd-"* ]]; then
145         sudo rm -f -- "${RAW_IMAGE}"
146     else
147         sudo rm -f -- "${QCOW_IMAGE}"
148     fi
149
150     echo "Glance image id: $GLANCE_IMAGE_ID"
151 }
152
153 load_cirros_image()
154 {
155     if [[ -n $(openstack image list | grep -e Cirros-0.3.5) ]]; then
156         echo "Cirros-0.3.5 image already exist, skip loading cirros image"
157     else
158         echo
159         echo "========== Loading cirros cloud image =========="
160
161         local image_file=/home/opnfv/images/cirros-0.3.5-x86_64-disk.img
162
163         EXTRA_PARAMS=""
164         # VPP requires guest memory to be backed by large pages
165         if [[ "$DEPLOY_SCENARIO" == *"-fdio-"* ]]; then
166             EXTRA_PARAMS=$EXTRA_PARAMS" --property hw_mem_page_size=large"
167         fi
168
169         output=$(openstack image create \
170             --disk-format qcow2 \
171             --container-format bare \
172             ${EXTRA_PARAMS} \
173             --file ${image_file} \
174             cirros-0.3.5)
175         echo "$output"
176
177         CIRROS_IMAGE_ID=$(echo "$output" | grep " id " | awk '{print $(NF-1)}')
178         if [ -z "$CIRROS_IMAGE_ID" ]; then
179             echo 'Failed uploading cirros image to cloud'.
180             exit 1
181         fi
182
183         echo "Cirros image id: $CIRROS_IMAGE_ID"
184     fi
185 }
186
187 load_ubuntu_image()
188 {
189     echo
190     echo "========== Loading ubuntu cloud image =========="
191
192     local ubuntu_image_file=/home/opnfv/images/trusty-server-cloudimg-amd64-disk1.img
193
194     EXTRA_PARAMS=""
195     # VPP requires guest memory to be backed by large pages
196     if [[ "$DEPLOY_SCENARIO" == *"-fdio-"* ]]; then
197         EXTRA_PARAMS=$EXTRA_PARAMS" --property hw_mem_page_size=large"
198     fi
199
200     output=$(openstack image create \
201         --disk-format qcow2 \
202         --container-format bare \
203         $EXTRA_PARAMS \
204         --file $ubuntu_image_file \
205         Ubuntu-14.04)
206     echo "$output"
207
208     UBUNTU_IMAGE_ID=$(echo "$output" | grep " id " | awk '{print $(NF-1)}')
209
210     if [ -z "$UBUNTU_IMAGE_ID" ]; then
211         echo 'Failed uploading UBUNTU image to cloud'.
212         exit 1
213     fi
214
215     echo "Ubuntu image id: $UBUNTU_IMAGE_ID"
216 }
217
218 create_nova_flavor()
219 {
220     if ! openstack flavor list | grep -q yardstick-flavor; then
221         echo
222         echo "========== Create nova flavor =========="
223         # Create the nova flavor used by some sample test cases
224         openstack flavor create --id 100 --ram 512 --disk 3 --vcpus 1 yardstick-flavor
225         # DPDK-enabled OVS requires guest memory to be backed by large pages
226         if [[ $DEPLOY_SCENARIO == *[_-]ovs[_-]* ]]; then
227             openstack flavor set --property hw:mem_page_size=large yardstick-flavor
228         fi
229         # VPP requires guest memory to be backed by large pages
230         if [[ "$DEPLOY_SCENARIO" == *"-fdio-"* ]]; then
231             openstack flavor set --property hw:mem_page_size=large yardstick-flavor
232         fi
233     fi
234 }
235
236 main()
237 {
238     QCOW_IMAGE="/tmp/workspace/yardstick/yardstick-image.img"
239     RAW_IMAGE="/tmp/workspace/yardstick/yardstick-image.tar.gz"
240
241     build_yardstick_image
242     load_yardstick_image
243     if [ "${YARD_IMG_ARCH}" == "arm64" ]; then
244         sed -i 's/image: {{image}}/image: TestVM/g' tests/opnfv/test_cases/opnfv_yardstick_tc002.yaml
245         sed -i 's/image: cirros-0.3.5/image: TestVM/g' samples/ping.yaml
246         #We have overlapping IP with the real network
247         for filename in tests/opnfv/test_cases/*; do
248             sed -i "s/cidr: '10.0.1.0\/24'/cidr: '10.3.1.0\/24'/g" "${filename}"
249         done
250     else
251         load_cirros_image
252         load_ubuntu_image
253     fi
254     create_nova_flavor
255 }
256
257 main