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