Fix bug where PMSH pushes config to non-active pnf 83/104583/2
authoremartin <ephraim.martin@est.tech>
Fri, 27 Mar 2020 16:31:48 +0000 (16:31 +0000)
committeremartin <ephraim.martin@est.tech>
Fri, 27 Mar 2020 16:46:55 +0000 (16:46 +0000)
Issue-ID: DCAEGEN2-2173
Signed-off-by: emartin <ephraim.martin@est.tech>
Change-Id: Ib93a71e825f621721b5acda059cadcb7824f997d

components/pm-subscription-handler/Changelog.md [changed mode: 0644->0755]
components/pm-subscription-handler/pmsh_service/mod/aai_client.py
components/pm-subscription-handler/pmsh_service/mod/aai_event_handler.py
components/pm-subscription-handler/pmsh_service/mod/network_function.py
components/pm-subscription-handler/tests/test_aai_event_handler.py
components/pm-subscription-handler/tests/test_subscription.py

old mode 100644 (file)
new mode 100755 (executable)
index 0542d13..e44539e
@@ -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
index 489d035..86cecb5 100755 (executable)
@@ -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))
index ee75fbf..e40060f 100755 (executable)
@@ -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)
 
 
index 1cdf57a..bf22318 100755 (executable)
@@ -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'
index 0fd9e77..f57df4c 100755 (executable)
@@ -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):
index d152863..c95e2ab 100755 (executable)
@@ -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)