summaryrefslogtreecommitdiffstats
path: root/dovetail
diff options
context:
space:
mode:
authorxudan <xudan16@huawei.com>2018-12-20 01:49:22 -0500
committerxudan <xudan16@huawei.com>2018-12-20 21:57:03 -0500
commit78b0062ce9dc4d23b967112a0896f12cc6526e1c (patch)
tree9709b51d30bf87a1b2458f118d90cd1b2610e53c /dovetail
parent8ab783f403984b3ef9a6c3010a9a81c0f29c4236 (diff)
Simplify project conf files
1. use copy commands instead of pre_copy 2. remove redundant items in project conf files 3. make the volume mapping clearer Change-Id: I6c6aa58fac65d7e40105e0a54f6544ee5c47db31 Signed-off-by: xudan <xudan16@huawei.com>
Diffstat (limited to 'dovetail')
-rwxr-xr-xdovetail/run.py10
-rw-r--r--dovetail/test_runner.py29
-rw-r--r--dovetail/testcase.py24
-rw-r--r--dovetail/tests/unit/test_run.py11
-rw-r--r--dovetail/tests/unit/test_test_runner.py120
-rw-r--r--dovetail/tests/unit/test_testcase.py21
6 files changed, 35 insertions, 180 deletions
diff --git a/dovetail/run.py b/dovetail/run.py
index 6d2bcf6..1579ff6 100755
--- a/dovetail/run.py
+++ b/dovetail/run.py
@@ -149,14 +149,16 @@ def get_result_path():
'pre_config')
dt_cfg.dovetail_config['patch_dir'] = os.path.join(dovetail_home,
'patches')
+ dt_cfg.dovetail_config['userconfig_dir'] = os.path.join(dovetail_home,
+ 'userconfig')
return dovetail_home
def copy_userconfig_files(logger):
- pre_config_path = dt_cfg.dovetail_config['config_dir']
- if not os.path.isdir(pre_config_path):
- os.makedirs(pre_config_path)
- cmd = 'sudo cp -r %s/* %s' % (constants.USERCONF_PATH, pre_config_path)
+ userconfig_path = dt_cfg.dovetail_config['userconfig_dir']
+ if not os.path.isdir(userconfig_path):
+ os.makedirs(userconfig_path)
+ cmd = 'sudo cp -r %s/* %s' % (constants.USERCONF_PATH, userconfig_path)
dt_utils.exec_cmd(cmd, logger, exit_on_error=False)
diff --git a/dovetail/test_runner.py b/dovetail/test_runner.py
index 884ce1a..2fa1eee 100644
--- a/dovetail/test_runner.py
+++ b/dovetail/test_runner.py
@@ -63,26 +63,6 @@ class DockerRunner(Runner):
def create_log(cls):
cls.logger = dt_logger.Logger(__name__ + '.DockerRunner').getLogger()
- def pre_copy(self, container=None, dest_path=None,
- src_file=None, exist_file=None):
- if not container:
- self.logger.error("Container instance is None.")
- return None
- if not dest_path:
- self.logger.error("There has no dest_path in {} config file."
- .format(self.testcase.name()))
- return None
- if src_file:
- self.testcase.mk_src_file()
- file_path = dt_cfg.dovetail_config[self.type]['result']['dir']
- src_path = os.path.join(file_path, src_file)
- if exist_file:
- file_path = dt_cfg.dovetail_config[self.type]['config']['dir']
- src_path = os.path.join(file_path, 'pre_config', exist_file)
-
- container.copy_file(src_path, dest_path)
- return dest_path
-
def run(self):
container = Container(self.testcase)
docker_image = container.get_docker_image()
@@ -104,14 +84,7 @@ class DockerRunner(Runner):
self.logger.debug('container id: {}'.format(container_id))
- dest_path = self.testcase.pre_copy_path('dest_path')
- src_file_name = self.testcase.pre_copy_path('src_file')
- exist_file_name = self.testcase.pre_copy_path('exist_src_file')
-
- if src_file_name or exist_file_name:
- if not self.pre_copy(container, dest_path, src_file_name,
- exist_file_name):
- return
+ self.testcase.mk_src_file()
cmds = self.testcase.pre_condition()
if cmds:
diff --git a/dovetail/testcase.py b/dovetail/testcase.py
index b79bcfa..74fbbea 100644
--- a/dovetail/testcase.py
+++ b/dovetail/testcase.py
@@ -136,21 +136,20 @@ class Testcase(object):
return post_condition
def mk_src_file(self):
- testcase_src_file = self.pre_copy_path('src_file')
- try:
- file_path = os.path.join(dt_cfg.dovetail_config['result_dir'],
- testcase_src_file)
- with open(file_path, 'w+') as src_file:
- if self.sub_testcase() is not None:
+ test_list = os.path.join(dt_cfg.dovetail_config['result_dir'],
+ 'tempest_custom.txt')
+ if self.sub_testcase() is not None:
+ try:
+ with open(test_list, 'w+') as src_file:
for sub_test in self.sub_testcase():
self.logger.debug(
'Save test cases {}'.format(sub_test))
src_file.write(sub_test + '\n')
- self.logger.debug('Save test cases to {}'.format(file_path))
- return file_path
- except Exception:
- self.logger.exception('Failed to save: {}'.format(file_path))
- return None
+ self.logger.debug('Save test cases to {}'.format(test_list))
+ return test_list
+ except Exception:
+ self.logger.exception('Failed to save: {}'.format(test_list))
+ return None
def run(self):
runner = TestRunnerFactory.create(self)
@@ -294,8 +293,7 @@ class FunctestTestcase(Testcase):
# patch inside the functest container
if dt_cfg.dovetail_config['no_api_validation']:
patch_cmd = os.path.join(
- dt_cfg.dovetail_config['functest']['config']['dir'],
- 'patches',
+ dt_cfg.dovetail_config['functest']['patches_dir'],
'functest',
'disable-api-validation',
'apply.sh')
diff --git a/dovetail/tests/unit/test_run.py b/dovetail/tests/unit/test_run.py
index c7fe4d6..fed198c 100644
--- a/dovetail/tests/unit/test_run.py
+++ b/dovetail/tests/unit/test_run.py
@@ -259,7 +259,8 @@ class RunTesting(unittest.TestCase):
dovetail_home = 'dovetail_home'
mock_os.environ = {'DOVETAIL_HOME': dovetail_home}
mock_os.path.join.side_effect = [
- 'result_path', 'images_dir', 'pre_config_path', 'patch_set_path']
+ 'result_path', 'images_dir', 'pre_config_path', 'patch_set_path',
+ 'userconfig_dir']
mock_config.dovetail_config = {}
result = dt_run.get_result_path()
@@ -268,12 +269,14 @@ class RunTesting(unittest.TestCase):
call(dovetail_home, 'results'),
call(dovetail_home, 'images'),
call(dovetail_home, 'pre_config'),
- call(dovetail_home, 'patches')])
+ call(dovetail_home, 'patches'),
+ call(dovetail_home, 'userconfig')])
expected_dict = {
'result_dir': 'result_path',
'images_dir': 'images_dir',
'config_dir': 'pre_config_path',
- 'patch_dir': 'patch_set_path'}
+ 'patch_dir': 'patch_set_path',
+ 'userconfig_dir': 'userconfig_dir'}
self.assertEquals(expected_dict, mock_config.dovetail_config)
self.assertEquals(dovetail_home, result)
@@ -291,7 +294,7 @@ class RunTesting(unittest.TestCase):
@patch('dovetail.run.os')
def test_copy_userconfig_files(self, mock_os, mock_utils, mock_config,
mock_constants):
- mock_config.dovetail_config = {'config_dir': 'value'}
+ mock_config.dovetail_config = {'userconfig_dir': 'value'}
mock_os.path.isdir.return_value = False
mock_constants.USERCONF_PATH = 'value'
logger = Mock()
diff --git a/dovetail/tests/unit/test_test_runner.py b/dovetail/tests/unit/test_test_runner.py
index 08dbde6..2570ec7 100644
--- a/dovetail/tests/unit/test_test_runner.py
+++ b/dovetail/tests/unit/test_test_runner.py
@@ -43,65 +43,6 @@ class TestRunnerTesting(unittest.TestCase):
@patch('dovetail.test_runner.dt_utils')
@patch('dovetail.test_runner.dt_cfg')
- def test_pre_copy_no_container(self, mock_config, mock_utils):
- t_runner.FunctestRunner.create_log()
- mock_config.dovetail_config = {'result_dir': 'result_dir'}
- docker_runner = t_runner.FunctestRunner(self.testcase)
-
- result = docker_runner.pre_copy(
- container=None, dest_path=None,
- src_file=None, exist_file=None)
-
- docker_runner.logger.error.assert_called_once_with(
- 'Container instance is None.')
- self.assertEquals(None, result)
-
- @patch('dovetail.test_runner.dt_utils')
- @patch('dovetail.test_runner.dt_cfg')
- def test_pre_copy_no_dest_path(self, mock_config, mock_utils):
- t_runner.FunctestRunner.create_log()
- mock_config.dovetail_config = {'result_dir': 'result_dir'}
- docker_runner = t_runner.FunctestRunner(self.testcase)
-
- result = docker_runner.pre_copy(
- container='container', dest_path=None,
- src_file=None, exist_file=None)
-
- docker_runner.logger.error.assert_called_once_with(
- 'There has no dest_path in {} config file.'.format(
- self.testcase_name))
- self.assertEquals(None, result)
-
- @patch('dovetail.test_runner.dt_cfg')
- @patch('dovetail.test_runner.os.path')
- def test_pre_copy(self, mock_path, mock_config):
- t_runner.FunctestRunner.create_log()
- docker_runner = t_runner.FunctestRunner(self.testcase)
- mock_config.dovetail_config = {
- 'functest': {
- 'result': {
- 'dir': 'result_dir'
- },
- 'config': {
- 'dir': 'config_dir'
- }
- }
- }
- container_obj = Mock()
- mock_path.join.return_value = 'join'
-
- result = docker_runner.pre_copy(
- container=container_obj, dest_path='dest_path',
- src_file='src_file', exist_file='exist_file')
-
- mock_path.join.assert_has_calls([
- call('result_dir', 'src_file'),
- call('config_dir', 'pre_config', 'exist_file')])
- container_obj.copy_file.assert_called_once_with('join', 'dest_path')
- self.assertEquals('dest_path', result)
-
- @patch('dovetail.test_runner.dt_utils')
- @patch('dovetail.test_runner.dt_cfg')
@patch('dovetail.test_runner.Container')
def test_run_offline_not_exist(self, mock_container, mock_config,
mock_utils):
@@ -178,50 +119,10 @@ class TestRunnerTesting(unittest.TestCase):
docker_runner.logger.error.assert_called_once_with(
'Failed to create container.')
- @patch('dovetail.test_runner.dt_cfg')
- @patch('dovetail.test_runner.Container')
- @patch.object(t_runner.DockerRunner, 'pre_copy')
- def test_run__not_offline_src_file_no_precopy(self, mock_precopy,
- mock_container, mock_config):
- t_runner.VnftestRunner.create_log()
- docker_runner = t_runner.VnftestRunner(self.testcase)
- mock_config.dovetail_config = {
- 'offline': False
- }
- container_obj = Mock()
- docker_img_obj = Mock()
- container_obj.get_docker_image.return_value = docker_img_obj
- container_obj.pull_image.return_value = True
- container_id = '12345'
- container_obj.create.return_value = container_id
- mock_container.return_value = container_obj
- dest_path = 'dest_path'
- src_file_name = 'src_file'
- exist_file_name = 'exist_src_file'
- self.testcase.pre_copy_path.side_effect = [
- dest_path, src_file_name, exist_file_name]
- mock_precopy.return_value = False
-
- docker_runner.run()
-
- mock_container.assert_called_once_with(self.testcase)
- container_obj.get_docker_image.assert_called_once_with()
- container_obj.pull_image.assert_called_once_with(docker_img_obj)
- container_obj.create.assert_called_once_with(docker_img_obj)
- docker_runner.logger.debug.assert_called_with(
- 'container id: {}'.format(container_id))
- self.testcase.pre_copy_path.assert_has_calls([
- call(dest_path),
- call(src_file_name),
- call(exist_file_name)])
- mock_precopy.assert_called_once_with(
- container_obj, dest_path, src_file_name, exist_file_name)
-
@patch('dovetail.test_runner.dt_utils')
@patch('dovetail.test_runner.dt_cfg')
@patch('dovetail.test_runner.Container')
- @patch.object(t_runner.DockerRunner, 'pre_copy')
- def test_run__not_offline_no_prepare(self, mock_precopy, mock_container,
+ def test_run__not_offline_no_prepare(self, mock_container,
mock_config, mock_utils):
t_runner.FunctestRunner.create_log()
mock_config.dovetail_config = {
@@ -238,12 +139,10 @@ class TestRunnerTesting(unittest.TestCase):
container_id = '12345'
container_obj.create.return_value = container_id
mock_container.return_value = container_obj
- self.testcase.pre_copy_path.return_value = None
self.testcase.pre_condition.return_value = ['cmd']
self.testcase.prepare_cmd.return_value = False
self.testcase.post_condition.return_value = ['cmd']
container_obj.exec_cmd.return_value = (1, 'error')
- mock_precopy.return_value = False
docker_runner.run()
@@ -253,10 +152,6 @@ class TestRunnerTesting(unittest.TestCase):
container_obj.create.assert_called_once_with(docker_img_obj)
docker_runner.logger.debug.assert_called_with(
'container id: {}'.format(container_id))
- self.testcase.pre_copy_path.assert_has_calls([
- call('dest_path'),
- call('src_file'),
- call('exist_src_file')])
self.testcase.pre_condition.assert_called_once_with()
container_obj.exec_cmd.assert_has_calls([
call('cmd'), call('cmd')])
@@ -271,8 +166,7 @@ class TestRunnerTesting(unittest.TestCase):
@patch('dovetail.test_runner.dt_utils')
@patch('dovetail.test_runner.dt_cfg')
@patch('dovetail.test_runner.Container')
- @patch.object(t_runner.DockerRunner, 'pre_copy')
- def test_run__not_offline_prepare(self, mock_precopy, mock_container,
+ def test_run__not_offline_prepare(self, mock_container,
mock_config, mock_utils):
t_runner.FunctestRunner.create_log()
mock_config.dovetail_config = {
@@ -288,13 +182,11 @@ class TestRunnerTesting(unittest.TestCase):
container_id = '12345'
container_obj.create.return_value = container_id
mock_container.return_value = container_obj
- self.testcase.pre_copy_path.return_value = None
self.testcase.pre_condition.return_value = ['cmd']
self.testcase.prepare_cmd.return_value = True
self.testcase.post_condition.return_value = ['cmd']
self.testcase.cmds = ['cmd']
container_obj.exec_cmd.return_value = (1, 'error')
- mock_precopy.return_value = False
docker_runner.run()
@@ -304,10 +196,6 @@ class TestRunnerTesting(unittest.TestCase):
container_obj.create.assert_called_once_with(docker_img_obj)
docker_runner.logger.debug.assert_called_with(
'container id: {}'.format(container_id))
- self.testcase.pre_copy_path.assert_has_calls([
- call('dest_path'),
- call('src_file'),
- call('exist_src_file')])
self.testcase.pre_condition.assert_called_once_with()
container_obj.exec_cmd.assert_has_calls([
call('cmd'), call('cmd'), call('cmd')])
@@ -323,9 +211,9 @@ class TestRunnerTesting(unittest.TestCase):
@patch('dovetail.test_runner.dt_utils')
@patch('dovetail.test_runner.os')
def test_archive_logs_no_files(self, mock_os, mock_utils, mock_config):
- t_runner.FunctestRunner.create_log()
+ t_runner.VnftestRunner.create_log()
mock_config.dovetail_config = {'result_dir': 'result_dir'}
- docker_runner = t_runner.FunctestRunner(self.testcase)
+ docker_runner = t_runner.VnftestRunner(self.testcase)
mock_os.environ = {'DOVETAIL_HOME': 'dovetail_home'}
mock_utils.get_value_from_dict.return_value = []
diff --git a/dovetail/tests/unit/test_testcase.py b/dovetail/tests/unit/test_testcase.py
index e2b0b74..c3eb683 100644
--- a/dovetail/tests/unit/test_testcase.py
+++ b/dovetail/tests/unit/test_testcase.py
@@ -239,9 +239,8 @@ class TestcaseTesting(unittest.TestCase):
@patch('__builtin__.open')
@patch('dovetail.testcase.os.path')
@patch('dovetail.testcase.dt_cfg')
- @patch.object(tcase.Testcase, 'pre_copy_path')
@patch.object(tcase.Testcase, 'sub_testcase')
- def test_mk_src_file(self, mock_sub_testcase, mock_pre_copy, mock_config,
+ def test_mk_src_file(self, mock_sub_testcase, mock_config,
mock_path, mock_open):
testcase = tcase.Testcase(self.testcase_yaml)
logger_obj = Mock()
@@ -249,8 +248,6 @@ class TestcaseTesting(unittest.TestCase):
mock_config.dovetail_config = {'result_dir': 'value'}
sub_test = 'sub_test'
file_path = 'file_path'
- testcase_src_file = 'testcase_src_file'
- mock_pre_copy.return_value = testcase_src_file
mock_path.join.return_value = file_path
mock_sub_testcase.return_value = [sub_test]
file_obj = Mock()
@@ -258,8 +255,7 @@ class TestcaseTesting(unittest.TestCase):
result = testcase.mk_src_file()
- mock_pre_copy.assert_called_once_with('src_file')
- mock_path.join.assert_called_once_with('value', testcase_src_file)
+ mock_path.join.assert_called_once_with('value', 'tempest_custom.txt')
mock_open.assert_called_once_with(file_path, 'w+')
file_obj.write.assert_called_once_with(sub_test + '\n')
logger_obj.debug.assert_has_calls([
@@ -270,9 +266,8 @@ class TestcaseTesting(unittest.TestCase):
@patch('__builtin__.open')
@patch('dovetail.testcase.os.path')
@patch('dovetail.testcase.dt_cfg')
- @patch.object(tcase.Testcase, 'pre_copy_path')
@patch.object(tcase.Testcase, 'sub_testcase')
- def test_mk_src_file_exception(self, mock_sub_testcase, mock_pre_copy,
+ def test_mk_src_file_exception(self, mock_sub_testcase,
mock_config, mock_path, mock_open):
testcase = tcase.Testcase(self.testcase_yaml)
logger_obj = Mock()
@@ -280,16 +275,13 @@ class TestcaseTesting(unittest.TestCase):
mock_config.dovetail_config = {'result_dir': 'value'}
sub_test = 'sub_test'
file_path = 'file_path'
- testcase_src_file = 'testcase_src_file'
- mock_pre_copy.return_value = testcase_src_file
mock_path.join.return_value = file_path
mock_sub_testcase.return_value = [sub_test]
mock_open.return_value.__enter__.side_effect = Exception()
result = testcase.mk_src_file()
- mock_pre_copy.assert_called_once_with('src_file')
- mock_path.join.assert_called_once_with('value', testcase_src_file)
+ mock_path.join.assert_called_once_with('value', 'tempest_custom.txt')
mock_open.assert_called_once_with(file_path, 'w+')
logger_obj.exception('Failed to save: {}'.format(file_path))
self.assertEquals(None, result)
@@ -572,14 +564,13 @@ class TestcaseTesting(unittest.TestCase):
mock_prepare.return_value = True
mock_config.dovetail_config = {
'no_api_validation': True,
- 'functest': {'config': {'dir': 'value'}}}
+ 'functest': {'patches_dir': 'value'}}
mock_path.join.return_value = 'patch_cmd'
result = testcase.prepare_cmd('type')
mock_path.join.assert_called_once_with(
- 'value', 'patches', 'functest', 'disable-api-validation',
- 'apply.sh')
+ 'value', 'functest', 'disable-api-validation', 'apply.sh')
logger_obj.debug.assert_called_once_with(
'Updated list of commands for test run with '
'disabled API response validation: {}'