Merge branch 'py3' features 8029 8030

Change-Id: Ia670d01fc45d63f4051209ef73ca272054895873
Signed-off-by: tierno <alfonso.tiernosepulveda@telefonica.com>
diff --git a/test-docker/Dockerfile-devops b/test-docker/Dockerfile-devops
new file mode 100644
index 0000000..25eb013
--- /dev/null
+++ b/test-docker/Dockerfile-devops
@@ -0,0 +1,65 @@
+##
+# Copyright 2019 ETSI
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
+# not use this file except in compliance with the License. You may obtain
+# a copy of the License at
+#
+#         http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+##
+
+########################################################################
+
+from ubuntu:18.04
+
+MAINTAINER  Alfonso Tierno <alfonso.tiernosepulveda@telefoncia.com>
+
+RUN apt-get update && apt-get -y install curl software-properties-common git tox python3-pip \
+    && python3 -m pip install --upgrade pip && python3 -m pip install pyangbind
+
+ARG REPOSITORY_BASE=http://osm-download.etsi.org/repository/osm/debian
+ARG RELEASE=ReleaseSIX-daily
+ARG REPOSITORY_KEY=OSM%20ETSI%20Release%20Key.gpg
+ARG REPOSITORY=testing
+
+RUN curl ${REPOSITORY_BASE}/${RELEASE}/${REPOSITORY_KEY} | apt-key add -
+RUN add-apt-repository -y "deb ${REPOSITORY_BASE}/${RELEASE} ${REPOSITORY} IM common openvim" && apt-get update
+
+ARG RO_VERSION
+ARG IM_VERSION
+
+COPY temp /app
+RUN DEBIAN_FRONTEND=noninteractive apt-get install -y python3-osm-im${IM_VERSION} \
+    && DEBIAN_FRONTEND=noninteractive dpkg -i --force-depends /app/*.deb \
+    && DEBIAN_FRONTEND=noninteractive apt-get  -y -f install
+
+EXPOSE 9090
+
+# Two mysql databases are needed (DB and DB_OVIM). Can be hosted on same or separated containers
+# These ENV must be provided
+ENV RO_DB_HOST=""
+ENV RO_DB_OVIM_HOST=""
+    # if empty RO_DB_HOST is assumed
+
+# These ENV should be provided first time for creating database. It will create and init only if empty!
+ENV RO_DB_ROOT_PASSWORD=""
+ENV RO_DB_OVIM_ROOT_PASSWORD=""
+    # if empty RO_DB_ROOT_PASSWORD is assumed
+
+# These ENV can be provided, but default values are ok
+ENV RO_DB_USER=mano
+ENV RO_DB_OVIM_USER=mano
+ENV RO_DB_PASSWORD=manopw
+ENV RO_DB_OVIM_PASSWORD=manopw
+ENV RO_DB_PORT=3306
+ENV RO_DB_OVIM_PORT=3306
+ENV RO_DB_NAME=mano_db
+ENV RO_DB_OVIM_NAME=mano_vim_db
+
+CMD RO-start.sh
diff --git a/test-docker/test-gen-devops.sh b/test-docker/test-gen-devops.sh
new file mode 100755
index 0000000..3d04c1f
--- /dev/null
+++ b/test-docker/test-gen-devops.sh
@@ -0,0 +1,66 @@
+#!/bin/bash
+
+##
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
+# not use this file except in compliance with the License. You may obtain
+# a copy of the License at
+#
+#         http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+#
+# For those usages not covered by the Apache License, Version 2.0 please
+# contact with: nfvlabs@tid.es
+##
+
+# Generates the debian packages; and then generates a docker image base on Dockerfile-devops and update a
+# running docker stack with the generated image
+
+HERE=$(dirname $(readlink -f ${BASH_SOURCE[0]}))
+export RO_BASE=$(dirname $HERE)
+
+# clean
+docker rm -f ro_pkg 2>/dev/null && echo docker ro_pkg removed
+rm -rf $HERE/temp/*
+find $RO_BASE  -name "*.pyc" -exec rm {} ";"
+mkdir -p $HERE/temp
+
+echo -e "\n\n[STAGE 1] Builind dockerfile userd for the package generation"
+docker build $RO_BASE -f $RO_BASE/Dockerfile  -t opensourcemano/ro_pkg
+sleep 2
+
+echo "[STAGE 1.1] Generting packages inside docker ro_pkg"
+docker run -d --name ro_pkg opensourcemano/ro_pkg bash -c 'sleep 3600'
+docker cp $RO_BASE ro_pkg:/RO
+docker exec ro_pkg bash -c 'cd /RO;  ./devops-stages/stage-build.sh'
+deb_files=`docker exec ro_pkg bash -c 'ls /RO/deb_dist/'`
+[ -z "$deb_files" ] && echo "No packages generated" >&2 && exit 1
+echo $deb_files
+
+echo -e "\n\n[STAGE 1.2] Print package information and copy to '$HERE/temp/'"
+# print package information and copy to "$HERE/temp/"
+for deb_file in $deb_files ; do
+   echo; echo; echo
+   echo $deb_file info:
+   echo "===========================" 
+   docker cp ro_pkg:/RO/deb_dist/$deb_file $HERE/temp/
+   dpkg -I $HERE/temp/$(basename $deb_file)
+done
+
+# docker rm -f ro_pkg
+echo -e "\n\n[STAGE 2] Building docker image opensourcemano/ro:py3_devops based on debian packages"
+docker build $HERE -f $HERE/Dockerfile-devops  -t opensourcemano/ro:py3_devops ||
+    ! echo "error generating devops dockerfile" >&2 || exit 1
+sleep 2
+# docker run -d --name ro_devops opensourcemano/ro:py3_devops
+# docker run -ti exec ro_devops ro tenant-list  || ! echo "Cannot exec ro client to get server tenants" >&2 || exit 1
+
+echo -e "\n\n[STAGE 3] Update service osm_ro with generated docker image"
+docker service update osm_ro --force --image opensourcemano/ro:py3_devops
+sleep 2
+docker container prune -f
+docker service logs osm_ro
diff --git a/test-docker/test-gen-local.sh b/test-docker/test-gen-local.sh
new file mode 100755
index 0000000..0b9c73e
--- /dev/null
+++ b/test-docker/test-gen-local.sh
@@ -0,0 +1,32 @@
+#!/bin/bash
+
+##
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
+# not use this file except in compliance with the License. You may obtain
+# a copy of the License at
+#
+#         http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+#
+# For those usages not covered by the Apache License, Version 2.0 please
+# contact with: nfvlabs@tid.es
+##
+
+# Generates a docker image base on Dockerfile-local and update a running docker stack with the generated image
+
+HERE=$(dirname $(readlink -f ${BASH_SOURCE[0]}))
+export RO_BASE=$(dirname $HERE)
+
+echo -e "\n\n[STAGE 1] Building docker image opensourcemano/ro:py3_local based on debian packages"
+docker build $RO_BASE -f $RO_BASE/Dockerfile-local -t opensourcemano/ro:py3_local ||
+    ! echo "error generating local dockerfile" >&2 || exit 1
+sleep 2
+docker service update osm_ro --force --image opensourcemano/ro:py3_local
+sleep 2
+docker container prune -f
+docker service logs osm_ro