summaryrefslogtreecommitdiffstats
path: root/jjb/joid/joid-deploy.sh
blob: 59ba01588bcd053aed8b942e3b8a1eefc3923875 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
#!/bin/bash
# SPDX-license-identifier: Apache-2.0
##############################################################################
# Copyright (c) 2016 Orange and others.
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Apache License, Version 2.0
# which accompanies this distribution, and is available at
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################
set +e
set -o nounset

PWD_FILENAME="passwords.sh"

##
##
##
function exit_on_error {
    RES=$1
    MSG=$2
    if [ $RES != 0 ]; then
        echo "FAILED - $MSG"
        exit $RES
    fi
}


##
## Create LAB_CONFIG folder if not exists
##
mkdir -p $LAB_CONFIG

##
## Override default passwords with local settings if needed
##

if [ -e "$LAB_CONFIG/$PWD_FILENAME" ]; then
    echo "------ Load local passwords ------"
    source $LAB_CONFIG/$PWD_FILENAME
else
    export MAAS_USER=ubuntu
    export MAAS_PASSWORD=ubuntu
    export OS_ADMIN_PASSWORD=openstack
fi

##
## Set Joid pod config name
##
    # This part will be removed when pod names will be synced between jenkins and joid config
    case $NODE_NAME in
        orange-fr-pod2)
            POD=orange-pod2 ;;
        juniper-us-test-1)
            POD=juniper-pod1 ;;
        *virtual*)
            POD=default ;;
        *)
            POD=$NODE_NAME ;;
    esac
    export POD_NAME=${POD/-}

##
## Parse Network config
##

EXTERNAL_NETWORK=${EXTERNAL_NETWORK:-}
# split EXTERNAL_NETWORK=name;type;first ip;last ip; gateway;network
IFS=';' read -r -a EXTNET <<< "$EXTERNAL_NETWORK"
EXTNET_NAME=${EXTNET[0]}
EXTNET_TYPE=${EXTNET[1]}
EXTNET_FIP=${EXTNET[2]}
EXTNET_LIP=${EXTNET[3]}
EXTNET_GW=${EXTNET[4]}
EXTNET_NET=${EXTNET[5]}

##
## Redeploy MAAS or recover the previous config
##

cd $WORKSPACE/ci
if [ -e "$LAB_CONFIG/environments.yaml" ] && [ "$MAAS_REINSTALL" == "false" ]; then
    echo "------ Recover Juju environment to use MAAS ------"
    cp $LAB_CONFIG/environments.yaml .
else
    MAASCONFIG=$WORKSPACE/ci/maas/${POD/-*}/${POD/*-}/deployment.yaml
    echo "------ Set MAAS password ------"
    sed -i -- "s/user: ubuntu/user: $MAAS_USER/" $MAASCONFIG
    sed -i -- "s/password: ubuntu/password: $MAAS_PASSWORD/" $MAASCONFIG
    echo "------ Redeploy MAAS ------"
    ./02-maasdeploy.sh $POD_NAME
    exit_on_error $? "MAAS Deploy FAILED"
fi

##
## Configure Joid deployment
##

# Based on scenario naming we can get joid options
# naming convention:
#    os-<controller>-<nfvfeature>-<mode>[-<extrastuff>]
# With parameters:
#    controller=(nosdn|odl_l3|odl_l2|onos|ocl)
#       No odl_l3 today
#    nfvfeature=(kvm|ovs|dpdk|nofeature)
#       '_' list separated.
#    mode=(ha|noha)
#    extrastuff=(none)
#       Optional field - Not used today

IFS='-' read -r -a DEPLOY_OPTIONS <<< "${DEPLOY_SCENARIO}--"
#last -- need to avoid nounset error

SDN_CONTROLLER=${DEPLOY_OPTIONS[1]}
NFV_FEATURES=${DEPLOY_OPTIONS[2]}
HA_MODE=${DEPLOY_OPTIONS[3]}
EXTRA=${DEPLOY_OPTIONS[4]}

if [ "$SDN_CONTROLLER" == 'odl_l2' ] || [ "$SDN_CONTROLLER" == 'odl_l3' ]; then
    SDN_CONTROLLER='odl'
fi
if [ "$HA_MODE" == 'noha' ]; then
    HA_MODE='nonha'
fi
SRCBUNDLE="${WORKSPACE}/ci/${SDN_CONTROLLER}/juju-deployer/"
SRCBUNDLE="${SRCBUNDLE}/ovs-${SDN_CONTROLLER}-${HA_MODE}.yaml"


# Modify Bundle
echo "------ Set openstack password ------"
sed -i -- "s/admin-password: openstack/admin-password: $OS_ADMIN_PASSWORD/" $SRCBUNDLE

if [ -n "$EXTNET_NAME" ]; then
    echo "------ Set openstack default network ------"
    sed -i -- "s/neutron-external-network: ext_net/neutron-external-network: $EXTNET_NAME/" $SRCBUNDLE
fi

echo "------ Set ceph disks ------"
#Find the first line of osd-devices to change the one for ceph, then the other for ceph-osd
sed -i -- "s@osd-devices: /srv@osd-devices: $CEPH_DISKS@" $SRCBUNDLE
sed -i -r -- "s/^(\s+osd-reformat: )'no'/\1'$CEPH_REFORMAT'/" $SRCBUNDLE

##
## Configure Joid deployment
##

echo "------ Deploy with juju ------"
echo "Execute: ./deploy.sh -t $HA_MODE -o $OS_RELEASE -s $SDN_CONTROLLER -l $POD_NAME"

./deploy.sh -t $HA_MODE -o $OS_RELEASE -s $SDN_CONTROLLER -l $POD_NAME
exit_on_error $? "Main deploy FAILED"

##
## Set Admin RC
##
JOID_ADMIN_OPENRC=$LAB_CONFIG/admin-openrc
echo "------ Create OpenRC file [$JOID_ADMIN_OPENRC] ------"

# get Keystone ip
case "$HA_MODE" in
    "ha")
        KEYSTONE=$(cat bundles.yaml |shyaml get-value openstack-phase2.services.keystone.options.vip)
        ;;
    *)
        KEYSTONE=$(juju status keystone |grep public-address|sed -- 's/.*\: //')
        ;;
esac


# get controller IP
case "$SDN_CONTROLLER" in
    "odl")
        SDN_CONTROLLER_IP=$(juju status odl-controller/0 |grep public-address|sed -- 's/.*\: //')
        ;;
    "onos")
        SDN_CONTROLLER_IP=$(juju status onos-controller/0 |grep public-address|sed -- 's/.*\: //')
        ;;
    *)
        SDN_CONTROLLER_IP='none'
        ;;
esac
SDN_PASSWORD='admin'

# export the openrc file
cat << EOF > $JOID_ADMIN_OPENRC
export OS_USERNAME=admin
export OS_PASSWORD=$OS_ADMIN_PASSWORD
export OS_TENANT_NAME=admin
export OS_AUTH_URL=http://$KEYSTONE:5000/v2.0
export OS_REGION_NAME=Canonical
export SDN_CONTROLLER=$SDN_CONTROLLER_IP
export SDN_PASSWORD=$SDN_PASSWORD
EOF

##
## Backup local juju env
##

echo "------ Backup Juju environment ------"
cp environments.yaml $LAB_CONFIG/

##
## Basic test to return a realistic result to jenkins
##

echo "------ Do basic test ------"
source $JOID_ADMIN_OPENRC
curl -i -sw '%{http_code}' -H "Content-Type: application/json"   -d "
{ \"auth\": {
    \"identity\": {
      \"methods\": [\"password\"],
      \"password\": {
        \"user\": {
          \"name\": \"admin\",
          \"domain\": { \"id\": \"default\" },
          \"password\": \"$OS_ADMIN_PASSWORD\"
        }
      }
    }
  }
}"   http://$KEYSTONE:5000/v3/auth/tokens |grep "HTTP/1.1 20" 2>&1 >/dev/null;
exit_on_error $? "Deploy FAILED to auth to openstack"


##
## Create external network if needed
##

# If we have more information than only the name, try to create it
if [ -z "$EXTNET_TYPE" ]; then
    echo "------ No data for external network creation, pass ------"
elif [[ "$DEPLOY_SCENARIO" =~ "onos" ]]; then
    echo "------ ONOS have created the external network, pass ------"
else
    echo "------ External network creation ------"
    neutron net-create $EXTNET_NAME --router:external True \
      --provider:physical_network external --provider:network_type $EXTNET_TYPE
    exit_on_error $? "External network creation failed"
    neutron subnet-create $EXTNET_NAME --name $EXTNET_NAME \
      --allocation-pool start=$EXTNET_FIP,end=$EXTNET_LIP \
      --disable-dhcp --gateway $EXTNET_GW $EXTNET_NET
    exit_on_error $? "External subnet creation failed"
    neutron net-update $EXTNET_NAME --shared
    exit_on_error $? "External network sharing failed"
fi

##
## Exit success
##

echo "Deploy success"
exit 0