diff options
author | 2020-04-01 17:54:19 +0100 | |
---|---|---|
committer | 2020-04-02 12:10:25 +0100 | |
commit | e97cde0ff09bc602a1ff665f573786c4f5a746ba (patch) | |
tree | ad7f9d6645903f9431eb8b5fe404dd7ccdc6c4bf /components | |
parent | c3ab68bdccbff73659ceb1fe196e2d53d141e38f (diff) |
[PMSH] Fix bug of deactivation during undeploy1.0.3
Signed-off-by: ERIMROB <robertas.rimkus@est.tech>
Issue-ID: DCAEGEN2-2175
Change-Id: I70998a0d643b899c1b4d3ba86346297271a9b276
Diffstat (limited to 'components')
4 files changed, 45 insertions, 3 deletions
diff --git a/components/pm-subscription-handler/Changelog.md b/components/pm-subscription-handler/Changelog.md index 0ae01975..3d2af6c3 100755 --- a/components/pm-subscription-handler/Changelog.md +++ b/components/pm-subscription-handler/Changelog.md @@ -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 diff --git a/components/pm-subscription-handler/pmsh_service/mod/exit_handler.py b/components/pm-subscription-handler/pmsh_service/mod/exit_handler.py index adc4941c..3cb05daa 100755 --- a/components/pm-subscription-handler/pmsh_service/mod/exit_handler.py +++ b/components/pm-subscription-handler/pmsh_service/mod/exit_handler.py @@ -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 diff --git a/components/pm-subscription-handler/pmsh_service/mod/subscription.py b/components/pm-subscription-handler/pmsh_service/mod/subscription.py index 99a787da..3add7200 100755 --- a/components/pm-subscription-handler/pmsh_service/mod/subscription.py +++ b/components/pm-subscription-handler/pmsh_service/mod/subscription.py @@ -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 diff --git a/components/pm-subscription-handler/tests/test_subscription.py b/components/pm-subscription-handler/tests/test_subscription.py index c95e2ab0..e6ee2b57 100755 --- a/components/pm-subscription-handler/tests/test_subscription.py +++ b/components/pm-subscription-handler/tests/test_subscription.py @@ -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) |