Merge "Create a new container when restart a container when necessary"
This commit is contained in:
commit
6c33871071
@ -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):
|
||||
|
@ -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')})
|
||||
|
Loading…
Reference in New Issue
Block a user