summaryrefslogtreecommitdiffstats
path: root/dovetail/tests/unit
diff options
context:
space:
mode:
authorxudan <xudan16@huawei.com>2018-11-14 04:42:11 -0500
committerxudan <xudan16@huawei.com>2018-11-23 03:59:56 -0500
commit6e69ce0329437fcc5a4181eb4d70e44a6c2dbaa5 (patch)
treeb1417ba562ccf81afd2a13c7a0df730704c19dc4 /dovetail/tests/unit
parent0c49866f76164c912308d7b9d1e5b7ce2dd23d34 (diff)
Integrate k8s test casses
In order to integrate k8s test cases, Dovetail framework should do some refactor and make it more general for k8s test cases as well as ONAP ones. Integrate 2 k8s test cases. JIRA: DOVETAIL-748 Change-Id: Ibd87754ffb5fb29f6b4ce79232af860c2ed2da9c Signed-off-by: xudan <xudan16@huawei.com>
Diffstat (limited to 'dovetail/tests/unit')
-rw-r--r--dovetail/tests/unit/test_container.py243
-rw-r--r--dovetail/tests/unit/test_report.py45
-rw-r--r--dovetail/tests/unit/test_run.py64
-rw-r--r--dovetail/tests/unit/test_test_runner.py215
-rw-r--r--dovetail/tests/unit/test_testcase.py5
-rw-r--r--dovetail/tests/unit/utils/test_dovetail_utils.py41
6 files changed, 272 insertions, 341 deletions
diff --git a/dovetail/tests/unit/test_container.py b/dovetail/tests/unit/test_container.py
index ec6871ab..70e01d8e 100644
--- a/dovetail/tests/unit/test_container.py
+++ b/dovetail/tests/unit/test_container.py
@@ -397,49 +397,6 @@ class ContainerTesting(unittest.TestCase):
@patch('dovetail.container.dt_cfg')
@patch('dovetail.container.os.path')
- def test_openrc_volume(self, mock_path, mock_config):
- v_one = 'v_one'
- v_two = 'v_two'
- v_three = 'v_three'
- v_four = 'v_four'
- mock_path.join.return_value = '/'.join([v_one, v_two])
- mock_path.isfile.return_value = True
- mock_config.dovetail_config = {'config_dir': v_one,
- 'env_file': v_two,
- 'openrc': v_three,
- 'bottlenecks': {'openrc': v_four}}
-
- expected = ' -v {}/{}:{} '.format(v_one, v_two, v_four)
- result = self.container.openrc_volume()
-
- mock_path.join.assert_called_once_with(v_one, v_two)
- mock_path.isfile.assert_called_once_with('/'.join([v_one, v_two]))
- self.assertEquals(expected, result)
-
- @patch('dovetail.container.dt_cfg')
- @patch('dovetail.container.os.path')
- def test_openrc_volume_error(self, mock_path, mock_config):
- v_one = 'v_one'
- v_two = 'v_two'
- v_three = 'v_three'
- v_four = 'v_four'
- mock_path.join.return_value = '/'.join([v_one, v_two])
- mock_path.isfile.return_value = False
- mock_config.dovetail_config = {'config_dir': v_one,
- 'env_file': v_two,
- 'openrc': v_three,
- 'bottlenecks': {'openrc': v_four}}
-
- result = self.container.openrc_volume()
-
- mock_path.join.assert_called_once_with(v_one, v_two)
- mock_path.isfile.assert_called_once_with('/'.join([v_one, v_two]))
- self.logger.error.assert_called_once_with(
- "File {} doesn't exist.".format('/'.join([v_one, v_two])))
- self.assertEquals(None, result)
-
- @patch('dovetail.container.dt_cfg')
- @patch('dovetail.container.os.path')
def test_set_vnftest_config_no_file(self, mock_path, mock_config):
v_one = 'v_one'
v_two = 'v_two'
@@ -485,194 +442,99 @@ class ContainerTesting(unittest.TestCase):
mock_path.isfile.assert_called_once_with('/'.join([v_two, v_three]))
self.assertEquals(expected, result)
- @patch('dovetail.container.dt_cfg')
- @patch.object(Container, 'openrc_volume')
- def test_create_no_openrc(self, mock_openrc, mock_config):
- mock_openrc.return_value = None
-
- result = self.container.create('docker_image')
-
- mock_openrc.assert_called_once_with()
- self.assertEquals(None, result)
-
@patch('dovetail.container.dt_utils')
@patch('dovetail.container.dt_cfg')
- @patch('dovetail.container.os.getenv')
- @patch.object(Container, 'openrc_volume')
- def test_create(self, mock_openrc, mock_getenv, mock_config, mock_utils):
+ def test_create(self, mock_config, mock_utils):
docker_image = 'docker_image'
container_id = 'container_id'
- mock_openrc.return_value = 'openrc'
mock_utils.get_value_from_dict.side_effect = [
- 'opts', 'envs', ['volume_one']]
- mock_getenv.side_effect = ['True', 'dovetail_home', 'cacert', 'True']
+ 'opts', 'envs', ['volume_one', 'volume_two']]
mock_utils.get_hosts_info.return_value = 'host_info'
- mock_utils.check_cacert_file.return_value = True
mock_utils.exec_cmd.return_value = (0, container_id)
- v_one = 'v_one'
- v_two = 'v_two'
- v_three = 'v_three'
- v_four = 'v_four'
- v_five = 'v_five'
- v_six = 'v_six'
- project_config = {
- 'config': {'dir': v_one, 'images': v_two},
- 'result': {'dir': v_three}}
- mock_config.dovetail_config = {
- 'bottlenecks': project_config,
- 'build_tag': v_four,
- 'images_dir': v_five,
- 'result_dir': v_six}
+ project_config = {}
+ mock_config.dovetail_config = {'bottlenecks': project_config}
expected = container_id
result = self.container.create(docker_image)
- mock_openrc.assert_called_once_with()
mock_utils.get_value_from_dict.assert_has_calls([
call('opts', project_config),
call('envs', project_config),
call('volumes', project_config)])
- mock_getenv.assert_has_calls([
- call('DEBUG'),
- call('DOVETAIL_HOME'),
- call('OS_CACERT'),
- call('OS_INSECURE')])
mock_utils.get_hosts_info.assert_called_once_with(self.logger)
- mock_utils.check_https_enabled.assert_called_once_with(self.logger)
- mock_utils.check_cacert_file.assert_called_once_with('cacert',
- self.logger)
mock_utils.exec_cmd.assert_called_once_with(
- 'sudo docker run opts envs -e CI_DEBUG=true '
- '-e BUILD_TAG=v_four-name volume_one host_info openrc '
- '-v cacert:cacert -v dovetail_home:v_one -v v_six:v_three '
- '-v v_five:v_two docker_image /bin/bash',
- self.logger)
+ 'sudo docker run opts envs volume_one volume_two host_info '
+ 'docker_image /bin/bash', self.logger)
self.assertEquals(expected, result)
@patch('dovetail.container.dt_utils')
@patch('dovetail.container.dt_cfg')
@patch('dovetail.container.os.getenv')
- @patch.object(Container, 'openrc_volume')
- def test_create_error(self, mock_openrc, mock_getenv, mock_config,
- mock_utils):
+ def test_create_error(self, mock_getenv, mock_config, mock_utils):
docker_image = 'docker_image'
- mock_openrc.return_value = 'openrc'
mock_utils.get_value_from_dict.side_effect = [
'opts', 'envs', ['volume_one']]
mock_getenv.side_effect = ['True', 'dovetail_home', None, 'True']
mock_utils.get_hosts_info.return_value = 'host_info'
mock_utils.check_https_enabled.return_value = True
mock_utils.exec_cmd.return_value = (1, 'error')
- v_one = 'v_one'
- v_two = 'v_two'
- v_three = 'v_three'
- v_four = 'v_four'
- v_five = 'v_five'
- v_six = 'v_six'
- project_config = {
- 'config': {'dir': v_one, 'images': v_two},
- 'result': {'dir': v_three}}
- mock_config.dovetail_config = {
- 'bottlenecks': project_config,
- 'build_tag': v_four,
- 'images_dir': v_five,
- 'result_dir': v_six}
-
+ project_config = {}
+ mock_config.dovetail_config = {'bottlenecks': project_config}
result = self.container.create(docker_image)
- mock_openrc.assert_called_once_with()
mock_utils.get_value_from_dict.assert_has_calls([
call('opts', project_config),
call('envs', project_config),
call('volumes', project_config)])
- mock_getenv.assert_has_calls([
- call('DEBUG'),
- call('DOVETAIL_HOME'),
- call('OS_CACERT'),
- call('OS_INSECURE')])
mock_utils.get_hosts_info.assert_called_once_with(self.logger)
- mock_utils.check_https_enabled.assert_called_once_with(self.logger)
mock_utils.exec_cmd.assert_called_once_with(
- 'sudo docker run opts envs -e CI_DEBUG=true '
- '-e BUILD_TAG=v_four-name volume_one host_info openrc '
- '-v dovetail_home:v_one -v v_six:v_three '
- '-v v_five:v_two docker_image /bin/bash',
- self.logger)
- self.logger.debug.assert_called_once_with(
- 'Use the insecure mode...')
+ 'sudo docker run opts envs volume_one host_info '
+ 'docker_image /bin/bash', self.logger)
self.assertEquals(None, result)
@patch('dovetail.container.dt_utils')
@patch('dovetail.container.dt_cfg')
@patch('dovetail.container.os.getenv')
- @patch.object(Container, 'openrc_volume')
@patch.object(Container, 'set_vnftest_config')
@patch.object(Container, 'set_vnftest_conf_file')
def test_create_vnftest(self, mock_setvnffile, mock_setvnfconf,
- mock_openrc, mock_getenv, mock_config, mock_utils):
+ mock_getenv, mock_config, mock_utils):
docker_image = 'docker_image'
container_id = 'container_id'
- mock_openrc.return_value = 'openrc'
mock_utils.get_value_from_dict.side_effect = [
'opts', 'envs', ['volume_one']]
mock_getenv.side_effect = ['False', 'dovetail_home', 'cacert', 'True']
mock_setvnfconf.return_value = 'vnftest_config'
mock_utils.get_hosts_info.return_value = 'host_info'
- mock_utils.check_cacert_file.return_value = True
mock_utils.exec_cmd.return_value = (0, container_id)
- v_one = 'v_one'
- v_two = 'v_two'
- v_three = 'v_three'
- v_four = 'v_four'
- v_five = 'v_five'
- v_six = 'v_six'
- project_config = {
- 'config': {'dir': v_one, 'images': v_two},
- 'result': {'dir': v_three}}
- mock_config.dovetail_config = {
- 'vnftest': project_config,
- 'build_tag': v_four,
- 'images_dir': v_five,
- 'result_dir': v_six}
+ project_config = {}
+ mock_config.dovetail_config = {'vnftest': project_config}
expected = container_id
self.container.valid_type = 'vnftest'
result = self.container.create(docker_image)
self.container.valid_type = 'bottlenecks'
- mock_openrc.assert_called_once_with()
mock_utils.get_value_from_dict.assert_has_calls([
call('opts', project_config),
call('envs', project_config),
call('volumes', project_config)])
- mock_getenv.assert_has_calls([
- call('DEBUG'),
- call('DOVETAIL_HOME'),
- call('OS_CACERT'),
- call('OS_INSECURE')])
mock_utils.get_hosts_info.assert_called_once_with(self.logger)
mock_setvnfconf.assert_called_once_with()
mock_setvnffile.assert_called_once_with(container_id)
- mock_utils.check_https_enabled.assert_called_once_with(self.logger)
- mock_utils.check_cacert_file.assert_called_once_with('cacert',
- self.logger)
mock_utils.exec_cmd.assert_called_once_with(
- 'sudo docker run opts envs -e CI_DEBUG=false '
- '-e BUILD_TAG=v_four-name volume_one vnftest_config host_info '
- 'openrc -v cacert:cacert -v dovetail_home:v_one '
- '-v v_six:v_three -v v_five:v_two docker_image /bin/bash',
+ 'sudo docker run opts envs volume_one vnftest_config host_info '
+ 'docker_image /bin/bash',
self.logger)
self.assertEquals(expected, result)
@patch('dovetail.container.dt_utils')
@patch('dovetail.container.dt_cfg')
@patch('dovetail.container.os.getenv')
- @patch.object(Container, 'openrc_volume')
@patch.object(Container, 'set_vnftest_config')
- def test_create_vnftest_error(self, mock_setvnfconf, mock_openrc,
+ def test_create_vnftest_error(self, mock_setvnfconf,
mock_getenv, mock_config, mock_utils):
docker_image = 'docker_image'
- mock_openrc.return_value = 'openrc'
mock_utils.get_value_from_dict.side_effect = [
'opts', 'envs', ['volume_one']]
mock_getenv.return_value = 'True'
@@ -685,81 +547,10 @@ class ContainerTesting(unittest.TestCase):
result = self.container.create(docker_image)
self.container.valid_type = 'bottlenecks'
- mock_openrc.assert_called_once_with()
mock_utils.get_value_from_dict.assert_has_calls([
call('opts', 'value'),
call('envs', 'value'),
call('volumes', 'value')])
- mock_getenv.assert_called_once_with('DEBUG')
mock_utils.get_hosts_info.assert_called_once_with(self.logger)
mock_setvnfconf.assert_called_once_with()
self.assertEquals(None, result)
-
- @patch('dovetail.container.dt_utils')
- @patch('dovetail.container.dt_cfg')
- @patch('dovetail.container.os.getenv')
- @patch.object(Container, 'openrc_volume')
- def test_create_https_enabled_error(self, mock_openrc, mock_getenv,
- mock_config, mock_utils):
- mock_openrc.return_value = 'openrc'
- mock_utils.get_value_from_dict.side_effect = [
- 'opts', 'envs', ['volume_one']]
- mock_getenv.side_effect = ['True', 'dovetail_home', None, 'False']
- mock_utils.get_hosts_info.return_value = 'host_info'
- project_config = {'config': {'dir': 'v_one'}}
- mock_config.dovetail_config = {
- 'bottlenecks': project_config,
- 'build_tag': 'v_two'}
-
- result = self.container.create('docker_image')
-
- mock_openrc.assert_called_once_with()
- mock_utils.get_value_from_dict.assert_has_calls([
- call('opts', project_config),
- call('envs', project_config),
- call('volumes', project_config)])
- mock_getenv.assert_has_calls([
- call('DEBUG'),
- call('DOVETAIL_HOME'),
- call('OS_CACERT'),
- call('OS_INSECURE')])
- mock_utils.get_hosts_info.assert_called_once_with(self.logger)
- mock_utils.check_https_enabled.assert_called_once_with(self.logger)
- self.logger.error.assert_called_once_with(
- 'https enabled, please set OS_CACERT or insecure mode...')
- self.assertEquals(None, result)
-
- @patch('dovetail.container.dt_utils')
- @patch('dovetail.container.dt_cfg')
- @patch('dovetail.container.os.getenv')
- @patch.object(Container, 'openrc_volume')
- def test_create_cacert_error(self, mock_openrc, mock_getenv, mock_config,
- mock_utils):
- mock_openrc.return_value = 'openrc'
- mock_utils.get_value_from_dict.side_effect = [
- 'opts', 'envs', ['volume_one']]
- mock_getenv.side_effect = ['True', 'dovetail_home', 'cacert', 'True']
- mock_utils.get_hosts_info.return_value = 'host_info'
- mock_utils.check_cacert_file.return_value = False
- project_config = {'config': {'dir': 'v_one'}}
- mock_config.dovetail_config = {
- 'bottlenecks': project_config,
- 'build_tag': 'v_two'}
-
- result = self.container.create('docker_image')
-
- mock_openrc.assert_called_once_with()
- mock_utils.get_value_from_dict.assert_has_calls([
- call('opts', project_config),
- call('envs', project_config),
- call('volumes', project_config)])
- mock_getenv.assert_has_calls([
- call('DEBUG'),
- call('DOVETAIL_HOME'),
- call('OS_CACERT'),
- call('OS_INSECURE')])
- mock_utils.get_hosts_info.assert_called_once_with(self.logger)
- mock_utils.check_https_enabled.assert_called_once_with(self.logger)
- mock_utils.check_cacert_file.assert_called_once_with('cacert',
- self.logger)
- self.assertEquals(None, result)
diff --git a/dovetail/tests/unit/test_report.py b/dovetail/tests/unit/test_report.py
index ad236e9d..fa5a02e0 100644
--- a/dovetail/tests/unit/test_report.py
+++ b/dovetail/tests/unit/test_report.py
@@ -30,16 +30,18 @@ class ReportTesting(unittest.TestCase):
def teardown_method(self, method):
dt_report.FunctestCrawler.logger = None
+ dt_report.FunctestK8sCrawler.logger = None
dt_report.YardstickCrawler.logger = None
dt_report.BottlenecksCrawler.logger = None
dt_report.VnftestCrawler.logger = None
dt_report.FunctestChecker.logger = None
+ dt_report.FunctestK8sChecker.logger = None
dt_report.YardstickChecker.logger = None
dt_report.BottlenecksChecker.logger = None
dt_report.VnftestChecker.logger = None
dt_report.Report.logger = None
dt_report.Report.results = {
- 'functest': {}, 'yardstick': {},
+ 'functest': {}, 'yardstick': {}, 'functest-k8s': {},
'bottlenecks': {}, 'shell': {}, 'vnftest': {}}
def _produce_report_initial_text(self, report_data):
@@ -623,6 +625,36 @@ class ReportTesting(unittest.TestCase):
self.assertEquals(None, result)
@patch('dovetail.report.dt_logger')
+ def test_functestk8s_crawler_create_log(self, mock_logger):
+ getlogger_obj = Mock()
+ logger_obj = Mock()
+ logger_obj.getLogger.return_value = getlogger_obj
+ mock_logger.Logger.return_value = logger_obj
+
+ dt_report.FunctestK8sCrawler.create_log()
+
+ self.assertEquals(getlogger_obj, dt_report.FunctestK8sCrawler.logger)
+
+ @patch('dovetail.report.FunctestK8sCrawler.crawl_from_file')
+ @patch('dovetail.report.dt_cfg')
+ @patch('dovetail.report.os.path')
+ def test_functestk8s_crawler_crawl_none(self, mock_path, mock_config,
+ mock_crawl):
+ logger_obj = Mock()
+ dt_report.FunctestK8sCrawler.logger = logger_obj
+ mock_crawl.return_value = None
+ testcase = 'testcase'
+ file_path = 'file_path'
+
+ crawler = dt_report.FunctestK8sCrawler()
+
+ result = crawler.crawl(testcase, file_path)
+
+ dt_report.FunctestK8sCrawler.crawl_from_file.assert_called_once_with(
+ 'testcase', 'file_path')
+ self.assertEquals(None, result)
+
+ @patch('dovetail.report.dt_logger')
def test_yardstick_crawler_create_log(self, mock_logger):
getlogger_obj = Mock()
logger_obj = Mock()
@@ -1052,6 +1084,17 @@ class ReportTesting(unittest.TestCase):
testcase_obj.passed.assert_has_calls([call('PASS'), call('FAIL')])
@patch('dovetail.report.dt_logger')
+ def test_functestk8s_checker_create_log(self, mock_logger):
+ getlogger_obj = Mock()
+ logger_obj = Mock()
+ logger_obj.getLogger.return_value = getlogger_obj
+ mock_logger.Logger.return_value = logger_obj
+
+ dt_report.FunctestK8sChecker.create_log()
+
+ self.assertEquals(getlogger_obj, dt_report.FunctestK8sChecker.logger)
+
+ @patch('dovetail.report.dt_logger')
def test_yardstick_checker_create_log(self, mock_logger):
getlogger_obj = Mock()
logger_obj = Mock()
diff --git a/dovetail/tests/unit/test_run.py b/dovetail/tests/unit/test_run.py
index 1e48fe69..c7fe4d6d 100644
--- a/dovetail/tests/unit/test_run.py
+++ b/dovetail/tests/unit/test_run.py
@@ -321,24 +321,6 @@ class RunTesting(unittest.TestCase):
mock_utils.exec_cmd.assert_called_once_with(
'sudo cp -a -r value/* value', logger, exit_on_error=False)
- @patch('dovetail.run.dt_cfg')
- @patch('dovetail.run.dt_utils')
- @patch('dovetail.run.os')
- def test_env_init(self, mock_os, mock_utils, mock_config):
- mock_config.dovetail_config = {'config_dir': 'a', 'env_file': 'b'}
- join_path = 'join_path'
- mock_os.path.join.return_value = join_path
- mock_os.path.isfile.return_value = False
- logger = Mock()
-
- dt_run.env_init(logger)
-
- mock_os.path.join.assert_called_once_with('a', 'b')
- mock_os.path.isfile.assert_called_once_with(join_path)
- logger.error.assert_called_once_with(
- "File {} does not exist.".format(join_path))
- mock_utils.source_env.assert_called_once_with(join_path)
-
@patch('dovetail.run.os')
def test_update_deploy_scenario(self, mock_os):
logger = Mock()
@@ -350,23 +332,6 @@ class RunTesting(unittest.TestCase):
self.assertEquals({'DEPLOY_SCENARIO': 'a'}, mock_os.environ)
@patch('dovetail.run.dt_cfg')
- @patch('dovetail.run.os.path')
- def test_check_hosts_file(self, mock_path, mock_config):
- mock_config.dovetail_config = {'config_dir': 'value'}
- hosts_file = 'h_file'
- mock_path.join.return_value = hosts_file
- mock_path.isfile.return_value = False
- logger = Mock()
-
- dt_run.check_hosts_file(logger)
-
- mock_path.join.assert_called_once_with('value', 'hosts.yaml')
- mock_path.isfile.assert_called_once_with(hosts_file)
- logger.warn.assert_called_once_with(
- 'There is no hosts file {}, may be some issues with '
- 'domain name resolution.'.format(hosts_file))
-
- @patch('dovetail.run.dt_cfg')
@patch.object(dt_run, 'filter_config')
def test_cli_no_validation(self, mock_filter, mock_config):
mock_config.dovetail_config = {}
@@ -517,17 +482,15 @@ class RunTesting(unittest.TestCase):
@patch.object(dt_run, 'clean_results_dir')
@patch.object(dt_run, 'parse_cli')
@patch.object(dt_run, 'update_deploy_scenario')
- @patch.object(dt_run, 'env_init')
@patch.object(dt_run, 'copy_userconfig_files')
@patch.object(dt_run, 'copy_patch_files')
- @patch.object(dt_run, 'check_hosts_file')
@patch.object(dt_run, 'get_testcase_list')
@patch.object(dt_run, 'run_test')
@patch.object(dt_run, 'create_logs')
- def test_main(self, mock_create_logs, mock_run, mock_get_list, mock_check,
- mock_copy_patch, mock_copy_userconf, mock_env_init,
- mock_update, mock_parse, mock_clean, mock_get_result,
- mock_utils, mock_config, mock_logger, mock_uuid, mock_os):
+ def test_main(self, mock_create_logs, mock_run, mock_get_list,
+ mock_copy_patch, mock_copy_userconf, mock_update, mock_parse,
+ mock_clean, mock_get_result, mock_utils, mock_config,
+ mock_logger, mock_uuid, mock_os):
mock_config.dovetail_config = {}
mock_os.environ = {}
logger_obj = Mock()
@@ -566,13 +529,9 @@ class RunTesting(unittest.TestCase):
call('Build tag: daily-master-42')])
mock_parse.assert_called_once_with(logger_obj, **kwargs_dict)
mock_update.assert_called_once_with(logger_obj, **kwargs_dict)
- mock_env_init.assert_called_once_with(logger_obj)
mock_copy_userconf.assert_called_once_with(logger_obj)
mock_copy_patch.assert_called_once_with(logger_obj)
mock_utils.check_docker_version.assert_called_once_with(logger_obj)
- mock_utils.get_openstack_endpoint.assert_called_once_with(logger_obj)
- mock_check.assert_called_once_with(logger_obj)
- mock_utils.get_hardware_info.assert_called_once_with(logger_obj)
mock_get_list.assert_called_once_with(logger_obj, **kwargs_dict)
mock_run.assert_called_once_with(
testcase_list, kwargs_dict['report'], logger_obj)
@@ -604,19 +563,16 @@ class RunTesting(unittest.TestCase):
@patch('dovetail.run.dt_utils')
@patch.object(dt_run, 'get_result_path')
@patch.object(dt_run, 'clean_results_dir')
- @patch.object(dt_run, 'parse_cli')
@patch.object(dt_run, 'update_deploy_scenario')
- @patch.object(dt_run, 'env_init')
@patch.object(dt_run, 'copy_userconfig_files')
@patch.object(dt_run, 'copy_patch_files')
- @patch.object(dt_run, 'check_hosts_file')
@patch.object(dt_run, 'get_testcase_list')
+ @patch.object(dt_run, 'parse_cli')
@patch.object(dt_run, 'run_test')
@patch.object(dt_run, 'create_logs')
- def test_main_no_testcaselist(self, mock_create_logs, mock_run,
- mock_get_list, mock_check, mock_copy_patch,
- mock_copy_userconf, mock_env_init,
- mock_update, mock_parse, mock_clean,
+ def test_main_no_testcaselist(self, mock_create_logs, mock_run, mock_parse,
+ mock_get_list, mock_copy_patch,
+ mock_copy_userconf, mock_update, mock_clean,
mock_get_result, mock_utils, mock_config,
mock_logger, mock_uuid, mock_os):
mock_config.dovetail_config = {}
@@ -657,11 +613,7 @@ class RunTesting(unittest.TestCase):
call('Build tag: daily-master-42')])
mock_parse.assert_called_once_with(logger_obj, **kwargs_dict)
mock_update.assert_called_once_with(logger_obj, **kwargs_dict)
- mock_env_init.assert_called_once_with(logger_obj)
mock_copy_userconf.assert_called_once_with(logger_obj)
mock_copy_patch.assert_called_once_with(logger_obj)
mock_utils.check_docker_version.assert_called_once_with(logger_obj)
- mock_utils.get_openstack_endpoint.assert_called_once_with(logger_obj)
- mock_check.assert_called_once_with(logger_obj)
- mock_utils.get_hardware_info.assert_called_once_with(logger_obj)
mock_get_list.assert_called_once_with(logger_obj, **kwargs_dict)
diff --git a/dovetail/tests/unit/test_test_runner.py b/dovetail/tests/unit/test_test_runner.py
index f11bd928..08dbde69 100644
--- a/dovetail/tests/unit/test_test_runner.py
+++ b/dovetail/tests/unit/test_test_runner.py
@@ -20,7 +20,8 @@ class TestRunnerTesting(unittest.TestCase):
def setUp(self):
self.patcher1 = patch.object(t_runner, 'dt_logger')
- self.patcher2 = patch.object(t_runner.DockerRunner, '_update_config')
+ self.patcher2 = patch.object(t_runner.DockerRunner,
+ '_update_config')
self.logger = self.patcher1.start().return_value
self._update_config = self.patcher2.start().return_value
@@ -29,7 +30,7 @@ class TestRunnerTesting(unittest.TestCase):
self.testcase_name = 'testcase_name'
self.testcase_type = 'functest'
self.testcase_dict = {}
- self.testcase_valid = True
+ self.testcase_valid = 'validate_testcase'
self.testcase.testcase = self.testcase_dict
self.testcase.name.return_value = self.testcase_name
@@ -40,8 +41,11 @@ class TestRunnerTesting(unittest.TestCase):
self.patcher1.stop()
self.patcher2.stop()
- def test_pre_copy_no_container(self):
+ @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(
@@ -52,8 +56,11 @@ class TestRunnerTesting(unittest.TestCase):
'Container instance is None.')
self.assertEquals(None, result)
- def test_pre_copy_no_dest_path(self):
+ @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(
@@ -93,14 +100,17 @@ class TestRunnerTesting(unittest.TestCase):
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):
+ def test_run_offline_not_exist(self, mock_container, mock_config,
+ mock_utils):
t_runner.FunctestRunner.create_log()
- docker_runner = t_runner.TestRunnerFactory.create(self.testcase)
mock_config.dovetail_config = {
- 'offline': True
+ 'offline': True, 'result_dir': 'result_dir'
}
+ docker_runner = t_runner.TestRunnerFactory.create(self.testcase)
+
container_obj = Mock()
docker_img_obj = Mock()
container_obj.get_docker_image.return_value = docker_img_obj
@@ -116,14 +126,17 @@ class TestRunnerTesting(unittest.TestCase):
"{} image doesn't exist, can't run offline.".format(
self.testcase_type))
+ @patch('dovetail.test_runner.dt_utils')
@patch('dovetail.test_runner.dt_cfg')
@patch('dovetail.test_runner.Container')
- def test_run__not_offline_no_pull(self, mock_container, mock_config):
+ def test_run__not_offline_no_pull(self, mock_container, mock_config,
+ mock_utils):
t_runner.YardstickRunner.create_log()
- docker_runner = t_runner.YardstickRunner(self.testcase)
mock_config.dovetail_config = {
- 'offline': False
+ 'offline': False, 'result_dir': 'result_dir'
}
+ docker_runner = t_runner.YardstickRunner(self.testcase)
+
container_obj = Mock()
docker_img_obj = Mock()
container_obj.get_docker_image.return_value = docker_img_obj
@@ -138,14 +151,17 @@ class TestRunnerTesting(unittest.TestCase):
docker_runner.logger.error.assert_called_once_with(
'Failed to pull the image.')
+ @patch('dovetail.test_runner.dt_utils')
@patch('dovetail.test_runner.dt_cfg')
@patch('dovetail.test_runner.Container')
- def test_run__not_offline_no_create(self, mock_container, mock_config):
+ def test_run__not_offline_no_create(self, mock_container, mock_config,
+ mock_utils):
t_runner.BottlenecksRunner.create_log()
- docker_runner = t_runner.BottlenecksRunner(self.testcase)
mock_config.dovetail_config = {
- 'offline': False
+ 'offline': False, 'result_dir': 'result_dir'
}
+ docker_runner = t_runner.BottlenecksRunner(self.testcase)
+
container_obj = Mock()
docker_img_obj = Mock()
container_obj.get_docker_image.return_value = docker_img_obj
@@ -201,17 +217,20 @@ class TestRunnerTesting(unittest.TestCase):
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,
- mock_config):
+ mock_config, mock_utils):
t_runner.FunctestRunner.create_log()
- docker_runner = t_runner.FunctestRunner(self.testcase)
mock_config.dovetail_config = {
'offline': False,
- 'noclean': False
+ 'noclean': False,
+ 'result_dir': 'result_dir'
}
+ docker_runner = t_runner.FunctestRunner(self.testcase)
+
container_obj = Mock()
docker_img_obj = Mock()
container_obj.get_docker_image.return_value = docker_img_obj
@@ -249,17 +268,19 @@ class TestRunnerTesting(unittest.TestCase):
.format(self.testcase_name))])
container_obj.clean.assert_called_once_with()
+ @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,
- mock_config):
+ mock_config, mock_utils):
t_runner.FunctestRunner.create_log()
- docker_runner = t_runner.FunctestRunner(self.testcase)
mock_config.dovetail_config = {
'offline': False,
- 'noclean': False
+ 'noclean': False,
+ 'result_dir': 'result_dir'
}
+ docker_runner = t_runner.FunctestRunner(self.testcase)
container_obj = Mock()
docker_img_obj = Mock()
container_obj.get_docker_image.return_value = docker_img_obj
@@ -298,33 +319,38 @@ class TestRunnerTesting(unittest.TestCase):
.format('cmd', 1, 'error'))])
container_obj.clean.assert_called_once_with()
+ @patch('dovetail.test_runner.dt_cfg')
@patch('dovetail.test_runner.dt_utils')
@patch('dovetail.test_runner.os')
- def test_archive_logs_no_files(self, mock_os, mock_utils):
+ def test_archive_logs_no_files(self, mock_os, mock_utils, mock_config):
t_runner.FunctestRunner.create_log()
+ mock_config.dovetail_config = {'result_dir': 'result_dir'}
docker_runner = t_runner.FunctestRunner(self.testcase)
mock_os.environ = {'DOVETAIL_HOME': 'dovetail_home'}
mock_utils.get_value_from_dict.return_value = []
result = docker_runner.archive_logs()
- mock_os.path.join.assert_called_once_with('dovetail_home', 'results')
+ mock_os.path.join.assert_has_calls([call('dovetail_home', 'results')])
mock_utils.get_value_from_dict.assert_has_calls([
call('report.source_archive_files', self.testcase_dict),
call('report.dest_archive_files', self.testcase_dict)])
self.assertEquals(True, result)
+ @patch('dovetail.test_runner.dt_cfg')
@patch('dovetail.test_runner.dt_utils')
@patch('dovetail.test_runner.os')
- def test_archive_logs_difference_in_files(self, mock_os, mock_utils):
+ def test_archive_logs_difference_in_files(self, mock_os, mock_utils,
+ mock_config):
t_runner.FunctestRunner.create_log()
+ mock_config.dovetail_config = {'result_dir': 'result_dir'}
docker_runner = t_runner.FunctestRunner(self.testcase)
mock_os.environ = {'DOVETAIL_HOME': 'dovetail_home'}
mock_utils.get_value_from_dict.side_effect = [[], ['file']]
result = docker_runner.archive_logs()
- mock_os.path.join.assert_called_once_with('dovetail_home', 'results')
+ mock_os.path.join.assert_has_calls([call('dovetail_home', 'results')])
mock_utils.get_value_from_dict.assert_has_calls([
call('report.source_archive_files', self.testcase_dict),
call('report.dest_archive_files', self.testcase_dict)])
@@ -334,10 +360,13 @@ class TestRunnerTesting(unittest.TestCase):
.format(self.testcase_name))
self.assertEquals(False, result)
+ @patch('dovetail.test_runner.dt_cfg')
@patch('dovetail.test_runner.dt_utils')
@patch('dovetail.test_runner.os')
- def test_archive_logs_src_file_error(self, mock_os, mock_utils):
+ def test_archive_logs_src_file_error(self, mock_os, mock_utils,
+ mock_config):
t_runner.FunctestRunner.create_log()
+ mock_config.dovetail_config = {'result_dir': 'result_dir'}
docker_runner = t_runner.FunctestRunner(self.testcase)
mock_os.environ = {'DOVETAIL_HOME': 'dovetail_home'}
mock_utils.get_value_from_dict.side_effect = [['src_file'],
@@ -355,15 +384,18 @@ class TestRunnerTesting(unittest.TestCase):
mock_utils.get_value_from_dict.assert_has_calls([
call('report.source_archive_files', self.testcase_dict),
call('report.dest_archive_files', self.testcase_dict)])
- mock_os.path.isfile.assert_called_once_with('src_file_path')
+ mock_os.path.isfile.assert_has_calls([call('src_file_path')])
docker_runner.logger.error.assert_called_once_with(
"Can't find file {}.".format('src_file_path'))
self.assertEquals(False, result)
+ @patch('dovetail.test_runner.dt_cfg')
@patch('dovetail.test_runner.dt_utils')
@patch('dovetail.test_runner.os')
- def test_archive_logs_src_file_exists(self, mock_os, mock_utils):
+ def test_archive_logs_src_file_exists(self, mock_os, mock_utils,
+ mock_config):
t_runner.FunctestRunner.create_log()
+ mock_config.dovetail_config = {'result_dir': 'result_dir'}
docker_runner = t_runner.FunctestRunner(self.testcase)
mock_os.environ = {'DOVETAIL_HOME': 'dovetail_home'}
mock_utils.get_value_from_dict.side_effect = [['src_file'],
@@ -381,7 +413,7 @@ class TestRunnerTesting(unittest.TestCase):
mock_utils.get_value_from_dict.assert_has_calls([
call('report.source_archive_files', self.testcase_dict),
call('report.dest_archive_files', self.testcase_dict)])
- mock_os.path.isfile.assert_called_once_with('src_file_path')
+ mock_os.path.isfile.assert_has_calls([call('src_file_path')])
mock_os.renames.assert_called_once_with(
'src_file_path', 'dest_file_path')
self.assertEquals(True, result)
@@ -399,20 +431,27 @@ class TestRunnerTesting(unittest.TestCase):
template_obj.render.assert_called_with()
self.assertEquals(render_obj, result)
+ @patch('dovetail.test_runner.dt_cfg')
@patch('dovetail.test_runner.os')
- def test_add_testcase_info(self, mock_os):
- mock_os.getenv.side_effect = ['os_insecure', 'dovetail_home']
+ def test_add_testcase_info(self, mock_os, mock_config):
+ mock_os.getenv.side_effect = ['os_insecure', 'dovetail_home', 'debug',
+ 'os_cacert']
mock_os.environ = {'DEPLOY_SCENARIO': 'deploy_scenario'}
+ mock_config.dovetail_config = {'build_tag': 'build_tag'}
expected = {
- 'os_insecure': 'os_insecure', 'dovetail_home': 'dovetail_home',
- 'testcase': 'testcase_name', 'validate_testcase': True,
- 'deploy_scenario': 'deploy_scenario'}
+ 'validate_testcase': 'validate_testcase',
+ 'testcase': 'testcase_name', 'os_insecure': 'os_insecure',
+ 'deploy_scenario': 'deploy_scenario',
+ 'dovetail_home': 'dovetail_home', 'debug': 'debug',
+ 'build_tag': 'build_tag', 'cacert': 'os_cacert'}
result = t_runner.FunctestRunner._add_testcase_info(self.testcase)
self.testcase.validate_testcase.assert_called_once_with()
+ self.testcase.name.assert_called_once_with()
mock_os.getenv.assert_has_calls([
- call('OS_INSECURE'), call('DOVETAIL_HOME')])
+ call('OS_INSECURE'), call('DOVETAIL_HOME'), call('DEBUG'),
+ call('OS_CACERT')])
self.assertEquals(expected, result)
@patch('dovetail.test_runner.dt_utils')
@@ -422,10 +461,10 @@ class TestRunnerTesting(unittest.TestCase):
def test_update_config_no_task_template(self, mock_const, mock_path,
mock_config, mock_utils):
t_runner.FunctestRunner.create_log()
- docker_runner = t_runner.FunctestRunner(self.testcase)
- mock_path.join.side_effect = ['pod_file', 'config_file']
mock_config.dovetail_config = {
- 'config_dir': 'one', 'pod_file': 'two'}
+ 'config_dir': 'one', 'pod_file': 'two', 'result_dir': 'three'}
+ docker_runner = t_runner.FunctestRunner(self.testcase)
+ mock_path.join.side_effect = ['config_file', 'pod_file']
mock_utils.read_yaml_file.return_value = 'pod_info'
mock_utils.read_plain_file.return_value = None
mock_const.CONF_PATH = 'conf_path'
@@ -435,10 +474,8 @@ class TestRunnerTesting(unittest.TestCase):
self.patcher2.start()
mock_path.join.assert_has_calls([
- call('one', 'two'),
+ call('three', 'endpoint_info.json'),
call('conf_path', docker_runner.config_file_name)])
- mock_utils.read_yaml_file.assert_called_once_with(
- 'pod_file', docker_runner.logger)
mock_utils.read_plain_file.assert_called_once_with(
'config_file', docker_runner.logger)
self.assertEquals(None, result)
@@ -454,10 +491,10 @@ class TestRunnerTesting(unittest.TestCase):
mock_const, mock_path, mock_config,
mock_utils, mock_load):
t_runner.FunctestRunner.create_log()
- docker_runner = t_runner.FunctestRunner(self.testcase)
- mock_path.join.side_effect = ['pod_file', 'config_file']
mock_config.dovetail_config = {
- 'config_dir': 'one', 'pod_file': 'two'}
+ 'config_dir': 'one', 'pod_file': 'two', 'result_dir': 'three'}
+ docker_runner = t_runner.FunctestRunner(self.testcase)
+ mock_path.join.side_effect = ['config_file', 'pod_file']
mock_utils.read_yaml_file.return_value = {'key': 'value'}
mock_utils.read_plain_file.return_value = True
mock_const.CONF_PATH = 'conf_path'
@@ -470,15 +507,17 @@ class TestRunnerTesting(unittest.TestCase):
self.patcher2.start()
mock_path.join.assert_has_calls([
- call('one', 'two'),
- call('conf_path', docker_runner.config_file_name)])
+ call('three', 'endpoint_info.json'),
+ call('conf_path', docker_runner.config_file_name),
+ call('one', 'two')])
mock_add_info.assert_called_once_with(self.testcase)
mock_render.assert_called_once_with(True, config_item='item')
mock_load.assert_called_once_with('full_task')
self.assertEquals(
{'config_dir': 'one',
'pod_file': 'two',
- 'full_task_yaml': 'full_value'},
+ 'full_task_yaml': 'full_value',
+ 'result_dir': 'three'},
result)
@patch('dovetail.test_runner.yaml.safe_load')
@@ -492,10 +531,10 @@ class TestRunnerTesting(unittest.TestCase):
mock_const, mock_path, mock_config,
mock_utils, mock_load):
t_runner.FunctestRunner.create_log()
- docker_runner = t_runner.FunctestRunner(self.testcase)
- mock_path.join.side_effect = ['pod_file', 'config_file']
mock_config.dovetail_config = {
- 'config_dir': 'one', 'pod_file': 'two'}
+ 'config_dir': 'one', 'pod_file': 'two', 'result_dir': 'three'}
+ docker_runner = t_runner.FunctestRunner(self.testcase)
+ mock_path.join.side_effect = ['config_file', 'pod_file']
mock_utils.read_yaml_file.return_value = False
mock_utils.read_plain_file.return_value = True
mock_const.CONF_PATH = 'conf_path'
@@ -508,15 +547,17 @@ class TestRunnerTesting(unittest.TestCase):
self.patcher2.start()
mock_path.join.assert_has_calls([
- call('one', 'two'),
- call('conf_path', docker_runner.config_file_name)])
+ call('three', 'endpoint_info.json'),
+ call('conf_path', docker_runner.config_file_name),
+ call('one', 'two')])
mock_add_info.assert_called_once_with(self.testcase)
mock_render.assert_called_once_with(True, config_item='item')
mock_load.assert_called_once_with('full_task')
self.assertEquals(
{'config_dir': 'one',
'pod_file': 'two',
- 'full_task_yaml': 'full_value'},
+ 'full_task_yaml': 'full_value',
+ 'result_dir': 'three'},
result)
@patch('dovetail.test_runner.yaml.safe_load')
@@ -530,10 +571,10 @@ class TestRunnerTesting(unittest.TestCase):
mock_const, mock_path, mock_config,
mock_utils, mock_load):
t_runner.FunctestRunner.create_log()
- docker_runner = t_runner.FunctestRunner(self.testcase)
- mock_path.join.side_effect = ['pod_file', 'config_file']
mock_config.dovetail_config = {
- 'config_dir': 'one', 'pod_file': 'two'}
+ 'config_dir': 'one', 'pod_file': 'two', 'result_dir': 'three'}
+ docker_runner = t_runner.FunctestRunner(self.testcase)
+ mock_path.join.side_effect = ['config_file', 'pod_file']
mock_utils.read_yaml_file.return_value = {
'process_info': [
{'key': 'value'}, {'testcase_name': self.testcase_name}
@@ -549,8 +590,9 @@ class TestRunnerTesting(unittest.TestCase):
self.patcher2.start()
mock_path.join.assert_has_calls([
- call('one', 'two'),
- call('conf_path', docker_runner.config_file_name)])
+ call('three', 'endpoint_info.json'),
+ call('conf_path', docker_runner.config_file_name),
+ call('one', 'two')])
mock_add_info.assert_called_once_with(
self.testcase, {'testcase_name': self.testcase_name})
docker_runner.logger.error.assert_called_once_with(
@@ -560,7 +602,8 @@ class TestRunnerTesting(unittest.TestCase):
self.assertEquals(
{'config_dir': 'one',
'pod_file': 'two',
- 'full_task_yaml': 'full_value'},
+ 'full_task_yaml': 'full_value',
+ 'result_dir': 'three'},
result)
@patch('__builtin__.open')
@@ -650,3 +693,61 @@ class TestRunnerTesting(unittest.TestCase):
result = docker_runner.create(self.testcase)
self.assertEquals(None, result)
+
+ @patch('dovetail.test_runner.constants')
+ @patch('dovetail.test_runner.dt_utils')
+ @patch('dovetail.test_runner.os.path')
+ def test_k8s_update_config_no_task_template(self, mock_path, mock_utils,
+ mock_const):
+ t_runner.FunctestK8sRunner.create_log()
+ mock_utils.read_plain_file.return_value = None
+ mock_path.join.side_effect = ['config_file']
+ mock_const.CONF_PATH = 'conf_path'
+ docker_runner = t_runner.FunctestK8sRunner(self.testcase)
+
+ self.patcher2.stop()
+ result = docker_runner._update_config(self.testcase, update_pod=False)
+ self.patcher2.start()
+
+ mock_path.join.assert_has_calls([
+ call('conf_path', docker_runner.config_file_name)])
+ mock_utils.read_plain_file.assert_has_calls([
+ call('config_file', docker_runner.logger)])
+ self.assertEquals(None, result)
+
+ @patch('dovetail.test_runner.yaml.safe_load')
+ @patch('dovetail.test_runner.constants')
+ @patch('dovetail.test_runner.dt_utils')
+ @patch('dovetail.test_runner.os.path')
+ @patch('dovetail.test_runner.dt_cfg')
+ @patch.object(t_runner.DockerRunner, '_add_testcase_info')
+ @patch.object(t_runner.DockerRunner, '_render')
+ def test_k8s_update_config(self, mock_render, mock_add_info, mock_config,
+ mock_path, mock_utils, mock_const, mock_load):
+ t_runner.FunctestK8sRunner.create_log()
+ mock_utils.read_plain_file.return_value = True
+ mock_path.join.side_effect = ['config_file', 'config_file']
+ mock_const.CONF_PATH = 'conf_path'
+ mock_add_info.return_value = {'config_item': 'item'}
+ mock_render.return_value = 'full_task'
+ mock_load.return_value = {'full_task_yaml': 'full_value'}
+ mock_config.dovetail_config = {
+ 'config_dir': 'one', 'pod_file': 'two'}
+
+ docker_runner = t_runner.FunctestK8sRunner(self.testcase)
+ self.patcher2.stop()
+ result = docker_runner._update_config(self.testcase, update_pod=False)
+ self.patcher2.start()
+
+ mock_path.join.assert_has_calls([
+ call('conf_path', docker_runner.config_file_name)])
+ mock_utils.read_plain_file.assert_has_calls([
+ call('config_file', docker_runner.logger)])
+ mock_add_info.assert_has_calls([call(self.testcase)])
+ mock_render.assert_has_calls([call(True, config_item='item')])
+ mock_load.assert_has_calls([call('full_task')])
+ self.assertEquals(
+ {'config_dir': 'one',
+ 'pod_file': 'two',
+ 'full_task_yaml': 'full_value'},
+ result)
diff --git a/dovetail/tests/unit/test_testcase.py b/dovetail/tests/unit/test_testcase.py
index 5dbb9cb1..0d303206 100644
--- a/dovetail/tests/unit/test_testcase.py
+++ b/dovetail/tests/unit/test_testcase.py
@@ -600,6 +600,11 @@ class TestcaseTesting(unittest.TestCase):
tcase.TestcaseFactory.create('unknown',
self.testcase_yaml))
+ def test_testfactory_k8s(self):
+ k8s_testcase = tcase.TestcaseFactory.create('functest-k8s',
+ self.testcase_yaml)
+ self.assertEquals('functest-k8s', k8s_testcase.type)
+
@patch('dovetail.testcase.dt_logger')
def test_testsuite_create_log(self, mock_logger):
getlogger_obj = Mock()
diff --git a/dovetail/tests/unit/utils/test_dovetail_utils.py b/dovetail/tests/unit/utils/test_dovetail_utils.py
index 60278732..0f0e14f3 100644
--- a/dovetail/tests/unit/utils/test_dovetail_utils.py
+++ b/dovetail/tests/unit/utils/test_dovetail_utils.py
@@ -225,9 +225,10 @@ class DovetailUtilsTesting(unittest.TestCase):
dovetail_utils.dt_cfg.dovetail_config = {'config_dir': file_path}
mock_path.join.return_value = file_complete_name
mock_path.isfile.return_value = False
+ logger = Mock()
expected = ''
- result = dovetail_utils.get_hosts_info(file_path)
+ result = dovetail_utils.get_hosts_info(logger)
mock_path.join.assert_called_once_with(file_path, 'hosts.yaml')
mock_path.isfile.assert_called_once_with(file_complete_name)
@@ -1316,3 +1317,41 @@ class DovetailUtilsTesting(unittest.TestCase):
mock_getenv.assert_called_once_with('DEBUG')
mock_bar.assert_called_once_with(1)
mock_exit.assert_called_once_with(1)
+
+ @patch('os.path', autospec=True)
+ def test_get_openstack_info_no_openrc(self, mock_path):
+ logger = Mock()
+ config_dir = 'config_dir'
+ env_file = 'env_file'
+ dovetail_utils.dt_cfg.dovetail_config = {
+ 'config_dir': config_dir, 'env_file': env_file}
+ mock_path.join.side_effect = ['openrc']
+ mock_path.isfile.return_value = False
+ dovetail_utils.get_openstack_info(logger)
+
+ mock_path.join.assert_called_once_with(config_dir, env_file)
+ mock_path.isfile.assert_called_once_with('openrc')
+ logger.error.assert_called_once_with('File openrc does not exist.')
+
+ @patch('dovetail.utils.dovetail_utils.source_env')
+ @patch('dovetail.utils.dovetail_utils.get_hosts_info')
+ @patch('dovetail.utils.dovetail_utils.get_openstack_endpoint')
+ @patch('dovetail.utils.dovetail_utils.get_hardware_info')
+ @patch('os.path', autospec=True)
+ def test_get_openstack_info(self, mock_path, mock_hardware, mock_endpoint,
+ mock_host, mock_env):
+ logger = Mock()
+ config_dir = 'config_dir'
+ env_file = 'env_file'
+ dovetail_utils.dt_cfg.dovetail_config = {
+ 'config_dir': config_dir, 'env_file': env_file}
+ mock_path.join.side_effect = ['openrc']
+ mock_path.isfile.return_value = True
+ dovetail_utils.get_openstack_info(logger)
+
+ mock_path.join.assert_called_once_with(config_dir, env_file)
+ mock_path.isfile.assert_called_once_with('openrc')
+ mock_env.assert_called_once()
+ mock_host.assert_called_once()
+ mock_endpoint.assert_called_once()
+ mock_hardware.assert_called_once()