X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=planetstack%2Fhpc_observer%2Fsteps%2Fsync_contentprovider.py;h=cebe1869264592b7cfa60c38d321841376b0fcbb;hb=7c30a429254eaf1cd2fe6721f783c2d3cb7e8d67;hp=e10dca95b89678044628f592943ed45c262716dd;hpb=b2b4484421b94ff9d92b84d69c567fd14a61ecb1;p=plstackapi.git diff --git a/planetstack/hpc_observer/steps/sync_contentprovider.py b/planetstack/hpc_observer/steps/sync_contentprovider.py index e10dca9..cebe186 100644 --- a/planetstack/hpc_observer/steps/sync_contentprovider.py +++ b/planetstack/hpc_observer/steps/sync_contentprovider.py @@ -24,6 +24,20 @@ class SyncContentProvider(SyncStep, HpcLibrary): SyncStep.__init__(self, **args) HpcLibrary.__init__(self) + def fetch_pending(self, deleted): + self.sanity_check() + + return SyncStep.fetch_pending(self, deleted) + + def sanity_check(self): + # sanity check to make sure our PS objects have CMI objects behind them + all_cp_ids = [x["content_provider_id"] for x in self.client.onev.ListAll("ContentProvider")] + for cp in ContentProvider.objects.all(): + if (cp.content_provider_id is not None) and (cp.content_provider_id not in all_cp_ids): + logger.info("Content provider %s was not found on CMI" % cp.content_provider_id) + cp.content_provider_id=None + cp.save() + def sync_record(self, cp): logger.info("sync'ing content provider %s" % str(cp)) account_name = self.make_account_name(cp.name) @@ -48,5 +62,6 @@ class SyncContentProvider(SyncStep, HpcLibrary): cp.save() def delete_record(self, m): - self.client.onev.Delete("ContentProvider", m.content_provider_id) + if m.content_provider_id is not None: + self.client.onev.Delete("ContentProvider", m.content_provider_id)