diff --git a/ansible/library/kolla_docker.py b/ansible/library/kolla_docker.py index 6f5a940cd6..341fdd0b7f 100644 --- a/ansible/library/kolla_docker.py +++ b/ansible/library/kolla_docker.py @@ -574,10 +574,13 @@ class DockerWorker(object): if not container: self.start_container() - elif container and config_strategy == 'COPY_ONCE': + return + # If config_strategy is COPY_ONCE or container's parameters are + # changed, try to start a new one. + if config_strategy == 'COPY_ONCE' or self.check_container_differs(): self.remove_container() self.start_container() - elif container and config_strategy == 'COPY_ALWAYS': + elif config_strategy == 'COPY_ALWAYS': self.restart_container() def start_container(self): diff --git a/tests/test_kolla_docker.py b/tests/test_kolla_docker.py index bc5e910e68..0a28f63d74 100644 --- a/tests/test_kolla_docker.py +++ b/tests/test_kolla_docker.py @@ -396,11 +396,26 @@ class TestContainer(base.BaseTestCase): self.dw.check_container = mock.Mock( return_value=self.fake_data['containers'][0]) self.dw.restart_container = mock.Mock() + self.dw.check_container_differs = mock.Mock(return_value=False) self.dw.recreate_or_restart_container() self.dw.restart_container.assert_called_once_with() + def test_recreate_or_restart_container_container_copy_always_differs(self): + self.dw = get_DockerWorker({ + 'environment': dict(KOLLA_CONFIG_STRATEGY='COPY_ALWAYS')}) + self.dw.check_container = mock.Mock( + return_value=self.fake_data['containers'][0]) + self.dw.start_container = mock.Mock() + self.dw.remove_container = mock.Mock() + self.dw.check_container_differs = mock.Mock(return_value=True) + + self.dw.recreate_or_restart_container() + + self.dw.remove_container.assert_called_once_with() + self.dw.start_container.assert_called_once_with() + def test_recreate_or_restart_container_container_copy_once(self): self.dw = get_DockerWorker({ 'environment': dict(KOLLA_CONFIG_STRATEGY='COPY_ONCE')})