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