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