Merge pull request #3336 from quay/small-cleanup

Some small cleanup to the tag backfill worker
This commit is contained in:
Joseph Schorr 2019-01-21 13:43:46 -05:00 committed by GitHub
commit 171e2ec39b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 4 additions and 7 deletions

View file

@ -194,10 +194,6 @@ class DockerSchema1Manifest(ManifestInterface):
if validate: if validate:
self._validate() self._validate()
@classmethod
def for_latin1_bytes(cls, encoded_bytes, validate=True):
return DockerSchema1Manifest(Bytes.for_string_or_unicode(encoded_bytes), validate)
def _validate(self): def _validate(self):
if not self._signatures: if not self._signatures:
return return

View file

@ -131,7 +131,7 @@ def test_validate_manifest_with_unicode_encoded():
with open(os.path.join(test_dir, 'manifest_unicode_row.json'), 'r') as f: with open(os.path.join(test_dir, 'manifest_unicode_row.json'), 'r') as f:
manifest_bytes = json.loads(f.read())[0]['json_data'] manifest_bytes = json.loads(f.read())[0]['json_data']
manifest = DockerSchema1Manifest.for_latin1_bytes(manifest_bytes, validate=True) manifest = DockerSchema1Manifest(Bytes.for_string_or_unicode(manifest_bytes), validate=True)
digest = manifest.digest digest = manifest.digest
assert digest == 'sha256:dde3714ce7e23edc6413aa85c0b42792e4f2f79e9ea36afc154d63ff3d04e86c' assert digest == 'sha256:dde3714ce7e23edc6413aa85c0b42792e4f2f79e9ea36afc154d63ff3d04e86c'
assert manifest.created_datetime assert manifest.created_datetime

View file

@ -175,7 +175,7 @@ def backfill_tag(repositorytag):
if lookup_map_row(repositorytag): if lookup_map_row(repositorytag):
return False return False
# Grab the manifest for the RepositoryTag, backfilling is necessary. # Grab the manifest for the RepositoryTag, backfilling as necessary.
manifest_id = _get_manifest_id(repositorytag) manifest_id = _get_manifest_id(repositorytag)
if manifest_id is None: if manifest_id is None:
return False return False
@ -269,7 +269,8 @@ def _backfill_manifest(tag_manifest):
# without additional rows or data, as it will eventually not be useful. # without additional rows or data, as it will eventually not be useful.
is_broken = False is_broken = False
try: try:
manifest = DockerSchema1Manifest.for_latin1_bytes(tag_manifest.json_data, validate=False) manifest = DockerSchema1Manifest(Bytes.for_string_or_unicode(tag_manifest.json_data),
validate=False)
except ManifestException: except ManifestException:
logger.exception('Exception when trying to parse manifest %s', tag_manifest.id) logger.exception('Exception when trying to parse manifest %s', tag_manifest.id)
manifest = BrokenManifest(tag_manifest.digest, tag_manifest.json_data) manifest = BrokenManifest(tag_manifest.digest, tag_manifest.json_data)