Merge "Fix bug where PMSH pushes config to non-active pnf"
diff --git a/components/pm-subscription-handler/Changelog.md b/components/pm-subscription-handler/Changelog.md
old mode 100644
new mode 100755
index 0542d13..e44539e
--- a/components/pm-subscription-handler/Changelog.md
+++ b/components/pm-subscription-handler/Changelog.md
@@ -5,6 +5,10 @@
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 489d035..86cecb5 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 @@
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 ee75fbf..e40060f 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 @@
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 @@
'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 1cdf57a..bf22318 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 @@
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 0fd9e77..f57df4c 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 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 d152863..c95e2ab 100755
--- a/components/pm-subscription-handler/tests/test_subscription.py
+++ b/components/pm-subscription-handler/tests/test_subscription.py
@@ -26,7 +26,7 @@
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 @@
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)