From 4b2b1445bef3b760ed29efa1c7c78977dde73452 Mon Sep 17 00:00:00 2001 From: egernug Date: Wed, 14 Oct 2020 08:52:49 +0100 Subject: [PMSH] Add Resource Name to filter options Issue-ID: DCAEGEN2-2402 Change-Id: I2242d36ca34e0b8ac085ce790b19b7ad51352c63 Signed-off-by: egernug --- components/pm-subscription-handler/Changelog.md | 1 + .../pmsh_service/mod/aai_client.py | 2 +- .../pmsh_service/mod/aai_event_handler.py | 2 +- .../pmsh_service/mod/api/db_models.py | 6 +- .../pmsh_service/mod/network_function.py | 20 ++++-- .../tests/data/filter_test_data.json | 76 ++++++++++++++++++++++ .../tests/test_aai_event_handler.py | 2 +- .../tests/test_aai_service.py | 2 +- .../tests/test_network_function.py | 4 +- .../tests/test_network_function_filter.py | 18 +++-- 10 files changed, 117 insertions(+), 16 deletions(-) (limited to 'components/pm-subscription-handler') diff --git a/components/pm-subscription-handler/Changelog.md b/components/pm-subscription-handler/Changelog.md index 09afe1c5..ea375ba3 100755 --- a/components/pm-subscription-handler/Changelog.md +++ b/components/pm-subscription-handler/Changelog.md @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ## [1.2.0] ### Changed * Bug fix prevent sub threads from crashing permanently (DCAEGEN2-2501) +* Added Resource Name (model-name) to filter (DCAEGEN2-2402) ## [1.1.2] ### Changed diff --git a/components/pm-subscription-handler/pmsh_service/mod/aai_client.py b/components/pm-subscription-handler/pmsh_service/mod/aai_client.py index 48f757da..fff91e7e 100755 --- a/components/pm-subscription-handler/pmsh_service/mod/aai_client.py +++ b/components/pm-subscription-handler/pmsh_service/mod/aai_client.py @@ -138,7 +138,7 @@ def _filter_nf_data(nf_data, app_conf): ip_address=nf['properties'].get('ipaddress-v4-oam'), model_invariant_id=nf['properties'].get('model-invariant-id'), model_version_id=nf['properties'].get('model-version-id')) - if not new_nf.set_sdnc_params(app_conf): + if not new_nf.set_nf_model_params(app_conf): continue if app_conf.nf_filter.is_nf_in_filter(new_nf): nf_list.append(new_nf) diff --git a/components/pm-subscription-handler/pmsh_service/mod/aai_event_handler.py b/components/pm-subscription-handler/pmsh_service/mod/aai_event_handler.py index f39f1f46..fd9f6252 100755 --- a/components/pm-subscription-handler/pmsh_service/mod/aai_event_handler.py +++ b/components/pm-subscription-handler/pmsh_service/mod/aai_event_handler.py @@ -66,7 +66,7 @@ def process_aai_events(mr_sub, mr_pub, app, app_conf): ip_address=aai_entity['ipaddress-v4-oam'], model_invariant_id=aai_entity['model-invariant-id'], model_version_id=aai_entity['model-version-id']) - if not nf.set_sdnc_params(app_conf): + if not nf.set_nf_model_params(app_conf): continue if app_conf.nf_filter.is_nf_in_filter(nf): _process_event(action, nf, mr_pub, app_conf) 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 b6735cc9..ea9603ef 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 @@ -60,6 +60,7 @@ class NetworkFunctionModel(db.Model): ip_address = Column(String(50)) model_invariant_id = Column(String(100)) model_version_id = Column(String(100)) + model_name = Column(String(100)) sdnc_model_name = Column(String(100)) sdnc_model_version = Column(String(100)) @@ -68,12 +69,14 @@ class NetworkFunctionModel(db.Model): cascade='all, delete-orphan', backref='nf') - def __init__(self, nf_name, ip_address, model_invariant_id, model_version_id, sdnc_model_name, + def __init__(self, nf_name, ip_address, model_invariant_id, + model_version_id, model_name, sdnc_model_name, sdnc_model_version): self.nf_name = nf_name self.ip_address = ip_address self.model_invariant_id = model_invariant_id self.model_version_id = model_version_id + self.model_name = model_name self.sdnc_model_name = sdnc_model_name self.sdnc_model_version = sdnc_model_version @@ -128,5 +131,6 @@ class NfSubRelationalModel(db.Model): 'nf_sub_status': self.nf_sub_status, 'model_invariant_id': nf.model_invariant_id, 'model_version_id': nf.model_version_id, + 'model_name': nf.model_name, 'sdnc_model_name': nf.sdnc_model_name, 'sdnc_model_version': nf.sdnc_model_version} diff --git a/components/pm-subscription-handler/pmsh_service/mod/network_function.py b/components/pm-subscription-handler/pmsh_service/mod/network_function.py index 3f383885..a6d2164f 100755 --- a/components/pm-subscription-handler/pmsh_service/mod/network_function.py +++ b/components/pm-subscription-handler/pmsh_service/mod/network_function.py @@ -30,12 +30,14 @@ class NetworkFunction: self.ip_address = kwargs.get('ip_address') self.model_invariant_id = kwargs.get('model_invariant_id') self.model_version_id = kwargs.get('model_version_id') + self.model_name = kwargs.get('model_name') self.sdnc_model_name = sdnc_model_name self.sdnc_model_version = sdnc_model_version @classmethod def nf_def(cls): - return cls(nf_name=None, ip_address=None, model_invariant_id=None, model_version_id=None, + return cls(nf_name=None, ip_address=None, model_invariant_id=None, + model_version_id=None, model_name=None, sdnc_model_name=None, sdnc_model_version=None) def __str__(self): @@ -43,6 +45,7 @@ class NetworkFunction: f'ipaddress-v4-oam: {self.ip_address}, ' \ f'model-invariant-id: {self.model_invariant_id}, ' \ f'model-version-id: {self.model_version_id}, ' \ + f'model-name: {self.model_name}, ' \ f'sdnc-model-name: {self.sdnc_model_name}, ' \ f'sdnc-model-version: {self.sdnc_model_version}' @@ -52,12 +55,14 @@ class NetworkFunction: self.ip_address == other.ip_address and \ self.model_invariant_id == other.model_invariant_id and \ self.model_version_id == other.model_version_id and \ + self.model_name == other.model_name and \ self.sdnc_model_name == other.sdnc_model_name and \ self.sdnc_model_version == other.sdnc_model_version def __hash__(self): return hash((self.nf_name, self.ip_address, self.model_invariant_id, - self.model_version_id, self.sdnc_model_name, self.sdnc_model_version)) + self.model_version_id, self.model_name, + self.sdnc_model_name, self.sdnc_model_version)) def create(self): """ Creates a NetworkFunction database entry """ @@ -69,6 +74,7 @@ class NetworkFunction: ip_address=self.ip_address, model_invariant_id=self.model_invariant_id, model_version_id=self.model_version_id, + model_name=self.model_name, sdnc_model_name=self.sdnc_model_name, sdnc_model_version=self.sdnc_model_version) db.session.add(new_nf) @@ -80,23 +86,24 @@ class NetworkFunction: f' returning this network function..') return existing_nf - def set_sdnc_params(self, app_conf): + def set_nf_model_params(self, app_conf): params_set = True try: sdnc_model_data = mod.aai_client.get_aai_model_data(app_conf, self.model_invariant_id, self.model_version_id, self.nf_name) + try: self.sdnc_model_name = sdnc_model_data['sdnc-model-name'] self.sdnc_model_version = sdnc_model_data['sdnc-model-version'] + self.model_name = sdnc_model_data['model-name'] return params_set except KeyError as e: logger.info(f'Skipping NF {self.nf_name} as there is no ' f'sdnc-model data associated in AAI: {e}', exc_info=True) - return not params_set except Exception as e: logger.error(f'Failed to get sdnc-model info for XNF {self.nf_name} from AAI: {e}', exc_info=True) - return not params_set + return not params_set @staticmethod def get(nf_name): @@ -140,6 +147,7 @@ class NetworkFunctionFilter: self.nf_names = kwargs.get('nfNames') self.model_invariant_ids = kwargs.get('modelInvariantIDs') self.model_version_ids = kwargs.get('modelVersionIDs') + self.model_names = kwargs.get('modelNames') self.regex_matcher = re.compile('|'.join(raw_regex for raw_regex in self.nf_names)) def is_nf_in_filter(self, nf): @@ -158,4 +166,6 @@ class NetworkFunctionFilter: match = False if self.model_version_ids and nf.model_version_id not in self.model_version_ids: match = False + if self.model_names and nf.model_name not in self.model_names: + match = False return match diff --git a/components/pm-subscription-handler/tests/data/filter_test_data.json b/components/pm-subscription-handler/tests/data/filter_test_data.json index 0d8fc7c8..2033624e 100644 --- a/components/pm-subscription-handler/tests/data/filter_test_data.json +++ b/components/pm-subscription-handler/tests/data/filter_test_data.json @@ -1,4 +1,48 @@ [ + { + "testName": "test_filter_model_name_true", + "nfFilter":{ + "nfNames":[ + "^pnf.*", + "^vnf.*" + ], + "modelInvariantIDs": [ + ], + "modelVersionIDs": [ + + ], + "modelNames": [ + "pnf102" + ] + }, + "nfName": "pnf1", + "modelInvariantUUID": "7129e420-d396-4efb-af02-6b83499b12f8", + "modelVersionID": "e80a6ae3-cafd-4d24-850d-e14c084a5ca9", + "modelName": "pnf102", + "expectedResult": true + }, + { + "testName": "test_filter_model_name_false", + "nfFilter":{ + "nfNames":[ + "^pnf.*", + "^vnf.*" + ], + "modelInvariantIDs": [ + ], + "modelVersionIDs": [ + + ], + "modelNames": [ + "pnf102" + ] + }, + "nfName": "pnf1", + "modelInvariantUUID": "7129e420-d396-4efb-af02-6b83499b12f8", + "modelVersionID": "e80a6ae3-cafd-4d24-850d-e14c084a5ca9", + "modelName": "Wrong_Model_Name", + "expectedResult": false + }, { "testName": "test_filter_true_on_xnf", "nfFilter":{ @@ -11,11 +55,15 @@ ], "modelVersionIDs": [ + ], + "modelNames": [ + ] }, "nfName": "pnf1", "modelInvariantUUID": "7129e420-d396-4efb-af02-6b83499b12f8", "modelVersionID": "e80a6ae3-cafd-4d24-850d-e14c084a5ca9", + "modelName": "pnf102", "expectedResult": true }, { @@ -30,11 +78,15 @@ ], "modelVersionIDs": [ + ], + "modelNames": [ + ] }, "nfName": "PNF-33", "modelInvariantUUID": "7129e420-d396-4efb-af02-6b83499b12f8", "modelVersionID": "e80a6ae3-cafd-4d24-850d-e14c084a5ca9", + "modelName": "pnf102", "expectedResult": false }, { @@ -48,11 +100,15 @@ ], "modelVersionIDs": [ + ], + "modelNames": [ + ] }, "nfName": "pnf1", "modelInvariantUUID": "7129e420-d396-4efb-af02-6b83499b12f8", "modelVersionID": "e80a6ae3-cafd-4d24-850d-e14c084a5ca9", + "modelName": "pnf102", "expectedResult": true }, { @@ -66,11 +122,15 @@ ], "modelVersionIDs": [ + ], + "modelNames": [ + ] }, "nfName": "pnf1", "modelInvariantUUID": "WrongModelInvariantUUID", "modelVersionID": "e80a6ae3-cafd-4d24-850d-e14c084a5ca9", + "modelName": "pnf102", "expectedResult": false }, { @@ -85,11 +145,15 @@ ], "modelVersionIDs": [ + ], + "modelNames": [ + ] }, "nfName": "pnf1", "modelInvariantUUID": "WrongModelInvariantUUID", "modelVersionID": "e80a6ae3-cafd-4d24-850d-e14c084a5ca9", + "modelName": "pnf102", "expectedResult": false }, { @@ -101,11 +165,15 @@ ], "modelVersionIDs": [ "e80a6ae3-cafd-4d24-850d-e14c084a5ca9" + ], + "modelNames": [ + ] }, "nfName": "pnf1", "modelInvariantUUID": "7129e420-d396-4efb-af02-6b83499b12f8", "modelVersionID": "e80a6ae3-cafd-4d24-850d-e14c084a5ca9", + "modelName": "pnf102", "expectedResult": true }, { @@ -117,11 +185,15 @@ ], "modelVersionIDs": [ "e80a6ae3-cafd-4d24-850d-e14c084a5ca9" + ], + "modelNames": [ + ] }, "nfName": "pnf1", "modelInvariantUUID": "7129e420-d396-4efb-af02-6b83499b12f8", "modelVersionID": "WrongModelVersionID", + "modelName": "pnf102", "expectedResult": false }, { @@ -135,11 +207,15 @@ ], "modelVersionIDs": [ "e80a6ae3-cafd-4d24-850d-e14c084a5ca9" + ], + "modelNames": [ + ] }, "nfName": "pnf1", "modelInvariantUUID": "7129e420-d396-4efb-af02-6b83499b12f8", "modelVersionID": "WrongModelVersionID", + "modelName": "pnf102", "expectedResult": false } ] diff --git a/components/pm-subscription-handler/tests/test_aai_event_handler.py b/components/pm-subscription-handler/tests/test_aai_event_handler.py index dc5243d7..47a36f5c 100755 --- a/components/pm-subscription-handler/tests/test_aai_event_handler.py +++ b/components/pm-subscription-handler/tests/test_aai_event_handler.py @@ -44,7 +44,7 @@ class AAIEventHandlerTest(BaseClassSetup): def tearDownClass(cls): super().tearDownClass() - @patch('mod.network_function.NetworkFunction.set_sdnc_params') + @patch('mod.network_function.NetworkFunction.set_nf_model_params') @patch('mod.subscription.Subscription.activate_subscription') @patch('mod.aai_event_handler.NetworkFunction.delete') def test_process_aai_update_and_delete_events(self, mock_nf_delete, mock_activate_sub, diff --git a/components/pm-subscription-handler/tests/test_aai_service.py b/components/pm-subscription-handler/tests/test_aai_service.py index 27694851..27c0f402 100644 --- a/components/pm-subscription-handler/tests/test_aai_service.py +++ b/components/pm-subscription-handler/tests/test_aai_service.py @@ -47,7 +47,7 @@ class AaiClientTestCase(BaseClassSetup): def tearDownClass(cls): super().tearDownClass() - @patch('mod.network_function.NetworkFunction.set_sdnc_params') + @patch('mod.network_function.NetworkFunction.set_nf_model_params') @patch.object(Session, 'get') @patch.object(Session, 'put') def test_aai_client_get_pm_sub_data_success(self, mock_put_session, mock_get_session, diff --git a/components/pm-subscription-handler/tests/test_network_function.py b/components/pm-subscription-handler/tests/test_network_function.py index c930c41d..5a1a6ba8 100755 --- a/components/pm-subscription-handler/tests/test_network_function.py +++ b/components/pm-subscription-handler/tests/test_network_function.py @@ -90,9 +90,9 @@ class NetworkFunctionTests(BaseClassSetup): @patch('mod.aai_client.get_aai_model_data') def test_set_sdnc_params_true(self, mock_get_aai_model): mock_get_aai_model.return_value = self.good_model_info - self.assertTrue(self.nf_1.set_sdnc_params(self.app_conf)) + self.assertTrue(self.nf_1.set_nf_model_params(self.app_conf)) @patch('mod.aai_client.get_aai_model_data') def test_set_sdnc_params_false(self, mock_get_aai_model): mock_get_aai_model.return_value = self.bad_model_info - self.assertFalse(self.nf_1.set_sdnc_params(self.app_conf)) + self.assertFalse(self.nf_1.set_nf_model_params(self.app_conf)) diff --git a/components/pm-subscription-handler/tests/test_network_function_filter.py b/components/pm-subscription-handler/tests/test_network_function_filter.py index 2151925d..f5369377 100644 --- a/components/pm-subscription-handler/tests/test_network_function_filter.py +++ b/components/pm-subscription-handler/tests/test_network_function_filter.py @@ -44,12 +44,14 @@ def load_test_cases(): class NetworkFunctionFilterTest(TestCase): @parameterized.expand(load_test_cases, name_func=custom_name_func) - def test(self, test_name, nf_filter, nf_name, model_invariant_uuid, model_version_id, + def test(self, test_name, nf_filter, nf_name, model_invariant_uuid, + model_version_id, model_name, expected_result): nf_filter = NetworkFunctionFilter(**nf_filter) self.assertEqual(nf_filter.is_nf_in_filter(NetworkFunction(nf_name=nf_name, model_invariant_id=model_invariant_uuid, - model_version_id=model_version_id)), + model_version_id=model_version_id, + model_name=model_name)), expected_result) def test_filter_true_on_multiple_modelInvariantIDs(self): @@ -61,12 +63,16 @@ class NetworkFunctionFilterTest(TestCase): '7129e420-d396-4efb-af02-6b83499b12f8' ], "modelVersionIDs": [ + ], + "modelNames": [ + ] }) self.assertTrue(nf_filter.is_nf_in_filter( NetworkFunction(nf_name='pnf1', model_invariant_id='7129e420-d396-4efb-af02-6b83499b12f8', - model_version_id='e80a6ae3-cafd-4d24-850d-e14c084a5ca9'))) + model_version_id='e80a6ae3-cafd-4d24-850d-e14c084a5ca9', + model_name='pnf_102'))) def test_filter_false_on_modelInvariantIDs_being_false_and_pnfname_being_true(self): nf_filter = NetworkFunctionFilter(**{ @@ -79,9 +85,13 @@ class NetworkFunctionFilterTest(TestCase): '7129e420-d396-4efb-af02-6b83499b12f8' ], "modelVersionIDs": [ + ], + "modelNames": [ + ] }) self.assertFalse(nf_filter.is_nf_in_filter( NetworkFunction(nf_name='pnf1', model_invariant_id='WrongModelInvariantUUID', - model_version_id='e80a6ae3-cafd-4d24-850d-e14c084a5ca9'))) + model_version_id='e80a6ae3-cafd-4d24-850d-e14c084a5ca9', + model_name='pnf_102'))) -- cgit 1.2.3-korg