Add "docker tag" option for each testcase containers. 41/24141/4
authorTomofumi Hayashi <tohayash@redhat.com>
Thu, 10 Nov 2016 05:49:46 +0000 (14:49 +0900)
committerTomofumi Hayashi <tohayash@redhat.com>
Thu, 10 Nov 2016 08:40:08 +0000 (17:40 +0900)
JIRA: DOVETAIL-69

This commit is to add new option to specify docker tags for
each test containers, such as '--TAG "functest:stable"'.

Change-Id: Ica11e16abfb21649a3eea9c7d7d5cd31502d2e21
Signed-off-by: Tomofumi Hayashi <tohayash@redhat.com>
dovetail/conf/cmd_config.yml
dovetail/run.py

index 63d51ed..4099456 100644 (file)
@@ -43,3 +43,8 @@ cli:
           - '-s'
         default: 'basic'
         help: 'certification scenario.'
+      tag:
+        flags:
+          - '--tag'
+          - '-o'
+        help: 'Overwrite tags for each docker container (e.g. "functest:stable,yardstick:latest")'
index 310ef2a..1306a5a 100755 (executable)
@@ -9,6 +9,7 @@
 
 
 import click
+import sys
 
 import utils.dovetail_logger as dt_logger
 
@@ -29,6 +30,14 @@ def load_scenario(scenario):
     return Scenario.get(SCENARIO_NAMING_FMT % scenario)
 
 
+def set_container_tags(option_str):
+    for script_tag_opt in option_str.split(','):
+        option_str = script_tag_opt.split(':')
+        script_type = option_str[0].strip()
+        script_tag = option_str[1].strip()
+        dovetail_config[script_type]['docker_tag'] = script_tag
+
+
 def load_testcase():
     Testcase.load()
 
@@ -75,6 +84,16 @@ def run_test(scenario):
         Report.check_result(testcase, db_result)
 
 
+def validate_options(input_dict):
+    # for 'tag' option
+    for key, value in input_dict.items():
+        if key == 'tag':
+            for tag in value.split(','):
+                if len(tag.split(':')) != 2:
+                    logger.error('TAGS option must be "<image>:<tag>,..."')
+                    sys.exit(1)
+
+
 def filter_env_options(input_dict):
     envs_options = {}
     for key, value in input_dict.items():
@@ -89,6 +108,7 @@ def main(*args, **kwargs):
     logger.info('=======================================')
     logger.info('Dovetail certification: %s!' % (kwargs['scenario']))
     logger.info('=======================================')
+    validate_options(kwargs)
     envs_options = filter_env_options(kwargs)
     update_envs(envs_options)
     logger.info('Your new envs for functest: %s' %
@@ -97,6 +117,8 @@ def main(*args, **kwargs):
                 dovetail_config['yardstick']['envs'])
     load_testcase()
     scenario_yaml = load_scenario(kwargs['scenario'])
+    if 'tag' in kwargs:
+        set_container_tags(kwargs['tag'])
     run_test(scenario_yaml)
     Report.generate(scenario_yaml)