Fix project delete failures 31/1431/1
authorPhilip Joseph <philip.joseph@riftio.com>
Thu, 30 Mar 2017 19:55:29 +0000 (01:25 +0530)
committerPhilip Joseph <philip.joseph@riftio.com>
Thu, 30 Mar 2017 19:55:29 +0000 (01:25 +0530)
Signed-off-by: Philip Joseph <philip.joseph@riftio.com>
common/python/rift/mano/cloud/config.py
common/python/rift/mano/cloud/operdata.py
common/python/rift/mano/dts/subscriber/core.py
rwlaunchpad/plugins/rwlaunchpadtasklet/rift/tasklets/rwlaunchpad/tasklet.py
rwlaunchpad/plugins/rwnsm/rift/tasklets/rwnsmtasklet/rwnsm_conman.py
rwlaunchpad/plugins/rwnsm/rift/tasklets/rwnsmtasklet/rwnsmtasklet.py
rwlaunchpad/plugins/rwresmgr/rift/tasklets/rwresmgrtasklet/rwresmgr_config.py
rwlaunchpad/plugins/rwvnfm/rift/tasklets/rwvnfmtasklet/rwvnfmtasklet.py

index f7906fd..a5ed7b5 100644 (file)
@@ -128,6 +128,7 @@ class CloudAccountConfigSubscriber(object):
             self._reg.deregister()
             self._reg = None
 
+    @asyncio.coroutine
     def register(self):
         @asyncio.coroutine
         def apply_config(dts, acg, xact, action, scratch):
index a86f638..59084ef 100644 (file)
@@ -73,6 +73,7 @@ class CloudAccountDtsOperdataHandler(object):
         self._log.info("Notification called by creating dts query: %s", ac_status)
 
 
+    @asyncio.coroutine
     def _register_show_status(self):
         def get_xpath(cloud_name=None):
             return "D,/rw-cloud:cloud/account{}/connection-status".format(
@@ -83,7 +84,8 @@ class CloudAccountDtsOperdataHandler(object):
         def on_prepare(xact_info, action, ks_path, msg):
             path_entry = RwCloudYang.CloudAcc.schema().keyspec_to_entry(ks_path)
             cloud_account_name = path_entry.key00.name
-            self._log.debug("Got show cloud connection status request: %s", ks_path.create_string())
+            self._log.debug("Got show cloud connection status request (action: %s): %s",
+                            xact_info.query_action, ks_path.create_string())
 
             try:
                 saved_accounts = self.get_saved_cloud_accounts(cloud_account_name)
@@ -111,6 +113,7 @@ class CloudAccountDtsOperdataHandler(object):
                 flags=rwdts.Flag.PUBLISHER,
                 )
 
+    @asyncio.coroutine
     def _register_validate_rpc(self):
         def get_xpath():
             return "/rw-cloud:update-cloud-status"
@@ -150,9 +153,11 @@ class CloudAccountDtsOperdataHandler(object):
 
     @asyncio.coroutine
     def register(self):
+        self._log.debug("Register cloud account for project %s", self._project.name)
         yield from self._register_show_status()
         yield from self._register_validate_rpc()
 
     def deregister(self):
-        yield from self._rpc.deregister()
-        yield from self._regh.deregister()
+        self._log.debug("De-register cloud account for project %s", self._project.name)
+        self._rpc.deregister()
+        self._regh.deregister()
index ebd38f9..a2181e8 100644 (file)
@@ -161,11 +161,6 @@ class AbstractConfigSubscriber(SubscriberDtsHandler):
     def register(self):
         """ Register for VNFD configuration"""
 
-        if self.reg:
-            self._log.warning("RPC already registered for project {}".
-                              format(self._project.name))
-            return
-
         def on_apply(dts, acg, xact, action, scratch):
             """Apply the  configuration"""
             is_recovery = xact.xact is None and action == rwdts.AppconfAction.INSTALL
@@ -188,6 +183,8 @@ class AbstractConfigSubscriber(SubscriberDtsHandler):
         @asyncio.coroutine
         def on_prepare(dts, acg, xact, xact_info, ks_path, msg, scratch):
             """ on prepare callback """
+            self._log.debug("Subscriber DTS prepare for project %s: %s",
+                            self.project, xact_info.query_action)
             xact_info.respond_xpath(rwdts.XactRspCode.ACK)
 
         acg_hdl = rift.tasklets.AppConfGroup.Handler(on_apply=on_apply)
index f38bbc6..d416f9c 100644 (file)
@@ -314,12 +314,12 @@ class CloudAccountHandlers(object):
 
     @asyncio.coroutine
     def register(self):
-        self.cloud_cfg_handler.register()
+        yield from self.cloud_cfg_handler.register()
         yield from self.cloud_operdata_handler.register()
 
     def deregister(self):
         self.cloud_cfg_handler.deregister()
-        yield from self.cloud_operdata_handler.deregister()
+        self.cloud_operdata_handler.deregister()
 
 
 class LaunchpadProject(ManoProject):
@@ -385,8 +385,9 @@ class LaunchpadProject(ManoProject):
 
     @asyncio.coroutine
     def delete_prepare(self):
-        if self.nsd_catalog or self.vnfd_catalog or self.vld_catalog:
-            return False
+        # TODO: Do we need this check
+        # if self.nsd_catalog or self.vnfd_catalog or self.vld_catalog:
+        #     return False
         return True
 
     @property
index 1988cc4..7d05457 100644 (file)
@@ -120,7 +120,7 @@ class ROConfigManager(object):
     @asyncio.coroutine
     def register(self):
         """ Register for cm-state changes """
-        
+
         @asyncio.coroutine
         def on_prepare(xact_info, query_action, ks_path, msg):
             """ cm-state changed """
@@ -152,4 +152,9 @@ class ROConfigManager(object):
                                                              handler=handler)
         except Exception as e:
             self._log.error("Failed to register for cm-state changes as %s", str(e))
-            
+
+
+    def deregister(self):
+        if self.dts_reg_hdl:
+            self.dts_reg_hdl.deregister()
+            self.dts_reg_hdl = None
index e739684..ff00b2b 100755 (executable)
@@ -2823,11 +2823,17 @@ class NsdDtsHandler(object):
             is_recovery = xact.xact is None and action == rwdts.AppconfAction.INSTALL
             self._log.debug("Got nsd apply cfg (xact:%s) (action:%s)",
                             xact, action)
-            # Create/Update an NSD record
-            for cfg in self._regh.get_xact_elements(xact):
-                # Only interested in those NSD cfgs whose ID was received in prepare callback
-                if cfg.id in scratch.get('nsds', []) or is_recovery:
-                    self._nsm.update_nsd(cfg)
+
+            if self._regh:
+                # Create/Update an NSD record
+                for cfg in self._regh.get_xact_elements(xact):
+                    # Only interested in those NSD cfgs whose ID was received in prepare callback
+                    if cfg.id in scratch.get('nsds', []) or is_recovery:
+                        self._nsm.update_nsd(cfg)
+
+            else:
+                self._log.error("No reg handle for {} for project {}".
+                                format(self.__class__, self._project.name))
 
             scratch.pop('nsds', None)
 
@@ -2929,15 +2935,20 @@ class VnfdDtsHandler(object):
             self._log.debug("Got NSM VNFD apply (xact: %s) (action: %s)(scr: %s)",
                             xact, action, scratch)
 
-            # Create/Update a VNFD record
-            for cfg in self._regh.get_xact_elements(xact):
-                # Only interested in those VNFD cfgs whose ID was received in prepare callback
-                if cfg.id in scratch.get('vnfds', []):
-                    self._nsm.update_vnfd(cfg)
+            if self._regh:
+                # Create/Update a VNFD record
+                for cfg in self._regh.get_xact_elements(xact):
+                    # Only interested in those VNFD cfgs whose ID was received in prepare callback
+                    if cfg.id in scratch.get('vnfds', []):
+                        self._nsm.update_vnfd(cfg)
 
-            for cfg in self._regh.elements:
-                if cfg.id in scratch.get('deleted_vnfds', []):
-                    yield from self._nsm.delete_vnfd(cfg.id)
+                        for cfg in self._regh.elements:
+                            if cfg.id in scratch.get('deleted_vnfds', []):
+                                yield from self._nsm.delete_vnfd(cfg.id)
+
+            else:
+                self._log.error("Reg handle none for {} in project {}".
+                                format(self.__class__, self._project))
 
             scratch.pop('vnfds', None)
             scratch.pop('deleted_vnfds', None)
@@ -3349,11 +3360,20 @@ class NsrDtsHandler(object):
 
             if action == rwdts.AppconfAction.INSTALL and xact.id is None:
                 key_pairs = []
-                for element in self._key_pair_regh.elements:
-                    key_pairs.append(element)
-                for element in self._nsr_regh.elements:
-                    nsr = handle_create_nsr(element, key_pairs, restart_mode=True)
-                    self._loop.create_task(begin_instantiation(nsr))
+                if self._key_pair_regh:
+                    for element in self._key_pair_regh.elements:
+                        key_pairs.append(element)
+                else:
+                    self._log.error("Reg handle none for key pair in project {}".
+                                    format(self._project))
+
+                if self._nsr_regh:
+                    for element in self._nsr_regh.elements:
+                        nsr = handle_create_nsr(element, key_pairs, restart_mode=True)
+                        self._loop.create_task(begin_instantiation(nsr))
+                else:
+                    self._log.error("Reg handle none for NSR in project {}".
+                                    format(self._project))
 
 
             (added_msgs, deleted_msgs, updated_msgs) = get_add_delete_update_cfgs(self._nsr_regh,
@@ -3662,7 +3682,7 @@ class VnfrDtsHandler(object):
 
     def deregister(self):
         self._log.debug("De-register VNFR for project {}".
-                        format(self._project.name))
+                        format(self._nsm._project.name))
         if self._regh:
             self._regh.deregister()
             self._regh = None
@@ -3724,7 +3744,7 @@ class NsdRefCountDtsHandler(object):
 
     def deregister(self):
         self._log.debug("De-register NSD Ref count for project {}".
-                        format(self._project.name))
+                        format(self._nsm._project.name))
         if self._regh:
             self._regh.deregister()
             self._regh = None
@@ -3850,7 +3870,7 @@ class NsManager(object):
     def deregister(self):
         """ Register all static DTS handlers """
         for dts_handle in self._dts_handlers:
-            yield from dts_handle.deregister()
+            dts_handle.deregister()
 
 
     def get_ns_by_nsr_id(self, nsr_id):
@@ -4537,6 +4557,14 @@ class NsmProject(ManoProject):
         self._vnffgmgr.deregister()
         self._cloud_account_handler.deregister()
         self._ro_plugin_selector.deregister()
+        self._nsm = None
+
+    @asyncio.coroutine
+    def delete_prepare(self):
+        # Check if any NS instance is present
+        if self._nsm and self._nsm._nsrs:
+            return False
+        return True
 
 
 class NsmTasklet(rift.tasklets.Tasklet):
index 1b1c9bf..9f6dcfd 100644 (file)
@@ -57,7 +57,7 @@ class ResourceMgrConfig(object):
     @asyncio.coroutine
     def register(self):
         yield from self.register_resource_pool_operational_data()
-        self.register_cloud_account_config()
+        yield from self.register_cloud_account_config()
 
     def deregister(self):
         self._log.debug("De-register for project {}".format(self._project.name))
@@ -71,6 +71,7 @@ class ResourceMgrConfig(object):
             self._res_sub.deregister()
             self._res_sub = None
 
+    @asyncio.coroutine
     def register_cloud_account_config(self):
         def on_add_cloud_account_apply(account):
             self._log.debug("Received on_add_cloud_account: %s", account)
@@ -95,7 +96,7 @@ class ResourceMgrConfig(object):
             self._dts, self._log, self._rwlog_hdl,
             self._project, cloud_callbacks
         )
-        self._cloud_sub.register()
+        yield from self._cloud_sub.register()
 
     @asyncio.coroutine
     def register_resource_pool_operational_data(self):
index b198dd8..a6277f1 100755 (executable)
@@ -2622,7 +2622,7 @@ class VnfManager(object):
     def deregister(self):
         self.log.debug("De-register VNFM project {}".format(self.name))
         for hdl in self._dts_handlers:
-            yield from hdl.deregister()
+            hdl.deregister()
 
     @asyncio.coroutine
     def run(self):