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