summaryrefslogtreecommitdiffstats
path: root/dovetail/tests/unit
diff options
context:
space:
mode:
authorxudan <xudan16@huawei.com>2019-11-13 03:32:24 -0500
committerDan Xu <xudan16@huawei.com>2019-11-19 10:57:03 +0000
commit88dee82da16683c7796036ae6e20a2d7c1f6b162 (patch)
treed82bb8ead2c4b8bdfe66d817e9159c90f1a6fb6a /dovetail/tests/unit
parentb88e2328f7960d88aa979d01ad6ba6f06519b899 (diff)
Fix exception when running HA tests without pod.yaml
1. use volumes '-v' to map files/directories which may be non-existing 2. use mounts '--mount' to map files/directories which couldn't be non-existing JIRA: DOVETAIL-789 Change-Id: I2184e5baed3d1491a2df4d3a1a77a11e3e9b4fc8 Signed-off-by: xudan <xudan16@huawei.com>
Diffstat (limited to 'dovetail/tests/unit')
-rw-r--r--dovetail/tests/unit/test_container.py30
-rw-r--r--dovetail/tests/unit/test_test_runner.py12
-rw-r--r--dovetail/tests/unit/utils/test_dovetail_utils.py20
3 files changed, 54 insertions, 8 deletions
diff --git a/dovetail/tests/unit/test_container.py b/dovetail/tests/unit/test_container.py
index 01c1d8fd..86da9d3c 100644
--- a/dovetail/tests/unit/test_container.py
+++ b/dovetail/tests/unit/test_container.py
@@ -409,6 +409,7 @@ class ContainerTesting(unittest.TestCase):
container_id = 'container_id'
mock_utils.get_value_from_dict.side_effect = [
{'key': 'value'}, 'shell', 'envs', ['volume_one', 'volume_two']]
+ mock_utils.get_mount_list.side_effect = [['mount', 'list'], 'success']
mock_utils.get_hosts_info.return_value = 'host_info'
container_obj = Mock()
container_obj.id = container_id
@@ -417,7 +418,7 @@ class ContainerTesting(unittest.TestCase):
mock_config.dovetail_config = {'bottlenecks': project_config}
expected = container_id
- result = self.container.create(docker_image)
+ result, msg = self.container.create(docker_image)
mock_utils.get_value_from_dict.assert_has_calls([
call('opts', project_config),
@@ -426,6 +427,7 @@ class ContainerTesting(unittest.TestCase):
call('volumes', project_config)])
mock_utils.get_hosts_info.assert_called_once_with(self.logger)
self.assertEqual(expected, result)
+ self.assertEqual('Successfully to create container.', msg)
@patch('dovetail.container.dt_utils')
@patch('dovetail.container.dt_cfg')
@@ -435,12 +437,32 @@ class ContainerTesting(unittest.TestCase):
mock_utils.get_value_from_dict.side_effect = ['opts', None]
mock_utils.get_hosts_info.return_value = 'host_info'
- result = self.container.create(docker_image)
+ result, msg = self.container.create(docker_image)
mock_utils.get_value_from_dict.assert_has_calls([
call('opts', 'value'),
call('shell', 'value')])
self.assertEqual(None, result)
+ self.assertEqual("Lacking of key word 'shell' in config file.", msg)
+
+ @patch('dovetail.container.dt_utils')
+ @patch('dovetail.container.dt_cfg')
+ def test_create_mounts_none(self, mock_config, mock_utils):
+ docker_image = 'docker_image'
+ project_config = {}
+ mock_config.dovetail_config = {'bottlenecks': project_config}
+ mock_utils.get_value_from_dict.side_effect = [
+ {'key': 'value'}, 'shell', ['envs'], ['volume_one']]
+ mock_utils.get_mount_list.side_effect = [[None, 'error']]
+ mock_utils.get_hosts_info.return_value = 'host_info'
+
+ result, msg = self.container.create(docker_image)
+
+ mock_utils.get_value_from_dict.assert_has_calls([
+ call('opts', project_config), call('shell', project_config),
+ call('envs', project_config), call('volumes', project_config)])
+ self.assertEqual(None, result)
+ self.assertEqual('error', msg)
@patch('dovetail.container.dt_utils')
@patch('dovetail.container.dt_cfg')
@@ -448,13 +470,14 @@ class ContainerTesting(unittest.TestCase):
docker_image = 'docker_image'
mock_utils.get_value_from_dict.side_effect = [
{'key': 'value'}, 'shell', ['envs'], ['volume_one']]
+ mock_utils.get_mount_list.side_effect = [['mount', 'list'], 'success']
mock_utils.get_hosts_info.return_value = 'host_info'
mock_utils.check_https_enabled.return_value = True
self.client.containers.run.side_effect = \
docker.errors.ImageNotFound('error')
project_config = {}
mock_config.dovetail_config = {'bottlenecks': project_config}
- result = self.container.create(docker_image)
+ result, msg = self.container.create(docker_image)
mock_utils.get_value_from_dict.assert_has_calls([
call('opts', project_config),
@@ -463,3 +486,4 @@ class ContainerTesting(unittest.TestCase):
call('volumes', project_config)])
mock_utils.get_hosts_info.assert_called_once_with(self.logger)
self.assertEqual(None, result)
+ self.assertEqual('error', str(docker.errors.ImageNotFound('error')))
diff --git a/dovetail/tests/unit/test_test_runner.py b/dovetail/tests/unit/test_test_runner.py
index 3cb27536..232de7b1 100644
--- a/dovetail/tests/unit/test_test_runner.py
+++ b/dovetail/tests/unit/test_test_runner.py
@@ -107,7 +107,7 @@ class TestRunnerTesting(unittest.TestCase):
docker_img_obj = Mock()
container_obj.get_docker_image.return_value = docker_img_obj
container_obj.pull_image.return_value = True
- container_obj.create.return_value = False
+ container_obj.create.return_value = [None, 'error']
mock_container.return_value = container_obj
docker_runner.run()
@@ -116,8 +116,8 @@ class TestRunnerTesting(unittest.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.error.assert_called_once_with(
- 'Failed to create container.')
+ docker_runner.logger.error.assert_has_calls([
+ call('Failed to create container.'), call('error')])
@patch('dovetail.test_runner.dt_utils')
@patch('dovetail.test_runner.dt_cfg')
@@ -137,7 +137,8 @@ class TestRunnerTesting(unittest.TestCase):
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
+ container_msg = 'Successfully to create container.'
+ container_obj.create.return_value = [container_id, container_msg]
mock_container.return_value = container_obj
self.testcase.pre_condition.return_value = ['cmd']
self.testcase.prepare_cmd.return_value = False
@@ -180,7 +181,8 @@ class TestRunnerTesting(unittest.TestCase):
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
+ container_msg = 'Successfully to create container.'
+ container_obj.create.return_value = [container_id, container_msg]
mock_container.return_value = container_obj
self.testcase.pre_condition.return_value = ['cmd']
self.testcase.prepare_cmd.return_value = True
diff --git a/dovetail/tests/unit/utils/test_dovetail_utils.py b/dovetail/tests/unit/utils/test_dovetail_utils.py
index 7ec177d1..7d1fddc1 100644
--- a/dovetail/tests/unit/utils/test_dovetail_utils.py
+++ b/dovetail/tests/unit/utils/test_dovetail_utils.py
@@ -1380,3 +1380,23 @@ class DovetailUtilsTesting(unittest.TestCase):
logger.debug.assert_not_called()
logger.exception.assert_called_once_with(
"The results cannot be pushed to DB.")
+
+ def test_get_mount_list_error_mount(self):
+ project_cfg = {'mounts': ['aaa']}
+ res, msg = dovetail_utils.get_mount_list(project_cfg)
+ self.assertEqual(None, res)
+ self.assertEqual('Error mount aaa.', msg)
+
+ def test_get_mount_list_keyerror_exception(self):
+ project_cfg = {'mounts': ['aaa=a,bbb=b', '']}
+ res, msg = dovetail_utils.get_mount_list(project_cfg)
+ self.assertEqual(None, res)
+ self.assertEqual("'target'", str(msg))
+
+ def test_get_mount_list(self):
+ project_cfg = {'mounts': ['target=a,source=b', '']}
+ res, msg = dovetail_utils.get_mount_list(project_cfg)
+ expected = [{'Source': 'b', 'Type': 'bind', 'ReadOnly': False,
+ 'Target': 'a'}]
+ self.assertEqual(expected, res)
+ self.assertEqual('Successfully to get mount list.', msg)