Fill backfill script for recent changes

We forgot that we need to lookup by user *object* and we need to lookup locations on their own
This commit is contained in:
Joseph Schorr 2017-04-19 16:50:51 -04:00
parent 624d8e1851
commit 08b9c4b0d4

View file

@ -2,7 +2,8 @@ import logging
import features import features
from app import storage, image_replication_queue from app import storage, image_replication_queue
from data.database import Image, ImageStorage, Repository, User from data.database import (Image, ImageStorage, Repository, User, ImageStoragePlacement,
ImageStorageLocation)
from data import model from data import model
from util.registry.replication import queue_storage_replication from util.registry.replication import queue_storage_replication
@ -19,10 +20,17 @@ def backfill_replication():
if image.storage.uuid in encountered: if image.storage.uuid in encountered:
continue continue
namespace = image.repository.namespace_user.username namespace = image.repository.namespace_user
locations = model.user.get_region_locations(namespace) locations = model.user.get_region_locations(namespace)
locations_required = locations | set(storage.default_locations) locations_required = locations | set(storage.default_locations)
locations_missing = locations_required - set(image.storage.locations)
query = (ImageStoragePlacement
.select(ImageStoragePlacement, ImageStorageLocation)
.where(ImageStoragePlacement.storage == image.storage)
.join(ImageStorageLocation))
existing_locations = set([p.location.name for p in query])
locations_missing = locations_required - existing_locations
if locations_missing: if locations_missing:
print "Enqueueing image storage %s to be replicated" % (image.storage.uuid) print "Enqueueing image storage %s to be replicated" % (image.storage.uuid)
encountered.add(image.storage.uuid) encountered.add(image.storage.uuid)