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