Parameterize infracloud playbook by platforms
[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
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 export VM_DISK=100
38 TEST_PLAYBOOK="test-bifrost-infracloud.yaml"
39 USE_INSPECTOR=true
40 USE_CIRROS=false
41 TESTING_USER=root
42 VM_MEMORY_SIZE="8192"
43 DOWNLOAD_IPA=true
44 CREATE_IPA_IMAGE=false
45 INSPECT_NODES=true
46 INVENTORY_DHCP=false
47 INVENTORY_DHCP_STATIC_IP=false
48 WRITE_INTERFACES_FILE=true
49
50 # Set BIFROST_INVENTORY_SOURCE
51 export BIFROST_INVENTORY_SOURCE=/tmp/baremetal.csv
52
53 # DIB custom elements path
54 export ELEMENTS_PATH=/usr/share/diskimage-builder/elements:/opt/puppet-infracloud/files/elements
55
56 # settings for console access
57 export DIB_DEV_USER_PWDLESS_SUDO=yes
58 export DIB_DEV_USER_PASSWORD=devuser
59
60 # settings for distro: trusty/ubuntu-minimal, 7/centos-minimal
61 export DIB_OS_RELEASE=${DIB_OS_RELEASE:-trusty}
62 export DIB_OS_ELEMENT=${DIB_OS_ELEMENT:-ubuntu-minimal}
63
64 # for centos 7: "openssh-server,vim,less,bridge-utils,iputils,rsyslog,curl"
65 export DIB_OS_PACKAGES=${DIB_OS_PACKAGES:-"openssh-server,vlan,vim,less,bridge-utils,language-pack-en,iputils-ping,rsyslog,curl"}
66
67 # Source Ansible
68 # NOTE(TheJulia): Ansible stable-1.9 source method tosses an error deep
69 # under the hood which -x will detect, so for this step, we need to suspend
70 # and then re-enable the feature.
71 set +x +o nounset
72 $SCRIPT_HOME/env-setup.sh
73 source ${ANSIBLE_INSTALL_ROOT}/ansible/hacking/env-setup
74 ANSIBLE=$(which ansible-playbook)
75 set -x -o nounset
76
77 # Change working directory
78 cd $BIFROST_HOME/playbooks
79
80 # Syntax check of dynamic inventory test path
81 for task in syntax-check list-tasks; do
82     ${ANSIBLE} -vvvv \
83            -i inventory/localhost \
84            test-bifrost-create-vm.yaml \
85            --${task}
86     ${ANSIBLE} -vvvv \
87            -i inventory/localhost \
88            ${TEST_PLAYBOOK} \
89            --${task} \
90            -e testing_user=${TESTING_USER}
91 done
92
93 # Create the test VMS
94 ${ANSIBLE} -vvvv \
95        -i inventory/localhost \
96        test-bifrost-create-vm.yaml \
97        -e test_vm_num_nodes=${TEST_VM_NUM_NODES} \
98        -e test_vm_memory_size=${VM_MEMORY_SIZE} \
99        -e enable_venv=${ENABLE_VENV} \
100        -e test_vm_domain_type=${VM_DOMAIN_TYPE}
101
102 # Execute the installation and VM startup test.
103 ${ANSIBLE} -vvvv \
104     -i inventory/bifrost_inventory.py \
105     ${TEST_PLAYBOOK} \
106     -e use_cirros=${USE_CIRROS} \
107     -e testing_user=${TESTING_USER} \
108     -e test_vm_num_nodes=${TEST_VM_NUM_NODES} \
109     -e inventory_dhcp=${INVENTORY_DHCP} \
110     -e inventory_dhcp_static_ip=${INVENTORY_DHCP_STATIC_IP} \
111     -e enable_venv=${ENABLE_VENV} \
112     -e enable_inspector=${USE_INSPECTOR} \
113     -e inspect_nodes=${INSPECT_NODES} \
114     -e download_ipa=${DOWNLOAD_IPA} \
115     -e create_ipa_image=${CREATE_IPA_IMAGE} \
116     -e write_interfaces_file=${WRITE_INTERFACES_FILE} \
117     -e ipv4_gateway=192.168.122.1
118 EXITCODE=$?
119
120 if [ $EXITCODE != 0 ]; then
121     echo "****************************"
122     echo "Test failed. See logs folder"
123     echo "****************************"
124 fi
125
126 $SCRIPT_HOME/collect-test-info.sh
127
128 exit $EXITCODE