Merge "bifrost: test-bifrost-deployment.sh: Use the new 'openssh-server' dib element"
[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 PROVISION_WAIT_TIMEOUT=${PROVISION_WAIT_TIMEOUT:-3600}
22
23 # Set defaults for ansible command-line options to drive the different
24 # tests.
25
26 # NOTE(TheJulia/cinerama): The variables defined on the command line
27 # for the default and DHCP tests are to drive the use of Cirros as the
28 # deployed operating system, and as such sets the test user to cirros,
29 # and writes a debian style interfaces file out to the configuration
30 # drive as cirros does not support the network_info.json format file
31 # placed in the configuration drive. The "build image" test does not
32 # use cirros.
33
34 TEST_VM_NUM_NODES=3
35 export TEST_VM_NODE_NAMES="jumphost.opnfvlocal controller00.opnfvlocal compute00.opnfvlocal"
36 export VM_DOMAIN_TYPE="kvm"
37 export VM_CPU=${VM_CPU:-4}
38 export VM_DISK=${VM_DISK:-100}
39 TEST_PLAYBOOK="test-bifrost-infracloud.yaml"
40 USE_INSPECTOR=true
41 USE_CIRROS=false
42 TESTING_USER=root
43 VM_MEMORY_SIZE=${VM_MEMORY_SIZE:-8192}
44 DOWNLOAD_IPA=true
45 CREATE_IPA_IMAGE=false
46 INSPECT_NODES=true
47 INVENTORY_DHCP=false
48 INVENTORY_DHCP_STATIC_IP=false
49 WRITE_INTERFACES_FILE=true
50
51 # Set BIFROST_INVENTORY_SOURCE
52 export BIFROST_INVENTORY_SOURCE=/tmp/baremetal.csv
53
54 # DIB custom elements path
55 export ELEMENTS_PATH=/usr/share/diskimage-builder/elements:/opt/puppet-infracloud/files/elements
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 # Change working directory
82 cd $BIFROST_HOME/playbooks
83
84 # Syntax check of dynamic inventory test path
85 for task in syntax-check list-tasks; do
86     ${ANSIBLE} -vvvv \
87            -i inventory/localhost \
88            test-bifrost-create-vm.yaml \
89            --${task}
90     ${ANSIBLE} -vvvv \
91            -i inventory/localhost \
92            ${TEST_PLAYBOOK} \
93            --${task} \
94            -e testing_user=${TESTING_USER}
95 done
96
97 # Create the test VMS
98 ${ANSIBLE} -vvvv \
99        -i inventory/localhost \
100        test-bifrost-create-vm.yaml \
101        -e test_vm_num_nodes=${TEST_VM_NUM_NODES} \
102        -e test_vm_memory_size=${VM_MEMORY_SIZE} \
103        -e enable_venv=${ENABLE_VENV} \
104        -e test_vm_domain_type=${VM_DOMAIN_TYPE}
105
106 # Execute the installation and VM startup test.
107 ${ANSIBLE} -vvvv \
108     -i inventory/bifrost_inventory.py \
109     ${TEST_PLAYBOOK} \
110     -e use_cirros=${USE_CIRROS} \
111     -e testing_user=${TESTING_USER} \
112     -e test_vm_num_nodes=${TEST_VM_NUM_NODES} \
113     -e inventory_dhcp=${INVENTORY_DHCP} \
114     -e inventory_dhcp_static_ip=${INVENTORY_DHCP_STATIC_IP} \
115     -e enable_venv=${ENABLE_VENV} \
116     -e enable_inspector=${USE_INSPECTOR} \
117     -e inspect_nodes=${INSPECT_NODES} \
118     -e download_ipa=${DOWNLOAD_IPA} \
119     -e create_ipa_image=${CREATE_IPA_IMAGE} \
120     -e write_interfaces_file=${WRITE_INTERFACES_FILE} \
121     -e ipv4_gateway=192.168.122.1 \
122     -e wait_timeout=${PROVISION_WAIT_TIMEOUT}
123 EXITCODE=$?
124
125 if [ $EXITCODE != 0 ]; then
126     echo "****************************"
127     echo "Test failed. See logs folder"
128     echo "****************************"
129 fi
130
131 $SCRIPT_HOME/collect-test-info.sh
132
133 exit $EXITCODE