Merge "Update yardstick framework architecture in userguide"
[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     echo
156     echo "========== Loading cirros cloud image =========="
157
158     local image_file=/home/opnfv/images/cirros-0.3.3-x86_64-disk.img
159
160     EXTRA_PARAMS=""
161     # VPP requires guest memory to be backed by large pages
162     if [[ "$DEPLOY_SCENARIO" == *"-fdio-"* ]]; then
163         EXTRA_PARAMS=$EXTRA_PARAMS" --property hw_mem_page_size=large"
164     fi
165
166     output=$(openstack image create \
167         --disk-format qcow2 \
168         --container-format bare \
169         ${EXTRA_PARAMS} \
170         --file ${image_file} \
171         cirros-0.3.3)
172     echo "$output"
173
174     CIRROS_IMAGE_ID=$(echo "$output" | grep " id " | awk '{print $(NF-1)}')
175     if [ -z "$CIRROS_IMAGE_ID" ]; then
176         echo 'Failed uploading cirros image to cloud'.
177         exit 1
178     fi
179
180     echo "Cirros image id: $CIRROS_IMAGE_ID"
181 }
182
183 load_ubuntu_image()
184 {
185     echo
186     echo "========== Loading ubuntu cloud image =========="
187
188     local ubuntu_image_file=/home/opnfv/images/trusty-server-cloudimg-amd64-disk1.img
189
190     EXTRA_PARAMS=""
191     # VPP requires guest memory to be backed by large pages
192     if [[ "$DEPLOY_SCENARIO" == *"-fdio-"* ]]; then
193         EXTRA_PARAMS=$EXTRA_PARAMS" --property hw_mem_page_size=large"
194     fi
195
196     output=$(openstack image create \
197         --disk-format qcow2 \
198         --container-format bare \
199         $EXTRA_PARAMS \
200         --file $ubuntu_image_file \
201         Ubuntu-14.04)
202     echo "$output"
203
204     UBUNTU_IMAGE_ID=$(echo "$output" | grep " id " | awk '{print $(NF-1)}')
205
206     if [ -z "$UBUNTU_IMAGE_ID" ]; then
207         echo 'Failed uploading UBUNTU image to cloud'.
208         exit 1
209     fi
210
211     echo "Ubuntu image id: $UBUNTU_IMAGE_ID"
212 }
213
214 create_nova_flavor()
215 {
216     if ! openstack flavor list | grep -q yardstick-flavor; then
217         echo
218         echo "========== Create nova flavor =========="
219         # Create the nova flavor used by some sample test cases
220         openstack flavor create --id 100 --ram 512 --disk 3 --vcpus 1 yardstick-flavor
221         # DPDK-enabled OVS requires guest memory to be backed by large pages
222         if [[ $DEPLOY_SCENARIO == *[_-]ovs[_-]* ]]; then
223             openstack flavor set --property hw:mem_page_size=large yardstick-flavor
224         fi
225         # VPP requires guest memory to be backed by large pages
226         if [[ "$DEPLOY_SCENARIO" == *"-fdio-"* ]]; then
227             openstack flavor set --property hw:mem_page_size=large yardstick-flavor
228         fi
229     fi
230 }
231
232 main()
233 {
234     QCOW_IMAGE="/tmp/workspace/yardstick/yardstick-image.img"
235     RAW_IMAGE="/tmp/workspace/yardstick/yardstick-image.tar.gz"
236
237     build_yardstick_image
238     load_yardstick_image
239     if [ "${YARD_IMG_ARCH}" == "arm64" ]; then
240         sed -i 's/image: {{image}}/image: TestVM/g' tests/opnfv/test_cases/opnfv_yardstick_tc002.yaml
241         sed -i 's/image: cirros-0.3.3/image: TestVM/g' samples/ping.yaml
242         #We have overlapping IP with the real network
243         for filename in tests/opnfv/test_cases/*; do
244             sed -i "s/cidr: '10.0.1.0\/24'/cidr: '10.3.1.0\/24'/g" "${filename}"
245         done
246     else
247         load_cirros_image
248         load_ubuntu_image
249     fi
250     create_nova_flavor
251 }
252
253 main