Merge "Support opera test in functest releng"
[releng.git] / prototypes / xci / xci-deploy.sh
1 #!/bin/bash
2 set -o errexit
3 set -o nounset
4 set -o pipefail
5
6 #-------------------------------------------------------------------------------
7 # This script must run as root
8 #-------------------------------------------------------------------------------
9 if [[ $(whoami) != "root" ]]; then
10     echo "Error: This script must be run as root!"
11     exit 1
12 fi
13
14 #-------------------------------------------------------------------------------
15 # Set environment variables
16 #-------------------------------------------------------------------------------
17 # The order of sourcing the variable files is significant so please do not
18 # change it or things might stop working.
19 # - user-vars: variables that can be configured or overriden by user.
20 # - pinned-versions: versions to checkout. These can be overriden if you want to
21 #   use different/more recent versions of the tools but you might end up using
22 #   something that is not verified by OPNFV XCI.
23 # - flavor-vars: settings for VM nodes for the chosen flavor.
24 # - env-vars: variables for the xci itself and you should not need to change or
25 #   override any of them.
26 #-------------------------------------------------------------------------------
27 # find where are we
28 XCI_PATH="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
29 # source user vars
30 source $XCI_PATH/config/user-vars
31 # source pinned versions
32 source $XCI_PATH/config/pinned-versions
33 # source flavor configuration
34 source "$XCI_PATH/config/${XCI_FLAVOR}-vars"
35 # source xci configuration
36 source $XCI_PATH/config/env-vars
37
38 #-------------------------------------------------------------------------------
39 # Log info to console
40 #-------------------------------------------------------------------------------
41 echo "Info: Starting XCI Deployment"
42 echo "Info: Deployment parameters"
43 echo "-------------------------------------------------------------------------"
44 echo "xci flavor: $XCI_FLAVOR"
45 echo "opnfv/releng version: $OPNFV_RELENG_VERSION"
46 echo "openstack/bifrost version: $OPENSTACK_BIFROST_VERSION"
47 echo "openstack/openstack-ansible version: $OPENSTACK_OSA_VERSION"
48 echo "-------------------------------------------------------------------------"
49
50 #-------------------------------------------------------------------------------
51 # Install ansible on localhost
52 #-------------------------------------------------------------------------------
53 pip install ansible==$XCI_ANSIBLE_PIP_VERSION
54
55 # TODO: The xci playbooks can be put into a playbook which will be done later.
56
57 #-------------------------------------------------------------------------------
58 # Start provisioning VM nodes
59 #-------------------------------------------------------------------------------
60 # This playbook
61 # - removes directories that were created by the previous xci run
62 # - clones opnfv/releng and openstack/bifrost repositories
63 # - combines opnfv/releng and openstack/bifrost scripts/playbooks
64 # - destorys VMs, removes ironic db, leases, logs
65 # - creates and provisions VMs for the chosen flavor
66 #-------------------------------------------------------------------------------
67 echo "Info: Starting provisining VM nodes using openstack/bifrost"
68 echo "-------------------------------------------------------------------------"
69 cd $XCI_PATH/playbooks
70 ansible-playbook $ANSIBLE_VERBOSITY -i inventory provision-vm-nodes.yml
71 echo "-----------------------------------------------------------------------"
72 echo "Info: VM nodes are provisioned!"
73 source $OPENSTACK_BIFROST_PATH/env-vars
74 ironic node-list
75 echo
76 #-------------------------------------------------------------------------------
77 # Configure localhost
78 #-------------------------------------------------------------------------------
79 # This playbook
80 # - removes directories that were created by the previous xci run
81 # - clones opnfv/releng repository
82 # - creates log directory
83 # - copies flavor files such as playbook, inventory, and var file
84 #-------------------------------------------------------------------------------
85 echo "Info: Configuring localhost for openstack-ansible"
86 echo "-----------------------------------------------------------------------"
87 cd $XCI_PATH/playbooks
88 ansible-playbook $ANSIBLE_VERBOSITY -i inventory configure-localhost.yml
89 echo "-----------------------------------------------------------------------"
90 echo "Info: Configured localhost host for openstack-ansible"
91
92 #-------------------------------------------------------------------------------
93 # Configure openstack-ansible deployment host, opnfv
94 #-------------------------------------------------------------------------------
95 # This playbook
96 # - removes directories that were created by the previous xci run
97 # - clones opnfv/releng and openstack/openstack-ansible repositories
98 # - configures network
99 # - generates/prepares ssh keys
100 # - bootstraps ansible
101 # - copies flavor files to be used by openstack-ansible
102 #-------------------------------------------------------------------------------
103 echo "Info: Configuring opnfv deployment host for openstack-ansible"
104 echo "-----------------------------------------------------------------------"
105 cd $OPNFV_RELENG_PATH/prototypes/xci/playbooks
106 ansible-playbook $ANSIBLE_VERBOSITY -i inventory configure-opnfvhost.yml
107 echo "-----------------------------------------------------------------------"
108 echo "Info: Configured opnfv deployment host for openstack-ansible"
109
110 #-------------------------------------------------------------------------------
111 # Skip the rest if the flavor is aio since the target host for aio is opnfv
112 #-------------------------------------------------------------------------------
113 if [[ $XCI_FLAVOR == "aio" ]]; then
114     echo "xci: aio has been installed"
115     exit 0
116 fi
117
118 #-------------------------------------------------------------------------------
119 # Configure target hosts for openstack-ansible
120 #-------------------------------------------------------------------------------
121 # This playbook
122 # - adds public keys to target hosts
123 # - configures network
124 # - configures nfs
125 #-------------------------------------------------------------------------------
126 echo "Info: Configuring target hosts for openstack-ansible"
127 echo "-----------------------------------------------------------------------"
128 cd $OPNFV_RELENG_PATH/prototypes/xci/playbooks
129 ansible-playbook $ANSIBLE_VERBOSITY -i inventory configure-targethosts.yml
130 echo "-----------------------------------------------------------------------"
131 echo "Info: Configured target hosts"
132
133 #-------------------------------------------------------------------------------
134 # Set up target hosts for openstack-ansible
135 #-------------------------------------------------------------------------------
136 # This is openstack-ansible playbook. Check upstream documentation for details.
137 #-------------------------------------------------------------------------------
138 echo "Info: Setting up target hosts for openstack-ansible"
139 echo "-----------------------------------------------------------------------"
140 sudo -E /bin/sh -c "ssh root@$OPNFV_HOST_IP openstack-ansible \
141      $OPENSTACK_OSA_PATH/playbooks/setup-hosts.yml" | \
142      tee $LOG_PATH/setup-hosts.log
143 echo "-----------------------------------------------------------------------"
144 # check the log to see if we have any error
145 if grep -q 'failed=1\|unreachable=1' $LOG_PATH/setup-hosts.log; then
146     echo "Error: OpenStack node setup failed!"
147     exit 1
148 fi
149 echo "Info: Set up target hosts for openstack-ansible successfuly"
150
151 #-------------------------------------------------------------------------------
152 # Set up infrastructure
153 #-------------------------------------------------------------------------------
154 # This is openstack-ansible playbook. Check upstream documentation for details.
155 #-------------------------------------------------------------------------------
156 echo "Info: Setting up infrastructure"
157 echo "-----------------------------------------------------------------------"
158 echo "xci: running ansible playbook setup-infrastructure.yml"
159 sudo -E /bin/sh -c "ssh root@$OPNFV_HOST_IP openstack-ansible \
160      $OPENSTACK_OSA_PATH/playbooks//setup-infrastructure.yml" | \
161      tee $LOG_PATH/setup-infrastructure.log
162 echo "-----------------------------------------------------------------------"
163 # check the log to see if we have any error
164 if grep -q 'failed=1\|unreachable=1' $LOG_PATH/setup-infrastructure.log; then
165     echo "Error: OpenStack node setup failed!"
166     exit 1
167 fi
168
169 #-------------------------------------------------------------------------------
170 # Verify database cluster
171 #-------------------------------------------------------------------------------
172 echo "Info: Verifying database cluster"
173 echo "-----------------------------------------------------------------------"
174 sudo -E /bin/sh -c "ssh root@$OPNFV_HOST_IP ansible -i $OPENSTACK_OSA_PATH/playbooks/inventory/ \
175            galera_container -m shell \
176            -a "mysql -h localhost -e 'show status like \"%wsrep_cluster_%\";'"" \
177            | tee $LOG_PATH/galera.log
178 echo "-----------------------------------------------------------------------"
179 # check the log to see if we have any error
180 if grep -q 'FAILED' $LOG_PATH/galera.log; then
181     echo "Error: Database cluster verification failed!"
182     exit 1
183 fi
184 echo "Info: Database cluster verification successful!"
185
186 #-------------------------------------------------------------------------------
187 # Install OpenStack
188 #-------------------------------------------------------------------------------
189 # This is openstack-ansible playbook. Check upstream documentation for details.
190 #-------------------------------------------------------------------------------
191 echo "Info: Installing OpenStack on target hosts"
192 echo "-----------------------------------------------------------------------"
193 sudo -E /bin/sh -c "ssh root@$OPNFV_HOST_IP openstack-ansible \
194      $OPENSTACK_OSA_PATH/playbooks/setup-openstack.yml" | \
195      tee $LOG_PATH/opnfv-setup-openstack.log
196 echo "-----------------------------------------------------------------------"
197 # check the log to see if we have any error
198 if grep -q 'failed=1\|unreachable=1' $LOG_PATH/opnfv-setup-openstack.log; then
199    echo "Error: OpenStack installation failed!"
200    exit 1
201 fi
202 echo "Info: OpenStack installation is successfully completed!"