[functest] Fuel: Replace Gambia with Hunter jobs
[releng.git] / jjb / joid / joid-deploy.sh
1 #!/bin/bash
2 # SPDX-license-identifier: Apache-2.0
3 ##############################################################################
4 # Copyright (c) 2016 Orange 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 +e
11 set -o nounset
12
13 ##
14 ## Functions
15 ##
16 function exit_on_error {
17     RES=$1
18     MSG=$2
19     if [ $RES != 0 ]; then
20         echo "FAILED - $MSG"
21         exit $RES
22     fi
23 }
24
25 ##
26 ## Create LAB_CONFIG folder if not exists
27 ##
28
29 mkdir -p $LAB_CONFIG
30
31 ##
32 ## Set Joid pod config name
33 ##
34
35 case $NODE_NAME in
36     *virtual*)
37         POD=default ;;
38     *)
39         POD=$NODE_NAME ;;
40 esac
41 export POD_NAME=${POD/-}
42
43 ##
44 ## Redeploy MAAS or recover the previous config
45 ##
46
47 cd $WORKSPACE/ci
48
49 if [ -e "$LAB_CONFIG/deployconfig.yaml" ] && [ "$MAAS_REINSTALL" == "false" ]; then
50     echo "------ Recover Juju environment to use MAAS ------"
51     if [ ! -e deployconfig.yaml ]; then
52         cp $LAB_CONFIG/deployconfig.yaml .
53         cp $LAB_CONFIG/deployment.yaml .
54         cp $LAB_CONFIG/labconfig.yaml .
55     fi
56 else
57     if ["$NODE_NAME" == "default" ]; then
58         echo "------ Redeploy MAAS ------"
59         ./03-maasdeploy.sh default
60         exit_on_error $? "MAAS Deploy FAILED"
61     else
62         echo "------ Redeploy MAAS ------"
63         ./03-maasdeploy.sh custom $LAB_CONFIG/labconfig.yaml
64         exit_on_error $? "MAAS Deploy FAILED"
65     fi
66 fi
67
68 ##
69 ## Configure Joid deployment
70 ##
71
72 # Based on scenario naming we can get joid options
73 # naming convention:
74 #    <model>-<controller>-<nfvfeature>-<mode>[-<extrastuff>]
75 # With parameters:
76 #    model=(os|k8)
77 #    controller=(nosdn|odl_l3|odl_l2|onos|ocl)
78 #       No odl_l3 today
79 #    nfvfeature=(kvm|ovs|dpdk|nofeature)
80 #       '_' list separated.
81 #    mode=(ha|noha)
82 #    extrastuff=(none)
83 #       Optional field - Not used today
84
85 IFS='-' read -r -a DEPLOY_OPTIONS <<< "${DEPLOY_SCENARIO}--"
86 #last -- need to avoid nounset error
87
88 JOID_MODEL=${DEPLOY_OPTIONS[0]}
89 SDN_CONTROLLER=${DEPLOY_OPTIONS[1]}
90 NFV_FEATURES=${DEPLOY_OPTIONS[2]}
91 HA_MODE=${DEPLOY_OPTIONS[3]}
92 EXTRA=${DEPLOY_OPTIONS[4]}
93
94 if [ "$SDN_CONTROLLER" == 'odl_l2' ] || [ "$SDN_CONTROLLER" == 'odl_l3' ]; then
95     SDN_CONTROLLER='odl'
96 fi
97
98 # Add extra to features
99 if [ "$EXTRA" != "" ];then
100     NFV_FEATURES="${NFV_FEATURES}_${EXTRA}"
101 fi
102
103 # temporary sfc feature is availble only on onos and trusty
104 if [ "$NFV_FEATURES" == 'sfc' ] && [ "$SDN_CONTROLLER" == 'onos' ];then
105     UBUNTU_DISTRO=trusty
106 fi
107
108 ##
109 ## Configure Joid deployment
110 ##
111
112 if [ "$JOID_MODEL" == 'k8' ]; then
113   echo "------ Deploy with juju ------"
114   echo "Execute: ./deploy.sh -m $JOID_MODEL -s $SDN_CONTROLLER -l $POD_NAME -d $UBUNTU_DISTRO -f $NFV_FEATURES"
115
116   ./deploy.sh -m kubernetes -s $SDN_CONTROLLER -l $POD_NAME -d $UBUNTU_DISTRO -f $NFV_FEATURES
117   exit_on_error $? "Main deploy FAILED"
118 fi
119
120 ##
121 ## Set Admin RC
122 ##
123 if [ "$JOID_MODEL" == 'os' ]; then
124   echo "------ Deploy with juju ------"
125   echo "Execute: ./deploy.sh -m $JOID_MODEL -t $HA_MODE -o $OS_RELEASE -s $SDN_CONTROLLER -l $POD_NAME -d $UBUNTU_DISTRO -f $NFV_FEATURES"
126
127   ./deploy.sh -m openstack -t $HA_MODE -o $OS_RELEASE -s $SDN_CONTROLLER -l $POD_NAME -d $UBUNTU_DISTRO -f $NFV_FEATURES
128   exit_on_error $? "Main deploy FAILED"
129
130   JOID_ADMIN_OPENRC=$LAB_CONFIG/admin-openrc
131   echo "------ Create OpenRC file [$JOID_ADMIN_OPENRC] ------"
132
133   # get controller IP
134   case "$SDN_CONTROLLER" in
135       "odl")
136           SDN_CONTROLLER_IP=$(juju status odl-controller/0 |grep public-address|sed -- 's/.*\: //')
137           ;;
138       "onos")
139           SDN_CONTROLLER_IP=$(juju status onos-controller/0 |grep public-address|sed -- 's/.*\: //')
140           ;;
141       *)
142           SDN_CONTROLLER_IP='none'
143           ;;
144   esac
145   SDN_PASSWORD='admin'
146
147   # export the openrc file by getting the one generated by joid and add SDN
148   # controller for Functest
149   # cp ./cloud/admin-openrc $JOID_ADMIN_OPENRC
150   echo export SDN_CONTROLLER=$SDN_CONTROLLER_IP >> $JOID_ADMIN_OPENRC
151   echo export SDN_PASSWORD=$SDN_PASSWORD >> $JOID_ADMIN_OPENRC
152
153 fi
154
155 ##
156 ## Exit success
157 ##
158
159 echo "Deploy success"
160 exit 0