Merge "bugfix: show testcase api return type error"
[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         if [ ! -f "${RAW_IMAGE}" ];then
49             local cmd
50             cmd="sudo $(which yardstick-img-lxd-modify) $(pwd)/tools/ubuntu-server-cloudimg-modify.sh"
51
52             # Build the image. Retry once if the build fails
53             $cmd || $cmd
54
55             if [ ! -f "${RAW_IMAGE}" ]; then
56                 echo "Failed building RAW image"
57                 exit 1
58             fi
59         fi
60     else
61         if [ ! -f "${QCOW_IMAGE}" ];then
62             local cmd
63             cmd="sudo $(which yardstick-img-modify) $(pwd)/tools/ubuntu-server-cloudimg-modify.sh"
64
65             # Build the image. Retry once if the build fails
66             $cmd || $cmd
67
68             if [ ! -f "${QCOW_IMAGE}" ]; then
69                 echo "Failed building QCOW image"
70                 exit 1
71             fi
72         fi
73     fi
74 }
75
76 load_yardstick_image()
77 {
78     echo
79     echo "========== Loading yardstick cloud image =========="
80     EXTRA_PARAMS=""
81     if [[ "${YARD_IMG_ARCH}" == "arm64" && "${YARD_IMG_AKI}" == "true" ]]; then
82         CLOUD_IMAGE="/tmp/${release}-server-cloudimg-${YARD_IMG_ARCH}.tar.gz"
83         CLOUD_KERNEL="/tmp/${release}-server-cloudimg-${YARD_IMG_ARCH}-vmlinuz-generic"
84         cd /tmp
85         if [ ! -f "${CLOUD_IMAGE}" ]; then
86             wget "${CLOUD_IMG_URL}"
87         fi
88         if [ ! -f "${CLOUD_KERNEL}" ]; then
89             tar xf "${CLOUD_IMAGE}" "${CLOUD_KERNEL##**/}"
90         fi
91         create_kernel=$(openstack ${SECURE} image create \
92                 --public \
93                 --disk-format qcow2 \
94                 --container-format bare \
95                 --file ${CLOUD_KERNEL} \
96                 yardstick-${release}-kernel)
97
98         GLANCE_KERNEL_ID=$(echo "$create_kernel" | awk '/ id / {print $(NF-1)}')
99         if [ -z "$GLANCE_KERNEL_ID" ]; then
100             echo 'Failed uploading kernel to cloud'.
101             exit 1
102         fi
103
104         command_line="root=/dev/vdb1 console=tty0 console=ttyS0 console=ttyAMA0 rw"
105
106         EXTRA_PARAMS="--property kernel_id=$GLANCE_KERNEL_ID --property os_command_line=\"$command_line\""
107
108         rm -f -- "${CLOUD_KERNEL}" "${CLOUD_IMAGE}"
109         cd "${YARDSTICK_REPO_DIR}"
110     fi
111
112     # VPP requires guest memory to be backed by large pages
113     if [[ "$DEPLOY_SCENARIO" == *"-fdio-"* ]]; then
114         EXTRA_PARAMS=$EXTRA_PARAMS" --property hw_mem_page_size=large"
115     fi
116
117     if [[ -n "${HW_FW_TYPE}" ]]; then
118         EXTRA_PARAMS=$EXTRA_PARAMS" --property hw_firmware_type=${HW_FW_TYPE}"
119     fi
120
121     if [[ "$DEPLOY_SCENARIO" == *"-lxd-"* ]]; then
122         output=$(eval openstack ${SECURE} image create \
123             --public \
124             --disk-format raw \
125             --container-format bare \
126             ${EXTRA_PARAMS} \
127             --file ${RAW_IMAGE} \
128             yardstick-image)
129     else
130         output=$(eval openstack ${SECURE} image create \
131             --public \
132             --disk-format qcow2 \
133             --container-format bare \
134             ${EXTRA_PARAMS} \
135             --file ${QCOW_IMAGE} \
136             yardstick-image)
137     fi
138
139     echo "$output"
140
141     GLANCE_IMAGE_ID=$(echo "$output" | grep " id " | awk '{print $(NF-1)}')
142
143     if [ -z "$GLANCE_IMAGE_ID" ]; then
144         echo 'Failed uploading image to cloud'.
145         exit 1
146     fi
147
148     echo "Glance image id: $GLANCE_IMAGE_ID"
149 }
150
151 load_cirros_image()
152 {
153     if [[ "${YARD_IMG_ARCH}" == "arm64" ]]; then
154         CIRROS_IMAGE_VERSION="cirros-d161201"
155         CIRROS_IMAGE_PATH="/home/opnfv/images/cirros-d161201-aarch64-disk.img"
156     else
157         CIRROS_IMAGE_VERSION="Cirros-0.3.5"
158         CIRROS_IMAGE_PATH="/home/opnfv/images/cirros-0.3.5-x86_64-disk.img"
159     fi
160
161     if [[ -n $(openstack ${SECURE} image list | grep -e "${CIRROS_IMAGE_VERSION}") ]]; then
162         echo "${CIRROS_IMAGE_VERSION} image already exist, skip loading cirros image"
163     else
164         echo
165         echo "========== Loading cirros cloud image =========="
166
167         local image_file="${CIRROS_IMAGE_PATH}"
168
169         EXTRA_PARAMS=""
170         # VPP requires guest memory to be backed by large pages
171         if [[ "$DEPLOY_SCENARIO" == *"-fdio-"* ]]; then
172             EXTRA_PARAMS=$EXTRA_PARAMS" --property hw_mem_page_size=large"
173         fi
174
175         output=$(openstack ${SECURE} image create \
176             --disk-format qcow2 \
177             --container-format bare \
178             ${EXTRA_PARAMS} \
179             --file ${image_file} \
180             cirros-0.3.5)
181         echo "$output"
182
183         CIRROS_IMAGE_ID=$(echo "$output" | grep " id " | awk '{print $(NF-1)}')
184         if [ -z "$CIRROS_IMAGE_ID" ]; then
185             echo 'Failed uploading cirros image to cloud'.
186             exit 1
187         fi
188
189         echo "Cirros image id: $CIRROS_IMAGE_ID"
190     fi
191 }
192
193 load_ubuntu_image()
194 {
195     echo
196     echo "========== Loading ubuntu cloud image =========="
197
198     local ubuntu_image_file=/home/opnfv/images/xenial-server-cloudimg-amd64-disk1.img
199
200     EXTRA_PARAMS=""
201     # VPP requires guest memory to be backed by large pages
202     if [[ "$DEPLOY_SCENARIO" == *"-fdio-"* ]]; then
203         EXTRA_PARAMS=$EXTRA_PARAMS" --property hw_mem_page_size=large"
204     fi
205
206     output=$(openstack ${SECURE} image create \
207         --disk-format qcow2 \
208         --container-format bare \
209         $EXTRA_PARAMS \
210         --file $ubuntu_image_file \
211         Ubuntu-16.04)
212     echo "$output"
213
214     UBUNTU_IMAGE_ID=$(echo "$output" | grep " id " | awk '{print $(NF-1)}')
215
216     if [ -z "$UBUNTU_IMAGE_ID" ]; then
217         echo 'Failed uploading UBUNTU image to cloud'.
218         exit 1
219     fi
220
221     echo "Ubuntu image id: $UBUNTU_IMAGE_ID"
222 }
223
224 create_nova_flavor()
225 {
226     if ! openstack ${SECURE} flavor list | grep -q yardstick-flavor; then
227         echo
228         echo "========== Creating yardstick-flavor =========="
229         # Create the nova flavor used by some sample test cases
230         openstack ${SECURE} flavor create --id 100 --ram 1024 --disk 3 --vcpus 1 yardstick-flavor
231         # DPDK-enabled OVS requires guest memory to be backed by large pages
232         if [[ $DEPLOY_SCENARIO == *[_-]ovs[_-]* ]]; then
233             openstack ${SECURE} flavor set --property hw:mem_page_size=large yardstick-flavor
234         fi
235         # VPP requires guest memory to be backed by large pages
236         if [[ "$DEPLOY_SCENARIO" == *"-fdio-"* ]]; then
237             openstack ${SECURE} flavor set --property hw:mem_page_size=large yardstick-flavor
238         fi
239     fi
240
241     if ! openstack ${SECURE} flavor list | grep -q storperf; then
242         echo
243         echo "========== Creating storperf flavor =========="
244         # Create the nova flavor used by storperf test case
245         openstack ${SECURE} flavor create --id auto --ram 8192 --disk 4 --vcpus 2 storperf
246     fi
247 }
248
249 main()
250 {
251     QCOW_IMAGE="/tmp/workspace/yardstick/yardstick-image.img"
252     RAW_IMAGE="/tmp/workspace/yardstick/yardstick-image.tar.gz"
253
254     if [ -f /home/opnfv/images/yardstick-image.img ];then
255         QCOW_IMAGE='/home/opnfv/images/yardstick-image.img'
256     fi
257     if [ -f /home/opnfv/images/yardstick-image.tar.gz ];then
258         RAW_IMAGE='/home/opnfv/images/yardstick-image.tar.gz'
259     fi
260
261     if [ $OS_INSECURE ] && [ "$(echo $OS_INSECURE | tr '[:upper:]' '[:lower:]')" = "true" ]; then
262         SECURE="--insecure"
263     else
264         SECURE=""
265     fi
266
267     build_yardstick_image
268     load_yardstick_image
269     if [ "${YARD_IMG_ARCH}" == "arm64" ]; then
270         sed -i 's/image: {{image}}/image: TestVM/g' tests/opnfv/test_cases/opnfv_yardstick_tc002.yaml
271         sed -i 's/image: cirros-0.3.5/image: TestVM/g' samples/ping.yaml
272         #We have overlapping IP with the real network
273         for filename in tests/opnfv/test_cases/*; do
274             sed -i "s/cidr: '10.0.1.0\/24'/cidr: '10.3.1.0\/24'/g" "${filename}"
275         done
276     else
277         load_cirros_image
278         load_ubuntu_image
279     fi
280     create_nova_flavor
281 }
282
283 main