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