summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoseph O'Leary <joseph.o.leary@est.tech>2020-04-02 07:21:35 +0000
committerGerrit Code Review <gerrit@onap.org>2020-04-02 07:21:35 +0000
commit78c11b8fcafd3bfb178fb568548cd29cafad8719 (patch)
tree4eede196ce15e86f25ee111fb735dd44c5fc1807
parent4dd50dd8d3416000ea3df34460fd9226f5a52009 (diff)
parent01dfa52c169aa902e2cd8f58b65daaaf3af5e8e8 (diff)
Merge "Fix bug where PMSH pushes config to non-active pnf"
-rwxr-xr-x[-rw-r--r--]components/pm-subscription-handler/Changelog.md4
-rwxr-xr-xcomponents/pm-subscription-handler/pmsh_service/mod/aai_client.py4
-rwxr-xr-xcomponents/pm-subscription-handler/pmsh_service/mod/aai_event_handler.py7
-rwxr-xr-xcomponents/pm-subscription-handler/pmsh_service/mod/network_function.py13
-rwxr-xr-xcomponents/pm-subscription-handler/tests/test_aai_event_handler.py4
-rwxr-xr-xcomponents/pm-subscription-handler/tests/test_subscription.py7
6 files changed, 24 insertions, 15 deletions
diff --git a/components/pm-subscription-handler/Changelog.md b/components/pm-subscription-handler/Changelog.md
index 0542d131..e44539eb 100644..100755
--- a/components/pm-subscription-handler/Changelog.md
+++ b/components/pm-subscription-handler/Changelog.md
@@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
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)
+
## [1.0.2]
### Changed
* Moved subscription processing from main into its own subscription_handler module
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 489d035b..86cecb50 100755
--- a/components/pm-subscription-handler/pmsh_service/mod/aai_client.py
+++ b/components/pm-subscription-handler/pmsh_service/mod/aai_client.py
@@ -120,8 +120,8 @@ def _filter_nf_data(nf_data, nf_filter):
for nf in nf_data['results']:
name_identifier = 'pnf-name' if nf['node-type'] == 'pnf' else 'vnf-name'
orchestration_status = nf['properties'].get('orchestration-status')
- if nf_filter.is_nf_in_filter(nf['properties'].get(name_identifier)) \
- and orchestration_status == 'Active':
+ if nf_filter.is_nf_in_filter(nf['properties'].get(name_identifier),
+ orchestration_status):
nf_set.add(NetworkFunction(
nf_name=nf['properties'].get(name_identifier),
orchestration_status=orchestration_status))
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 ee75fbf5..e40060f0 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
@@ -33,11 +33,6 @@ class AAIEvent(Enum):
UPDATE = 'UPDATE'
-class OrchestrationStatus(Enum):
- ACTIVE = 'Active'
- INVENTORIED = 'Inventoried'
-
-
def process_aai_events(mr_sub, subscription, mr_pub, app, app_conf):
"""
Processes AAI UPDATE events for each filtered xNFs where orchestration status is set to Active.
@@ -64,7 +59,7 @@ def process_aai_events(mr_sub, subscription, mr_pub, app, app_conf):
'vnf-name']
new_status = aai_xnf['orchestration-status']
- if NetworkFunctionFilter(**subscription.nfFilter).is_nf_in_filter(xnf_name):
+ if NetworkFunctionFilter(**subscription.nfFilter).is_nf_in_filter(xnf_name, new_status):
_process_event(action, new_status, xnf_name, subscription, mr_pub, app_conf)
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 1cdf57a0..bf223184 100755
--- a/components/pm-subscription-handler/pmsh_service/mod/network_function.py
+++ b/components/pm-subscription-handler/pmsh_service/mod/network_function.py
@@ -17,6 +17,8 @@
# ============LICENSE_END=====================================================
import re
+from enum import Enum
+
from mod import pmsh_logging as logger, db
from mod.db_models import NetworkFunctionModel
@@ -95,13 +97,20 @@ class NetworkFunctionFilter:
self.nf_names = kwargs.get('nfNames')
self.regex_matcher = re.compile('|'.join(raw_regex for raw_regex in self.nf_names))
- def is_nf_in_filter(self, nf_name):
+ def is_nf_in_filter(self, nf_name, orchestration_status):
"""Match the nf name against regex values in Subscription.nfFilter.nfNames
Args:
nf_name: the AAI nf name.
+ orchestration_status: orchestration status of the nf
Returns:
bool: True if matched, else False.
"""
- return self.regex_matcher.search(nf_name)
+ return self.regex_matcher.search(nf_name) and \
+ orchestration_status == OrchestrationStatus.ACTIVE.value
+
+
+class OrchestrationStatus(Enum):
+ ACTIVE = 'Active'
+ INVENTORIED = 'Inventoried'
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 0fd9e77e..f57df4cd 100755
--- a/components/pm-subscription-handler/tests/test_aai_event_handler.py
+++ b/components/pm-subscription-handler/tests/test_aai_event_handler.py
@@ -20,8 +20,8 @@ from os import path
from unittest import TestCase
from unittest.mock import patch, Mock
-from mod.aai_event_handler import OrchestrationStatus, process_aai_events
-from mod.network_function import NetworkFunction
+from mod.aai_event_handler import process_aai_events
+from mod.network_function import NetworkFunction, OrchestrationStatus
class AAIEventHandlerTest(TestCase):
diff --git a/components/pm-subscription-handler/tests/test_subscription.py b/components/pm-subscription-handler/tests/test_subscription.py
index d152863d..c95e2ab0 100755
--- a/components/pm-subscription-handler/tests/test_subscription.py
+++ b/components/pm-subscription-handler/tests/test_subscription.py
@@ -26,7 +26,7 @@ from tenacity import stop_after_attempt
import mod.aai_client as aai_client
from mod import db, create_app
-from mod.network_function import NetworkFunction, NetworkFunctionFilter
+from mod.network_function import NetworkFunction, NetworkFunctionFilter, OrchestrationStatus
from mod.pmsh_utils import AppConfig
from mod.subscription import Subscription
@@ -72,10 +72,11 @@ class SubscriptionTest(TestCase):
self.app_context.pop()
def test_xnf_filter_true(self):
- self.assertTrue(self.xnf_filter.is_nf_in_filter('pnf1'))
+ self.assertTrue(self.xnf_filter.is_nf_in_filter('pnf1', OrchestrationStatus.ACTIVE.value))
def test_xnf_filter_false(self):
- self.assertFalse(self.xnf_filter.is_nf_in_filter('PNF-33'))
+ self.assertFalse(self.xnf_filter.is_nf_in_filter('PNF-33',
+ OrchestrationStatus.ACTIVE.value))
def test_sub_measurement_group(self):
self.assertEqual(len(self.sub_1.measurementGroups), 2)