bugfix: copy hosts file
[bottlenecks.git] / testsuites / run_testsuite.py
index 7ec67ef..0f03d3e 100644 (file)
@@ -36,6 +36,15 @@ LOG = log.Logger(__name__).getLogger()
 # ------------------------------------------------------
 
 
+def copy_hosts_file():
+    LOG.info("Begin copying hosts file to Bottlenecks-Yardstick")
+    os.system('cp /etc/hosts /tmp/hosts')
+    yardstick_docker = docker_env.docker_find('Bottlenecks-Yardstick')
+    cp_cmd = 'sudo cp -f /tmp/hosts /etc/hosts'
+    docker_env.docker_exec_cmd(yardstick_docker, cp_cmd)
+    LOG.info("Done with copying hosts file to Bottlenecks-Yardstick")
+
+
 def posca_testcase_run(testsuite, testcase_script, test_config):
 
     module_string = "testsuites.%s.testcase_script.%s" % (testsuite,
@@ -52,7 +61,7 @@ def report(testcase, start_date, stop_date, criteria, details_doc):
         "description": ("test results for " + testcase),
         "pod_name": os.environ.get('NODE_NAME', 'unknown'),
         "installer": os.environ.get('INSTALLER_TYPE', 'unknown'),
-        "version": os.environ.get('BRANCH', 'unknown'),
+        "version": os.path.basename(os.environ.get('BRANCH', 'unknown')),
         "build_tag": os.environ.get('BUILD_TAG', 'unknown'),
         "stop_date": str(stop_date),
         "start_date": str(start_date),
@@ -60,10 +69,11 @@ def report(testcase, start_date, stop_date, criteria, details_doc):
         "scenario": os.environ.get('DEPLOY_SCENARIO', 'unknown')
     }
     results['details'] = {"test_results": details_doc}
-
-    target = "http://testresults.opnfv.org/test/api/v1/results"
+    target = os.environ.get(
+        'BOTTLENECKS_DB_TARGET',
+        'http://testresults.opnfv.org/test/api/v1/results')
+    print ('Address of the target DB is: %s.' % target)
     timeout = 5
-
     try:
         LOG.debug('Test result : %s', jsonutils.dump_as_bytes(results))
         res = requests.post(target,
@@ -77,6 +87,7 @@ def report(testcase, start_date, stop_date, criteria, details_doc):
 
 
 def docker_env_prepare(config):
+    LOG.info("Begin to prepare docker environment")
     if 'contexts' in config.keys() and config["contexts"] is not None:
         context_config = config["contexts"]
         if 'yardstick' in context_config.keys() and \
@@ -89,6 +100,7 @@ def docker_env_prepare(config):
             conf_parser.Parser.convert_docker_env(config, "dashboard")
             LOG.debug('Waiting for ELK init')
             time.sleep(15)
+    LOG.info("Docker environment have prepared")
     return
 
 
@@ -104,11 +116,17 @@ def testsuite_run(test_level, test_name, REPORT="False"):
             conf_parser.Parser.testcase_out_dir(testcase)
         start_date = datetime.datetime.now()
         docker_env_prepare(config[testcase])
+        copy_hosts_file()
+        #try:
+        #    posca_testcase_run(tester_parser[0], testcase, config[testcase])
+        #except Exception, e:
+        #    LOG.warning('e.message:\t%s', e.message)
         posca_testcase_run(tester_parser[0], testcase, config[testcase])
         stop_date = datetime.datetime.now()
         LOG.info("End of %s testcase in POSCA testsuite", testcase)
         criteria = "FAIL"
         if REPORT == "True":
+            print ('Testing results are about to be sent to the target DB.')
             details_doc = []
             if os.path.exists(config[testcase]['out_file']):
                 with open(config[testcase]['out_file']) as details_result:
@@ -116,6 +134,8 @@ def testsuite_run(test_level, test_name, REPORT="False"):
                     if len(details_doc):
                         criteria = "PASS"
             report(testcase, start_date, stop_date, criteria, details_doc)
+        else:
+            print ('Testing results have not been sent to the target DB.')
 
 
 def main():