Add jenkins jobs for automatic reporting dashboard deployment 35/36735/26
authorrohitsakala <rohitsakala@gmail.com>
Thu, 29 Jun 2017 16:38:05 +0000 (22:08 +0530)
committerSakala Venkata Krishna Rohit <rohitsakala@gmail.com>
Sun, 2 Jul 2017 19:46:25 +0000 (19:46 +0000)
Jenkins Jobs have been added for automating the deployment of the
reporting dashboard. Also multijob has been added for automating the
update of docker in the docker hub and generating docs which is empty
for now. Modified unit tests of reporting to make it run from any
directory.

Modified the testapi jenkins jobs yaml file to generic so that many
other modules which may have the same usecases can be integrated easily
just like the reporting one that is done now.

Change-Id: Id13a55416e17199dae1dd6ce64f7c167d117ba37
Signed-off-by: Sakala Venkata Krishna Rohit <rohitsakala@gmail.com>
jjb/releng/automate.yml [moved from jjb/releng/testapi-automate.yml with 78% similarity]
jjb/releng/docker-deploy.sh [moved from jjb/releng/testapi-docker-deploy.sh with 63% similarity]
jjb/releng/docker-update.sh [new file with mode: 0644]
jjb/releng/testapi-docker-update.sh [deleted file]
utils/test/reporting/docker/requirements.pip
utils/test/reporting/run_test.sh [new file with mode: 0755]
utils/test/reporting/run_unit_tests.sh [deleted file]

similarity index 78%
rename from jjb/releng/testapi-automate.yml
rename to jjb/releng/automate.yml
index dd76538..9eb281d 100644 (file)
@@ -1,20 +1,22 @@
 - project:
-    name: testapi-automate
+    name: utils-automate
     stream:
         - master:
             branch: '{stream}'
-            gs-pathname: ''
+
+    module:
+        - 'testapi'
+        - 'reporting'
 
     phase:
-        - 'docker-update'
         - 'docker-deploy':
             slave-label: 'testresults'
         - 'generate-doc'
 
     jobs:
-        - 'testapi-automate-{stream}'
-        - 'testapi-automate-{phase}-{stream}'
-        - 'testapi-verify-{stream}'
+        - '{module}-automate-{stream}'
+        - '{module}-automate-{phase}-{stream}'
+        - '{module}-verify-{stream}'
 
     project: 'releng'
 
@@ -44,7 +46,7 @@
         - mongodb-backup
 
 - job-template:
-    name: 'testapi-verify-{stream}'
+    name: '{module}-verify-{stream}'
 
     parameters:
         - project-parameter:
                     branch-pattern: '**/{branch}'
                 file-paths:
                   - compare-type: 'ANT'
-                    pattern: 'utils/test/testapi/**'
+                    pattern: 'utils/test/{module}/**'
 
     builders:
-        - run-unit-tests
+        - shell: |
+            bash ./utils/test/{module}/run_test.sh
 
     publishers:
         - junit:
                     failing: 30
 
 - job-template:
-    name: 'testapi-automate-{stream}'
+    name: '{module}-automate-{stream}'
 
     project-type: multijob
 
             branch: '{branch}'
         - string:
             name: DOCKER_TAG
-            default: "latest"
-            description: "Tag name for testapi docker image"
+            default: 'latest'
+            description: 'Tag name for {module} docker image'
+        - string:
+            name: MODULE_NAME
+            default: '{module}'
+            description: "Name of the module"
         - 'opnfv-build-defaults'
 
     scm:
                     branch-pattern: '**/{branch}'
                 file-paths:
                   - compare-type: 'ANT'
-                    pattern: 'utils/test/testapi/**'
+                    pattern: 'utils/test/{module}/**'
 
     builders:
         - description-setter:
             description: "Built on $NODE_NAME"
-        - multijob:
-            name: docker-update
-            condition: SUCCESSFUL
-            projects:
-                - name: 'testapi-automate-docker-update-{stream}'
-                  current-parameters: true
-                  kill-phase-on: FAILURE
-                  abort-all-job: true
+        - docker-update
         - multijob:
             name: docker-deploy
             condition: SUCCESSFUL
             projects:
-                - name: 'testapi-automate-docker-deploy-{stream}'
+                - name: '{module}-automate-docker-deploy-{stream}'
                   current-parameters: false
                   predefined-parameters: |
                     GIT_BASE=$GIT_BASE
             name: generate-doc
             condition: SUCCESSFUL
             projects:
-                - name: 'testapi-automate-generate-doc-{stream}'
+                - name: '{module}-automate-generate-doc-{stream}'
                   current-parameters: true
                   kill-phase-on: FAILURE
                   abort-all-job: true
         - 'email-publisher'
 
 - job-template:
-    name: 'testapi-automate-{phase}-{stream}'
+    name: '{module}-automate-{phase}-{stream}'
 
     properties:
         - throttle:
         - project-parameter:
             project: '{project}'
             branch: '{branch}'
-        - string:
-            name: DOCKER_TAG
-            default: "latest"
-            description: "Tag name for testapi docker image"
 
     wrappers:
         - ssh-agent-wrapper
     builders:
         - description-setter:
             description: "Built on $NODE_NAME"
-        - 'testapi-automate-{phase}-macro'
+        - '{module}-automate-{phase}-macro'
 
 ################################
 # job builders
 ################################
 - builder:
-    name: mongodb-backup
-    builders:
-        - shell: |
-            bash ./jjb/releng/testapi-backup-mongodb.sh
-
-- builder:
-    name: 'run-unit-tests'
+    name: 'docker-update'
     builders:
-        - shell: |
-            bash ./utils/test/testapi/run_test.sh
-
-- builder:
-    name: 'testapi-automate-docker-update-macro'
-    builders:
-        - shell: |
-            bash ./jjb/releng/testapi-docker-update.sh
+        - shell:
+            !include-raw: ./docker-update.sh
 
 - builder:
     name: 'testapi-automate-generate-doc-macro'
         - shell: |
             bash ./utils/test/testapi/htmlize/push-doc-artifact.sh
 
+- builder:
+    name: 'reporting-automate-generate-doc-macro'
+    builders:
+        - shell: echo "To Be Done"
+
 - builder:
     name: 'testapi-automate-docker-deploy-macro'
     builders:
         - shell: |
-            bash ./jjb/releng/testapi-docker-deploy.sh
+            bash ./jjb/releng/docker-deploy.sh 'sudo docker run -dti -p 8082:8000 -e mongodb_url=mongodb://172.17.0.1:27017 -e swagger_url=http://testresults.opnfv.org/test opnfv/testapi' "http://testresults.opnfv.org/test/swagger/APIs"
+- builder:
+    name: 'reporting-automate-docker-deploy-macro'
+    builders:
+        - shell: |
+            bash ./jjb/releng/docker-deploy.sh 'sudo docker run -itd -p 8084:8000 -e SERVER_URL=http://testresults.opnfv.org/reporting2:8084 opnfv/reporting' "http://testresults.opnfv.org/reporting2/reporting/index.html"
+
+- builder:
+    name: mongodb-backup
+    builders:
+        - shell: |
+            bash ./jjb/releng/testapi-backup-mongodb.sh
 
 ################################
 # job publishers
     name: 'email-publisher'
     publishers:
         - email:
-            recipients: rohitsakala@gmail.com feng.xiaowei@zte.com.cn
+            recipients: rohitsakala@gmail.com feng.xiaowei@zte.com.cn morgan.richomme@orange.com
             notify-every-unstable-build: false
             send-to-individuals: true
similarity index 63%
rename from jjb/releng/testapi-docker-deploy.sh
rename to jjb/releng/docker-deploy.sh
index 02c5e3a..b3b930f 100644 (file)
@@ -1,10 +1,30 @@
 #!/bin/bash
+#  Licensed to the Apache Software Foundation (ASF) under one   *
+#  or more contributor license agreements.  See the NOTICE file *
+#  distributed with this work for additional information        *
+#  regarding copyright ownership.  The ASF licenses this file   *
+#  to you 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.                                           *
+
+# Assigning Variables
+command=$1
+url=$2
 
 function check() {
 
     # Verify hosted
     sleep 5
-    cmd=`curl -s --head  --request GET http://testresults.opnfv.org/test/swagger/APIs | grep '200 OK' > /dev/null`
+    cmd=`curl -s --head  --request GET ${url} | grep '200 OK' > /dev/null`
     rc=$?
     echo $rc
 
@@ -63,7 +83,7 @@ else
 fi
 
 echo "Running a container with the new image"
-sudo docker run -dti -p "8082:8000" -e "mongodb_url=mongodb://172.17.0.1:27017" -e "swagger_url=http://testresults.opnfv.org/test" opnfv/testapi:latest
+$command:latest
 
 if check; then
     echo "TestResults Hosted."
@@ -71,7 +91,7 @@ else
     echo "TestResults Hosting Failed"
     if [[ $(sudo docker images | grep "opnfv/testapi" | grep "old" | awk '{print $3}') ]]; then
         echo "Running old Image"
-        sudo docker run -dti -p "8082:8000" -e "mongodb_url=mongodb://172.17.0.1:27017" -e "swagger_url=http://testresults.opnfv.org/test" opnfv/testapi:old
+        $command:old
         exit 1
     fi
 fi
diff --git a/jjb/releng/docker-update.sh b/jjb/releng/docker-update.sh
new file mode 100644 (file)
index 0000000..559ac83
--- /dev/null
@@ -0,0 +1,34 @@
+#!/bin/bash
+#  Licensed to the Apache Software Foundation (ASF) under one   *
+#  or more contributor license agreements.  See the NOTICE file *
+#  distributed with this work for additional information        *
+#  regarding copyright ownership.  The ASF licenses this file   *
+#  to you 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.                                           *
+
+set -o errexit
+set -o nounset
+
+cd $WORKSPACE/utils/test/$MODULE_NAME/docker/
+
+# Remove previous containers
+docker ps -a | grep "opnfv/$MODULE_NAME" | awk '{ print $1 }' | xargs -r docker rm -f
+
+# Remove previous images
+docker images | grep "opnfv/$MODULE_NAME" | awk '{ print $3 }' | xargs -r docker rmi -f
+
+# Start build
+docker build --no-cache -t opnfv/$MODULE_NAME:$DOCKER_TAG .
+
+# Push Image
+docker push opnfv/$MODULE_NAME:$DOCKER_TAG
diff --git a/jjb/releng/testapi-docker-update.sh b/jjb/releng/testapi-docker-update.sh
deleted file mode 100644 (file)
index 84f5c32..0000000
+++ /dev/null
@@ -1,18 +0,0 @@
-#!/bin/bash
-
-set -o errexit
-set -o nounset
-
-cd $WORKSPACE/utils/test/testapi/docker/
-
-# Remove previous containers
-docker ps -a | grep "opnfv/testapi" | awk '{ print $1 }' | xargs -r docker rm -f
-
-# Remove previous images
-docker images | grep "opnfv/testapi" | awk '{ print $3 }' | xargs -r docker rmi -f
-
-# Start build
-docker build --no-cache -t opnfv/testapi:$DOCKER_TAG .
-
-# Push Image
-docker push opnfv/testapi:$DOCKER_TAG
index 6de856e..aeee3ba 100644 (file)
@@ -12,3 +12,4 @@ PyYAML==3.11
 simplejson==3.8.1
 jinja2==2.8
 tornado==4.4.2
+requests==2.12.5
diff --git a/utils/test/reporting/run_test.sh b/utils/test/reporting/run_test.sh
new file mode 100755 (executable)
index 0000000..8c674ce
--- /dev/null
@@ -0,0 +1,44 @@
+#!/bin/bash
+set -o errexit
+set -o pipefail
+
+
+# Get script directory
+SCRIPTDIR=`dirname $0`
+
+# Creating virtual environment
+if [ ! -z $VIRTUAL_ENV ]; then
+    venv=$VIRTUAL_ENV
+else
+    venv=$SCRIPTDIR/.venv
+    virtualenv $venv
+fi
+
+source $venv/bin/activate
+
+export CONFIG_REPORTING_YAML=$SCRIPTDIR/reporting.yaml
+
+# ***************
+# Run unit tests
+# ***************
+echo "Running unit tests..."
+
+# install python packages
+easy_install -U setuptools
+easy_install -U pip
+pip install -r $SCRIPTDIR/docker/requirements.pip
+pip install -e $SCRIPTDIR
+
+python $SCRIPTDIR/setup.py develop
+
+# unit tests
+# TODO: remove cover-erase
+# To be deleted when all functest packages will be listed
+nosetests --with-xunit \
+         --cover-package=$SCRIPTDIR/utils \
+         --with-coverage \
+         --cover-xml \
+         $SCRIPTDIR/tests/unit
+rc=$?
+
+deactivate
diff --git a/utils/test/reporting/run_unit_tests.sh b/utils/test/reporting/run_unit_tests.sh
deleted file mode 100755 (executable)
index 6b0e3b2..0000000
+++ /dev/null
@@ -1,43 +0,0 @@
-#!/bin/bash
-set -o errexit
-set -o pipefail
-
-# ******************************
-# prepare the env for the tests
-# ******************************
-# Either Workspace is set (CI)
-if [ -z $WORKSPACE ]
-then
-    WORKSPACE="."
-fi
-
-export CONFIG_REPORTING_YAML=./reporting.yaml
-
-# ***************
-# Run unit tests
-# ***************
-echo "Running unit tests..."
-
-# start vitual env
-virtualenv $WORKSPACE/reporting_venv
-source $WORKSPACE/reporting_venv/bin/activate
-
-# install python packages
-easy_install -U setuptools
-easy_install -U pip
-pip install -r $WORKSPACE/docker/requirements.pip
-pip install -e $WORKSPACE
-
-python $WORKSPACE/setup.py develop
-
-# unit tests
-# TODO: remove cover-erase
-# To be deleted when all functest packages will be listed
-nosetests --with-xunit \
-         --cover-package=utils \
-         --with-coverage \
-         --cover-xml \
-         tests/unit
-rc=$?
-
-deactivate