Bug 154 Fix terminate VL during terminate NS 78/978/1
authorPhilip Joseph <philip.joseph@riftio.com>
Wed, 18 Jan 2017 12:00:40 +0000 (17:30 +0530)
committerPhilip Joseph <philip.joseph@riftio.com>
Wed, 18 Jan 2017 12:00:40 +0000 (17:30 +0530)
Signed-off-by: Philip Joseph <philip.joseph@riftio.com>
rwlaunchpad/plugins/rwnsm/rift/tasklets/rwnsmtasklet/cloud.py
rwlaunchpad/plugins/rwnsm/rift/tasklets/rwnsmtasklet/openmano_nsm.py
rwlaunchpad/plugins/rwnsm/rift/tasklets/rwnsmtasklet/rwnsmplugin.py
rwlaunchpad/plugins/rwnsm/rift/tasklets/rwnsmtasklet/rwnsmtasklet.py

index 32efff2..007e62c 100644 (file)
@@ -40,6 +40,9 @@ class RwNsPlugin(rwnsmplugin.NsmPluginBase):
         self._log = log
         self._loop = loop
 
+    def set_state(self, nsr_id, state):
+        pass
+
     def create_nsr(self, nsr_msg, nsd,key_pairs=None):
         """
         Create Network service record
index 6c18946..e009ba3 100644 (file)
@@ -244,17 +244,18 @@ class OpenmanoVnfr(object):
 
 class OpenmanoNSRecordState(Enum):
     """ Network Service Record State """
+    # Make sure the values match with NetworkServiceRecordState
     INIT = 101
     INSTANTIATION_PENDING = 102
-    RUNNING = 103
-    SCALING_OUT = 104
-    SCALING_IN = 105
-    TERMINATE = 106
-    TERMINATE_RCVD = 107
-    TERMINATED = 108
-    FAILED = 109
-    VL_INSTANTIATE = 110
-    VL_TERMINATE = 111
+    RUNNING = 106
+    SCALING_OUT = 107
+    SCALING_IN = 108
+    TERMINATE = 109
+    TERMINATE_RCVD = 110
+    TERMINATED = 114
+    FAILED = 115
+    VL_INSTANTIATE = 116
+    VL_TERMINATE = 117
 
 
 class OpenmanoNsr(object):
@@ -421,6 +422,13 @@ class OpenmanoNsr(object):
 
     @asyncio.coroutine
     def remove_vlr(self, vlr):
+        if vlr in self._vlrs:
+            self._vlrs.remove(vlr)
+            yield from self._publisher.unpublish_vlr(None, vlr.vlr_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)
             if not  vlr.vld_msg.vim_network_name:
@@ -815,6 +823,15 @@ class OpenmanoNsPlugin(rwnsmplugin.NsmPluginBase):
                 ro_account.openmano.tenant_id,
                 )
 
+    def set_state(self, nsr_id, state):
+        # Currently we update only during terminate to
+        # decide how to handle VL terminate
+        if state.value == OpenmanoNSRecordState.TERMINATE.value:
+            self._openmano_nsrs[nsr_id]._state = \
+                [member.value for name, member in \
+                 OpenmanoNSRecordState.__members__.items() \
+                 if member.value == state.value]
+
     def create_nsr(self, nsr_config_msg, nsd_msg, key_pairs=None):
         """
         Create Network service record
@@ -920,6 +937,7 @@ class OpenmanoNsPlugin(rwnsmplugin.NsmPluginBase):
         """
         self._log.debug("Received terminate VL for VLR {}".format(vlr))
         openmano_nsr = self._openmano_nsrs[vlr._nsr_id]
-        yield from openmano_nsr.remove_vlr(vlr)
-
-
+        if openmano_nsr._state == OpenmanoNSRecordState.RUNNING:
+            yield from openmano_nsr.delete_vlr(vlr)
+        else:
+            yield from openmano_nsr.remove_vlr(vlr)
index ec16259..77fa57c 100755 (executable)
@@ -48,6 +48,11 @@ class NsmPluginBase(object):
     def nsm(self):
         return self._nsm
 
+    @abc.abstractmethod
+    def set_state(self, nsr_id, state):
+        pass
+
+    @abc.abstractmethod
     def create_nsr(self, nsr):
         """ Create an NSR """
         pass
index 0537cc5..3153a48 100755 (executable)
@@ -1296,6 +1296,7 @@ class NetworkServiceRecord(object):
             self._vnf_phase_completed = True
 
         self._op_status.set_state(state)
+        self._nsm_plugin.set_state(self.id, state)
 
     @property
     def id(self):