Use docker image id instead of tag to remove yardstick Docker image with tag:<None>
[releng.git] / prototypes / bifrost / scripts / test-bifrost-deployment.sh
1 #!/bin/bash
2 # SPDX-license-identifier: Apache-2.0
3 ##############################################################################
4 # Copyright (c) 2016 Ericsson AB and others.
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 -eux
12 set -o pipefail
13 export PYTHONUNBUFFERED=1
14 SCRIPT_HOME="$(cd "$(dirname "$0")" && pwd)"
15 BIFROST_HOME=$SCRIPT_HOME/..
16 ANSIBLE_INSTALL_ROOT=${ANSIBLE_INSTALL_ROOT:-/opt/stack}
17 ENABLE_VENV="false"
18 USE_DHCP="false"
19 USE_VENV="false"
20 BUILD_IMAGE=true
21 export BAREMETAL_DATA_FILE=${BAREMETAL_DATA_FILE:-'/tmp/baremetal.json'}
22 export BIFROST_INVENTORY_SOURCE=${BIFROST_INVENTORY_SOURCE:-'/tmp/baremetal.csv'}
23 PROVISION_WAIT_TIMEOUT=${PROVISION_WAIT_TIMEOUT:-3600}
24
25 # Set defaults for ansible command-line options to drive the different
26 # tests.
27
28 # NOTE(TheJulia/cinerama): The variables defined on the command line
29 # for the default and DHCP tests are to drive the use of Cirros as the
30 # deployed operating system, and as such sets the test user to cirros,
31 # and writes a debian style interfaces file out to the configuration
32 # drive as cirros does not support the network_info.json format file
33 # placed in the configuration drive. The "build image" test does not
34 # use cirros.
35
36 TEST_VM_NUM_NODES=3
37 export TEST_VM_NODE_NAMES="jumphost.opnfvlocal controller00.opnfvlocal compute00.opnfvlocal"
38 export VM_DOMAIN_TYPE="kvm"
39 export VM_CPU=${VM_CPU:-4}
40 export VM_DISK=${VM_DISK:-100}
41 export VM_DISK_CACHE=${VM_DISK_CACHE:-unsafe}
42 TEST_PLAYBOOK="opnfv-virtual.yaml"
43 USE_INSPECTOR=true
44 USE_CIRROS=false
45 TESTING_USER=root
46 VM_MEMORY_SIZE=${VM_MEMORY_SIZE:-8192}
47 DOWNLOAD_IPA=true
48 CREATE_IPA_IMAGE=false
49 INSPECT_NODES=true
50 INVENTORY_DHCP=false
51 INVENTORY_DHCP_STATIC_IP=false
52 WRITE_INTERFACES_FILE=true
53
54 # Set BIFROST_INVENTORY_SOURCE
55 export BIFROST_INVENTORY_SOURCE=/tmp/baremetal.json
56
57 # settings for console access
58 export DIB_DEV_USER_PWDLESS_SUDO=yes
59 export DIB_DEV_USER_PASSWORD=devuser
60
61 # settings for distro: trusty/ubuntu-minimal, 7/centos7
62 export DIB_OS_RELEASE=${DIB_OS_RELEASE:-trusty}
63 export DIB_OS_ELEMENT=${DIB_OS_ELEMENT:-ubuntu-minimal}
64
65 # for centos 7: "vim,less,bridge-utils,iputils,rsyslog,curl"
66 export DIB_OS_PACKAGES=${DIB_OS_PACKAGES:-"vlan,vim,less,bridge-utils,language-pack-en,iputils-ping,rsyslog,curl"}
67
68 # Additional dib elements
69 export EXTRA_DIB_ELEMENTS=${EXTRA_DIB_ELEMENTS:-"openssh-server"}
70
71 # Source Ansible
72 # NOTE(TheJulia): Ansible stable-1.9 source method tosses an error deep
73 # under the hood which -x will detect, so for this step, we need to suspend
74 # and then re-enable the feature.
75 set +x +o nounset
76 $SCRIPT_HOME/env-setup.sh
77 source ${ANSIBLE_INSTALL_ROOT}/ansible/hacking/env-setup
78 ANSIBLE=$(which ansible-playbook)
79 set -x -o nounset
80
81 logs_on_exit() {
82     $SCRIPT_HOME/collect-test-info.sh
83 }
84 trap logs_on_exit EXIT
85
86 # Change working directory
87 cd $BIFROST_HOME/playbooks
88
89 # Syntax check of dynamic inventory test path
90 for task in syntax-check list-tasks; do
91     ${ANSIBLE} -vvvv \
92            -i inventory/localhost \
93            test-bifrost-create-vm.yaml \
94            --${task}
95     ${ANSIBLE} -vvvv \
96            -i inventory/localhost \
97            ${TEST_PLAYBOOK} \
98            --${task} \
99            -e testing_user=${TESTING_USER}
100 done
101
102 # Create the test VMS
103 ${ANSIBLE} -vvvv \
104        -i inventory/localhost \
105        test-bifrost-create-vm.yaml \
106        -e test_vm_num_nodes=${TEST_VM_NUM_NODES} \
107        -e test_vm_memory_size=${VM_MEMORY_SIZE} \
108        -e enable_venv=${ENABLE_VENV} \
109        -e test_vm_domain_type=${VM_DOMAIN_TYPE} \
110        -e baremetal_json_file=${BAREMETAL_DATA_FILE}
111
112 # Execute the installation and VM startup test.
113 ${ANSIBLE} -vvvv \
114     -i inventory/bifrost_inventory.py \
115     ${TEST_PLAYBOOK} \
116     -e use_cirros=${USE_CIRROS} \
117     -e testing_user=${TESTING_USER} \
118     -e test_vm_num_nodes=${TEST_VM_NUM_NODES} \
119     -e inventory_dhcp=${INVENTORY_DHCP} \
120     -e inventory_dhcp_static_ip=${INVENTORY_DHCP_STATIC_IP} \
121     -e enable_venv=${ENABLE_VENV} \
122     -e enable_inspector=${USE_INSPECTOR} \
123     -e inspect_nodes=${INSPECT_NODES} \
124     -e download_ipa=${DOWNLOAD_IPA} \
125     -e create_ipa_image=${CREATE_IPA_IMAGE} \
126     -e write_interfaces_file=${WRITE_INTERFACES_FILE} \
127     -e ipv4_gateway=192.168.122.1 \
128     -e wait_timeout=${PROVISION_WAIT_TIMEOUT}
129 EXITCODE=$?
130
131 if [ $EXITCODE != 0 ]; then
132     echo "****************************"
133     echo "Test failed. See logs folder"
134     echo "****************************"
135 fi
136
137 exit $EXITCODE