Bug 260 - Termination Logic for Scaled Instances 65/1865/2
authorprithiv <prithiv.mohan@intel.com>
Wed, 24 May 2017 10:27:00 +0000 (11:27 +0100)
committerprithiv <prithiv.mohan@intel.com>
Mon, 12 Jun 2017 16:24:55 +0000 (17:24 +0100)
Change-Id: Ic4c3341c594cab8a73554a2782f8f6bf8791abee
Signed-off-by: prithiv <prithiv.mohan@intel.com>
rwlaunchpad/plugins/rwnsm/rift/tasklets/rwnsmtasklet/openmano_nsm.py
rwlaunchpad/plugins/rwnsm/rift/tasklets/rwnsmtasklet/rwnsmtasklet.py

index f8ce1aa..cf9b656 100644 (file)
@@ -70,6 +70,9 @@ def dump_openmano_descriptor(name, descriptor_str):
 
     return filepath
 
+class VNFExistError(Exception):
+    pass
+
 class VnfrConsoleOperdataDtsHandler(object):
     """ registers 'D,/vnfr:vnfr-console/vnfr:vnfr[id]/vdur[id]' and handles CRUD from DTS"""
     @property
@@ -505,6 +508,16 @@ class OpenmanoNsr(object):
             yield from self._publisher.unpublish_vlr(None, vlr.vlr_msg)
         yield from asyncio.sleep(1, loop=self._loop)
 
+    @asyncio.coroutine
+    def remove_vnf(self,vnf):
+        if vnf in self._vnfrs:
+            self._vnfrs.remove(vnf)
+            yield from self._publisher.unpublish_vnfr(
+                None,
+                vnfr_msg
+              )
+        yield from asyncio.sleep(1, loop=self._loop)
+
     @asyncio.coroutine
     def delete_vlr(self, vlr):
         if vlr in self._vlrs:
@@ -916,6 +929,8 @@ class OpenmanoNsPlugin(rwnsmplugin.NsmPluginBase):
         self._http_api = None
         self._openmano_nsrs = {}
         self._vnfr_uptime_tasks = {}
+        self._openmano_nsr_by_vnfr_id = {}
+        #self._nsr_uuid = None
 
         self._set_ro_account(ro_account)
 
@@ -992,9 +1007,14 @@ class OpenmanoNsPlugin(rwnsmplugin.NsmPluginBase):
                 openmano_nsr.nsd_msg,
                 openmano_nsr.nsr_config_msg,
                 openmano_nsr.key_pairs,
-                #openmano_nsr.nsr_msg,
                 vnfr.vnfd.id
             )
+            self._openmano_nsr_by_vnfr_id[nsr.id] = openmano_nsr
+            if vnfr.id in self._openmano_nsr_by_vnfr_id:
+                raise VNFExistError("VNF %s already exist", vnfr.id)
+            self._openmano_nsr_by_vnfr_id[vnfr.id] = openmano_vnf_nsr
+            self._log.debug("VNFRID %s %s %s", type(self._openmano_nsr_by_vnfr_id), type(openmano_vnf_nsr), type(self._openmano_nsr_by_vnfr_id[vnfr.id]))
+
             for vlr in openmano_nsr.vlrs:
                 yield from openmano_vnf_nsr.add_vlr(vlr)
             try:
@@ -1079,12 +1099,17 @@ class OpenmanoNsPlugin(rwnsmplugin.NsmPluginBase):
         openmano_nsr.delete()
 
     @asyncio.coroutine
-    def terminate_vnf(self, vnfr):
+    def terminate_vnf(self, nsr, vnfr, scalein=False):
         """
         Terminate the network service
         """
-        if vnfr.id in self._vnfr_uptime_tasks:
-            self._vnfr_uptime_tasks[vnfr.id].cancel()
+        if scalein:
+            openmano_vnf_nsr = self._openmano_nsr_by_vnfr_id[vnfr.id]
+            openmano_vnf_nsr.terminate()
+            openmano_vnf_nsr.delete()
+            yield from openmano_vnf_nsr.remove_vnf(vnfr)
+            if vnfr.id in self._vnfr_uptime_tasks:
+                self._vnfr_uptime_tasks[vnfr.id].cancel()
 
     @asyncio.coroutine
     def terminate_vl(self, vlr):
index afcb822..9936241 100755 (executable)
@@ -1755,7 +1755,7 @@ class NetworkServiceRecord(object):
 
             # Going ahead with terminate, even if there is an error in pre-scale-in config
             # as this could be result of scale out failure and we need to cleanup this group
-            yield from self.terminate_vnfrs(scale_instance.vnfrs)
+            yield from self.terminate_vnfrs(scale_instance.vnfrs, scalein=True)
             group.delete_instance(index)
 
             scale_instance.operational_status = "vnf_terminate_phase"
@@ -2404,11 +2404,13 @@ class NetworkServiceRecord(object):
         yield from self.publish()
 
     @asyncio.coroutine
-    def terminate_vnfrs(self, vnfrs):
+    def terminate_vnfrs(self, vnfrs, scalein=False):
         """ Terminate VNFRS in this network service """
         self._log.debug("Terminating VNFs in network service %s", self.id)
         for vnfr in vnfrs:
-            yield from self.nsm_plugin.terminate_vnf(vnfr)
+            self._log.debug("Terminating VNFs in network service %s %s", vnfr.id, self.id)
+            if scalein:
+                yield from self.nsm_plugin.terminate_vnf(self, vnfr, scalein=True)
 
     @asyncio.coroutine
     def terminate(self):
@@ -2453,9 +2455,7 @@ class NetworkServiceRecord(object):
         event_descr = "Terminating VLs in NS Id:%s" % self.id
         self.record_event("terminating-vls", event_descr)
         yield from terminate_vlrs()
-
         yield from self.nsm_plugin.terminate_ns(self)
-
         # Move the state to TERMINATED
         self.set_state(NetworkServiceRecordState.TERMINATED)
         event_descr = "Terminated NS Id:%s" % self.id