Skip to content

Commit 6e75c1f

Browse files
Zuulopenstack-gerrit
authored andcommitted
Merge "Fix retries when pushing images" into stable/stein
2 parents 89bf48d + f79df0f commit 6e75c1f

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

kolla/image/build.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,9 @@ def push_image(self, image):
368368
image.status = STATUS_ERROR
369369
self.logger.error(response['errorDetail']['message'])
370370

371+
# Reset any previous errors.
372+
image.status = STATUS_BUILT
373+
371374

372375
class BuildTask(DockerTask):
373376
"""Task that builds out an image."""

kolla/tests/test_build.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,40 @@ def test_push_image(self, mock_client):
7777
pusher.run()
7878
mock_client().push.assert_called_once_with(
7979
self.image.canonical_name, decode=True, stream=True)
80+
self.assertTrue(pusher.success)
81+
82+
@mock.patch('docker.version', '3.0.0')
83+
@mock.patch.dict(os.environ, clear=True)
84+
@mock.patch('docker.APIClient')
85+
def test_push_image_failure(self, mock_client):
86+
self.dc = mock_client
87+
mock_client().push.side_effect = Exception
88+
pusher = build.PushTask(self.conf, self.image)
89+
pusher.run()
90+
mock_client().push.assert_called_once_with(
91+
self.image.canonical_name, decode=True, stream=True)
92+
self.assertFalse(pusher.success)
93+
self.assertEqual(build.STATUS_PUSH_ERROR, self.image.status)
94+
95+
@mock.patch('docker.version', '3.0.0')
96+
@mock.patch.dict(os.environ, clear=True)
97+
@mock.patch('docker.APIClient')
98+
def test_push_image_failure_retry(self, mock_client):
99+
self.dc = mock_client
100+
mock_client().push.side_effect = [Exception, []]
101+
pusher = build.PushTask(self.conf, self.image)
102+
pusher.run()
103+
mock_client().push.assert_called_once_with(
104+
self.image.canonical_name, decode=True, stream=True)
105+
self.assertFalse(pusher.success)
106+
self.assertEqual(build.STATUS_PUSH_ERROR, self.image.status)
107+
108+
# Try again, this time without exception.
109+
pusher.reset()
110+
pusher.run()
111+
self.assertEqual(2, mock_client().push.call_count)
112+
self.assertTrue(pusher.success)
113+
self.assertEqual(build.STATUS_BUILT, self.image.status)
80114

81115
@mock.patch.dict(os.environ, clear=True)
82116
@mock.patch('docker.APIClient')

0 commit comments

Comments
 (0)