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