Merge "deployment.py: stdout not consumed when deploying changes"
[fuel.git] / prototypes / sfc_tacker / poc.tacker-up.sh
index 5f642f1..4dbb372 100755 (executable)
@@ -1,6 +1,5 @@
 #!/bin/bash
 
-
 #
 # POC Script to build/install/deploy/orchestrate Tacker on an OPNFV Brhamaputra Fuel cluster
 #         Script assuming it runs on the openstack primary controller (where is opendaylight
 #
 #         (c) 2016 Telefonaktiebolaget L. M. ERICSSON
 #
-#         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
+#         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
 #
 
 
@@ -25,16 +23,16 @@ MYREPO="tacker-server"
 CLIREPO="tacker-client"
 DEPREPO="jsonrpclib"
 
-CLIENT="python-python-tackerclient_0.0.1~dev48-1_all.deb"
-JSONRPC="python-jsonrpclib_0.1.7-1_all.deb"
-SERVER="python-tacker_2014.2.0~dev176-1_all.deb"
+CLIENT=$(echo python-python-tackerclient_*_all.deb)
+JSONRPC=$(echo python-jsonrpclib_*_all.deb)
+SERVER=$(echo python-tacker_*_all.deb)
 
 # Function checks whether crudini is available, if not - installs
 function chkCrudini () {
     if [[ ! -f '/usr/bin/crudini' ]]; then
         wget -N http://mirrors.kernel.org/ubuntu/pool/universe/p/python-iniparse/python-iniparse_0.4-2.1build1_all.deb
         wget -N http://archive.ubuntu.com/ubuntu/pool/universe/c/crudini/crudini_0.3-1_amd64.deb
-        dpkg -i python-iniparse_0.4-2.1build1_all.deb crudini_0.3-1_amd64.deb crudini_0.3-1_amd64.deb
+        dpkg -i python-iniparse_0.4-2.1build1_all.deb crudini_0.3-1_amd64.deb
     fi
 }
 
@@ -58,7 +56,7 @@ ____EOF
 # Function setting up the build/deploy environment
 function envSetup () {
     apt-get update
-    apt-get install -y git python-pip python-all debhelper crudini
+    apt-get install -y git python-pip python-all debhelper
     chkPPkg stdeb
     chkCrudini
 }
@@ -76,6 +74,7 @@ function deployJsonrpclib () {
     dpkg --purge python-jsonrpclib
     python setup.py --command-packages=stdeb.command bdist_deb
     cd "deb_dist"
+    JSONRPC=$(echo python-jsonrpclib_*_all.deb)
     cp $JSONRPC $MYDIR
     dpkg -i $JSONRPC
 }
@@ -119,6 +118,9 @@ EOFSCP
 
 # Function corrects and installs the Tacker-server debian package
 function blessPackage () {
+    pushd "${MYDIR}/${MYREPO}/deb_dist"
+    SERVER=$(echo python-tacker_*_all.deb)
+    popd
     DEBFILE="${MYDIR}/${MYREPO}/deb_dist/${SERVER}"
     TMPDIR=$(mktemp -d /tmp/deb.XXXXXX) || exit 1
     OUTPUT=$(basename "$DEBFILE")
@@ -146,9 +148,9 @@ diff -ruN a/DEBIAN/control b/DEBIAN/control
 EOFDC
     cd "$MYDIR"
     echo "Patching  deb..."
-    dpkg -b "$TMPDIR" "${MYDIR}/${OUTPUT}"
+    dpkg -b "$TMPDIR" "${MYDIR}/${SERVER}"
     rm -r "$TMPDIR"
-    dpkg -i "${MYDIR}/${OUTPUT}"
+    dpkg -i "${MYDIR}/${SERVER}"
 }
 
 # Function deploys Tacker-server (installs missing mandatory files: upstart, default)
@@ -212,21 +214,11 @@ function deployTackerClient() {
     dpkg --purge python-tackerclient
     git clone -b 'SFC_refactor' https://github.com/trozet/python-tackerclient.git $CLIREPO
     cd $CLIREPO
-#    patch -p 1 <<EOFCSC
-#--- a/setup.cfg       2016-02-09 08:51:48.424937110 +0000
-#+++ b/setup.cfg       2016-02-09 08:52:17.084938135 +0000
-#@@ -1,5 +1,5 @@
-# [metadata]
-#-name = python-tackerclient
-#+name = tackerclient
-# summary = CLI and Client Library for OpenStack Networking
-# description-file =
-#     README.rst
-#EOFCSC
     python setup.py --command-packages=stdeb.command bdist_deb
     cd "deb_dist"
+    CLIENT=$(echo python-python-tackerclient_*_all.deb)
     cp $CLIENT $MYDIR
-    dpkg -i $CLIENT
+    dpkg -i "${MYDIR}/${CLIENT}"
 }
 
 # Function removes the cloned git repositories
@@ -242,12 +234,11 @@ function populate_client() {
     dpkg -i deb &&\
     rm deb
 
-    sshpass -p "r00tme" scp ${SSH_OPTIONS[@]}  root@10.20.0.2:.ssh/id_rsa ${HOME}/.ssh/id_rsa
-    clusternodes=$(ssh ${SSH_OPTIONS[@]} root@10.20.0.2 fuel node | cut -d '|' -f 5 | grep -E -o "([0-9]{1,3}[\.]){3}[0-9]{1,3}" )
+    clusternodes=$(sshpass -p "r00tme" ssh ${SSH_OPTIONS[@]} root@10.20.0.2 fuel node | cut -d '|' -f 5 | grep -E -o "([0-9]{1,3}[\.]){3}[0-9]{1,3}" )
     myaddr=$(ifconfig br-fw-admin | sed -n '/inet addr/s/.*addr.\([^ ]*\) .*/\1/p')
     for anode in $clusternodes ; do
         if [ "$anode" != "$myaddr" ] ; then
-            echo "installing $CLIENT on $anode"
+            echo "Installing $CLIENT on $anode"
             scp ${SSH_OPTIONS[@]} $CLIENT $anode:$CLIENT
             ssh ${SSH_OPTIONS[@]} $anode dpkg -i $CLIENT
             ssh ${SSH_OPTIONS[@]} $anode rm $CLIENT
@@ -264,21 +255,27 @@ function orchestarte () {
     popd
 
     ### Facts ###
+
+    # Port(s)   Protocol ServiceDetails Source
+    # 8805-8872 tcp,udp  Unassigned     IANA
+    bind_port='8808'
+
     auth_uri=$(crudini --get '/etc/heat/heat.conf' 'keystone_authtoken' 'auth_uri')
     identity_uri=$(crudini --get '/etc/heat/heat.conf' 'keystone_authtoken' 'identity_uri')
-    database_connection="mysql://tacker:tacker@$(hiera database_vip)/tacker"
+    mgmt_addr=$(ifconfig br-mgmt | sed -n '/inet addr/s/.*addr.\([^ ]*\) .*/\1/p')
+    pub_addr=$(ifconfig br-ex-lnx | sed -n '/inet addr/s/.*addr.\([^ ]*\) .*/\1/p')
     rabbit_host=$(crudini --get '/etc/heat/heat.conf' 'oslo_messaging_rabbit' 'rabbit_hosts'| cut -d ':' -f 1)
     rabbit_password=$(crudini --get '/etc/heat/heat.conf' 'oslo_messaging_rabbit' 'rabbit_password')
     sql_host=$(hiera database_vip)
-    admin_url="http://$(hiera management_vip):8888/"
-    public_url="http://$(hiera public_vip):8888/"
+    database_connection="mysql://tacker:tacker@${sql_host}/tacker"
+    admin_url="http://${mgmt_addr}:${bind_port}"
+    public_url="http://${pub_addr}:${bind_port}"
     heat_api_vip=$(crudini --get '/etc/heat/heat.conf' 'heat_api' 'bind_host')
-    mgmt_addr=$(ifconfig br-mgmt | sed -n '/inet addr/s/.*addr.\([^ ]*\) .*/\1/p')
-    allowed_hosts="[ '${HOSTNAME}', 'localhost', '127.0.0.1',  '%' ]"
+    allowed_hosts="[ '${sql_host}', '${HOSTNAME%%.domain.tld}', 'localhost', '127.0.0.1', '%' ]"
     heat_uri="http://${heat_api_vip}:8004/v1"
     odl_port='8282'
     service_tenant='services'
-    myRegion='regionOne'
+    myRegion='RegionOne'
     myPassword='tacker'
 
     cat > configure_tacker.pp << EOF
@@ -290,7 +287,7 @@ function orchestarte () {
    class { 'tacker':
      package_ensure        => 'absent',
      client_package_ensure => 'absent',
-     bind_host             => '${mgmt_addr}',
+     bind_port             => '${bind_port}',
      keystone_password     => '${myPassword}',
      keystone_tenant       => '${service_tenant}',
      auth_uri              => '${auth_uri}',
@@ -305,7 +302,6 @@ function orchestarte () {
 
    class { 'tacker::db::mysql':
        password      => '${myPassword}',
-       host          => '${sql_host}',
        allowed_hosts => ${allowed_hosts},
    }
 
@@ -326,13 +322,14 @@ EOF
 export LC_ALL=C
 export OS_NO_CACHE='true'
 export OS_TENANT_NAME='${service_tenant}'
-export OS_PROJECT_NAME='${service_tenant}''
+export OS_PROJECT_NAME='${service_tenant}'
 export OS_USERNAME='tacker'
-export OS_PASSWORD='tacker'
+export OS_PASSWORD='${myPassword}'
 export OS_AUTH_URL='${auth_uri}'
 export OS_DEFAULT_DOMAIN='default'
 export OS_AUTH_STRATEGY='keystone'
-export OS_REGION_NAME='RegionOne'
+export OS_REGION_NAME='${myRegion}'
+export TACKER_ENDPOINT_TYPE='internalURL'
 EOFRC
     chmod +x tackerc
 }
@@ -343,17 +340,28 @@ function populate_rc() {
     dpkg -i deb &&\
     rm deb
 
-    sshpass -p "r00tme" scp ${SSH_OPTIONS[@]}  root@10.20.0.2:.ssh/id_rsa ${HOME}/.ssh/id_rsa
-    clusternodes=$(ssh ${SSH_OPTIONS[@]} root@10.20.0.2 fuel node | cut -d '|' -f 5 | grep -E -o "([0-9]{1,3}[\.]){3}[0-9]{1,3}" )
+    clusternodes=$(sshpass -p "r00tme" ssh ${SSH_OPTIONS[@]} root@10.20.0.2 fuel node | cut -d '|' -f 5 | grep -E -o "([0-9]{1,3}[\.]){3}[0-9]{1,3}" )
     myaddr=$(ifconfig br-fw-admin | sed -n '/inet addr/s/.*addr.\([^ ]*\) .*/\1/p')
     for anode in $clusternodes ; do
         if [ "$anode" != "$myaddr" ] ; then
-            echo "populating seetings  to  $anode"
+            echo "Populating seetings to $anode"
             scp ${SSH_OPTIONS[@]} tackerc $anode:tackerc
         fi
     done
 }
 
+
+#Configure ODL so that it allows the coexistence between Netvirt and SFC
+function coexistence() {
+    curl -i -u admin:admin -H 'Content-type: application/json' -X PUT \
+    -d '{"netvirt-providers-config":{"table-offset":"1"}}' \
+    http://${mgmt_addr}:${odl_port}/restconf/config/netvirt-providers-config:netvirt-providers-config
+
+    curl -i -u admin:admin -H 'Content-type: application/json' -X PUT \
+    -d '{"sfc-of-renderer-config":{"sfc-of-table-offset":"150","sfc-of-app-egress-table-offset":"11"}}' \
+    http://${mgmt_addr}:${odl_port}/restconf/config/sfc-of-renderer:sfc-of-renderer-config
+}
+
 envSetup
 deployTackerClient
 deployJsonrpclib
@@ -363,6 +371,7 @@ deployTackerServer
 populate_client
 orchestarte
 populate_rc
+coexistence
 
 remove_repo "$MYREPO"
 remove_repo "$DEPREPO"