Merge "Add ericsson-pod1 as it is complained by CI"
authorFatih Degirmenci <fatih.degirmenci@ericsson.com>
Fri, 20 Jan 2017 12:02:39 +0000 (12:02 +0000)
committerGerrit Code Review <gerrit@opnfv.org>
Fri, 20 Jan 2017 12:02:39 +0000 (12:02 +0000)
13 files changed:
jjb/infra/bifrost-upload-logs.sh [deleted file]
jjb/infra/bifrost-verify-jobs.yml
jjb/infra/bifrost-verify.sh
jjb/releng/testapi-automate.yml
utils/test/testapi/htmlize/doc-build.sh
utils/test/testapi/htmlize/htmlize.py
utils/test/testapi/opnfv_testapi/resources/scenario_handlers.py
utils/test/testapi/opnfv_testapi/resources/scenario_models.py
utils/test/testapi/opnfv_testapi/tests/unit/fake_pymongo.py
utils/test/testapi/opnfv_testapi/tests/unit/scenario-c1.json [moved from utils/test/testapi/opnfv_testapi/tests/unit/scenario-create.json with 99% similarity]
utils/test/testapi/opnfv_testapi/tests/unit/scenario-c2.json [new file with mode: 0644]
utils/test/testapi/opnfv_testapi/tests/unit/test_base.py
utils/test/testapi/opnfv_testapi/tests/unit/test_scenario.py

diff --git a/jjb/infra/bifrost-upload-logs.sh b/jjb/infra/bifrost-upload-logs.sh
deleted file mode 100755 (executable)
index 8e1982d..0000000
+++ /dev/null
@@ -1,52 +0,0 @@
-#!/bin/bash
-# SPDX-license-identifier: Apache-2.0
-##############################################################################
-# Copyright (c) 2016 SUSE.
-# 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
-##############################################################################
-
-set -eu
-set -o pipefail
-
-BIFROST_CONSOLE_LOG="${BUILD_URL}/consoleText"
-BIFROST_GS_URL=${BIFROST_LOG_URL/http:/gs:}
-BIFROST_COMPRESS_SUFFIX="tar.gz"
-BIFROST_COMPRESSED_LOGS=()
-
-echo "Uploading build logs to ${BIFROST_LOG_URL}"
-
-echo "Uploading console output"
-curl -L ${BIFROST_CONSOLE_LOG} | gsutil cp - ${BIFROST_GS_URL}/build_log.txt
-
-[[ ! -d ${WORKSPACE}/logs ]] && exit 0
-
-pushd ${WORKSPACE}/logs/ &> /dev/null
-for x in *.log; do
-    echo "Compressing and uploading $x"
-    tar -czf - $x | gsutil cp - ${BIFROST_GS_URL}/${x}.${BIFROST_COMPRESS_SUFFIX} 1>/dev/null
-    BIFROST_COMPRESSED_LOGS+=(${x}.${BIFROST_COMPRESS_SUFFIX})
-done
-popd &> /dev/null
-
-echo "Generating the landing page"
-cat > index.html << EOF
-<html>
-<h1>Build results for <a href=https://$GERRIT_NAME/#/c/$GERRIT_CHANGE_NUMBER>$GERRIT_NAME/$GERRIT_CHANGE_NUMBER</a></h1>
-<h2>Job: $JOB_NAME</h2>
-<ul>
-<li><a href=${BIFROST_LOG_URL}/build_log.txt>build_log.txt</a></li>
-EOF
-
-for x in ${BIFROST_COMPRESSED_LOGS[@]}; do
-    echo "<li><a href=${BIFROST_LOG_URL}/${x}>${x}</a></li>" >> index.html
-done
-
-cat >> index.html << EOF
-</ul>
-</html>
-EOF
-
-gsutil cp index.html ${BIFROST_GS_URL}/index.html
index 6232859..8184b63 100644 (file)
     builders:
         - bifrost-set-name
         - bifrost-build
-        - bifrost-artifacts-upload
 
     publishers:
         - email:
     builders:
         - shell:
             !include-raw: ./bifrost-verify.sh
-
-- builder:
-    name: bifrost-artifacts-upload
-    builders:
-        - shell:
-            !include-raw: ./bifrost-upload-logs.sh
index 9fbb1d0..201d3f2 100755 (executable)
@@ -11,7 +11,51 @@ set -o errexit
 set -o nounset
 set -o pipefail
 
-trap fix_ownership EXIT
+trap cleanup_and_upload EXIT
+
+function upload_logs() {
+    BIFROST_CONSOLE_LOG="${BUILD_URL}/consoleText"
+    BIFROST_GS_URL=${BIFROST_LOG_URL/http:/gs:}
+
+    echo "Uploading build logs to ${BIFROST_LOG_URL}"
+
+    echo "Uploading console output"
+    curl -s -L ${BIFROST_CONSOLE_LOG} > build_log.txt
+    gsutil -q cp -Z build_log.txt ${BIFROST_GS_URL}/build_log.txt
+    rm build_log.txt
+
+    [[ ! -d ${WORKSPACE}/logs ]] && exit 0
+
+    pushd ${WORKSPACE}/logs/ &> /dev/null
+    for x in *.log; do
+        echo "Compressing and uploading $x"
+        gsutil -q cp -Z ${x} ${BIFROST_GS_URL}/${x}
+    done
+
+    echo "Generating the landing page"
+    cat > index.html <<EOF
+<html>
+<h1>Build results for <a href=https://$GERRIT_NAME/#/c/$GERRIT_CHANGE_NUMBER/$GERRIT_PATCHSET_NUMBER>$GERRIT_NAME/$GERRIT_CHANGE_NUMBER/$GERRIT_PATCHSET_NUMBER</a></h1>
+<h2>Job: $JOB_NAME</h2>
+<ul>
+<li><a href=${BIFROST_LOG_URL}/build_log.txt>build_log.txt</a></li>
+EOF
+
+    for x in *.log; do
+        echo "<li><a href=${BIFROST_LOG_URL}/${x}>${x}</a></li>" >> index.html
+    done
+
+    cat >> index.html << EOF
+</ul>
+</html>
+EOF
+
+    gsutil -q cp index.html ${BIFROST_GS_URL}/index.html
+
+    rm index.html
+
+    popd &> /dev/null
+}
 
 function fix_ownership() {
     if [ -z "${JOB_URL+x}" ]; then
@@ -25,6 +69,13 @@ function fix_ownership() {
     fi
 }
 
+function cleanup_and_upload() {
+    original_exit=$?
+    fix_ownership
+    upload_logs
+    exit $original_exit
+}
+
 # check distro to see if we support it
 if [[ ! "$DISTRO" =~ (trusty|centos7|suse) ]]; then
     echo "Distro $DISTRO is not supported!"
index 552c25f..c038352 100644 (file)
@@ -18,6 +18,7 @@
             project: '{project}'
         - gerrit-parameter:
             branch: '{branch}'
+        - 'opnfv-build-ubuntu-defaults'
 
     scm:
         - git-scm
index e492c97..427b437 100644 (file)
@@ -1,5 +1,7 @@
 #!/bin/bash
 
+set -o errexit
+
 # Create virtual environment
 source $WORKSPACE/testapi_venv/bin/activate
 
index 68d02fe..c07f98e 100644 (file)
@@ -28,7 +28,10 @@ def main(args):
     # Generating html page
     cmd = 'java -jar swagger-codegen-cli.jar generate \
         -i specs.json -l html2 -o %s' % (args.output_directory)
-    os.system(cmd)
+    if os.system(cmd) == 0:
+        exit(0)
+    else:
+        exit(1)
 
 if __name__ == '__main__':
     parser = argparse.ArgumentParser(description='Create \
index 7bf3d5d..28fe28e 100644 (file)
@@ -19,11 +19,49 @@ class ScenariosCLHandler(GenericScenarioHandler):
         """
             @description: Retrieve scenario(s).
             @notes: Retrieve scenario(s)
-            @return 200: all scenarios consist with query,
+                Available filters for this request are :
+                 - name : scenario name
+
+                GET /scenarios?name=scenario_1
+            @param name: scenario name
+            @type name: L{string}
+            @in name: query
+            @required name: False
+            @param installer: installer type
+            @type installer: L{string}
+            @in installer: query
+            @required installer: False
+            @param version: version
+            @type version: L{string}
+            @in version: query
+            @required version: False
+            @param project: project name
+            @type project: L{string}
+            @in project: query
+            @required project: False
+            @return 200: all scenarios satisfy queries,
                          empty list if no scenario is found
             @rtype: L{Scenarios}
         """
-        self._list()
+
+        def _set_query():
+            query = dict()
+            elem_query = dict()
+            for k in self.request.query_arguments.keys():
+                v = self.get_query_argument(k)
+                if k == 'installer':
+                    elem_query["installer"] = v
+                elif k == 'version':
+                    elem_query["versions.version"] = v
+                elif k == 'project':
+                    elem_query["versions.projects.project"] = v
+                else:
+                    query[k] = v
+            if elem_query:
+                query['installers'] = {'$elemMatch': elem_query}
+            return query
+
+        self._list(_set_query())
 
     @swagger.operation(nickname="Create a new scenario")
     def post(self):
@@ -58,6 +96,7 @@ class ScenarioGURHandler(GenericScenarioHandler):
             @return 200: scenario exist
             @raise 404: scenario not exist
         """
+        self._get_one({'name': name})
         pass
 
     @swagger.operation(nickname="Update the scenario by name")
@@ -65,7 +104,7 @@ class ScenarioGURHandler(GenericScenarioHandler):
         """
             @description: update a single scenario by name
             @param body: fields to be updated
-            @type body: L{string}
+            @type body: L{ScenarioCreateRequest}
             @in body: body
             @rtype: L{Scenario}
             @return 200: update success
index b4bb363..f89a124 100644 (file)
@@ -11,7 +11,7 @@ class ScenarioTI(models.ModelBase):
 
 @swagger.model()
 class ScenarioScore(models.ModelBase):
-    def __init__(self, date=None, score=''):
+    def __init__(self, date=None, score='0'):
         self.date = date
         self.score = score
 
@@ -27,14 +27,19 @@ class ScenarioProject(models.ModelBase):
         @ptype trust_indicators: C{list} of L{ScenarioTI}
     """
     def __init__(self,
-                 name='',
+                 project='',
                  customs=None,
                  scores=None,
                  trust_indicators=None):
-        self.name = name
+        self.project = project
         self.customs = customs
         self.scores = scores
-        self.trust_indicator = trust_indicators
+        self.trust_indicators = trust_indicators
+
+    @staticmethod
+    def attr_parser():
+        return {'scores': ScenarioScore,
+                'trust_indicators': ScenarioTI}
 
 
 @swagger.model()
@@ -43,10 +48,14 @@ class ScenarioVersion(models.ModelBase):
         @property projects:
         @ptype projects: C{list} of L{ScenarioProject}
     """
-    def __init__(self, version, projects=None):
+    def __init__(self, version=None, projects=None):
         self.version = version
         self.projects = projects
 
+    @staticmethod
+    def attr_parser():
+        return {'projects': ScenarioProject}
+
 
 @swagger.model()
 class ScenarioInstaller(models.ModelBase):
@@ -54,11 +63,14 @@ class ScenarioInstaller(models.ModelBase):
         @property versions:
         @ptype versions: C{list} of L{ScenarioVersion}
     """
-    def __init__(self, installer=None, owner=None, versions=None):
+    def __init__(self, installer=None, versions=None):
         self.installer = installer
-        self.owner = owner
         self.versions = versions if versions else list()
 
+    @staticmethod
+    def attr_parser():
+        return {'versions': ScenarioVersion}
+
 
 @swagger.model()
 class ScenarioCreateRequest(models.ModelBase):
@@ -70,6 +82,10 @@ class ScenarioCreateRequest(models.ModelBase):
         self.name = name
         self.installers = installers if installers else list()
 
+    @staticmethod
+    def attr_parser():
+        return {'installers': ScenarioInstaller}
+
 
 @swagger.model()
 class Scenario(models.ModelBase):
@@ -83,6 +99,10 @@ class Scenario(models.ModelBase):
         self.creation_date = create_date
         self.installers = installers if installers else list()
 
+    @staticmethod
+    def attr_parser():
+        return {'installers': ScenarioInstaller}
+
 
 @swagger.model()
 class Scenarios(models.ModelBase):
index d86d8ea..3c4fd01 100644 (file)
@@ -55,7 +55,8 @@ class MemCursor(object):
 
 class MemDb(object):
 
-    def __init__(self):
+    def __init__(self, name):
+        self.name = name
         self.contents = []
         pass
 
@@ -109,8 +110,59 @@ class MemDb(object):
                 return True
         return False
 
-    @staticmethod
-    def _in(content, *args):
+    def _in(self, content, *args):
+        if self.name == 'scenarios':
+            return self._in_scenarios(content, *args)
+        else:
+            return self._in_others(content, *args)
+
+    def _in_scenarios_installer(self, installer, content):
+        hit = False
+        for s_installer in content['installers']:
+            if installer == s_installer['installer']:
+                hit = True
+
+        return hit
+
+    def _in_scenarios_version(self, version, content):
+        hit = False
+        for s_installer in content['installers']:
+            for s_version in s_installer['versions']:
+                if version == s_version['version']:
+                    hit = True
+        return hit
+
+    def _in_scenarios_project(self, project, content):
+        hit = False
+        for s_installer in content['installers']:
+            for s_version in s_installer['versions']:
+                for s_project in s_version['projects']:
+                    if project == s_project['project']:
+                        hit = True
+
+        return hit
+
+    def _in_scenarios(self, content, *args):
+        for arg in args:
+            for k, v in arg.iteritems():
+                if k == 'installers':
+                    for inner in v.values():
+                        for i_k, i_v in inner.iteritems():
+                            if i_k == 'installer':
+                                return self._in_scenarios_installer(i_v,
+                                                                    content)
+                            elif i_k == 'versions.version':
+                                return self._in_scenarios_version(i_v,
+                                                                  content)
+                            elif i_k == 'versions.projects.project':
+                                return self._in_scenarios_project(i_v,
+                                                                  content)
+                elif content.get(k, None) != v:
+                    return False
+
+        return True
+
+    def _in_others(self, content, *args):
         for arg in args:
             for k, v in arg.iteritems():
                 if k == 'start_date':
@@ -185,8 +237,8 @@ def __getattr__(name):
     return globals()[name]
 
 
-pods = MemDb()
-projects = MemDb()
-testcases = MemDb()
-results = MemDb()
-scenarios = MemDb()
+pods = MemDb('pods')
+projects = MemDb('projects')
+testcases = MemDb('testcases')
+results = MemDb('results')
+scenarios = MemDb('scenarios')
diff --git a/utils/test/testapi/opnfv_testapi/tests/unit/scenario-c2.json b/utils/test/testapi/opnfv_testapi/tests/unit/scenario-c2.json
new file mode 100644 (file)
index 0000000..b6a3b83
--- /dev/null
@@ -0,0 +1,73 @@
+{
+  "name": "odl_2-nofeature-ha",
+  "installers":
+  [
+    {
+      "installer": "fuel",
+      "versions":
+      [
+        {
+          "owner": "Lucky",
+          "version": "colorado",
+          "projects":
+          [
+            {
+              "project": "functest",
+              "customs": [ "healthcheck", "vping_ssh"],
+              "scores": [],
+              "trust_indicators": [
+                {
+                  "date": "2017-01-18 22:46:44",
+                  "status": "silver"
+                }
+
+              ]
+            },
+            {
+              "project": "yardstick",
+              "customs": ["suite-a"],
+              "scores": [
+                {
+                  "date": "2017-01-08 22:46:44",
+                  "score": "0"
+                }
+              ],
+              "trust_indicators": [
+                {
+                  "date": "2017-01-18 22:46:44",
+                  "status": "gold"
+                }
+              ]
+            }
+          ]
+        },
+        {
+          "owner": "Luke",
+          "version": "colorado",
+          "projects":
+          [
+            {
+              "project": "functest",
+              "customs": [ "healthcheck", "vping_ssh"],
+              "scores":
+              [
+                {
+                  "date": "2017-01-09 22:46:44",
+                  "score": "11/14"
+                }
+
+              ],
+              "trust_indicators": []
+            },
+            {
+              "project": "yardstick",
+              "customs": [],
+              "scores": [],
+              "trust_indicators": []
+            }
+          ]
+        }
+      ]
+    }
+  ]
+}
index 9343ab2..fc780e4 100644 (file)
@@ -47,11 +47,11 @@ class TestBase(AsyncHTTPTestCase):
         return self.create_help(self.basePath, req, *args)
 
     def create_help(self, uri, req, *args):
-        if req and not isinstance(req, str):
-            req = json.dumps(req.format())
+        if req and not isinstance(req, str) and hasattr(req, 'format'):
+            req = req.format()
         res = self.fetch(self._update_uri(uri, *args),
                          method='POST',
-                         body=req if req else json.dumps(None),
+                         body=json.dumps(req),
                          headers=self.headers)
 
         return self._get_return(res, self.create_res)
@@ -97,7 +97,7 @@ class TestBase(AsyncHTTPTestCase):
         return uri.count('%s')
 
     def _get_query_uri(self, query):
-        return self.basePath + '?' + query
+        return self.basePath + '?' + query if query else self.basePath
 
     def _get_uri(self, *args):
         return self._update_uri(self.basePath, *args)
index 8e82781..ff59795 100644 (file)
@@ -4,15 +4,20 @@ import os
 from opnfv_testapi.common.constants import HTTP_BAD_REQUEST
 from opnfv_testapi.common.constants import HTTP_FORBIDDEN
 from opnfv_testapi.common.constants import HTTP_OK
+from opnfv_testapi.resources.scenario_models import Scenario
 from opnfv_testapi.resources.scenario_models import ScenarioCreateRequest
+from opnfv_testapi.resources.scenario_models import Scenarios
 from test_testcase import TestBase
 
 
 class TestScenarioBase(TestBase):
     def setUp(self):
         super(TestScenarioBase, self).setUp()
+        self.get_res = Scenario
+        self.list_res = Scenarios
         self.basePath = '/api/v1/scenarios'
-        self.load_request('scenario-create.json')
+        self.req_d = self._load_request('scenario-c1.json')
+        self.req_2 = self._load_request('scenario-c2.json')
 
     def tearDown(self):
         pass
@@ -20,10 +25,26 @@ class TestScenarioBase(TestBase):
     def assert_body(self, project, req=None):
         pass
 
-    def load_request(self, f_req):
-        with open(os.path.join(os.path.dirname(__file__), f_req), 'r') as f:
-            self.req_d = json.dumps(json.load(f))
+    @staticmethod
+    def _load_request(f_req):
+        abs_file = os.path.join(os.path.dirname(__file__), f_req)
+        with open(abs_file, 'r') as f:
+            loader = json.load(f)
             f.close()
+        return loader
+
+    def create_return_name(self, req):
+        _, res = self.create(req)
+        return res.href.split('/')[-1]
+
+    def assert_res(self, code, scenario, req=None):
+        self.assertEqual(code, HTTP_OK)
+        if req is None:
+            req = self.req_d
+        scenario_dict = scenario.format_http()
+        self.assertIsNotNone(scenario_dict['_id'])
+        self.assertIsNotNone(scenario_dict['creation_date'])
+        self.assertDictContainsSubset(req, scenario_dict)
 
 
 class TestScenarioCreate(TestScenarioBase):
@@ -53,3 +74,60 @@ class TestScenarioCreate(TestScenarioBase):
         (code, body) = self.create_d()
         self.assertEqual(code, HTTP_FORBIDDEN)
         self.assertIn('already exists', body)
+
+
+class TestScenarioGet(TestScenarioBase):
+    def setUp(self):
+        super(TestScenarioGet, self).setUp()
+        self.scenario_1 = self.create_return_name(self.req_d)
+        self.scenario_2 = self.create_return_name(self.req_2)
+
+    def test_getByName(self):
+        code, body = self.get(self.scenario_1)
+        self.assert_res(code, body, req=self.req_d)
+
+    def test_getAll(self):
+        self._query_and_assert(query=None, reqs=[self.req_d, self.req_2])
+
+    def test_queryName(self):
+        query = self._set_query('name=nosdn-nofeature-ha')
+        self._query_and_assert(query, reqs=[self.req_d])
+
+    def test_queryInstaller(self):
+        query = self._set_query('installer=apex')
+        self._query_and_assert(query, reqs=[self.req_d])
+
+    def test_queryVersion(self):
+        query = self._set_query('version=master')
+        self._query_and_assert(query, reqs=[self.req_d])
+
+    def test_queryProject(self):
+        query = self._set_query('project=functest')
+        self._query_and_assert(query, reqs=[self.req_d, self.req_2])
+
+    def test_queryCombination(self):
+        query = self._set_query('name=nosdn-nofeature-ha',
+                                'installer=apex',
+                                'version=master',
+                                'project=functest')
+
+        self._query_and_assert(query, reqs=[self.req_d])
+
+    @staticmethod
+    def _set_query(*args):
+        uri = ''
+        for arg in args:
+            uri += arg + '&'
+        return uri[0: -1]
+
+    def _query_and_assert(self, query, found=True, reqs=None):
+        code, body = self.query(query)
+        if not found:
+            self.assertEqual(code, HTTP_OK)
+            self.assertEqual(0, len(body.scenarios))
+        else:
+            self.assertEqual(len(reqs), len(body.scenarios))
+            for req in reqs:
+                for scenario in body.scenarios:
+                    if req['name'] == scenario.name:
+                        self.assert_res(code, scenario, req)