Browse Source

Merge "Attempt to pull image before stopping and removing container"

changes/15/694815/1
Zuul 3 weeks ago
parent
commit
82c22c9050
3 changed files with 35 additions and 0 deletions
  1. +5
    -0
      ansible/library/kolla_docker.py
  2. +6
    -0
      releasenotes/notes/fix-recreate-missing-pull-dba93327fd4c94c3.yaml
  3. +24
    -0
      tests/test_kolla_docker.py

+ 5
- 0
ansible/library/kolla_docker.py View File

@@ -742,6 +742,11 @@ class DockerWorker(object):
# 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():
# NOTE(mgoddard): Pull the image if necessary before stopping the
# container, otherwise a failure to pull the image will leave the
# container stopped.
if not self.check_image():
self.pull_image()
self.stop_container()
self.remove_container()
self.start_container()

+ 6
- 0
releasenotes/notes/fix-recreate-missing-pull-dba93327fd4c94c3.yaml View File

@@ -0,0 +1,6 @@
---
fixes:
- |
Fixes an issue where a failure in pulling an image could lead to a
container being removed and not replaced. See `bug 1852572
<https://bugs.launchpad.net/kolla-ansible/+bug/1852572>`__ for details.

+ 24
- 0
tests/test_kolla_docker.py View File

@@ -545,12 +545,15 @@ class TestContainer(base.BaseTestCase):
'environment': dict(KOLLA_CONFIG_STRATEGY='COPY_ALWAYS')})
self.dw.check_container = mock.Mock(
return_value=self.fake_data['containers'][0])
self.dw.check_image = mock.Mock(
return_value=self.fake_data['images'][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.check_image.assert_called_once_with()
self.dw.remove_container.assert_called_once_with()
self.dw.start_container.assert_called_once_with()

@@ -559,11 +562,32 @@ class TestContainer(base.BaseTestCase):
'environment': dict(KOLLA_CONFIG_STRATEGY='COPY_ONCE')})
self.dw.check_container = mock.Mock(
return_value=self.fake_data['containers'][0])
self.dw.check_image = mock.Mock(
return_value=self.fake_data['images'][0])
self.dw.start_container = mock.Mock()
self.dw.remove_container = mock.Mock()

self.dw.recreate_or_restart_container()

self.dw.check_image.assert_called_once_with()
self.dw.remove_container.assert_called_once_with()
self.dw.start_container.assert_called_once_with()

def test_recreate_or_restart_container_pull_before_stop(self):
# Testing fix for https://launchpad.net/bugs/1852572.
self.dw = get_DockerWorker({
'environment': dict(KOLLA_CONFIG_STRATEGY='COPY_ONCE')})
self.dw.check_container = mock.Mock(
return_value=self.fake_data['containers'][0])
self.dw.check_image = mock.Mock(return_value=None)
self.dw.pull_image = mock.Mock()
self.dw.start_container = mock.Mock()
self.dw.remove_container = mock.Mock()

self.dw.recreate_or_restart_container()

self.dw.check_image.assert_called_once_with()
self.dw.pull_image.assert_called_once_with()
self.dw.remove_container.assert_called_once_with()
self.dw.start_container.assert_called_once_with()


Loading…
Cancel
Save