Change the deployment mode from 'nonha' to 'noha'
[joid.git] / ci / deploy.sh
index 94ec5e8..8491ad4 100755 (executable)
@@ -6,10 +6,10 @@ set -ex
 # Below parameters are the default and we can according the release
 
 opnfvsdn=nosdn
-opnfvtype=nonha
-openstack=newton
+opnfvtype=noha
+openstack=ocata
 opnfvlab=default
-opnfvrel=d
+opnfvrel=e
 opnfvfeature=none
 opnfvdistro=xenial
 opnfvarch=amd64
@@ -26,7 +26,7 @@ read_config() {
 }
 
 usage() { echo "Usage: $0 [-s <nosdn|odl|opencontrail>]
-                         [-t <nonha|ha|tip>]
+                         [-t <noha|ha|tip>]
                          [-o <juno|liberty>]
                          [-l <default|intelpod5>]
                          [-f <ipv6,dpdk,lxd,dvr>]
@@ -88,7 +88,7 @@ createresource() {
         if [[ -z "$node_id" ]]; then
             sudo virt-install --connect qemu:///system --name $node \
                 --ram 8192 --cpu host --vcpus 4 \
-                --disk size=120,format=qcow2,bus=virtio,io=native,pool=default \
+                --disk size=120,format=qcow2,bus=virtio,cache=directsync,io=native,pool=default \
                 --network bridge=virbr0,model=virtio \
                 --network bridge=virbr0,model=virtio \
                 --boot network,hd,menu=off \
@@ -136,6 +136,11 @@ deploy() {
                 echo " MAAS not deployed please deploy MAAS first."
             fi
         fi
+#create json file which is missing in case of new deployment after maas and git tree cloned freshly.
+
+        python -c 'import sys, yaml, json; json.dump(yaml.load(sys.stdin), sys.stdout, indent=4)' < labconfig.yaml > labconfig.json
+        python -c 'import sys, yaml, json; json.dump(yaml.load(sys.stdin), sys.stdout, indent=4)' < deployconfig.yaml > deployconfig.json
+
     else
         if [ ! -f ./environments.yaml ] && [ -e ~/.juju/environments.yaml ]; then
             cp ~/.juju/environments.yaml ./environments.yaml
@@ -170,17 +175,19 @@ deploy() {
 
 #check whether charms are still executing the code even juju-deployer says installed.
 check_status() {
+    waitstatus=$1
     retval=0
     timeoutiter=0
 
     echo -n "executing the reltionship within charms ."
     while [ $retval -eq 0 ]; do
-       sleep 30
-       if juju status | grep -q "executing"; then
+        if juju status | grep -q $waitstatus; then
            echo -n '.'
            if [ $timeoutiter -ge 120 ]; then
                echo 'timed out'
                retval=1
+           else
+               sleep 30
            fi
            timeoutiter=$((timeoutiter+1))
        else
@@ -193,21 +200,52 @@ check_status() {
         juju expose ceph-radosgw || true
         #juju ssh ceph/0 \ 'sudo radosgw-admin user create --uid="ubuntu" --display-name="Ubuntu Ceph"'
     fi
+
     echo "...... deployment finishing ......."
-}
+ }
 
 echo "...... deployment started ......"
 deploy
 
-check_status
+check_status executing
 
 echo "...... deployment finished  ......."
 
-if [[ "$opnfvmodel" = "openstack" ]]; then
+
+echo "...... configuring public access  ......."
+
+# translate bundle.yaml to json
+python -c 'import sys, yaml, json; json.dump(yaml.load(sys.stdin), sys.stdout, indent=4)' < bundles.yaml > bundles.json
+# get services list having a public interface
+srv_list=$(cat bundles.json | jq -r ".services | to_entries[] | {\"key\": .key, \"value\": .value[\"bindings\"]} | select (.value!=null) | select(.value[] | contains(\"public-api\"))".key)
+# get cnt list from service list
+cnt_list=$(for cnt in $srv_list; do juju status $cnt --format=json | jq -r ".machines[].containers | to_entries[]".key; done)
+# get public network gateway (supposing it is the first ip of the network)
+public_api_gw=$(cat labconfig.json | jq --raw-output ".opnfv.spaces[] | select(.type==\"public\")".gateway)
+admin_gw=$(cat labconfig.json | jq --raw-output ".opnfv.spaces[] | select(.type==\"admin\")".gateway)
+
+if ([ $admin_gw ] && [ $admin_gw != "null" ]); then
+    # set default gateway to public api gateway
+    for cnt in $cnt_list; do
+        echo "changing default gw on $cnt"
+        if ([ $public_api_gw ] && [ $public_api_gw != "null" ]); then
+            juju ssh $cnt "sudo ip r d default && sudo ip r a default via $public_api_gw";
+            juju ssh $cnt "gw_dev=\$(ip  r l | grep 'via $public_api_gw' | cut -d \  -f5) &&\
+                   sudo cp /etc/network/interfaces /etc/network/interfaces.bak &&\
+                   echo 'removing old default gateway' &&\
+                   sudo perl -i -pe 's/^\ *gateway $admin_gw\n$//' /etc/network/interfaces &&\
+                   sudo perl -i -pe \"s/iface \$gw_dev inet static/iface \$gw_dev inet static\\n  gateway $public_api_gw/\" /etc/network/interfaces \
+                   ";
+        fi
+    done
+fi
+
+echo "...... configure  ......."
+
+if ([ $opnfvmodel == "openstack" ]); then
     ./openstack.sh "$opnfvsdn" "$opnfvlab" "$opnfvdistro" "$openstack" || true
 
     # creating heat domain after puching the public API into /etc/hosts
-
     if [[ "$jujuver" > "2" ]]; then
         status=`juju run-action heat/0 domain-setup`
         echo $status
@@ -216,13 +254,20 @@ if [[ "$opnfvmodel" = "openstack" ]]; then
         echo $status
     fi
 
-
     sudo ../juju/get-cloud-images || true
     ../juju/joid-configure-openstack || true
 
-fi
-if [[ "$opnfvmodel" = "kubernetes" ]]; then
+    if grep -q 'openbaton' bundles.yaml; then
+        juju add-relation openbaton keystone
+    fi
+
+elif ([ $opnfvmodel == "kubernetes" ]); then
     ./k8.sh
 fi
 
+# expose the juju gui-url to login into juju gui
+
+echo " ...... JUJU GUI can be access using the below URL ...... "
+juju gui --show-credentials --no-browser
+
 echo "...... finished  ......."