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