Merge "[JOID] Update Joid deploy script"
[releng.git] / prototypes / bifrost / scripts / test-bifrost-deployment.sh
1 # SPDX-license-identifier: Apache-2.0
2 ##############################################################################
3 # Copyright (c) 2016 Ericsson AB and others.
4 # All rights reserved. This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
7 # http://www.apache.org/licenses/LICENSE-2.0
8 ##############################################################################
9 #!/bin/bash
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
22 # Set defaults for ansible command-line options to drive the different
23 # tests.
24
25 # NOTE(TheJulia/cinerama): The variables defined on the command line
26 # for the default and DHCP tests are to drive the use of Cirros as the
27 # deployed operating system, and as such sets the test user to cirros,
28 # and writes a debian style interfaces file out to the configuration
29 # drive as cirros does not support the network_info.json format file
30 # placed in the configuration drive. The "build image" test does not
31 # use cirros.
32
33 TEST_VM_NUM_NODES=3
34 export TEST_VM_NODE_NAMES="jumphost.opnfvlocal controller00.opnfvlocal compute00.opnfvlocal"
35 export VM_DOMAIN_TYPE="kvm"
36 export VM_CPU=4
37 TEST_PLAYBOOK="test-bifrost-infracloud.yaml"
38 USE_INSPECTOR=true
39 USE_CIRROS=false
40 TESTING_USER=root
41 VM_MEMORY_SIZE="8192"
42 DOWNLOAD_IPA=true
43 CREATE_IPA_IMAGE=false
44 INSPECT_NODES=true
45 INVENTORY_DHCP=false
46 INVENTORY_DHCP_STATIC_IP=false
47 WRITE_INTERFACES_FILE=true
48
49 # Set BIFROST_INVENTORY_SOURCE
50 export BIFROST_INVENTORY_SOURCE=/tmp/baremetal.csv
51
52 # DIB custom elements path
53 export ELEMENTS_PATH=/usr/share/diskimage-builder/elements:/opt/puppet-infracloud/files/elements
54
55 # settings for console access
56 export DIB_DEV_USER_PWDLESS_SUDO=yes
57 export DIB_DEV_USER_PASSWORD=devuser
58
59 # Source Ansible
60 # NOTE(TheJulia): Ansible stable-1.9 source method tosses an error deep
61 # under the hood which -x will detect, so for this step, we need to suspend
62 # and then re-enable the feature.
63 set +x +o nounset
64 $SCRIPT_HOME/env-setup.sh
65 source ${ANSIBLE_INSTALL_ROOT}/ansible/hacking/env-setup
66 ANSIBLE=$(which ansible-playbook)
67 set -x -o nounset
68
69 # Change working directory
70 cd $BIFROST_HOME/playbooks
71
72 # Syntax check of dynamic inventory test path
73 ${ANSIBLE} -vvvv \
74        -i inventory/localhost \
75        test-bifrost-create-vm.yaml \
76        --syntax-check \
77        --list-tasks
78 ${ANSIBLE} -vvvv \
79        -i inventory/localhost \
80        ${TEST_PLAYBOOK} \
81        --syntax-check \
82        --list-tasks \
83        -e testing_user=${TESTING_USER}
84
85 # Create the test VMS
86 ${ANSIBLE} -vvvv \
87        -i inventory/localhost \
88        test-bifrost-create-vm.yaml \
89        -e test_vm_num_nodes=${TEST_VM_NUM_NODES} \
90        -e test_vm_memory_size=${VM_MEMORY_SIZE} \
91        -e enable_venv=${ENABLE_VENV} \
92        -e test_vm_domain_type=${VM_DOMAIN_TYPE}
93
94 # Execute the installation and VM startup test.
95 ${ANSIBLE} -vvvv \
96     -i inventory/bifrost_inventory.py \
97     ${TEST_PLAYBOOK} \
98     -e use_cirros=${USE_CIRROS} \
99     -e testing_user=${TESTING_USER} \
100     -e test_vm_num_nodes=${TEST_VM_NUM_NODES} \
101     -e inventory_dhcp=${INVENTORY_DHCP} \
102     -e inventory_dhcp_static_ip=${INVENTORY_DHCP_STATIC_IP} \
103     -e enable_venv=${ENABLE_VENV} \
104     -e enable_inspector=${USE_INSPECTOR} \
105     -e inspect_nodes=${INSPECT_NODES} \
106     -e download_ipa=${DOWNLOAD_IPA} \
107     -e create_ipa_image=${CREATE_IPA_IMAGE} \
108     -e write_interfaces_file=${WRITE_INTERFACES_FILE} \
109     -e ipv4_gateway=192.168.122.1
110 EXITCODE=$?
111
112 if [ $EXITCODE != 0 ]; then
113     echo "****************************"
114     echo "Test failed. See logs folder"
115     echo "****************************"
116 fi
117
118 $SCRIPT_HOME/collect-test-info.sh
119
120 exit $EXITCODE