Bug 260 - Termination Logic for Scaled Instances
Change-Id: Ic4c3341c594cab8a73554a2782f8f6bf8791abee
Signed-off-by: prithiv <prithiv.mohan@intel.com>
diff --git a/rwlaunchpad/plugins/rwnsm/rift/tasklets/rwnsmtasklet/openmano_nsm.py b/rwlaunchpad/plugins/rwnsm/rift/tasklets/rwnsmtasklet/openmano_nsm.py
index f8ce1aa..cf9b656 100644
--- a/rwlaunchpad/plugins/rwnsm/rift/tasklets/rwnsmtasklet/openmano_nsm.py
+++ b/rwlaunchpad/plugins/rwnsm/rift/tasklets/rwnsmtasklet/openmano_nsm.py
@@ -70,6 +70,9 @@
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
@@ -506,6 +509,16 @@
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:
self._vlrs.remove(vlr)
@@ -916,6 +929,8 @@
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 @@
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 @@
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):
diff --git a/rwlaunchpad/plugins/rwnsm/rift/tasklets/rwnsmtasklet/rwnsmtasklet.py b/rwlaunchpad/plugins/rwnsm/rift/tasklets/rwnsmtasklet/rwnsmtasklet.py
index afcb822..9936241 100755
--- a/rwlaunchpad/plugins/rwnsm/rift/tasklets/rwnsmtasklet/rwnsmtasklet.py
+++ b/rwlaunchpad/plugins/rwnsm/rift/tasklets/rwnsmtasklet/rwnsmtasklet.py
@@ -1755,7 +1755,7 @@
# 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 @@
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 @@
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