Merge "Create a new container when restart a container when necessary"

This commit is contained in:
Jenkins 2017-02-04 06:09:11 +00:00 committed by Gerrit Code Review
commit 6c33871071
2 changed files with 20 additions and 2 deletions

View File

@ -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):

View File

@ -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')})