[PMSH] Add NF list to the Read by Subname call
Issue-ID: DCAEGEN2-2992
Add the list of NFs when a request is made for a subscription. This will assist with testing and visibility for the user.
Change-Id: I6061f1dd1cbc6c579e98605c1d7bcbcea3c4e77b
Signed-off-by: egernug <gerard.nugent@est.tech>
diff --git a/components/pm-subscription-handler/Changelog.md b/components/pm-subscription-handler/Changelog.md
index 8e0ee2f..b346873 100755
--- a/components/pm-subscription-handler/Changelog.md
+++ b/components/pm-subscription-handler/Changelog.md
@@ -14,6 +14,7 @@
* Read subscription API by using subscription name (DCAEGEN2-2818)
* Read All subscriptions API (DCAEGEN2-2847)
* PMSH Response Event Handler Integration (DCAEGEN2-2915)
+* Updated to get NFs list when requesting a specific subscription (DCAEGEN2-2992)
## [1.3.2]
### Changed
diff --git a/components/pm-subscription-handler/pmsh_service/mod/api/db_models.py b/components/pm-subscription-handler/pmsh_service/mod/api/db_models.py
index 96a803b..9ecc80e 100755
--- a/components/pm-subscription-handler/pmsh_service/mod/api/db_models.py
+++ b/components/pm-subscription-handler/pmsh_service/mod/api/db_models.py
@@ -67,6 +67,7 @@
'operationalPolicyName': self.operational_policy_name,
'controlLoopName': self.control_loop_name,
'nfFilter': self.network_filter.serialize(),
+ 'nfs': [nf.nf_name for nf in self.nfs],
'measurementGroups':
[mg.serialize() for mg in self.measurement_groups]}}
diff --git a/components/pm-subscription-handler/pmsh_service/mod/api/services/subscription_service.py b/components/pm-subscription-handler/pmsh_service/mod/api/services/subscription_service.py
index c33c82f..7346782 100644
--- a/components/pm-subscription-handler/pmsh_service/mod/api/services/subscription_service.py
+++ b/components/pm-subscription-handler/pmsh_service/mod/api/services/subscription_service.py
@@ -306,7 +306,8 @@
logger.info(f'Attempting to fetch subscription by name: {subscription_name}')
subscription_model = db.session.query(SubscriptionModel) \
.options(joinedload(SubscriptionModel.network_filter),
- joinedload(SubscriptionModel.measurement_groups)) \
+ joinedload(SubscriptionModel.measurement_groups),
+ joinedload(SubscriptionModel.nfs)) \
.filter_by(subscription_name=subscription_name).first()
db.session.remove()
return subscription_model
diff --git a/components/pm-subscription-handler/tests/base_setup.py b/components/pm-subscription-handler/tests/base_setup.py
index be7d1b8..33e2e91 100755
--- a/components/pm-subscription-handler/tests/base_setup.py
+++ b/components/pm-subscription-handler/tests/base_setup.py
@@ -22,7 +22,7 @@
from unittest.mock import patch, MagicMock
from mod import create_app, db
-from mod.api.db_models import NetworkFunctionFilterModel, MeasurementGroupModel, SubscriptionModel
+from mod.api.db_models import NetworkFunctionFilterModel, MeasurementGroupModel, SubscriptionModel, NfSubRelationalModel
from mod.network_function import NetworkFunctionFilter
from mod.pmsh_utils import AppConfig
from mod.pmsh_config import AppConfig as NewAppConfig
@@ -66,6 +66,9 @@
'pmsh_control_loop_name', 'LOCKED')
subscription_model.network_filter = nf_filter
subscription_model.measurement_groups = mg_list
+ nf1 = NfSubRelationalModel(subscription_name, "pnf_101", "LOCKED")
+ nf2 = NfSubRelationalModel(subscription_name, "pnf_102", "LOCKED")
+ subscription_model.nfs = [nf1, nf2]
return subscription_model
diff --git a/components/pm-subscription-handler/tests/services/test_subscription_service.py b/components/pm-subscription-handler/tests/services/test_subscription_service.py
index 8f3f0f4..44fb4ef 100644
--- a/components/pm-subscription-handler/tests/services/test_subscription_service.py
+++ b/components/pm-subscription-handler/tests/services/test_subscription_service.py
@@ -370,6 +370,7 @@
['measurementGroupName'], 'MG1')
self.assertEqual(len(subs[1]['subscription']['measurementGroups']), 2)
self.assertEqual(len(subs), 2)
+ self.assertEqual(len(subs[0]['subscription']['nfs']), 2)
@patch('mod.api.services.subscription_service.query_all_subscriptions',
MagicMock(return_value=[]))