joid: Move multijob to build node and get rid of duplicated parameter
[releng.git] / jjb / joid / joid-deploy.sh
index 53255a3..51ddb31 100644 (file)
@@ -4,6 +4,19 @@ 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
 ##
@@ -29,6 +42,8 @@ fi
     case $NODE_NAME in
         orange-fr-pod2)
             POD=orange-pod2 ;;
+        juniper-us-test-1)
+            POD=juniper-pod1 ;;
         *)
             POD=$NODE_NAME ;;
     esac
@@ -49,23 +64,42 @@ else
     sed -i -- "s/password: ubuntu/password: $MAAS_PASSWORD/" $MAASCONFIG
     echo "------ Redeploy MAAS ------"
     ./02-maasdeploy.sh $POD_NAME
-    RES=$?
-    if [ $RES != 0 ]; then
-        echo "MAAS Deploy FAILED"
-        exit $RES
-    fi
+    exit_on_error $? "MAAS Deploy FAILED"
 fi
 
 ##
 ## Configure Joid deployment
 ##
 
-# Get juju deployer file
-if [ "$HA_MODE" == 'nonha' ]; then
-    SRCBUNDLE=$WORKSPACE/ci/$SDN_CONTROLLER/juju-deployer/ovs-$SDN_CONTROLLER.yaml
-else
-    SRCBUNDLE=$WORKSPACE/ci/$SDN_CONTROLLER/juju-deployer/ovs-$SDN_CONTROLLER-$HA_MODE.yaml
+# 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 files
 
@@ -73,9 +107,11 @@ echo "------ Set openstack password ------"
 sed -i -- "s/\"admin-password\": openstack/\"admin-password\": $OS_ADMIN_PASSWORD/" $SRCBUNDLE
 
 echo "------ Set ceph disks ------"
+CEPH_DISKS_CONTROLLERS=${CEPH_DISKS_CONTROLLERS:-}
 if [ -z "$CEPH_DISKS_CONTROLLERS" ]; then
     CEPH_DISKS_CONTROLLERS=$CEPH_DISKS
 fi
+
 #Find the first line of osd-devices to change the one for ceph, then the other for ceph-osd
 CEPH_DEV_LINE=$(grep -nr osd-devices $SRCBUNDLE |head -n1|cut -d: -f1)
 sed -i -- "${CEPH_DEV_LINE}s@osd-devices: /srv@osd-devices: $CEPH_DISKS@" $SRCBUNDLE
@@ -90,11 +126,7 @@ 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
-RES=$?
-if [ $RES != 0 ]; then
-    echo "Deploy FAILED"
-    exit $RES
-fi
+exit_on_error $? "Main deploy FAILED"
 
 ##
 ## Set Admin RC
@@ -139,10 +171,41 @@ curl -i -sw '%{http_code}' -H "Content-Type: application/json"   -d "
     }
   }
 }"   http://$KEYSTONE:5000/v3/auth/tokens |grep "HTTP/1.1 20" 2>&1 >/dev/null;
-RES=$?
-if [ $RES == 0 ]; then
-    echo "Deploy SUCCESS"
+exit_on_error $? "Deploy FAILED to auth to openstack"
+
+
+##
+## Create external network if needed
+##
+
+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]}
+# 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 ------"
 else
-    echo "Deploy FAILED to auth to openstack"
+    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 $RES
+
+##
+## Exit success
+##
+
+echo "Deploy success"
+exit 0