xci: Update main script and readme
[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/flavors/${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
74 #-------------------------------------------------------------------------------
75 # Configure localhost
76 #-------------------------------------------------------------------------------
77 # This playbook
78 # - removes directories that were created by the previous xci run
79 # - clones opnfv/releng repository
80 # - creates log directory
81 # - copies flavor files such as playbook, inventory, and var file
82 #-------------------------------------------------------------------------------
83 echo "Info: Configuring localhost for openstack-ansible"
84 echo "-----------------------------------------------------------------------"
85 cd $XCI_PATH/playbooks
86 ansible-playbook $ANSIBLE_VERBOSITY -i inventory configure-localhost.yml
87 echo "-----------------------------------------------------------------------"
88 echo "Info: Configured localhost host for openstack-ansible"
89
90 #-------------------------------------------------------------------------------
91 # Configure openstack-ansible deployment host, opnfv
92 #-------------------------------------------------------------------------------
93 # This playbook
94 # - removes directories that were created by the previous xci run
95 # - clones opnfv/releng and openstack/openstack-ansible repositories
96 # - configures network
97 # - generates/prepares ssh keys
98 # - bootstraps ansible
99 # - copies flavor files to be used by openstack-ansible
100 #-------------------------------------------------------------------------------
101 echo "Info: Configuring opnfv deployment host for openstack-ansible"
102 echo "-----------------------------------------------------------------------"
103 cd $OPNFV_RELENG_PATH/prototypes/xci/playbooks
104 ansible-playbook $ANSIBLE_VERBOSITY -i inventory configure-opnfvhost.yml
105 echo "-----------------------------------------------------------------------"
106 echo "Info: Configured opnfv deployment host for openstack-ansible"
107
108 #-------------------------------------------------------------------------------
109 # Skip the rest if the flavor is aio since the target host for aio is opnfv
110 #-------------------------------------------------------------------------------
111 if [[ $XCI_FLAVOR == "aio" ]]; then
112     echo "xci: aio has been installed"
113     exit 0
114 fi
115
116 #-------------------------------------------------------------------------------
117 # Configure target hosts for openstack-ansible
118 #-------------------------------------------------------------------------------
119 # This playbook
120 # - adds public keys to target hosts
121 # - configures network
122 # - configures nfs
123 #-------------------------------------------------------------------------------
124 echo "Info: Configuring target hosts for openstack-ansible"
125 echo "-----------------------------------------------------------------------"
126 cd $OPNFV_RELENG_PATH/prototypes/xci/playbooks
127 ansible-playbook $ANSIBLE_VERBOSITY -i inventory configure-targethosts.yml
128 echo "-----------------------------------------------------------------------"
129 echo "Info: Configured target hosts"
130
131 #-------------------------------------------------------------------------------
132 # Set up target hosts for openstack-ansible
133 #-------------------------------------------------------------------------------
134 # This is openstack-ansible playbook. Check upstream documentation for details.
135 #-------------------------------------------------------------------------------
136 echo "Info: Setting up target hosts for openstack-ansible"
137 echo "-----------------------------------------------------------------------"
138 sudo -E /bin/sh -c "ssh root@$OPNFV_HOST_IP openstack-ansible \
139      $OPENSTACK_OSA_PATH/playbooks/setup-hosts.yml" | \
140      tee $LOG_PATH/setup-hosts.log
141 echo "-----------------------------------------------------------------------"
142 # check the log to see if we have any error
143 if grep -q 'failed=1\|unreachable=1' $LOG_PATH/setup-hosts.log; then
144     echo "Error: OpenStack node setup failed!"
145     exit 1
146 fi
147 echo "Info: Set up target hosts for openstack-ansible successfuly"
148
149 #-------------------------------------------------------------------------------
150 # Set up infrastructure
151 #-------------------------------------------------------------------------------
152 # This is openstack-ansible playbook. Check upstream documentation for details.
153 #-------------------------------------------------------------------------------
154 echo "Info: Setting up infrastructure"
155 echo "-----------------------------------------------------------------------"
156 echo "xci: running ansible playbook setup-infrastructure.yml"
157 sudo -E /bin/sh -c "ssh root@$OPNFV_HOST_IP openstack-ansible \
158      $OPENSTACK_OSA_PATH/playbooks//setup-infrastructure.yml" | \
159      tee $LOG_PATH/setup-infrastructure.log
160 echo "-----------------------------------------------------------------------"
161 # check the log to see if we have any error
162 if grep -q 'failed=1\|unreachable=1' $LOG_PATH/setup-infrastructure.log; then
163     echo "Error: OpenStack node setup failed!"
164     exit 1
165 fi
166
167 #-------------------------------------------------------------------------------
168 # Verify database cluster
169 #-------------------------------------------------------------------------------
170 echo "Info: Verifying database cluster"
171 echo "-----------------------------------------------------------------------"
172 sudo -E /bin/sh -c "ssh root@$OPNFV_HOST_IP ansible -i $OPENSTACK_OSA_PATH/playbooks/inventory/ \
173            galera_container -m shell \
174            -a "mysql -h localhost -e 'show status like \"%wsrep_cluster_%\";'"" \
175            | tee $LOG_PATH/galera.log
176 echo "-----------------------------------------------------------------------"
177 # check the log to see if we have any error
178 if grep -q 'FAILED' $LOG_PATH/galera.log; then
179     echo "Error: Database cluster verification failed!"
180     exit 1
181 fi
182 echo "Info: Database cluster verification successful!"
183
184 #-------------------------------------------------------------------------------
185 # Install OpenStack
186 #-------------------------------------------------------------------------------
187 # This is openstack-ansible playbook. Check upstream documentation for details.
188 #-------------------------------------------------------------------------------
189 echo "Info: Installing OpenStack on target hosts"
190 echo "-----------------------------------------------------------------------"
191 sudo -E /bin/sh -c "ssh root@$OPNFV_HOST_IP openstack-ansible \
192      $OPENSTACK_OSA_PATH/playbooks/setup-openstack.yml" | \
193      tee $LOG_PATH/opnfv-setup-openstack.log
194 echo "-----------------------------------------------------------------------"
195 # check the log to see if we have any error
196 if grep -q 'failed=1\|unreachable=1' $LOG_PATH/opnfv-setup-openstack.log; then
197    echo "Error: OpenStack installation failed!"
198    exit 1
199 fi
200 echo "Info: OpenStack installation is successfully completed!"