818adcaf6354486f6d2bd3fb758533f76df70b8a
[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             ANSIBLE_SCRIPTS="${0%/*}/../../ansible"
67             cd ${ANSIBLE_SCRIPTS} &&\
68             ansible-playbook \
69                      -e img_property="normal" \
70                      -e YARD_IMG_ARCH=${YARD_IMG_ARCH} \
71                      -vvv -i inventory.ini build_yardstick_image.yml
72
73             if [ ! -f "${QCOW_IMAGE}" ]; then
74                 echo "Failed building QCOW image"
75                 exit 1
76             fi
77         fi
78         # DPDK compile is not enabled for arm64 yet so disable for now
79         # JIRA: YARSTICK-1124
80         if [[ ! -f "${QCOW_NSB_IMAGE}"  && ${DEPLOY_SCENARIO} == *[_-]ovs_dpdk[_-]* && "${YARD_IMG_ARCH}" != "arm64" ]]; then
81             ansible-playbook \
82                      -e img_property="nsb" \
83                      -e YARD_IMG_ARCH=${YARD_IMG_ARCH} \
84                      -vvv -i inventory.ini build_yardstick_image.yml
85             if [ ! -f "${QCOW_NSB_IMAGE}" ]; then
86                 echo "Failed building QCOW NSB image"
87                 exit 1
88             fi
89         fi
90     fi
91 }
92
93 load_yardstick_image()
94 {
95     echo
96     echo "========== Loading yardstick cloud image =========="
97     EXTRA_PARAMS=""
98     if [[ "${YARD_IMG_ARCH}" == "arm64" ]]; then
99         EXTRA_PARAMS="--property hw_video_model=vga"
100     fi
101
102     # VPP requires guest memory to be backed by large pages
103     if [[ "$DEPLOY_SCENARIO" == *"-fdio-"* ]]; then
104         EXTRA_PARAMS=$EXTRA_PARAMS" --property hw_mem_page_size=large"
105     fi
106
107     if [[ -n "${HW_FW_TYPE}" ]]; then
108         EXTRA_PARAMS=$EXTRA_PARAMS" --property hw_firmware_type=${HW_FW_TYPE}"
109     fi
110
111     if [[ "$DEPLOY_SCENARIO" == *"-lxd-"* ]]; then
112         output=$(eval openstack ${SECURE} image create \
113             --public \
114             --disk-format raw \
115             --container-format bare \
116             ${EXTRA_PARAMS} \
117             --file ${RAW_IMAGE} \
118             yardstick-image)
119     else
120         output=$(eval openstack ${SECURE} image create \
121             --public \
122             --disk-format qcow2 \
123             --container-format bare \
124             ${EXTRA_PARAMS} \
125             --file ${QCOW_IMAGE} \
126             yardstick-image)
127         # DPDK compile is not enabled for arm64 yet so disable NSB images for now
128         # JIRA: YARSTICK-1124
129         if [[ $DEPLOY_SCENARIO == *[_-]ovs_dpdk[_-]* && "${YARD_IMG_ARCH}" != "arm64" ]]; then
130             nsb_output=$(eval openstack ${SECURE} image create \
131                 --public \
132                 --disk-format qcow2 \
133                 --container-format bare \
134                 ${EXTRA_PARAMS} \
135                 --file ${QCOW_NSB_IMAGE} \
136                 yardstick-samplevnfs)
137             echo "$nsb_output"
138         fi
139     fi
140
141     echo "$output"
142
143     GLANCE_IMAGE_ID=$(echo "$output" | grep " id " | awk '{print $(NF-1)}')
144
145     if [ -z "$GLANCE_IMAGE_ID" ]; then
146         echo 'Failed uploading image to cloud'.
147         exit 1
148     fi
149
150     echo "Glance image id: $GLANCE_IMAGE_ID"
151 }
152
153 load_cirros_image()
154 {
155     EXTRA_PARAMS=""
156     if [[ "${YARD_IMG_ARCH}" == "arm64" ]]; then
157         CIRROS_IMAGE_VERSION="cirros-d161201"
158         CIRROS_IMAGE_PATH="/home/opnfv/images/cirros-d161201-aarch64-disk.img"
159         EXTRA_PARAMS="--property hw_video_model=vga --property short_id=ubuntu16.04"
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         # VPP requires guest memory to be backed by large pages
174         if [[ "$DEPLOY_SCENARIO" == *"-fdio-"* ]]; then
175             EXTRA_PARAMS=$EXTRA_PARAMS" --property hw_mem_page_size=large"
176         fi
177
178         if [[ -n "${HW_FW_TYPE}" ]]; then
179             EXTRA_PARAMS=$EXTRA_PARAMS" --property hw_firmware_type=${HW_FW_TYPE}"
180         fi
181
182         output=$(openstack ${SECURE} image create \
183             --disk-format qcow2 \
184             --container-format bare \
185             ${EXTRA_PARAMS} \
186             --file ${image_file} \
187             cirros-0.3.5)
188         echo "$output"
189
190         CIRROS_IMAGE_ID=$(echo "$output" | grep " id " | awk '{print $(NF-1)}')
191         if [ -z "$CIRROS_IMAGE_ID" ]; then
192             echo 'Failed uploading cirros image to cloud'.
193             exit 1
194         fi
195
196         echo "Cirros image id: $CIRROS_IMAGE_ID"
197     fi
198 }
199
200 load_ubuntu_image()
201 {
202     echo
203     echo "========== Loading ubuntu cloud image =========="
204
205     local ubuntu_image_file=/home/opnfv/images/xenial-server-cloudimg-amd64-disk1.img
206
207     EXTRA_PARAMS=""
208     # VPP requires guest memory to be backed by large pages
209     if [[ "$DEPLOY_SCENARIO" == *"-fdio-"* ]]; then
210         EXTRA_PARAMS=$EXTRA_PARAMS" --property hw_mem_page_size=large"
211     fi
212
213     output=$(openstack ${SECURE} image create \
214         --disk-format qcow2 \
215         --container-format bare \
216         $EXTRA_PARAMS \
217         --file $ubuntu_image_file \
218         Ubuntu-16.04)
219     echo "$output"
220
221     UBUNTU_IMAGE_ID=$(echo "$output" | grep " id " | awk '{print $(NF-1)}')
222
223     if [ -z "$UBUNTU_IMAGE_ID" ]; then
224         echo 'Failed uploading UBUNTU image to cloud'.
225         exit 1
226     fi
227
228     echo "Ubuntu image id: $UBUNTU_IMAGE_ID"
229 }
230
231 create_nova_flavor()
232 {
233     if ! openstack ${SECURE} flavor list | grep -q yardstick-flavor; then
234         echo
235         echo "========== Creating yardstick-flavor =========="
236         # Create the nova flavor used by some sample test cases
237         openstack ${SECURE} flavor create --id 100 --ram 1024 --disk 10 --vcpus 1 yardstick-flavor
238         # DPDK-enabled OVS requires guest memory to be backed by large pages
239         if [[ $DEPLOY_SCENARIO == *[_-]ovs[_-]* ]]; then
240             openstack ${SECURE} flavor set --property hw:mem_page_size=large yardstick-flavor
241         fi
242         # VPP requires guest memory to be backed by large pages
243         if [[ "$DEPLOY_SCENARIO" == *"-fdio-"* ]]; then
244             openstack ${SECURE} flavor set --property hw:mem_page_size=large yardstick-flavor
245         fi
246     fi
247
248     if ! openstack ${SECURE} flavor list | grep -q storperf; then
249         echo
250         echo "========== Creating storperf flavor =========="
251         # Create the nova flavor used by storperf test case
252         openstack ${SECURE} flavor create --id auto --ram 8192 --disk 4 --vcpus 2 storperf
253     fi
254 }
255
256 main()
257 {
258     QCOW_IMAGE="/tmp/workspace/yardstick/yardstick-image.img"
259     QCOW_NSB_IMAGE="/tmp/workspace/yardstick/yardstick-nsb-image.img"
260     RAW_IMAGE="/tmp/workspace/yardstick/yardstick-image.tar.gz"
261
262     if [ -f /home/opnfv/images/yardstick-image.img ];then
263         QCOW_IMAGE='/home/opnfv/images/yardstick-image.img'
264     fi
265     if [ -f /home/opnfv/images/yardstick-image.tar.gz ];then
266         RAW_IMAGE='/home/opnfv/images/yardstick-image.tar.gz'
267     fi
268
269     if [ $OS_INSECURE ] && [ "$(echo $OS_INSECURE | tr '[:upper:]' '[:lower:]')" = "true" ]; then
270         SECURE="--insecure"
271     else
272         SECURE=""
273     fi
274
275     build_yardstick_image
276     load_yardstick_image
277     if [ "${YARD_IMG_ARCH}" == "arm64" ]; then
278         #We have overlapping IP with the real network
279         for filename in ${YARDSTICK_REPO_DIR}/tests/opnfv/test_cases/*; do
280             sed -i "s/cidr: '10.0.1.0\/24'/cidr: '10.3.1.0\/24'/g" "${filename}"
281         done
282     else
283         load_ubuntu_image
284     fi
285     load_cirros_image
286     create_nova_flavor
287 }
288
289 main