Merge "adapt mong_to_elasticsearch.py to testAPI"
authorMorgan Richomme <morgan.richomme@orange.com>
Fri, 17 Jun 2016 10:06:24 +0000 (10:06 +0000)
committerGerrit Code Review <gerrit@172.30.200.206>
Fri, 17 Jun 2016 10:06:24 +0000 (10:06 +0000)
utils/test/dashboard/js/opnfv_dashboard_tests_conf.js
utils/test/reporting/functest/reportingConf.py
utils/test/reporting/functest/reportingUtils.py
utils/test/reporting/functest/testCase.py
utils/test/result_collection_api/update/changes.py
utils/test/result_collection_api/update/restore.py
utils/test/scripts/mongo_to_elasticsearch.py

index 6e230d8..870357c 100644 (file)
@@ -31,21 +31,21 @@ opnfv_dashboard_installers_scenarios['joid']=
 \r
 var opnfv_dashboard_testcases = {\r
     'VIM': {\r
-        'Tempest': ['Tempest duration',\r
+        'vping_ssh': ['vPing duration'],\r
+        'vping_userdata': ['vPing_userdata duration'],\r
+        'tempest': ['Tempest duration',\r
                 'Tempest nb tests/nb failures'],\r
-        'vPing': ['vPing duration'],\r
-        'vPing_userdata': ['vPing_userdata duration'],\r
-        'Rally': ['rally duration']\r
+        'rally_sanity': ['rally duration']\r
     },\r
     'Controller': {\r
-        'ODL': ['ODL nb tests/nb failures'],\r
-        'ONOS': ['ONOS FUNCvirNet duration ',\r
+        'odl': ['ODL nb tests/nb failures'],\r
+        'onos': ['ONOS FUNCvirNet duration ',\r
                 'ONOS FUNCvirNet nb tests/nb failures',\r
                 'ONOS FUNCvirNetL3 duration',\r
                 'ONOS FUNCvirNetL3 nb tests/nb failures']\r
     },\r
     'Features': {\r
-        'vIMS': ['vIMS nb tests passed/failed/skipped',\r
+        'vims': ['vIMS nb tests passed/failed/skipped',\r
                 'vIMS orchestrator/VNF/test duration'],\r
         'promise': ['Promise duration ',\r
                 'Promise nb tests/nb failures'],\r
index e390a18..649246d 100644 (file)
@@ -15,3 +15,4 @@ installers = ["apex", "compass", "fuel", "joid"]
 versions = ["master"]
 PERIOD = 10
 MAX_SCENARIO_CRITERIA = 18
+URL_BASE = 'http://testresults.opnfv.org/test/api/v1/results'
index 7170b83..0db570f 100644 (file)
@@ -19,7 +19,7 @@ def getApiResults(case, installer, scenario, version):
     # urllib2.install_opener(opener)
     # url = "http://127.0.0.1:8000/results?case=" + case + \
     #       "&period=30&installer=" + installer
-    url = ("http://testresults.opnfv.org/test/api/v1/results?case=" + case +
+    url = (reportingConf.URL_BASE + "?case=" + case +
            "&period=" + str(reportingConf.PERIOD) + "&installer=" + installer +
            "&scenario=" + scenario + "&version=" + version)
     request = Request(url)
@@ -38,7 +38,7 @@ def getScenarios(case, installer, version):
 
     case = case.getName()
     print case
-    url = ("http://testresults.opnfv.org/test/api/v1/results?case=" + case +
+    url = (reportingConf.URL_BASE + "?case=" + case +
            "&period=" + str(reportingConf.PERIOD) + "&installer=" + installer +
            "&version=" + version)
     request = Request(url)
index f6ab95a..f0e8f59 100644 (file)
@@ -86,17 +86,17 @@ class TestCase(object):
         # '<name in the config>':'<name in the DB>'
         # I know it is uggly...
         test_match_matrix = {'healthcheck': 'healthcheck',
-                             'vping_ssh': 'vPing',
-                             'vping_userdata': 'vPing_userdata',
-                             'odl': 'ODL',
-                             'onos': 'ONOS',
-                             'ovno': 'ovno',
-                             'tempest_smoke_serial': 'Tempest',
+                             'vping_ssh': 'vping_ssh',
+                             'vping_userdata': 'vping_userdata',
+                             'odl': 'odl',
+                             'onos': 'onos',
+                             'ocl': 'ocl',
+                             'tempest_smoke_serial': 'tempest_smoke_serial',
                              'tempest_full_parallel': 'tempest_full_parallel',
-                             'rally_sanity': 'Rally',
+                             'rally_sanity': 'rally_sanity',
                              'bgpvpn': 'bgpvpn',
                              'rally_full': 'rally_full',
-                             'vims': 'vIMS',
+                             'vims': 'vims',
                              'doctor': 'doctor-notification',
                              'promise': 'promise'
                              }
@@ -104,3 +104,25 @@ class TestCase(object):
             return test_match_matrix[self.name]
         except:
             return "unknown"
+
+    def getTestDisplayName(self):
+        # Correspondance name of the test case / name in the DB
+        test_match_matrix = {'healthcheck': 'healthcheck',
+                             'vping_ssh': 'vPing (ssh)',
+                             'vping_userdata': 'vPing (userdata)',
+                             'odl': 'ODL',
+                             'onos': 'ONOS',
+                             'ocl': 'OCL',
+                             'tempest_smoke_serial': 'Tempest (smoke)',
+                             'tempest_full_parallel': 'Tempest (full)',
+                             'rally_sanity': 'Rally (smoke)',
+                             'bgpvpn': 'bgpvpn',
+                             'rally_full': 'Rally (full)',
+                             'vims': 'vIMS',
+                             'doctor': 'Doctor',
+                             'promise': 'Promise'
+                             }
+        try:
+            return test_match_matrix[self.name]
+        except:
+            return "unknown"
index 42ab67b..b3e2380 100644 (file)
@@ -5,21 +5,43 @@
 # 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
+# 09/06/2016: change for migration after refactoring
+# 16/06/2016: Alignment of test name (JIRA: FUNCTEST-304)
 ##############################################################################
 collections_old2New = {
-    'pod': 'pods',
-    'test_projects': 'projects',
-    'test_testcases': 'testcases',
-    'test_results': 'results'
+    'pod': 'pods',
+    'test_projects': 'projects',
+    'test_testcases': 'testcases',
+    'test_results': 'results'
 }
 
 fields_old2New = {
-    'test_results': [({}, {'creation_date': 'start_date'})]
+    'test_results': [({}, {'creation_date': 'start_date'})]
 }
 
 docs_old2New = {
-    'test_results': [
-        ({'criteria': 'failed'}, {'criteria': 'FAILED'}),
-        ({'criteria': 'passed'}, {'criteria': 'PASS'})
+    # 'test_results': [
+    #    ({'criteria': 'failed'}, {'criteria': 'FAILED'}),
+    #    ({'criteria': 'passed'}, {'criteria': 'PASS'})
+    # ]
+    'testcases': [
+        ({'name': 'vPing'}, {'name': 'vping_ssh'}),
+        ({'name': 'Tempest'}, {'name': 'tempest_smoke_serial'}),
+        ({'name': 'Rally'}, {'name': 'rally_sanity'}),
+        ({'name': 'ODL'}, {'name': 'odl'}),
+        ({'name': 'vIMS'}, {'name': 'vims'}),
+        ({'name': 'ONOS'}, {'name': 'onos'}),
+        ({'name': 'vPing_userdata'}, {'name': 'vping_userdata'}),
+        ({'name': 'ovno'}, {'name': 'ocl'})
+    ],
+    'results': [
+        ({'case_name': 'vPing'}, {'case_name': 'vping_ssh'}),
+        ({'case_name': 'Tempest'}, {'case_name': 'tempest_smoke_serial'}),
+        ({'case_name': 'Rally'}, {'case_name': 'rally_sanity'}),
+        ({'case_name': 'ODL'}, {'case_name': 'odl'}),
+        ({'case_name': 'vIMS'}, {'case_name': 'vims'}),
+        ({'case_name': 'ONOS'}, {'case_name': 'onos'}),
+        ({'case_name': 'vPing_userdata'}, {'case_name': 'vping_userdata'}),
+        ({'case_name': 'ovno'}, {'case_name': 'ocl'})
     ]
 }
index c3e06cc..c45a0e6 100644 (file)
@@ -24,7 +24,7 @@ parser.add_argument('-i', '--input_dir',
 parser.add_argument('-d', '--db',
                     type=str,
                     required=False,
-                    default=None,
+                    default='test_results_collection',
                     help='database name after the restore.')
 
 
index beae959..8c36d30 100644 (file)
@@ -16,10 +16,13 @@ file_handler.setFormatter(logging.Formatter('%(asctime)s %(levelname)s: %(messag
 logger.addHandler(file_handler)
 
 
-def _get_dicts_from_list(dict_list, keys):
+def _get_dicts_from_list(testcase, dict_list, keys):
     dicts = []
     for dictionary in dict_list:
         # iterate over dictionaries in input list
+        if not isinstance(dictionary, dict):
+            logger.info("Skipping non-dict details testcase [{}]".format(testcase))
+            continue
         if keys == set(dictionary.keys()):
             # check the dictionary structure
             dicts.append(dictionary)
@@ -45,9 +48,16 @@ def _get_results_from_list_of_dicts(list_of_dict_statuses, dict_indexes, expecte
     return test_results
 
 
+def _convert_value(value):
+    return value if value != '' else 0
+
+
 def _convert_duration(duration):
     if (isinstance(duration, str) or isinstance(duration, unicode)) and ':' in duration:
         hours, minutes, seconds = duration.split(":")
+        hours = _convert_value(hours)
+        minutes = _convert_value(minutes)
+        seconds = _convert_value(seconds)
         int_duration = 3600 * int(hours) + 60 * int(minutes) + float(seconds)
     else:
         int_duration = duration
@@ -86,7 +96,7 @@ def modify_functest_vims(testcase):
         -> details.orchestrator.duration
     """
     testcase_details = testcase['details']
-    sig_test_results = _get_dicts_from_list(testcase_details['sig_test']['result'],
+    sig_test_results = _get_dicts_from_list(testcase, testcase_details['sig_test']['result'],
                                             {'duration', 'result', 'name', 'error'})
     if len(sig_test_results) < 1:
         logger.info("No 'result' from 'sig_test' found in vIMS details, skipping")
@@ -134,10 +144,10 @@ def modify_functest_onos(testcase):
     testcase_details = testcase['details']
 
     funcvirnet_details = testcase_details['FUNCvirNet']['status']
-    funcvirnet_statuses = _get_dicts_from_list(funcvirnet_details, {'Case result', 'Case name:'})
+    funcvirnet_statuses = _get_dicts_from_list(testcase, funcvirnet_details, {'Case result', 'Case name:'})
 
     funcvirnetl3_details = testcase_details['FUNCvirNetL3']['status']
-    funcvirnetl3_statuses = _get_dicts_from_list(funcvirnetl3_details, {'Case result', 'Case name:'})
+    funcvirnetl3_statuses = _get_dicts_from_list(testcase, funcvirnetl3_details, {'Case result', 'Case name:'})
 
     if len(funcvirnet_statuses) < 0:
         logger.info("No results found in 'FUNCvirNet' part of ONOS results")
@@ -186,7 +196,7 @@ def modify_functest_rally(testcase):
         -> details.tests
         -> details.success_percentage
     """
-    summaries = _get_dicts_from_list(testcase['details'], {'summary'})
+    summaries = _get_dicts_from_list(testcase, testcase['details'], {'summary'})
 
     if len(summaries) != 1:
         logger.info("Found zero or more than one 'summaries' in Rally details, skipping")
@@ -211,7 +221,8 @@ def modify_functest_odl(testcase):
         -> details.failures
         -> details.success_percentage?
     """
-    test_statuses = _get_dicts_from_list(testcase['details']['details'], {'test_status', 'test_doc', 'test_name'})
+    test_statuses = _get_dicts_from_list(testcase, testcase['details']['details'],
+                                         {'test_status', 'test_doc', 'test_name'})
     if len(test_statuses) < 1:
         logger.info("No 'test_status' found in ODL details, skipping")
         return False
@@ -360,7 +371,7 @@ def publish_mongo_data(output_destination):
             for mongo_json_line in fobj:
                 test_result = json.loads(mongo_json_line)
                 if modify_mongo_entry(test_result):
-                    shared_utils.publish_json(test_result, output_destination, es_user, es_passwd)
+                    shared_utils.publish_json(test_result, es_user, es_passwd, output_destination)
     finally:
         if os.path.exists(tmp_filename):
             os.remove(tmp_filename)