Move copyfile to container and remove hard-code 51/22151/2
authorxudan2189 <xudanstudy@gmail.com>
Wed, 21 Sep 2016 08:40:44 +0000 (04:40 -0400)
committerxudan <xudan16@huawei.com>
Fri, 23 Sep 2016 07:25:07 +0000 (03:25 -0400)
JIRA: DOVETAIL-17

Change-Id: Id4ad126169cf83c6c72a7b599f3309f0f930e461
Signed-off-by: xudan <xudan16@huawei.com>
scripts/conf/dovetail_config.py
scripts/conf/yardstick_config.yml
scripts/container.py
scripts/run.py

index 8d60cd9..92d1f47 100644 (file)
@@ -26,7 +26,3 @@ container_config = {}
 
 container_config['functest'] = dovetail_config['functest']
 container_config['yardstick'] = dovetail_config['yardstick']
-
-container_config['functest']['has_pull'] = False
-container_config['yardstick']['has_pull'] = False
-container_config['yardstick']['has_build_images'] = False
index 5c04a28..9eda6e5 100644 (file)
@@ -9,9 +9,12 @@ yardstick:
   result_dir: '/tmp/yardstick/result'
   shell_dir: '/tmp/yardstick'
   shell_dir_name: 'prepare_test_yard'
+  testcase:
+    build_test_cmd: '/tmp/yardstick/build_run_test.sh %s.yaml /tmp/yardstick/result/%s.out'
+    test_cmd: '/tmp/yardstick/run_test.sh %s.yaml /tmp/yardstick/result/%s.out'
   result:
     dir: '/tmp/yardstick/result'
     store_type: 'file'
     db_url: 'http://testresults.opnfv.org/test/api/v1/results?case=%s&last=1'
-    file_path: '/tmp/yardstick/result/yardstick.log'
+    file_path: '/home/opnfv/dovetail/results/yardstick.log'
 
index 4bbc5e5..678a092 100644 (file)
@@ -16,6 +16,8 @@ logger = dt_logger.Logger('container.py').getLogger()
 class Container:
 
     container_list = {}
+    has_pull_latest_image = {'yardstick':False, 'functest':False}
+    has_build_images = {'yardstick':False, 'functest':False}
 
     def __init__(cls):
         pass
@@ -48,12 +50,12 @@ class Container:
     @classmethod
     def pull_image(cls, type):
         docker_image = cls.get_docker_image(type)
-        if container_config[type]['has_pull'] == True:
+        if cls.has_pull_latest_image[type] == True:
             logger.debug('%s is already the newest version.' % (docker_image))
         else:
             cmd = 'sudo docker pull %s' % (docker_image)
             dt_utils.exec_cmd(cmd,logger)
-            container_config[type]['has_pull'] = True
+            cls.has_pull_latest_image[type] = True
 
     @classmethod
     def clean(cls, container_id):
@@ -67,4 +69,9 @@ class Container:
         cmd = 'sudo docker exec %s %s' % (container_id, sub_cmd)
         dt_utils.exec_cmd(cmd,logger,exit_on_error)
 
-
+    @classmethod
+    def copy_file(cls, file_dir, container_id, container_dir):
+        for root, dirs, files in os.walk(file_dir):
+            for file_name in files:
+                cmd = 'sudo docker cp %s %s:%s' % (os.path.join(file_dir,file_name), container_id, container_dir)
+                dt_utils.exec_cmd(cmd, logger, exit_on_error = False)
index a8ef819..9b59f76 100755 (executable)
@@ -29,12 +29,6 @@ def load_scenario(scenario):
 def load_testcase():
     Testcase.load()
 
-def copy_file(file_dir, container_id, container_dir):
-    for root, dirs, files in os.walk(file_dir):
-        for file_name in files:
-            cmd = 'sudo docker cp %s %s:%s' % (os.path.join(file_dir,file_name), container_id, container_dir)
-            dt_utils.exec_cmd(cmd, logger, exit_on_error = False)
-
 def run_functest(testcase, container_id):
     sub_cmd = dovetail_config[testcase.script_type()]['testcase']['pre_cmd']
     Container.exec_cmd(container_id, sub_cmd)
@@ -42,18 +36,15 @@ def run_functest(testcase, container_id):
     Container.exec_cmd(container_id, sub_cmd)
 
 def run_yardstick(testcase, container_id):
-    copy_file(os.path.join(os.getcwd(),container_config[testcase.script_type()]['shell_dir_name']),\
-        container_id,container_config[testcase.script_type()]['shell_dir'])
-    if container_config[testcase.script_type()]['has_build_images'] == True:
-        cmd = 'sudo docker exec %s %s/run_test.sh %s.yaml %s/%s.out' \
-            % (container_id, container_config[testcase.script_type()]['shell_dir'], testcase.script_testcase(),\
-              container_config[testcase.script_type()]['result_dir'], testcase.name())
+    type = testcase.script_type()
+    Container.copy_file(os.path.join(os.getcwd(), dovetail_config[type]['shell_dir_name']),\
+                        container_id, dovetail_config[type]['shell_dir'])
+    if Container.has_build_images[type] == True:
+        sub_cmd = dovetail_config[type]['testcase']['test_cmd'] % (testcase.script_testcase(), testcase.name())
     else:
-        container_config[testcase.script_type()]['has_build_images'] = True
-        cmd = 'sudo docker exec %s %s/build_run_test.sh %s.yaml %s/%s.out' \
-            % (container_id, container_config[testcase.script_type()]['shell_dir'], testcase.script_testcase(),\
-              container_config[testcase.script_type()]['result_dir'], testcase.name())
-    dt_utils.exec_cmd(cmd,logger,exit_on_error = False)
+        Container.has_build_images[type] = True
+        sub_cmd = dovetail_config[type]['testcase']['build_test_cmd'] % (testcase.script_testcase(), testcase.name())
+    Container.exec_cmd(container_id, sub_cmd)
     time.sleep(5)
 
 def run_test(scenario):