Merge "xci: Adjust how bifrost inventory files are specified"
[releng.git] / prototypes / bifrost / scripts / osa-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 # ensure the right inventory files is used based on branch
24 CURRENT_BIFROST_BRANCH=$(git rev-parse --abbrev-ref HEAD)
25 if [ $CURRENT_BIFROST_BRANCH = "master" ]; then
26     BAREMETAL_DATA_FILE=${BAREMETAL_DATA_FILE:-'/tmp/baremetal.json'}
27     INVENTORY_FILE_FORMAT="baremetal_json_file"
28 else
29     BAREMETAL_DATA_FILE=${BAREMETAL_DATA_FILE:-'/tmp/baremetal.csv'}
30     INVENTORY_FILE_FORMAT="baremetal_csv_file"
31 fi
32 export BIFROST_INVENTORY_SOURCE=$BAREMETAL_DATA_FILE
33
34 # Set defaults for ansible command-line options to drive the different
35 # tests.
36
37 # NOTE(TheJulia/cinerama): The variables defined on the command line
38 # for the default and DHCP tests are to drive the use of Cirros as the
39 # deployed operating system, and as such sets the test user to cirros,
40 # and writes a debian style interfaces file out to the configuration
41 # drive as cirros does not support the network_info.json format file
42 # placed in the configuration drive. The "build image" test does not
43 # use cirros.
44
45 TEST_VM_NUM_NODES=6
46 export TEST_VM_NODE_NAMES="xcimaster controller00 controller01 controller02 compute00 compute01"
47 export VM_DOMAIN_TYPE="kvm"
48 # 8 vCPU, 60 GB HDD are minimum equipment
49 export VM_CPU=${VM_CPU:-8}
50 export VM_DISK=${VM_DISK:-100}
51 export VM_DISK_CACHE=${VM_DISK_CACHE:-unsafe}
52 TEST_PLAYBOOK="opnfv-virtual.yaml"
53 USE_INSPECTOR=true
54 USE_CIRROS=false
55 TESTING_USER=root
56 # seting the memory to 16 GB to make more easily success
57 # 8 GB RAM is minimum equipment, but it work with at least 12 GB.
58 VM_MEMORY_SIZE=${VM_MEMORY_SIZE:-16384}
59 DOWNLOAD_IPA=true
60 CREATE_IPA_IMAGE=false
61 INSPECT_NODES=true
62 INVENTORY_DHCP=false
63 INVENTORY_DHCP_STATIC_IP=false
64 WRITE_INTERFACES_FILE=true
65
66
67 # settings for console access
68 export DIB_DEV_USER_PWDLESS_SUDO=yes
69 export DIB_DEV_USER_PASSWORD=devuser
70
71 # settings for distro: trusty/ubuntu-minimal, 7/centos7
72 export DIB_OS_RELEASE=${DIB_OS_RELEASE:-xenial}
73 export DIB_OS_ELEMENT=${DIB_OS_ELEMENT:-ubuntu-minimal}
74
75 # for centos 7: "vim,less,bridge-utils,iputils,rsyslog,curl"
76 export DIB_OS_PACKAGES=${DIB_OS_PACKAGES:-"vlan,vim,less,bridge-utils,sudo,language-pack-en,iputils-ping,rsyslog,curl,python,debootstrap,ifenslave,ifenslave-2.6,lsof,lvm2,tcpdump,nfs-kernel-server,chrony"}
77
78 # Additional dib elements
79 export EXTRA_DIB_ELEMENTS=${EXTRA_DIB_ELEMENTS:-"openssh-server"}
80
81 # Source Ansible
82 # NOTE(TheJulia): Ansible stable-1.9 source method tosses an error deep
83 # under the hood which -x will detect, so for this step, we need to suspend
84 # and then re-enable the feature.
85 set +x +o nounset
86 $SCRIPT_HOME/env-setup.sh
87 source ${ANSIBLE_INSTALL_ROOT}/ansible/hacking/env-setup
88 ANSIBLE=$(which ansible-playbook)
89 set -x -o nounset
90
91 logs_on_exit() {
92     $SCRIPT_HOME/collect-test-info.sh
93 }
94 trap logs_on_exit EXIT
95
96 # Change working directory
97 cd $BIFROST_HOME/playbooks
98
99 # Syntax check of dynamic inventory test path
100 for task in syntax-check list-tasks; do
101     ${ANSIBLE} \
102            -i inventory/localhost \
103            test-bifrost-create-vm.yaml \
104            --${task}
105     ${ANSIBLE} \
106            -i inventory/localhost \
107            ${TEST_PLAYBOOK} \
108            --${task} \
109            -e testing_user=${TESTING_USER}
110 done
111
112 # Create the test VMS
113 ${ANSIBLE} \
114        -i inventory/localhost \
115        test-bifrost-create-vm.yaml \
116        -e test_vm_num_nodes=${TEST_VM_NUM_NODES} \
117        -e test_vm_memory_size=${VM_MEMORY_SIZE} \
118        -e enable_venv=${ENABLE_VENV} \
119        -e test_vm_domain_type=${VM_DOMAIN_TYPE} \
120        -e ${INVENTORY_FILE_FORMAT}=${BAREMETAL_DATA_FILE}
121
122 # Execute the installation and VM startup test.
123 ${ANSIBLE} \
124     -i inventory/bifrost_inventory.py \
125     ${TEST_PLAYBOOK} \
126     -e use_cirros=${USE_CIRROS} \
127     -e testing_user=${TESTING_USER} \
128     -e test_vm_num_nodes=${TEST_VM_NUM_NODES} \
129     -e inventory_dhcp=${INVENTORY_DHCP} \
130     -e inventory_dhcp_static_ip=${INVENTORY_DHCP_STATIC_IP} \
131     -e enable_venv=${ENABLE_VENV} \
132     -e enable_inspector=${USE_INSPECTOR} \
133     -e inspect_nodes=${INSPECT_NODES} \
134     -e download_ipa=${DOWNLOAD_IPA} \
135     -e create_ipa_image=${CREATE_IPA_IMAGE} \
136     -e write_interfaces_file=${WRITE_INTERFACES_FILE} \
137     -e ipv4_gateway=192.168.122.1 \
138     -e wait_timeout=${PROVISION_WAIT_TIMEOUT}
139 EXITCODE=$?
140
141 if [ $EXITCODE != 0 ]; then
142     echo "****************************"
143     echo "Test failed. See logs folder"
144     echo "****************************"
145 fi
146
147 exit $EXITCODE