Merge "remove scenarios"
[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 # Sanitize local development environment variables
42 #-------------------------------------------------------------------------------
43 user_local_dev_vars=(OPNFV_RELENG_DEV_PATH OPNFV_OSA_DEV_PATH OPNFV_BIFROST_DEV_PATH)
44 for local_user_var in ${user_local_dev_vars[@]}; do
45     [[ -n ${!local_user_var} ]] && export $local_user_var=${!local_user_var%/}/
46 done
47 unset user_local_dev_vars local_user_var
48
49 #-------------------------------------------------------------------------------
50 # Log info to console
51 #-------------------------------------------------------------------------------
52 echo "Info: Starting XCI Deployment"
53 echo "Info: Deployment parameters"
54 echo "-------------------------------------------------------------------------"
55 echo "xci flavor: $XCI_FLAVOR"
56 echo "opnfv/releng version: $OPNFV_RELENG_VERSION"
57 echo "openstack/bifrost version: $OPENSTACK_BIFROST_VERSION"
58 echo "openstack/openstack-ansible version: $OPENSTACK_OSA_VERSION"
59 echo "-------------------------------------------------------------------------"
60
61 #-------------------------------------------------------------------------------
62 # Install ansible on localhost
63 #-------------------------------------------------------------------------------
64 source file/install-ansible.sh
65
66 # TODO: The xci playbooks can be put into a playbook which will be done later.
67
68 #-------------------------------------------------------------------------------
69 # Start provisioning VM nodes
70 #-------------------------------------------------------------------------------
71 # This playbook
72 # - removes directories that were created by the previous xci run
73 # - clones opnfv/releng and openstack/bifrost repositories
74 # - combines opnfv/releng and openstack/bifrost scripts/playbooks
75 # - destorys VMs, removes ironic db, leases, logs
76 # - creates and provisions VMs for the chosen flavor
77 #-------------------------------------------------------------------------------
78 echo "Info: Starting provisining VM nodes using openstack/bifrost"
79 echo "-------------------------------------------------------------------------"
80 cd $XCI_PATH/playbooks
81 ansible-playbook $ANSIBLE_VERBOSITY -i inventory provision-vm-nodes.yml
82 echo "-----------------------------------------------------------------------"
83 echo "Info: VM nodes are provisioned!"
84 source $OPENSTACK_BIFROST_PATH/env-vars
85 ironic node-list
86 echo
87 #-------------------------------------------------------------------------------
88 # Configure localhost
89 #-------------------------------------------------------------------------------
90 # This playbook
91 # - removes directories that were created by the previous xci run
92 # - clones opnfv/releng repository
93 # - creates log directory
94 # - copies flavor files such as playbook, inventory, and var file
95 #-------------------------------------------------------------------------------
96 echo "Info: Configuring localhost for openstack-ansible"
97 echo "-----------------------------------------------------------------------"
98 cd $XCI_PATH/playbooks
99 ansible-playbook $ANSIBLE_VERBOSITY -i inventory configure-localhost.yml
100 echo "-----------------------------------------------------------------------"
101 echo "Info: Configured localhost host for openstack-ansible"
102
103 #-------------------------------------------------------------------------------
104 # Configure openstack-ansible deployment host, opnfv
105 #-------------------------------------------------------------------------------
106 # This playbook
107 # - removes directories that were created by the previous xci run
108 # - clones opnfv/releng and openstack/openstack-ansible repositories
109 # - configures network
110 # - generates/prepares ssh keys
111 # - bootstraps ansible
112 # - copies flavor files to be used by openstack-ansible
113 #-------------------------------------------------------------------------------
114 echo "Info: Configuring opnfv deployment host for openstack-ansible"
115 echo "-----------------------------------------------------------------------"
116 cd $OPNFV_RELENG_PATH/prototypes/xci/playbooks
117 ansible-playbook $ANSIBLE_VERBOSITY -i inventory configure-opnfvhost.yml
118 echo "-----------------------------------------------------------------------"
119 echo "Info: Configured opnfv deployment host for openstack-ansible"
120
121 #-------------------------------------------------------------------------------
122 # Skip the rest if the flavor is aio since the target host for aio is opnfv
123 #-------------------------------------------------------------------------------
124 if [[ $XCI_FLAVOR == "aio" ]]; then
125     echo "xci: aio has been installed"
126     exit 0
127 fi
128
129 #-------------------------------------------------------------------------------
130 # Configure target hosts for openstack-ansible
131 #-------------------------------------------------------------------------------
132 # This playbook
133 # - adds public keys to target hosts
134 # - configures network
135 # - configures nfs
136 #-------------------------------------------------------------------------------
137 echo "Info: Configuring target hosts for openstack-ansible"
138 echo "-----------------------------------------------------------------------"
139 cd $OPNFV_RELENG_PATH/prototypes/xci/playbooks
140 ansible-playbook $ANSIBLE_VERBOSITY -i inventory configure-targethosts.yml
141 echo "-----------------------------------------------------------------------"
142 echo "Info: Configured target hosts"
143
144 #-------------------------------------------------------------------------------
145 # Set up target hosts for openstack-ansible
146 #-------------------------------------------------------------------------------
147 # This is openstack-ansible playbook. Check upstream documentation for details.
148 #-------------------------------------------------------------------------------
149 echo "Info: Setting up target hosts for openstack-ansible"
150 echo "-----------------------------------------------------------------------"
151 ssh root@$OPNFV_HOST_IP "openstack-ansible \
152      $OPENSTACK_OSA_PATH/playbooks/setup-hosts.yml" | \
153      tee $LOG_PATH/setup-hosts.log
154 echo "-----------------------------------------------------------------------"
155 # check the log to see if we have any error
156 if grep -q 'failed=1\|unreachable=1' $LOG_PATH/setup-hosts.log; then
157     echo "Error: OpenStack node setup failed!"
158     exit 1
159 fi
160 echo "Info: Set up target hosts for openstack-ansible successfuly"
161
162 #-------------------------------------------------------------------------------
163 # Set up infrastructure
164 #-------------------------------------------------------------------------------
165 # This is openstack-ansible playbook. Check upstream documentation for details.
166 #-------------------------------------------------------------------------------
167 echo "Info: Setting up infrastructure"
168 echo "-----------------------------------------------------------------------"
169 echo "xci: running ansible playbook setup-infrastructure.yml"
170 ssh root@$OPNFV_HOST_IP "openstack-ansible \
171      $OPENSTACK_OSA_PATH/playbooks//setup-infrastructure.yml" | \
172      tee $LOG_PATH/setup-infrastructure.log
173 echo "-----------------------------------------------------------------------"
174 # check the log to see if we have any error
175 if grep -q 'failed=1\|unreachable=1' $LOG_PATH/setup-infrastructure.log; then
176     echo "Error: OpenStack node setup failed!"
177     exit 1
178 fi
179
180 #-------------------------------------------------------------------------------
181 # Verify database cluster
182 #-------------------------------------------------------------------------------
183 echo "Info: Verifying database cluster"
184 echo "-----------------------------------------------------------------------"
185 ssh root@$OPNFV_HOST_IP "ansible -i $OPENSTACK_OSA_PATH/playbooks/inventory/ \
186            galera_container -m shell \
187            -a "mysql -h localhost -e 'show status like \"%wsrep_cluster_%\";'"" \
188            | tee $LOG_PATH/galera.log
189 echo "-----------------------------------------------------------------------"
190 # check the log to see if we have any error
191 if grep -q 'FAILED' $LOG_PATH/galera.log; then
192     echo "Error: Database cluster verification failed!"
193     exit 1
194 fi
195 echo "Info: Database cluster verification successful!"
196
197 #-------------------------------------------------------------------------------
198 # Install OpenStack
199 #-------------------------------------------------------------------------------
200 # This is openstack-ansible playbook. Check upstream documentation for details.
201 #-------------------------------------------------------------------------------
202 echo "Info: Installing OpenStack on target hosts"
203 echo "-----------------------------------------------------------------------"
204 ssh root@$OPNFV_HOST_IP "openstack-ansible \
205      $OPENSTACK_OSA_PATH/playbooks/setup-openstack.yml" | \
206      tee $LOG_PATH/opnfv-setup-openstack.log
207 echo "-----------------------------------------------------------------------"
208 # check the log to see if we have any error
209 if grep -q 'failed=1\|unreachable=1' $LOG_PATH/opnfv-setup-openstack.log; then
210    echo "Error: OpenStack installation failed!"
211    exit 1
212 fi
213 echo "Info: OpenStack installation is successfully completed!"