Merge "Revert "Cleanup dirty daisy build workspace directory""
[releng.git] / prototypes / openstack-ansible / scripts / osa-deploy.sh
1 #!/bin/bash
2 # SPDX-license-identifier: Apache-2.0
3 ##############################################################################
4 # Copyright (c) 2016 Huawei Technologies Co.,Ltd 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 set -o errexit
11 set -o nounset
12 set -o pipefail
13
14 export OSA_PATH=/opt/openstack-ansible
15 export LOG_PATH=$OSA_PATH/log
16 export PLAYBOOK_PATH=$OSA_PATH/playbooks
17 export OSA_BRANCH=${OSA_BRANCH:-"master"}
18 XCIMASTER_IP="192.168.122.2"
19
20 sudo /bin/rm -rf $LOG_PATH
21 sudo /bin/mkdir -p $LOG_PATH
22 sudo /bin/cp /root/.ssh/id_rsa.pub ../file/authorized_keys
23 echo -e '\n' | sudo tee --append ../file/authorized_keys
24
25 # log some info
26 echo -e "\n"
27 echo "***********************************************************************"
28 echo "*                                                                     *"
29 echo "*                        Configure XCI Master                         *"
30 echo "*                                                                     *"
31 echo "*  Bootstrap xci-master, configure network, clone openstack-ansible   *"
32 echo "*                Playbooks: configure-xcimaster.yml                   *"
33 echo "*                                                                     *"
34 echo "***********************************************************************"
35 echo -e "\n"
36
37 cd ../playbooks/
38 # this will prepare the jump host
39 # git clone the Openstack-Ansible, bootstrap and configure network
40 echo "xci: running ansible playbook configure-xcimaster.yml"
41 sudo -E ansible-playbook -i inventory configure-xcimaster.yml
42
43 echo "XCI Master is configured successfully!"
44
45 # log some info
46 echo -e "\n"
47 echo "***********************************************************************"
48 echo "*                                                                     *"
49 echo "*                          Configure Nodes                            *"
50 echo "*                                                                     *"
51 echo "*       Configure network on OpenStack Nodes, configure NFS           *"
52 echo "*                Playbooks: configure-targethosts.yml                 *"
53 echo "*                                                                     *"
54 echo "***********************************************************************"
55 echo -e "\n"
56
57 # this will prepare the target host
58 # such as configure network and NFS
59 echo "xci: running ansible playbook configure-targethosts.yml"
60 sudo -E ansible-playbook -i inventory configure-targethosts.yml
61
62 echo "Nodes are configured successfully!"
63
64 # log some info
65 echo -e "\n"
66 echo "***********************************************************************"
67 echo "*                                                                     *"
68 echo "*                       Set Up OpenStack Nodes                        *"
69 echo "*                                                                     *"
70 echo "*            Set up OpenStack Nodes using openstack-ansible           *"
71 echo "*         Playbooks: setup-hosts.yml, setup-infrastructure.yml        *"
72 echo "*                                                                     *"
73 echo "***********************************************************************"
74 echo -e "\n"
75
76 # using OpenStack-Ansible deploy the OpenStack
77 echo "xci: running ansible playbook setup-hosts.yml"
78 sudo -E /bin/sh -c "ssh root@$XCIMASTER_IP openstack-ansible \
79      $PLAYBOOK_PATH/setup-hosts.yml" | \
80      tee $LOG_PATH/setup-hosts.log
81
82 # check the result of openstack-ansible setup-hosts.yml
83 # if failed, exit with exit code 1
84 if grep -q 'failed=1\|unreachable=1' $LOG_PATH/setup-hosts.log; then
85     echo "OpenStack node setup failed!"
86     exit 1
87 fi
88
89 echo "xci: running ansible playbook setup-infrastructure.yml"
90 sudo -E /bin/sh -c "ssh root@$XCIMASTER_IP openstack-ansible \
91      $PLAYBOOK_PATH/setup-infrastructure.yml" | \
92      tee $LOG_PATH/setup-infrastructure.log
93
94 # check the result of openstack-ansible setup-infrastructure.yml
95 # if failed, exit with exit code 1
96 if grep -q 'failed=1\|unreachable=1' $LOG_PATH/setup-infrastructure.log; then
97     echo "OpenStack node setup failed!"
98     exit 1
99 fi
100
101 echo "OpenStack nodes are setup successfully!"
102
103 sudo -E /bin/sh -c "ssh root@$XCIMASTER_IP ansible -i $PLAYBOOK_PATH/inventory/ \
104            galera_container -m shell \
105            -a "mysql -h localhost -e 'show status like \"%wsrep_cluster_%\";'"" \
106            | tee $LOG_PATH/galera.log
107
108 if grep -q 'FAILED' $LOG_PATH/galera.log; then
109     echo "Database cluster verification failed!"
110     exit 1
111 else
112     echo "Database cluster verification successful!"
113 fi
114
115 # log some info
116 echo -e "\n"
117 echo "***********************************************************************"
118 echo "*                                                                     *"
119 echo "*                           Install OpenStack                         *"
120 echo "*                 Playbooks: opnfv-setup-openstack.yml                *"
121 echo "*                                                                     *"
122 echo "***********************************************************************"
123 echo -e "\n"
124
125 echo "xci: running ansible playbook opnfv-setup-openstack.yml"
126 sudo -E /bin/sh -c "ssh root@$XCIMASTER_IP openstack-ansible \
127      $PLAYBOOK_PATH/opnfv-setup-openstack.yml" | \
128      tee $LOG_PATH/opnfv-setup-openstack.log
129
130 if grep -q 'failed=1\|unreachable=1' $LOG_PATH/opnfv-setup-openstack.log; then
131    echo "OpenStack installation failed!"
132    exit 1
133 else
134    echo "OpenStack installation is successfully completed!"
135    exit 0
136 fi