summaryrefslogtreecommitdiffstats
path: root/components/pm-subscription-handler/tests
diff options
context:
space:
mode:
authoremartin <ephraim.martin@est.tech>2020-02-27 13:56:52 +0000
committeremartin <ephraim.martin@est.tech>2020-02-28 11:24:53 +0000
commitc19a0a85bbbc8dcf0633a32d26f4128f6c8c4544 (patch)
tree234c14ca8729b852f0ea229483807890b8f96362 /components/pm-subscription-handler/tests
parent82a39f7da3177a9b9b700c7291ed5ea47c90e478 (diff)
Update PM subscription event for PMSH
* Add control loop name * Remove invariant id reference Issue-ID: DCAEGEN2-2100 Signed-off-by: emartin <ephraim.martin@est.tech> Change-Id: I6bbb757e07f3d930ecd28bd3106df307a264ff65
Diffstat (limited to 'components/pm-subscription-handler/tests')
-rw-r--r--components/pm-subscription-handler/tests/data/cbs_data_1.json3
-rwxr-xr-xcomponents/pm-subscription-handler/tests/data/cbs_data_2.json1
-rwxr-xr-xcomponents/pm-subscription-handler/tests/data/pm_subscription_event.json54
-rwxr-xr-xcomponents/pm-subscription-handler/tests/test_aai_event_handler.py8
-rw-r--r--components/pm-subscription-handler/tests/test_pmsh_service.py7
-rw-r--r--components/pm-subscription-handler/tests/test_pmsh_utils.py2
-rwxr-xr-xcomponents/pm-subscription-handler/tests/test_subscription.py20
7 files changed, 83 insertions, 12 deletions
diff --git a/components/pm-subscription-handler/tests/data/cbs_data_1.json b/components/pm-subscription-handler/tests/data/cbs_data_1.json
index ccc0626d..8dc225dc 100644
--- a/components/pm-subscription-handler/tests/data/cbs_data_1.json
+++ b/components/pm-subscription-handler/tests/data/cbs_data_1.json
@@ -5,7 +5,6 @@
"administrativeState":"UNLOCKED",
"fileBasedGP":15,
"fileLocation":"\/pm\/pm.xml",
- "nfTypeModelInvariantId":"2829292",
"nfFilter":{
"swVersions":[
"1.0.0",
@@ -61,6 +60,8 @@
}
},
"config":{
+ "control_loop_name": "pmsh-control-loop",
+ "operational_policy_name": "pmsh-operational-policy",
"aaf_password":"demo123456!",
"aaf_identity":"dcae@dcae.onap.org",
"cert_path":"/opt/app/pm-mapper/etc/certs/cert.pem",
diff --git a/components/pm-subscription-handler/tests/data/cbs_data_2.json b/components/pm-subscription-handler/tests/data/cbs_data_2.json
index 43f67e88..c223ddea 100755
--- a/components/pm-subscription-handler/tests/data/cbs_data_2.json
+++ b/components/pm-subscription-handler/tests/data/cbs_data_2.json
@@ -6,7 +6,6 @@
"administrativeState": "UNLOCKED",
"fileBasedGP": 15,
"fileLocation": "c:\/\/PM",
- "nfTypeModelInvariantId": "2829292",
"nfFilter": {
"swVersions": [
"A21",
diff --git a/components/pm-subscription-handler/tests/data/pm_subscription_event.json b/components/pm-subscription-handler/tests/data/pm_subscription_event.json
new file mode 100755
index 00000000..e190aa26
--- /dev/null
+++ b/components/pm-subscription-handler/tests/data/pm_subscription_event.json
@@ -0,0 +1,54 @@
+{
+ "nfName":"pnf_1",
+ "policyName":"pmsh-operational-policy",
+ "changeType":"CREATE",
+ "closedLoopControlName":"pmsh-control-loop",
+ "subscription":{
+ "subscriptionName":"ExtraPM-All-gNB-R2B",
+ "administrativeState":"UNLOCKED",
+ "fileBasedGP":15,
+ "fileLocation":"/pm/pm.xml",
+ "measurementGroups":[
+ {
+ "measurementGroup":{
+ "measurementTypes":[
+ {
+ "measurementType":"countera"
+ },
+ {
+ "measurementType":"counterb"
+ }
+ ],
+ "managedObjectDNsBasic":[
+ {
+ "DN":"dna"
+ },
+ {
+ "DN":"dnb"
+ }
+ ]
+ }
+ },
+ {
+ "measurementGroup":{
+ "measurementTypes":[
+ {
+ "measurementType":"counterc"
+ },
+ {
+ "measurementType":"counterd"
+ }
+ ],
+ "managedObjectDNsBasic":[
+ {
+ "DN":"dnc"
+ },
+ {
+ "DN":"dnd"
+ }
+ ]
+ }
+ }
+ ]
+ }
+} \ No newline at end of file
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 add7b3f5..0fd9e77e 100755
--- a/components/pm-subscription-handler/tests/test_aai_event_handler.py
+++ b/components/pm-subscription-handler/tests/test_aai_event_handler.py
@@ -39,15 +39,17 @@ class AAIEventHandlerTest(TestCase):
@patch('mod.aai_event_handler.NetworkFunction.delete')
@patch('mod.aai_event_handler.NetworkFunction.get')
- def test_process_aai_update_and_delete_events(self, mock_nf_get, mock_nf_delete):
+ @patch('pmsh_service_main.AppConfig')
+ def test_process_aai_update_and_delete_events(self, mock_app_conf, mock_nf_get, mock_nf_delete):
pnf_already_active = NetworkFunction(nf_name='pnf_already_active',
orchestration_status=OrchestrationStatus.ACTIVE.value)
mock_nf_get.side_effect = [None, pnf_already_active]
expected_nf_for_processing = NetworkFunction(
nf_name='pnf_newly_discovered', orchestration_status=OrchestrationStatus.ACTIVE.value)
- process_aai_events(self.mock_mr_sub, self.mock_sub, self.mock_mr_pub, self.mock_app)
+ process_aai_events(self.mock_mr_sub, self.mock_sub,
+ self.mock_mr_pub, self.mock_app, mock_app_conf)
self.mock_sub.process_subscription.assert_called_once_with([expected_nf_for_processing],
- self.mock_mr_pub)
+ self.mock_mr_pub, mock_app_conf)
mock_nf_delete.assert_called_once_with(nf_name='pnf_to_be_deleted')
diff --git a/components/pm-subscription-handler/tests/test_pmsh_service.py b/components/pm-subscription-handler/tests/test_pmsh_service.py
index b7225677..cd28a5d9 100644
--- a/components/pm-subscription-handler/tests/test_pmsh_service.py
+++ b/components/pm-subscription-handler/tests/test_pmsh_service.py
@@ -46,7 +46,9 @@ class PMSHServiceTest(TestCase):
@patch('threading.Timer')
@patch('mod.aai_client.get_pmsh_subscription_data')
@patch('pmsh_service_main.PeriodicTask')
- def test_subscription_processor_changed_state(self, periodic_task, mock_get_aai, mock_thread):
+ @patch('pmsh_service_main.AppConfig')
+ def test_subscription_processor_changed_state(self, mock_app_conf, periodic_task, mock_get_aai,
+ mock_thread):
self.mock_config_handler.get_config.return_value = self.cbs_data_1
mock_get_aai.return_value = self.mock_sub, self.nfs
mock_thread.start.return_value = 1
@@ -55,7 +57,8 @@ class PMSHServiceTest(TestCase):
pmsh_service.subscription_processor(self.mock_config_handler, 'LOCKED',
self.mock_mr_pub, self.mock_app, self.mock_aai_sub)
- self.mock_sub.process_subscription.assert_called_with(self.nfs, self.mock_mr_pub)
+ self.mock_sub.process_subscription.assert_called_with(self.nfs, self.mock_mr_pub,
+ mock_app_conf.return_value)
@patch('threading.Timer')
@patch('mod.pmsh_logging.debug')
diff --git a/components/pm-subscription-handler/tests/test_pmsh_utils.py b/components/pm-subscription-handler/tests/test_pmsh_utils.py
index 03e8c691..ea657f49 100644
--- a/components/pm-subscription-handler/tests/test_pmsh_utils.py
+++ b/components/pm-subscription-handler/tests/test_pmsh_utils.py
@@ -91,7 +91,7 @@ class PmshUtilsTestCase(TestCase):
def test_mr_pub_publish_sub_event_data_success(self):
mr_policy_pub = self.app_conf.get_mr_pub('policy_pm_publisher')
with patch('mod.pmsh_utils._MrPub.publish_to_topic') as pub_to_topic_call:
- mr_policy_pub.publish_subscription_event_data(self.sub, 'pnf201')
+ mr_policy_pub.publish_subscription_event_data(self.sub, 'pnf201', self.app_conf)
pub_to_topic_call.assert_called_once()
@responses.activate
diff --git a/components/pm-subscription-handler/tests/test_subscription.py b/components/pm-subscription-handler/tests/test_subscription.py
index c357ad79..bd39f28a 100755
--- a/components/pm-subscription-handler/tests/test_subscription.py
+++ b/components/pm-subscription-handler/tests/test_subscription.py
@@ -27,6 +27,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
+from mod.pmsh_utils import AppConfig
from mod.subscription import Subscription, NetworkFunctionFilter
@@ -35,7 +36,8 @@ class SubscriptionTest(TestCase):
@patch('mod.pmsh_utils._MrSub')
@patch('mod.get_db_connection_url')
@patch.object(Session, 'put')
- def setUp(self, mock_session, mock_get_db_url, mock_mr_sub, mock_mr_pub):
+ @patch('pmsh_service_main.AppConfig')
+ def setUp(self, mock_app_config, mock_session, mock_get_db_url, mock_mr_sub, mock_mr_pub):
mock_get_db_url.return_value = 'sqlite://'
with open(os.path.join(os.path.dirname(__file__), 'data/aai_xnfs.json'), 'r') as data:
self.aai_response_data = data.read()
@@ -61,6 +63,7 @@ class SubscriptionTest(TestCase):
self.app = create_app()
self.app_context = self.app.app_context()
self.app_context.push()
+ self.mock_app_config = mock_app_config
db.create_all()
def tearDown(self):
@@ -163,7 +166,7 @@ class SubscriptionTest(TestCase):
def test_process_activate_subscription(self, mock_update_sub_status,
mock_update_sub_nf, mock_add_nfs):
self.sub_1.process_subscription.retry.stop = stop_after_attempt(1)
- self.sub_1.process_subscription([self.nf_1], self.mock_mr_pub)
+ self.sub_1.process_subscription([self.nf_1], self.mock_mr_pub, self.mock_app_config)
mock_update_sub_status.assert_called()
mock_add_nfs.assert_called()
@@ -177,7 +180,7 @@ class SubscriptionTest(TestCase):
mock_update_sub_nf):
self.sub_1.administrativeState = 'LOCKED'
self.sub_1.process_subscription.retry.stop = stop_after_attempt(1)
- self.sub_1.process_subscription([self.nf_1], self.mock_mr_pub)
+ self.sub_1.process_subscription([self.nf_1], self.mock_mr_pub, self.mock_app_config)
self.assertTrue(self.mock_mr_pub.publish_subscription_event_data.called)
mock_update_sub_nf.assert_called_with(self.sub_1.subscriptionName,
@@ -187,4 +190,13 @@ class SubscriptionTest(TestCase):
def test_process_subscription_exception(self):
self.sub_1.process_subscription.retry.stop = stop_after_attempt(1)
self.assertRaises(Exception, self.sub_1.process_subscription,
- [self.nf_1], 'not_mr_pub')
+ [self.nf_1], 'not_mr_pub', 'app_config')
+
+ def test_prepare_subscription_event(self):
+ with open(os.path.join(os.path.dirname(__file__),
+ 'data/pm_subscription_event.json'), 'r') as data:
+ expected_sub_event = json.load(data)
+ app_conf = AppConfig(**self.cbs_data_1['config'])
+ actual_sub_event = self.sub_1.prepare_subscription_event(self.nf_1.nf_name, app_conf)
+ print(actual_sub_event)
+ self.assertEqual(expected_sub_event, actual_sub_event)