add yardstick iruya 9.0.0 release notes
[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
17 if ! grep -q "Defaults env_keep += \"YARD_IMG_ARCH\"" "/etc/sudoers"; then
18     echo "Defaults env_keep += \"YARD_IMG_ARCH YARDSTICK_REPO_DIR\"" | sudo tee -a /etc/sudoers
19 fi
20
21 # Look for a compute node, that is online, and check if it is aarch64
22 if [ "${INSTALLER_TYPE}" == 'fuel' ]; then
23     ssh_options="-o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no"
24     COMPUTE_ARCH=$(ssh -l ubuntu ${INSTALLER_IP} -i ${SSH_KEY} ${ssh_options} \
25         "sudo salt 'cmp*' grains.get cpuarch --out yaml | awk '{print \$2; exit}'")
26     if [ "${COMPUTE_ARCH}" == 'aarch64' ]; then
27         YARD_IMG_ARCH=arm64
28     fi
29 fi
30 export YARD_IMG_ARCH
31
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         echo "Defaults env_keep += \"CLOUD_IMG_URL\"" | sudo tee -a /etc/sudoers
38     fi
39 fi
40
41 cleanup_loopbacks() {
42     # try again to cleanup loopbacks in case of error
43     losetup -a
44     losetup -O NAME,BACK-FILE | awk '/yardstick/ { print $1 }' | xargs -l1 losetup -v -d || true
45 }
46
47 build_yardstick_image()
48 {
49     echo
50     echo "========== Build yardstick cloud image =========="
51
52     if [[ "$DEPLOY_SCENARIO" == *"-lxd-"* ]]; then
53         if [ ! -f "${RAW_IMAGE}" ];then
54             local cmd
55             cmd="sudo $(which yardstick-img-lxd-modify) $(pwd)/tools/ubuntu-server-cloudimg-modify.sh"
56
57             # Build the image. Retry once if the build fails
58             $cmd || $cmd
59
60             cleanup_loopbacks
61             if [ ! -f "${RAW_IMAGE}" ]; then
62                 echo "Failed building RAW image"
63                 exit 1
64             fi
65         fi
66     else
67         if [ ! -f "${QCOW_IMAGE}" ];then
68             ANSIBLE_SCRIPTS="${0%/*}/../../ansible"
69             cd ${ANSIBLE_SCRIPTS} &&\
70             ansible-playbook \
71                      -e img_property="normal" \
72                      -e YARD_IMG_ARCH=${YARD_IMG_ARCH} \
73                      -vvv -i inventory.ini build_yardstick_image.yml
74
75             cleanup_loopbacks
76             if [ ! -f "${QCOW_IMAGE}" ]; then
77                 echo "Failed building QCOW image"
78                 exit 1
79             fi
80         fi
81         # DPDK compile is not enabled for arm64 yet so disable for now
82         # JIRA: YARSTICK-1124
83         if [[ ! -f "${QCOW_NSB_IMAGE}"  && ${DEPLOY_SCENARIO} == *[_-]ovs_dpdk[_-]* && "${YARD_IMG_ARCH}" != "arm64" ]]; then
84             ansible-playbook \
85                      -e img_property="nsb" \
86                      -e YARD_IMG_ARCH=${YARD_IMG_ARCH} \
87                      -vvv -i inventory.ini build_yardstick_image.yml
88             cleanup_loopbacks
89             if [ ! -f "${QCOW_NSB_IMAGE}" ]; then
90                 echo "Failed building QCOW NSB image"
91                 exit 1
92             fi
93         fi
94     fi
95 }
96
97 load_yardstick_image()
98 {
99     echo
100     echo "========== Loading yardstick cloud image =========="
101     EXTRA_PARAMS=""
102
103     # VPP requires guest memory to be backed by large pages
104     if [[ "$DEPLOY_SCENARIO" == *"-fdio-"* ]]; then
105         EXTRA_PARAMS=$EXTRA_PARAMS" --property hw_mem_page_size=large"
106     fi
107
108
109     if [[ "$DEPLOY_SCENARIO" == *"-lxd-"* ]]; then
110         output=$(eval openstack ${SECURE} image create \
111             --public \
112             --disk-format raw \
113             --container-format bare \
114             ${EXTRA_PARAMS} \
115             --file ${RAW_IMAGE} \
116             yardstick-image)
117     else
118         output=$(eval openstack ${SECURE} image create \
119             --public \
120             --disk-format qcow2 \
121             --container-format bare \
122             ${EXTRA_PARAMS} \
123             --file ${QCOW_IMAGE} \
124             yardstick-image)
125         # DPDK compile is not enabled for arm64 yet so disable NSB images for now
126         # JIRA: YARSTICK-1124
127         if [[ $DEPLOY_SCENARIO == *[_-]ovs_dpdk[_-]* && "${YARD_IMG_ARCH}" != "arm64" ]]; then
128             nsb_output=$(eval openstack ${SECURE} image create \
129                 --public \
130                 --disk-format qcow2 \
131                 --container-format bare \
132                 ${EXTRA_PARAMS} \
133                 --file ${QCOW_NSB_IMAGE} \
134                 yardstick-samplevnfs)
135             echo "$nsb_output"
136         fi
137     fi
138
139     echo "$output"
140
141     GLANCE_IMAGE_ID=$(echo "$output" | grep " id " | awk '{print $(NF-1)}')
142
143     if [ -z "$GLANCE_IMAGE_ID" ]; then
144         echo 'Failed uploading image to cloud'.
145         exit 1
146     fi
147
148     echo "Glance image id: $GLANCE_IMAGE_ID"
149 }
150
151 load_cirros_image()
152 {
153     EXTRA_PARAMS=""
154     if [[ "${YARD_IMG_ARCH}" == "arm64" ]]; then
155         CIRROS_IMAGE_VERSION="cirros-d161201"
156         CIRROS_IMAGE_PATH="/home/opnfv/images/cirros-d161201-aarch64-disk.img"
157         EXTRA_PARAMS="--property short_id=ubuntu16.04"
158     else
159         CIRROS_IMAGE_VERSION="cirros-0.3.5"
160         CIRROS_IMAGE_PATH="/home/opnfv/images/cirros-0.3.5-x86_64-disk.img"
161     fi
162
163     if [[ -n $(openstack ${SECURE} image list | grep -e "${CIRROS_IMAGE_VERSION}") ]]; then
164         echo "${CIRROS_IMAGE_VERSION} image already exist, skip loading cirros image"
165     else
166         echo
167         echo "========== Loading cirros cloud image =========="
168
169         local image_file="${CIRROS_IMAGE_PATH}"
170
171         # VPP requires guest memory to be backed by large pages
172         if [[ "$DEPLOY_SCENARIO" == *"-fdio-"* ]]; then
173             EXTRA_PARAMS=$EXTRA_PARAMS" --property hw_mem_page_size=large"
174         fi
175
176
177         output=$(openstack ${SECURE} image create \
178             --disk-format qcow2 \
179             --container-format bare \
180             ${EXTRA_PARAMS} \
181             --file ${image_file} \
182             cirros-0.3.5)
183         echo "$output"
184
185         CIRROS_IMAGE_ID=$(echo "$output" | grep " id " | awk '{print $(NF-1)}')
186         if [ -z "$CIRROS_IMAGE_ID" ]; then
187             echo 'Failed uploading cirros image to cloud'.
188             exit 1
189         fi
190
191         echo "Cirros image id: $CIRROS_IMAGE_ID"
192     fi
193 }
194
195 load_ubuntu_image()
196 {
197     echo
198     echo "========== Loading ubuntu cloud image =========="
199
200     local ubuntu_image_file=/home/opnfv/images/xenial-server-cloudimg-amd64-disk1.img
201
202     EXTRA_PARAMS=""
203     # VPP requires guest memory to be backed by large pages
204     if [[ "$DEPLOY_SCENARIO" == *"-fdio-"* ]]; then
205         EXTRA_PARAMS=$EXTRA_PARAMS" --property hw_mem_page_size=large"
206     fi
207
208     output=$(openstack ${SECURE} image create \
209         --disk-format qcow2 \
210         --container-format bare \
211         $EXTRA_PARAMS \
212         --file $ubuntu_image_file \
213         Ubuntu-16.04)
214     echo "$output"
215
216     UBUNTU_IMAGE_ID=$(echo "$output" | grep " id " | awk '{print $(NF-1)}')
217
218     if [ -z "$UBUNTU_IMAGE_ID" ]; then
219         echo 'Failed uploading UBUNTU image to cloud'.
220         exit 1
221     fi
222
223     echo "Ubuntu image id: $UBUNTU_IMAGE_ID"
224 }
225
226 create_nova_flavor()
227 {
228     if ! openstack ${SECURE} flavor list | grep -q yardstick-flavor; then
229         echo
230         echo "========== Creating yardstick-flavor =========="
231         # Create the nova flavor used by some sample test cases
232         openstack ${SECURE} flavor create --id 100 --ram 1024 --disk 10 --vcpus 1 yardstick-flavor
233         # DPDK-enabled OVS requires guest memory to be backed by large pages
234         if [[ $DEPLOY_SCENARIO == *[_-]ovs[_-]* ]]; then
235             openstack ${SECURE} flavor set --property hw:mem_page_size=large yardstick-flavor
236         fi
237         # VPP requires guest memory to be backed by large pages
238         if [[ "$DEPLOY_SCENARIO" == *"-fdio-"* ]]; then
239             openstack ${SECURE} flavor set --property hw:mem_page_size=large yardstick-flavor
240         fi
241     fi
242
243     if ! openstack ${SECURE} flavor list | grep -q storperf; then
244         echo
245         echo "========== Creating storperf flavor =========="
246         # Create the nova flavor used by storperf test case
247         openstack ${SECURE} flavor create --id auto --ram 8192 --disk 4 --vcpus 2 storperf
248     fi
249 }
250
251 main()
252 {
253     QCOW_IMAGE="/tmp/workspace/yardstick/yardstick-image.img"
254     QCOW_NSB_IMAGE="/tmp/workspace/yardstick/yardstick-nsb-image.img"
255     RAW_IMAGE="/tmp/workspace/yardstick/yardstick-image.tar.gz"
256
257     if [ -f /home/opnfv/images/yardstick-image.img ];then
258         QCOW_IMAGE='/home/opnfv/images/yardstick-image.img'
259     fi
260     if [ -f /home/opnfv/images/yardstick-image.tar.gz ];then
261         RAW_IMAGE='/home/opnfv/images/yardstick-image.tar.gz'
262     fi
263
264     if [ $OS_INSECURE ] && [ "$(echo $OS_INSECURE | tr '[:upper:]' '[:lower:]')" = "true" ]; then
265         SECURE="--insecure"
266     else
267         SECURE=""
268     fi
269
270     build_yardstick_image
271     load_yardstick_image
272     if [ "${YARD_IMG_ARCH}" == "arm64" ]; then
273         #We have overlapping IP with the real network
274         for filename in ${YARDSTICK_REPO_DIR}/tests/opnfv/test_cases/*; do
275             sed -i "s/cidr: '10.0.1.0\/24'/cidr: '10.3.1.0\/24'/g" "${filename}"
276         done
277     else
278         load_ubuntu_image
279     fi
280     load_cirros_image
281     create_nova_flavor
282 }
283
284 main