summaryrefslogtreecommitdiffstats
path: root/dovetail/container.py
diff options
context:
space:
mode:
authorxudan <xudan16@huawei.com>2017-03-22 07:51:37 +0000
committerxudan <xudan16@huawei.com>2017-03-25 08:59:53 +0000
commit223806ad2a5d60c9909f32f35b8cea16bf703a69 (patch)
treedfcd9c27f2876c3b185a5afb2266ca78e0e155d8 /dovetail/container.py
parent02d44a030687100d0ebf68d1645536536d42cbb9 (diff)
dovetail tool: Add an option cmd for pushing results into DB
JIRA: DOVETAIL-373 1. add an option --report/-r to choose the report type. 2. "-r file" will store results with files. 3. "-r http://192.168.135.2:8000/api/v1" will push results into DB. The DB url can replaced by user's local DB or official DB. 4. Default report type is defined as "report_dest" in dovetail_config.yml. 5. Yardstick can't push results of one testcase into DB now, so both "-r file" and "-r http://..." will be regarded as "file". Change-Id: Ieaa017ab59c5b15235bf306ef57cdc56beb22af8 Signed-off-by: xudan <xudan16@huawei.com>
Diffstat (limited to 'dovetail/container.py')
-rw-r--r--dovetail/container.py88
1 files changed, 63 insertions, 25 deletions
diff --git a/dovetail/container.py b/dovetail/container.py
index 6d5a8d4f..bfdbeb94 100644
--- a/dovetail/container.py
+++ b/dovetail/container.py
@@ -40,50 +40,88 @@ class Container(object):
return '%s:%s' % (dt_cfg.dovetail_config[type]['image_name'],
dt_cfg.dovetail_config[type]['docker_tag'])
+ # get the openrc_volume for creating the container
@classmethod
- def create(cls, type):
- sshkey = "-v /root/.ssh/id_rsa:/root/.ssh/id_rsa "
+ def openrc_volume(cls, type):
dovetail_config = dt_cfg.dovetail_config
- docker_image = cls.get_docker_image(type)
- opts = dovetail_config[type]['opts']
-
- # credentials file openrc.sh is neccessary
dovetail_config['openrc'] = os.path.abspath(dovetail_config['openrc'])
if os.path.isfile(dovetail_config['openrc']):
openrc = ' -v %s:%s ' % (dovetail_config['openrc'],
dovetail_config[type]['openrc'])
+ return openrc
else:
cls.logger.error("File %s is not exist", dovetail_config['openrc'])
return None
+ # set functest envs and TEST_DB_URL for creating functest container
+ @staticmethod
+ def set_functest_config():
+
+ # These are all just used by Functest's function push_results_to_db.
+ # And has nothing to do with DoveTail running test cases.
+ ins_type = " -e INSTALLER_TYPE=vendor-specific"
+ scenario = " -e DEPLOY_SCENARIO=default"
+ node = " -e NODE_NAME=master"
+ tag = " -e BUILD_TAG=daily-master-001"
+ envs = "%s %s %s %s" % (ins_type, scenario, node, tag)
+
+ dovetail_config = dt_cfg.dovetail_config
+ if dovetail_config['report_dest'].startswith("http"):
+ report = " -e TEST_DB_URL=%s " % dovetail_config['report_dest']
+ if dovetail_config['report_dest'] == "file":
+ file_path = dovetail_config["functest"]['result']['dir']
+ file_path = file_path[0:file_path.rfind('/results')]
+ report = " -e TEST_DB_URL=file://%s " % file_path
+ return "%s %s" % (envs, report)
+
+ # set yardstick external network name and log volume for its container.
+ # external network is necessary for yardstick.
+ @classmethod
+ def set_yardstick_config(cls):
+ dovetail_config = dt_cfg.dovetail_config
+ ext_net = dt_utils.get_ext_net_name(dovetail_config['openrc'],
+ cls.logger)
+ if ext_net:
+ envs = "%s%s" % (" -e EXTERNAL_NETWORK=", ext_net)
+ else:
+ cls.logger.error("Can't find any external network.")
+ return None
+
+ if dovetail_config['report_dest'].startswith("http"):
+ cls.logger.info("Yardstick can't push results to DB.")
+ cls.logger.info("Results will be stored with files.")
+
+ log_vol = '-v %s:%s ' % (dovetail_config['result_dir'],
+ dovetail_config["yardstick"]['result']['log'])
+ return "%s %s" % (envs, log_vol)
+
+ @classmethod
+ def create(cls, type):
+ sshkey = "-v /root/.ssh/id_rsa:/root/.ssh/id_rsa "
+ dovetail_config = dt_cfg.dovetail_config
+ docker_image = cls.get_docker_image(type)
+ opts = dovetail_config[type]['opts']
+
+ # credentials file openrc.sh is neccessary
+ openrc = cls.openrc_volume(type)
+ if not openrc:
+ return None
+
# This is used for showing the debug logs of the upstream projects
envs = ' -e CI_DEBUG=true'
- # These are all just used by Functest's function push_results_to_db
+ config = ""
if type.lower() == "functest":
- ins_type = " -e INSTALLER_TYPE=vendor-specific"
- scenario = " -e DEPLOY_SCENARIO=default"
- node = " -e NODE_NAME=default"
- tag = " -e BUILD_TAG=daily-master-001"
-
- envs = "%s %s %s %s %s" % (envs, ins_type, scenario, node, tag)
-
+ config = cls.set_functest_config()
if type.lower() == "yardstick":
- ext_net = dt_utils.get_ext_net_name(dovetail_config['openrc'],
- cls.logger)
- if ext_net:
- envs = "%s%s%s" % (envs, " -e EXTERNAL_NETWORK=", ext_net)
- else:
- cls.logger.error("Can't find any external network.")
- return None
+ config = cls.set_yardstick_config()
+ if not config:
+ return None
result_volume = ' -v %s:%s ' % (dovetail_config['result_dir'],
dovetail_config[type]['result']['dir'])
- log_volume = ' -v %s:%s ' % (dovetail_config['result_dir'],
- dovetail_config[type]['result']['log'])
cmd = 'sudo docker run %s %s %s %s %s %s %s /bin/bash' % \
- (opts, envs, sshkey, openrc, result_volume,
- log_volume, docker_image)
+ (opts, envs, config, sshkey, openrc, result_volume, docker_image)
dt_utils.exec_cmd(cmd, cls.logger)
ret, container_id = \
dt_utils.exec_cmd("sudo docker ps | grep " + docker_image +