Merge "Ignore unparsable/empty image upload ZNode data"

This commit is contained in:
Zuul 2020-09-03 05:41:59 +00:00 committed by Gerrit Code Review
commit 0bf8712c80
4 changed files with 40 additions and 3 deletions

View File

@ -417,6 +417,11 @@ class CleanupWorker(BaseWorker):
# between the getUploads() and the _inProgressUpload() check.
u = self._zk.getImageUpload(image, build_id, provider,
upload.id)
if not u:
self.log.warning(
"Ignoring invalid or empty image upload: %s", upload
)
continue
if upload.state != u.state:
continue
self.log.debug("Removing failed upload record: %s" % upload)

View File

@ -219,6 +219,8 @@ def image_list(zk):
image_name, build_no, provider):
upload = zk.getImageUpload(image_name, build_no,
provider, upload_no)
if not upload:
continue
values = [build_no, upload_no, provider, image_name,
upload.external_name,
upload.external_id,

View File

@ -130,6 +130,36 @@ class TestZooKeeper(tests.DBTestCase):
upload.id)
self.assertIsNone(self.zk.client.exists(path))
def test_imageUploadNumberLock_orphan(self):
upload = zk.ImageUpload()
upload.image_name = "ubuntu-trusty"
upload.build_id = "0000000003"
upload.provider_name = "providerA"
path = self.zk._imageUploadNumberLockPath(upload.image_name,
upload.build_id,
upload.provider_name,
upload.id)
with self.zk.imageUploadNumberLock(upload, blocking=False):
self.assertIsNotNone(self.zk.client.exists(path))
self.zk.deleteUpload(upload.image_name,
upload.build_id,
upload.provider_name,
upload.id)
# Pretend we still think the image upload exists
# (e.g. multiple cleanup workers itertating over uploads)
with self.zk.imageUploadNumberLock(upload, blocking=False):
# We now recreated an empty image upload number node
pass
self.assertIsNotNone(self.zk.client.exists(path))
# Should not throw an exception because of the empty upload
self.zk.getImageUpload(upload.image_name, upload.build_id,
upload.provider_name, upload.id)
def test_imageUploadNumberLock(self):
upload = zk.ImageUpload()
upload.image_name = "ubuntu-trusty"

View File

@ -1399,9 +1399,9 @@ class ZooKeeper(object):
image,
upload_number)
except json.decoder.JSONDecodeError:
self.log.exception('Error loading json data from image upload '
'%s, %s, %s', image, build_number, provider)
raise
self.log.exception('Error loading json data from image upload %s',
path)
return None
d.stat = stat
return d