[PMSH] Fix bug of deactivation during undeploy 01/104901/2 1.0.3
authorERIMROB <robertas.rimkus@est.tech>
Wed, 1 Apr 2020 16:54:19 +0000 (17:54 +0100)
committerERIMROB <robertas.rimkus@est.tech>
Thu, 2 Apr 2020 11:10:25 +0000 (12:10 +0100)
Signed-off-by: ERIMROB <robertas.rimkus@est.tech>
Issue-ID: DCAEGEN2-2175
Change-Id: I70998a0d643b899c1b4d3ba86346297271a9b276

components/pm-subscription-handler/Changelog.md
components/pm-subscription-handler/pmsh_service/mod/exit_handler.py
components/pm-subscription-handler/pmsh_service/mod/subscription.py
components/pm-subscription-handler/tests/test_subscription.py

index 0ae0197..3d2af6c 100755 (executable)
@@ -8,7 +8,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
 ## [1.0.3]
 ### Fixed
 * Fixed bug where PMSH pushes subscription to xnf regardless of it's orchestration status (DCAEGEN2-2173)
-* Bug fix to prevent aai_event handler from incorrectly LOCKING the subscription (DCAEGEN2-2181)
+* Fixed bug where undeploying PMSH would not deactivate newly added pnfs (DCAEGEN2-2175)
+* Fixed bug to prevent aai_event handler from incorrectly LOCKING the subscription (DCAEGEN2-2181)
 
 ## [1.0.2]
 ### Changed
index adc4941..3cb05da 100755 (executable)
@@ -42,7 +42,7 @@ class ExitHandler:
                 logger.debug(f'Cancelling periodic task with thread name: {thread.name}.')
                 thread.cancel()
             current_sub.administrativeState = AdministrativeState.LOCKED.value
-            current_sub.process_subscription(self.subscription_handler.current_nfs,
+            current_sub.process_subscription(current_sub.get_network_functions(),
                                              self.subscription_handler.mr_pub,
                                              self.subscription_handler.app_conf)
         ExitHandler.shutdown_signal_received = True
index 99a787d..3add720 100755 (executable)
@@ -22,7 +22,8 @@ from tenacity import retry, retry_if_exception_type, wait_exponential, stop_afte
 
 import mod.pmsh_logging as logger
 from mod import db
-from mod.db_models import SubscriptionModel, NfSubRelationalModel
+from mod.db_models import SubscriptionModel, NfSubRelationalModel, NetworkFunctionModel
+from mod.network_function import NetworkFunction
 
 
 class SubNfState(Enum):
@@ -218,3 +219,26 @@ class Subscription:
             update({NfSubRelationalModel.nf_sub_status: status}, synchronize_session='evaluate')
 
         db.session.commit()
+
+    def _get_nf_models(self):
+        nf_sub_relationships = NfSubRelationalModel.query.filter(
+            NfSubRelationalModel.subscription_name == self.subscriptionName)
+        nf_models = []
+        for nf_sub_entry in nf_sub_relationships:
+            nf_model_object = NetworkFunctionModel.query.filter(
+                NetworkFunctionModel.nf_name == nf_sub_entry.nf_name).one_or_none()
+            nf_models.append(nf_model_object)
+
+        return nf_models
+
+    def get_network_functions(self):
+        nfs = []
+        nf_models = self._get_nf_models()
+        for nf_model in nf_models:
+            nf = NetworkFunction(
+                nf_name=nf_model.nf_name,
+                orchestration_status=nf_model.orchestration_status
+            )
+            nfs.append(nf)
+
+        return nfs
index c95e2ab..e6ee2b5 100755 (executable)
@@ -26,6 +26,7 @@ from tenacity import stop_after_attempt
 
 import mod.aai_client as aai_client
 from mod import db, create_app
+from mod.db_models import NetworkFunctionModel
 from mod.network_function import NetworkFunction, NetworkFunctionFilter, OrchestrationStatus
 from mod.pmsh_utils import AppConfig
 from mod.subscription import Subscription
@@ -201,3 +202,19 @@ class SubscriptionTest(TestCase):
         actual_sub_event = self.sub_1.prepare_subscription_event(self.nf_1.nf_name, app_conf)
         print(actual_sub_event)
         self.assertEqual(expected_sub_event, actual_sub_event)
+
+    def test_get_nf_models(self):
+        nf_array = [self.nf_1, self.nf_2]
+        self.sub_1.add_network_functions_to_subscription(nf_array)
+        nf_models = self.sub_1._get_nf_models()
+
+        self.assertEqual(2, len(nf_models))
+        self.assertIsInstance(nf_models[0], NetworkFunctionModel)
+
+    def test_get_network_functions(self):
+        nf_array = [self.nf_1, self.nf_2]
+        self.sub_1.add_network_functions_to_subscription(nf_array)
+        nfs = self.sub_1.get_network_functions()
+
+        self.assertEqual(2, len(nfs))
+        self.assertIsInstance(nfs[0], NetworkFunction)