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): def get_digest_from_pull(events):
digest = None
for event in events: for event in events:
status = event.get('status') status = event.get('status')
if not status or 'Digest' not in status: if not status or 'Digest' not in status:
continue continue
else:
_, digest = status.split(':', 1) digest = status.split(':', 1)[1].strip()
return digest.strip() return digest
return None
def get_digest_from_push(events): def get_digest_from_push(events):

View File

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