diff options
-rw-r--r-- | dovetail/container.py | 8 | ||||
-rw-r--r-- | dovetail/tests/unit/test_container.py | 7 |
2 files changed, 11 insertions, 4 deletions
diff --git a/dovetail/container.py b/dovetail/container.py index ed006dc9..d44035cd 100644 --- a/dovetail/container.py +++ b/dovetail/container.py @@ -168,10 +168,10 @@ class Container(object): def clean(self): cmd = ('sudo docker rm -f {}'.format(self.container_id)) dt_utils.exec_cmd(cmd, self.logger) - if self.valid_type.lower() == 'bottlenecks': - containers = dt_utils.get_value_from_dict( - 'extra_container', dt_cfg.dovetail_config[self.valid_type]) - for container in containers: + extra_containers = dt_utils.get_value_from_dict( + 'extra_container', dt_cfg.dovetail_config[self.valid_type]) + if extra_containers: + for container in extra_containers: if self.check_container_exist(container): cmd = ('sudo docker rm -f {}'.format(container)) dt_utils.exec_cmd(cmd, self.logger) diff --git a/dovetail/tests/unit/test_container.py b/dovetail/tests/unit/test_container.py index 70e01d8e..25509a70 100644 --- a/dovetail/tests/unit/test_container.py +++ b/dovetail/tests/unit/test_container.py @@ -154,6 +154,13 @@ class ContainerTesting(unittest.TestCase): call('sudo docker rm -f None', self.logger), call('sudo docker rm -f container', self.logger)]) + @patch('dovetail.container.dt_cfg') + @patch('dovetail.container.dt_utils') + def test_clean_no_extra_container(self, mock_utils, mock_config): + mock_utils.get_value_from_dict.return_value = None + self.container.clean() + mock_utils.get_value_from_dict.assert_called_once() + @patch('dovetail.container.dt_utils') def test_check_container_exist_true(self, mock_utils): container_name = 'container' |