fix race condition after pulling image

Signed-off-by: Stephan Müller <mail@stephanmueller.eu>
This commit is contained in:
Stephan Müller 2019-01-09 23:14:12 +01:00
parent 4bd93b95a9
commit 56fbd22825
No known key found for this signature in database
GPG Key ID: 4650F39E5B5E1894
2 changed files with 23 additions and 21 deletions

View File

@ -98,14 +98,14 @@ def print_output_event(event, stream, is_terminal):
def get_digest_from_pull(events):
digest = None
for event in events:
status = event.get('status')
if not status or 'Digest' not in status:
continue
_, digest = status.split(':', 1)
return digest.strip()
return None
else:
digest = status.split(':', 1)[1].strip()
return digest
def get_digest_from_push(events):

View File

@ -97,8 +97,7 @@ class ProgressStreamTestCase(unittest.TestCase):
tf.seek(0)
assert tf.read() == '???'
def test_get_digest_from_push():
def test_get_digest_from_push(self):
digest = "sha256:abcd"
events = [
{"status": "..."},
@ -107,12 +106,15 @@ def test_get_digest_from_push():
]
assert progress_stream.get_digest_from_push(events) == digest
def test_get_digest_from_pull(self):
events = list()
assert progress_stream.get_digest_from_pull(events) is None
def test_get_digest_from_pull():
digest = "sha256:abcd"
events = [
{"status": "..."},
{"status": "..."},
{"status": "Digest: %s" % digest},
{"status": "..."},
]
assert progress_stream.get_digest_from_pull(events) == digest