From 828cdcf2bbdbd76ad4f9c89fa2d376df31c3c854 Mon Sep 17 00:00:00 2001 From: Andy Ning Date: Thu, 25 Apr 2019 10:03:01 -0400 Subject: [PATCH] Keystone DB sync - enhance dcorch first audit This commit enhanced dcorch find_missing algorithm so that the first audit after subcloud becomes managed won't try to create resources that have matches in the subcloud (otherwise the creation will fail for DB duplication error). This is neccessary for resources that are created at deployment time and existing resources not yet tracked by dcorch. Story: 2002842 Task: 22787 Change-Id: I60f94057caf71265942f3b37b400eeba4f368fed Signed-off-by: Andy Ning --- dcorch/engine/sync_services/identity.py | 16 +++++++++++++++- dcorch/engine/sync_services/network.py | 14 +++++++++++++- dcorch/engine/sync_thread.py | 8 ++++++++ 3 files changed, 36 insertions(+), 2 deletions(-) diff --git a/dcorch/engine/sync_services/identity.py b/dcorch/engine/sync_services/identity.py index 6a6a45d76..9e1cd7beb 100644 --- a/dcorch/engine/sync_services/identity.py +++ b/dcorch/engine/sync_services/identity.py @@ -22,6 +22,7 @@ from dcdbsync.dbsyncclient import exceptions as dbsync_exceptions from dcorch.common import consts from dcorch.common import exceptions from dcorch.engine.sync_thread import SyncThread +from dcorch.objects import resource from keystoneauth1 import exceptions as keystone_exceptions from keystoneclient import client as keystoneclient @@ -1404,6 +1405,7 @@ class IdentitySyncThread(SyncThread): return (m.id == sc.id and m.domain_id == sc.domain_id and m.name == sc.name and + m.description == sc.description and m.extra == sc.extra) def _has_same_role_ids(self, m, sc): @@ -1629,7 +1631,19 @@ class IdentitySyncThread(SyncThread): if self.has_same_ids(resource_type, m_r, sc_r): LOG.info("Mapping resource {} to existing subcloud resource {}" .format(m_r, sc_r), extra=self.log_extra) - self.persist_db_subcloud_resource(m_rsrc_db.id, + # If the resource is not even in master cloud resource DB, + # create it first. + rsrc = m_rsrc_db + if not rsrc: + master_id = self.get_resource_id(resource_type, m_r) + rsrc = resource.Resource( + self.ctxt, resource_type=resource_type, + master_id=master_id) + rsrc.create() + LOG.info("Resource created in DB {}/{}/{}".format( + rsrc.id, resource_type, master_id)) + + self.persist_db_subcloud_resource(rsrc.id, self.get_resource_id( resource_type, sc_r)) diff --git a/dcorch/engine/sync_services/network.py b/dcorch/engine/sync_services/network.py index 76e3e263d..8de4f08cb 100644 --- a/dcorch/engine/sync_services/network.py +++ b/dcorch/engine/sync_services/network.py @@ -354,7 +354,19 @@ class NetworkSyncThread(SyncThread): LOG.info( "Mapping resource {} to existing subcloud resource {}" .format(m_r, sc_r), extra=self.log_extra) - self.persist_db_subcloud_resource(m_rsrc_db.id, + # If the resource is not even in master cloud resource DB, + # create it first. + rsrc = m_rsrc_db + if not rsrc: + master_id = self.get_resource_id(resource_type, m_r) + rsrc = resource.Resource( + self.ctxt, resource_type=resource_type, + master_id=master_id) + rsrc.create() + LOG.info("Resource created in DB {}/{}/{}".format( + rsrc.id, resource_type, master_id)) + + self.persist_db_subcloud_resource(rsrc.id, sc_r['id']) return True return False diff --git a/dcorch/engine/sync_thread.py b/dcorch/engine/sync_thread.py index 5634fa39f..8527343a2 100644 --- a/dcorch/engine/sync_thread.py +++ b/dcorch/engine/sync_thread.py @@ -564,6 +564,14 @@ class SyncThread(object): LOG.info("{} not found in DB, will create it" .format(master_id), extra=self.log_extra) + # Check and see if there are any subcloud resources that + # match the master resource, and if so set up mappings. + # This returns true if it finds a match. + # This is for the case where the resource is not even in dcorch + # resource DB (ie, resource has not been tracked by dcorch yet) + if self.map_subcloud_resource(resource_type, m_r, + m_rsrc_db, sc_resources): + continue missing_resource = True if missing_resource: