ifailed in testing moving the haproxy to openstack.sh
[joid.git] / ci / openstack.sh
1 #!/bin/bash -ex
2
3 ##############################################################################
4 # All rights reserved. This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
7 # http://www.apache.org/licenses/LICENSE-2.0
8 ##############################################################################
9
10 opnfvlab=$2
11 opnfvsdn=$1
12
13 if [ -f ./deployconfig.yaml ];then
14     EXTERNAL_NETWORK=`grep floating-ip-range deployconfig.yaml | cut -d ' ' -f 4 `
15
16     # split EXTERNAL_NETWORK=first ip;last ip; gateway;network
17
18     EXTNET=(${EXTERNAL_NETWORK//,/ })
19
20     EXTNET_FIP=${EXTNET[0]}
21     EXTNET_LIP=${EXTNET[1]}
22     EXTNET_GW=${EXTNET[2]}
23     EXTNET_NET=${EXTNET[3]}
24     EXTNET_PORT=`grep "ext-port" deployconfig.yaml | cut -d ' ' -f 4 | sed -e 's/ //' | tr ',' ' '`
25     ADMNET_GW=`grep "admNetgway" deployconfig.yaml | cut -d ' ' -f 4 | sed -e 's/ //' | tr ',' ' '`
26     API_FQDN=`grep "os-domain-name" deployconfig.yaml | cut -d ' ' -f 4 | sed -e 's/ //' | tr ',' ' '`
27 fi
28
29 # launch eth on computer nodes and remove default gw route
30 launch_eth() {
31     computer_list=$(juju status --format short | grep -Eo 'nova-compute/[0-9]')
32     for node in $computer_list; do
33         echo "node name is ${node}"
34         juju ssh $node "sudo ifconfig $EXTNET_PORT up"
35         #juju ssh $node "sudo route del default gw $ADMNET_GW"
36     done
37 }
38
39 # Update gateway mac to onos for l3 function
40 update_gw_mac() {
41     ## get gateway mac
42     EXTNET_GW_MAC=$(juju ssh nova-compute/0 "arp -a ${EXTNET_GW} | grep -Eo '([0-9a-fA-F]{2})(([/\s:-][0-9a-fA-F]{2}){5})'")
43     ## set external gateway mac in onos
44     juju set onos-controller gateway-mac=$EXTNET_GW_MAC
45 }
46
47 unitAddress() {
48         juju status | python -c "import yaml; import sys; print yaml.load(sys.stdin)[\"services\"][\"$1\"][\"units\"][\"$1/$2\"][\"public-address\"]" 2> /dev/null
49 }
50
51 unitMachine() {
52         juju status | python -c "import yaml; import sys; print yaml.load(sys.stdin)[\"services\"][\"$1\"][\"units\"][\"$1/$2\"][\"machine\"]" 2> /dev/null
53 }
54
55 keystoneIp() {
56     KEYSTONE=$(juju status keystone |grep public-address|sed -- 's/.*\: //')
57     if [ $(echo $KEYSTONE|wc -w) == 1 ];then
58         echo $KEYSTONE
59     else
60         juju get keystone | python -c "import yaml; import sys; print yaml.load(sys.stdin)['settings']['vip']['value']"
61     fi
62 }
63
64 # create external network and subnet in openstack
65 create_openrc() {
66     mkdir -m 0700 -p cloud
67     keystoneIp=$(keystoneIp)
68     adminPasswd=$(juju get keystone | grep admin-password -A 5 | grep value | awk '{print $2}' 2> /dev/null)
69     configOpenrc admin $adminPasswd admin http://$keystoneIp:5000/v2.0 RegionOne > cloud/admin-openrc
70     chmod 0600 cloud/admin-openrc
71 }
72
73 configOpenrc() {
74 if [ "$API_FQDN" != "None" ]; then
75     cat <<-EOF
76         export OS_USERNAME=$1
77         export OS_PASSWORD=$2
78         export OS_TENANT_NAME=$3
79         export OS_AUTH_URL=$4
80         export OS_REGION_NAME=$5
81         export OS_ENDPOINT_TYPE='internalURL'
82         export CINDER_ENDPOINT_TYPE='internalURL'
83         export GLANCE_ENDPOINT_TYPE='internalURL'
84         export KEYSTONE_ENDPOINT_TYPE='internalURL'
85         export NEUTRON_ENDPOINT_TYPE='internalURL'
86         export NOVA_ENDPOINT_TYPE='internalURL'
87 EOF
88 else
89     cat <<-EOF
90         export OS_USERNAME=$1
91         export OS_PASSWORD=$2
92         export OS_TENANT_NAME=$3
93         export OS_AUTH_URL=$4
94         export OS_REGION_NAME=$5
95 EOF
96
97 fi
98 }
99
100 if [ "$API_FQDN" != "None" ]; then
101     # Push api fqdn local ip to all /etc/hosts
102     API_FQDN=$(juju get keystone | python -c "import yaml; import sys;\
103         print yaml.load(sys.stdin)['settings']['os-public-hostname']['value']")
104
105     KEYSTONEIP=$(keystoneIp)
106     juju run --all "if grep $API_FQDN /etc/hosts > /dev/null; then \
107                         echo 'API FQDN already present'; \
108                     else \
109                         sudo sh -c 'echo $KEYSTONEIP $API_FQDN >> /etc/hosts'; \
110                         echo 'API FQDN injected'; \
111                     fi"
112
113     #change in jumphost as well as below commands will run on jumphost
114
115     if grep $API_FQDN /etc/hosts; then
116         echo 'API FQDN already present'
117     else
118         sudo sh -c "echo $KEYSTONEIP $API_FQDN >> /etc/hosts"
119         echo 'API FQDN injected'
120     fi
121 fi
122
123 # Create an load openrc
124 create_openrc
125
126 . ./cloud/admin-openrc
127
128 echo "...... deploy public api proxy ......"
129
130 if [ "$opnfvlab" == "orangepod1" ] && [ "$opnfvsdn" == "nosdn" ]; then # only for first test phase
131     PUB_API_NET=$(grep floating-ip-range ./labconfig.yaml |cut -d/ -f2)
132     PUB_API_IP=$(grep public-api-ip ./labconfig.yaml |cut -d: -f2)
133     juju run --unit nodes/0 "sudo ip a a ${PUB_API_IP}/${PUB_API_NET} dev br-ex" || true
134     juju run --unit nodes/0 "sudo ip l set dev br-ex up" || true
135     python genPublicAPIProxyBundle.py -l labconfig.yaml >> bundles.yaml
136     juju-deployer -vW -d -t 7200 -r 5 -c bundles.yaml $opnfvdistro-"$openstack" || true
137 fi
138
139 echo "...... deploy end public api proxy ......"
140
141 ##
142 ## removing the swift API endpoint which is created by radosgw.
143 ## one option is not to used radosgw and other one is remove endpoint.
144 ##
145
146 #echo "Removing swift endpoint and service"
147 #swift_service_id=$(openstack service list | grep swift | cut -d ' ' -f 2)
148 #swift_endpoint_id=$(openstack endpoint list | grep swift | cut -d ' ' -f 2)
149 #openstack endpoint delete $swift_endpoint_id
150 #openstack service delete $swift_service_id
151
152 ##
153 ## Create external subnet Network
154 ##
155
156 if [ "onos" == "$opnfvsdn" ]; then
157     launch_eth
158     neutron net-show ext-net > /dev/null 2>&1 || neutron net-create ext-net --router:external=True
159     neutron subnet-show ext-subnet > /dev/null 2>&1 || neutron subnet-create ext-net \
160        --name ext-subnet --allocation-pool start=$EXTNET_FIP,end=$EXTNET_LIP \
161        --disable-dhcp --gateway $EXTNET_GW $EXTNET_NET
162     #neutron subnet-create ext-net --name ext-subnet $EXTNET_NET
163     #update_gw_mac
164 elif [ "nosdn" == "$opnfvsdn" ]; then
165     neutron net-show ext-net > /dev/null 2>&1 || neutron net-create ext-net \
166                                              --router:external=True \
167                                              --provider:network_type flat \
168                                               --provider:physical_network external
169
170     neutron subnet-show ext-subnet > /dev/null 2>&1 || neutron subnet-create ext-net \
171        --name ext-subnet --allocation-pool start=$EXTNET_FIP,end=$EXTNET_LIP \
172        --disable-dhcp --gateway $EXTNET_GW $EXTNET_NET
173 else
174     neutron net-show ext-net > /dev/null 2>&1 || neutron net-create ext-net --router:external=True
175     neutron subnet-show ext-subnet > /dev/null 2>&1 || neutron subnet-create ext-net \
176        --name ext-subnet --allocation-pool start=$EXTNET_FIP,end=$EXTNET_LIP \
177        --disable-dhcp --gateway $EXTNET_GW $EXTNET_NET
178 fi
179
180
181 # Create Congress datasources
182 sudo apt-get install -y python-congressclient
183
184 openstack congress datasource create nova "nova" \
185   --config username=$OS_USERNAME \
186   --config tenant_name=$OS_TENANT_NAME \
187   --config password=$OS_PASSWORD \
188   --config auth_url=http://$keystoneIp:5000/v2.0
189 openstack congress datasource create neutronv2 "neutronv2" \
190   --config username=$OS_USERNAME \
191   --config tenant_name=$OS_TENANT_NAME \
192   --config password=$OS_PASSWORD \
193   --config auth_url=http://$keystoneIp:5000/v2.0
194 openstack congress datasource create ceilometer "ceilometer" \
195   --config username=$OS_USERNAME \
196   --config tenant_name=$OS_TENANT_NAME \
197   --config password=$OS_PASSWORD \
198   --config auth_url=http://$keystoneIp:5000/v2.0
199 openstack congress datasource create cinder "cinder" \
200   --config username=$OS_USERNAME \
201   --config tenant_name=$OS_TENANT_NAME \
202   --config password=$OS_PASSWORD \
203   --config auth_url=http://$keystoneIp:5000/v2.0
204 openstack congress datasource create glancev2 "glancev2" \
205   --config username=$OS_USERNAME \
206   --config tenant_name=$OS_TENANT_NAME \
207   --config password=$OS_PASSWORD \
208   --config auth_url=http://$keystoneIp:5000/v2.0
209 openstack congress datasource create keystone "keystone" \
210   --config username=$OS_USERNAME \
211   --config tenant_name=$OS_TENANT_NAME \
212   --config password=$OS_PASSWORD \
213   --config auth_url=http://$keystoneIp:5000/v2.0
214