summaryrefslogtreecommitdiffstats
path: root/components/pm-subscription-handler/tests
diff options
context:
space:
mode:
authoregernug <gerard.nugent@est.tech>2021-02-22 11:35:35 +0000
committeregernug <gerard.nugent@est.tech>2021-06-21 10:21:46 +0100
commit1ac9847eb66a074b5413264c788152f7c3ffc28d (patch)
treed62f7495af22f7db652303f4b34bf9b34905a8a1 /components/pm-subscription-handler/tests
parentee67930973552a69830c30e6b3b1915091af8ebb (diff)
[PMSH] Update filter
User can edit/update the nfFilter to include/exclude selected NFs Changelog and version update Issue-ID: DCAEGEN2-2531 Signed-off-by: egernug <gerard.nugent@est.tech> Change-Id: I61388775a711687525b12087e9b533bee1c6b039
Diffstat (limited to 'components/pm-subscription-handler/tests')
-rwxr-xr-xcomponents/pm-subscription-handler/tests/data/pm_subscription_event.json2
-rw-r--r--components/pm-subscription-handler/tests/test_policy_response_handler.py48
-rwxr-xr-xcomponents/pm-subscription-handler/tests/test_subscription.py24
3 files changed, 59 insertions, 15 deletions
diff --git a/components/pm-subscription-handler/tests/data/pm_subscription_event.json b/components/pm-subscription-handler/tests/data/pm_subscription_event.json
index cd547d9d..a3a6ce3d 100755
--- a/components/pm-subscription-handler/tests/data/pm_subscription_event.json
+++ b/components/pm-subscription-handler/tests/data/pm_subscription_event.json
@@ -5,7 +5,7 @@
"policyName":"pmsh-operational-policy",
"changeType":"CREATE",
"closedLoopControlName":"pmsh-control-loop",
- "ipv4Address": "1.2.3.4",
+ "ipAddress": "1.2.3.4",
"subscription":{
"subscriptionName":"ExtraPM-All-gNB-R2B",
"administrativeState":"UNLOCKED",
diff --git a/components/pm-subscription-handler/tests/test_policy_response_handler.py b/components/pm-subscription-handler/tests/test_policy_response_handler.py
index 26a06fce..e678d839 100644
--- a/components/pm-subscription-handler/tests/test_policy_response_handler.py
+++ b/components/pm-subscription-handler/tests/test_policy_response_handler.py
@@ -1,5 +1,5 @@
# ============LICENSE_START===================================================
-# Copyright (C) 2019-2020 Nordix Foundation.
+# Copyright (C) 2019-2021 Nordix Foundation.
# ============================================================================
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -18,7 +18,7 @@
from unittest.mock import patch
from mod.api.db_models import SubscriptionModel
-from mod.network_function import NetworkFunction
+from mod.network_function import NetworkFunction, NetworkFunctionFilter
from mod.policy_response_handler import PolicyResponseHandler, policy_response_handle_functions
from mod.subscription import AdministrativeState, SubNfState
from tests.base_setup import BaseClassSetup
@@ -39,6 +39,20 @@ class PolicyResponseHandlerTest(BaseClassSetup):
self.policy_response_handler = PolicyResponseHandler(self.mock_policy_mr_sub,
self.app_conf,
mock_app)
+ self.nfFilter = NetworkFunctionFilter(**{
+ "nfNames": [
+ "^pnf.*"
+ ],
+ "modelInvariantIDs": [
+
+ ],
+ "modelVersionIDs": [
+
+ ],
+ "modelNames": [
+
+ ]
+ })
def tearDown(self):
super().tearDown()
@@ -54,7 +68,7 @@ class PolicyResponseHandlerTest(BaseClassSetup):
self.policy_response_handler._handle_response(
self.app_conf.subscription.subscriptionName,
AdministrativeState.LOCKED.value,
- self.nf.nf_name, 'success')
+ self.nf.nf_name, 'success', 'DELETED')
mock_delete.assert_called()
@@ -65,7 +79,7 @@ class PolicyResponseHandlerTest(BaseClassSetup):
self.policy_response_handler._handle_response(
self.app_conf.subscription.subscriptionName,
AdministrativeState.LOCKED.value,
- self.nf.nf_name, 'failed')
+ self.nf.nf_name, 'failed','DELETE_FAILED')
mock_update_sub_nf.assert_called_with(
subscription_name=self.app_conf.subscription.subscriptionName,
status=SubNfState.DELETE_FAILED.value, nf_name=self.nf.nf_name)
@@ -77,7 +91,7 @@ class PolicyResponseHandlerTest(BaseClassSetup):
self.policy_response_handler._handle_response(
self.app_conf.subscription.subscriptionName,
AdministrativeState.UNLOCKED.value,
- self.nf.nf_name, 'success')
+ self.nf.nf_name, 'success', 'CREATED')
mock_update_sub_nf.assert_called_with(
subscription_name=self.app_conf.subscription.subscriptionName,
status=SubNfState.CREATED.value, nf_name=self.nf.nf_name)
@@ -89,7 +103,7 @@ class PolicyResponseHandlerTest(BaseClassSetup):
self.policy_response_handler._handle_response(
self.app_conf.subscription.subscriptionName,
AdministrativeState.UNLOCKED.value,
- self.nf.nf_name, 'failed')
+ self.nf.nf_name, 'failed', 'CREATE_FAILED')
mock_update_sub_nf.assert_called_with(
subscription_name=self.app_conf.subscription.subscriptionName,
status=SubNfState.CREATE_FAILED.value, nf_name=self.nf.nf_name)
@@ -102,15 +116,17 @@ class PolicyResponseHandlerTest(BaseClassSetup):
@patch('mod.subscription.Subscription.get')
def test_poll_policy_topic_calls_methods_correct_sub(self, mock_get_sub, mock_handle_response):
response_data = ['{"name": "ResponseEvent","status": { "subscriptionName": '
- '"ExtraPM-All-gNB-R2B", "nfName": "pnf300", "message": "success" } }']
+ '"ExtraPM-All-gNB-R2B", "nfName": "pnf300", "message": "success", "changeType": "CREATED" } }']
self.mock_policy_mr_sub.get_from_topic.return_value = response_data
- mock_get_sub.return_value = SubscriptionModel(subscription_name='ExtraPM-All-gNB-R2B',
- status=AdministrativeState.UNLOCKED.value)
+ mock_get_sub.return_value = \
+ SubscriptionModel(subscription_name='ExtraPM-All-gNB-R2B',
+ nfFilter=self.nfFilter,
+ status=AdministrativeState.UNLOCKED.value)
self.policy_response_handler.poll_policy_topic()
self.mock_policy_mr_sub.get_from_topic.assert_called()
mock_handle_response.assert_called_with(self.app_conf.subscription.subscriptionName,
AdministrativeState.UNLOCKED.value, 'pnf300',
- 'success')
+ 'success', "CREATED")
@patch('mod.policy_response_handler.PolicyResponseHandler._handle_response')
@patch('mod.subscription.Subscription.get')
@@ -119,8 +135,10 @@ class PolicyResponseHandlerTest(BaseClassSetup):
response_data = ['{"name": "ResponseEvent","status": { "subscriptionName": '
'"Different_Subscription", "nfName": "pnf300", "message": "success" } }']
self.mock_policy_mr_sub.get_from_topic.return_value = response_data
- mock_get_sub.return_value = SubscriptionModel(subscription_name='ExtraPM-All-gNB-R2B',
- status=AdministrativeState.UNLOCKED.value)
+ mock_get_sub.return_value = \
+ SubscriptionModel(subscription_name='ExtraPM-All-gNB-R2B',
+ nfFilter=self.nfFilter,
+ status=AdministrativeState.UNLOCKED.value)
self.policy_response_handler.poll_policy_topic()
self.mock_policy_mr_sub.get_from_topic.assert_called()
@@ -131,7 +149,9 @@ class PolicyResponseHandlerTest(BaseClassSetup):
@patch('mod.subscription.Subscription.get')
def test_poll_policy_topic_exception(self, mock_get_sub, mock_logger):
self.mock_policy_mr_sub.get_from_topic.return_value = 'wrong_return'
- mock_get_sub.return_value = SubscriptionModel(subscription_name='ExtraPM-All-gNB-R2B',
- status=AdministrativeState.UNLOCKED.value)
+ mock_get_sub.return_value = \
+ SubscriptionModel(subscription_name='ExtraPM-All-gNB-R2B',
+ nfFilter=self.nfFilter,
+ status=AdministrativeState.UNLOCKED.value)
self.policy_response_handler.poll_policy_topic()
mock_logger.assert_called()
diff --git a/components/pm-subscription-handler/tests/test_subscription.py b/components/pm-subscription-handler/tests/test_subscription.py
index b18f41e8..16c9e509 100755
--- a/components/pm-subscription-handler/tests/test_subscription.py
+++ b/components/pm-subscription-handler/tests/test_subscription.py
@@ -19,6 +19,7 @@ import json
import os
from unittest.mock import patch, Mock
+from pmsh_service.mod.network_function import NetworkFunctionFilter
from requests import Session
import mod.aai_client as aai_client
@@ -43,6 +44,9 @@ class SubscriptionTest(BaseClassSetup):
mock_session_put.return_value.text = self.aai_response_data
with open(os.path.join(os.path.dirname(__file__), 'data/aai_model_info.json'), 'r') as data:
self.aai_model_data = data.read()
+ with open(os.path.join(os.path.dirname(__file__), 'data/cbs_data_1.json'), 'r') as data:
+ self.cbs_data = json.load(data)
+ self.nfFilter = NetworkFunctionFilter(**self.cbs_data['config']['pmsh_policy']['subscription']['nfFilter'])
mock_session_get.return_value.status_code = 200
mock_session_get.return_value.text = self.aai_model_data
self.mock_mr_sub = Mock()
@@ -156,3 +160,23 @@ class SubscriptionTest(BaseClassSetup):
self.assertEqual(3, len(nfs))
self.assertIsInstance(nfs[0], NetworkFunction)
+
+ def test_filter_diff_with_difference(self):
+ print(self.nfFilter)
+ networkFunction = '{"nfNames":["^pnf.*","^vnf.*"],"modelInvariantIDs": ["Extra Data"],"modelVersionIDs": ["Extra Data"],"modelNames": ["Extra Data""]}'
+ self.assertTrue(self.app_conf.subscription._filter_diff(networkFunction));
+
+ def test_filter_diff_without_difference(self):
+ networkFunction = '{"nfNames":["^pnf.*","^vnf.*"],"modelInvariantIDs": [],"modelVersionIDs": [],"modelNames": []}'
+ self.assertTrue(self.app_conf.subscription._filter_diff(networkFunction));
+ self.assertIsNotNone(self.app_conf.subscription)
+
+ def test_update_subscription_filter(self):
+ original_filter = self.app_conf.subscription.nfFilter
+ self.app_conf.subscription.nfFilter = '{"nfNames":["^pnf.*","^vnf.*"],"modelInvariantIDs": ["Extra Data"],"modelVersionIDs": ["Extra Data"],"modelNames": ["Extra Data""]}'
+ self.app_conf.subscription.update_subscription_filter()
+ updated_subscription = (self.app_conf.subscription.get())
+ self.assertTrue(updated_subscription.nfFilter == self.app_conf.subscription.nfFilter)
+ self.assertFalse(updated_subscription == original_filter)
+ print(self.app_conf.subscription.get_network_functions())
+