def create_subscription_data(subscription_name): """ Creates subscription model object Args: subscription_name (String): Name of the Subscription Returns SubscriptionModel: single subscription model object """ nf_filter = NetworkFunctionFilterModel(subscription_name, '{^pnf.*,^vnf.*}', '{}', '{}', '{}') mg_first = MeasurementGroupModel( subscription_name, 'MG1', 'UNLOCKED', 15, '/pm/pm.xml', '[{ "measurementType": "countera" }, ' '{ "measurementType": "counterb" }]', '[{ "DN":"dna"},{"DN":"dnb"}]') mg_second = copy.deepcopy(mg_first) mg_second.measurement_group_name = 'MG2' mg_second.administrative_state = 'LOCKED' mg_list = [mg_first, mg_second] subscription_model = SubscriptionModel(subscription_name, 'pmsh_operational_policy', 'pmsh_control_loop_name', 'LOCKED') subscription_model.network_filter = nf_filter subscription_model.measurement_groups = mg_list nf1 = NfSubRelationalModel(subscription_name, "pnf_101", "LOCKED") nf2 = NfSubRelationalModel(subscription_name, "pnf_102", "LOCKED") subscription_model.nfs = [nf1, nf2] return subscription_model
def test_publish_measurement_grp_to_nfs_failed(self, mock_filter_call, mock_logger, mock_publish, mock_model_aai, mock_aai): mock_aai.return_value = json.loads(self.aai_response_data) mock_model_aai.return_value = json.loads(self.good_model_info) mock_publish.side_effect = Exception('Publish failed') subscription = self.create_test_subs('xtraPM-All-gNB-R2B-new2', 'msrmt_grp_name-new2') subscription = json.loads(subscription)['subscription'] sub_model = SubscriptionModel(subscription["subscriptionName"], subscription['operationalPolicyName'], subscription['controlLoopName'], 'LOCKED') measurement_grp = MeasurementGroupModel('subscription_name_1', 'msrmt_grp_name', 'UNLOCKED', 15, 'pm.xml', [], []) measurement2 = self.create_measurement_grp(measurement_grp, 'meas2', 'UNLOCKED') measurement3 = self.create_measurement_grp(measurement_grp, 'meas3', 'LOCKED') measurement_grps = [measurement_grp, measurement2, measurement3] mock_filter_call.return_value = NetworkFunctionFilter( **subscription["nfFilter"]) filtered_nfs = nf_service.capture_filtered_nfs( subscription["subscriptionName"]) subscription_service.publish_measurement_grp_to_nfs( sub_model, filtered_nfs, measurement_grps) mock_logger.assert_called_with( 'Publish event failed for nf name, measure_grp_name, ' 'sub_name: pnf_33_ericsson,meas2, xtraPM-All-gNB-R2B-new2 ' 'with error: Publish failed')
def test_publish_measurement_grp_to_nfs(self, mock_filter_call, mock_publish, mock_model_aai, mock_aai): mock_aai.return_value = json.loads(self.aai_response_data) mock_model_aai.return_value = json.loads(self.good_model_info) mock_publish.return_value = None subscription = self.create_test_subs('xtraPM-All-gNB-R2B-new2', 'msrmt_grp_name-new2') subscription = json.loads(subscription)['subscription'] sub_model = SubscriptionModel(subscription["subscriptionName"], subscription['operationalPolicyName'], subscription['controlLoopName'], 'LOCKED') measurement_grp = MeasurementGroupModel('subscription_name_1', 'msrmt_grp_name', 'UNLOCKED', 15, 'pm.xml', [], []) measurement2 = self.create_measurement_grp(measurement_grp, 'meas2', 'UNLOCKED') measurement3 = self.create_measurement_grp(measurement_grp, 'meas3', 'UNLOCKED') measurement_grps = [measurement_grp, measurement2, measurement3] mock_filter_call.return_value = NetworkFunctionFilter( **subscription["nfFilter"]) filtered_nfs = nf_service.capture_filtered_nfs( subscription["subscriptionName"]) subscription_service.publish_measurement_grp_to_nfs( sub_model, filtered_nfs, measurement_grps) # Two unlocked measurement Group published self.assertEqual(mock_publish.call_count, 6)
def test_post_meas_group_with_duplicate(self): subscription_data = create_subscription_data('Post_MG') measurement_grp = MeasurementGroupModel( 'Post_MG', 'MG1', 'UNLOCKED', 15, '/pm/pm.xml', '[{ "measurementType": "countera" }, ' '{ "measurementType": "counterb" }]', '[{ "DN":"dna"},{"DN":"dnb"}]') db.session.add(subscription_data) db.session.commit() db.session.remove() _, status_code = post_meas_group('Post_MG', 'MG1', measurement_grp) self.assertEqual(status_code, 409)
def test_publish_measurement_group(self, mock_mr): super().setUp() nf_1 = NetworkFunction( **{ 'nf_name': 'pnf_1', 'ipv4_address': '204.120.0.15', 'ipv6_address': '2001:db8:3333:4444:5555:6666:7777:8888', 'model_invariant_id': 'some_id', 'model_version_id': 'some_other_id' }, sdnc_model_name='blah', sdnc_model_version=1.0, ) measurement_grp = MeasurementGroupModel( 'sub_publish', 'msg_publish', 'UNLOCKED', 15, 'pm.xml', [{ "measurementType": "counter_a" }], [{ "DN": "string" }]) sub_model = SubscriptionModel('sub_publish', 'pmsh-operational-policy', 'pmsh-control-loop', 'LOCKED') measurement_group_service.publish_measurement_group( sub_model, measurement_grp, nf_1, 'CREATE') mock_mr.assert_called_once_with( 'policy_pm_publisher', { 'nfName': 'pnf_1', 'ipAddress': '2001:db8:3333:4444:5555:6666:7777:8888', 'blueprintName': 'blah', 'blueprintVersion': 1.0, 'operationalPolicyName': 'pmsh-operational-policy', 'changeType': 'CREATE', 'controlLoopName': 'pmsh-control-loop', 'subscription': { 'administrativeState': 'UNLOCKED', 'subscriptionName': 'sub_publish', 'fileBasedGP': 15, 'fileLocation': 'pm.xml', 'measurementGroup': { 'measurementGroupName': 'msg_publish', 'measurementTypes': [{ "measurementType": "counter_a" }], 'managedObjectDNsBasic': [{ "DN": "string" }] } } })
def test_apply_measurement_grp_to_nfs(self, mock_filter_call, mock_apply_nf, mock_model_aai, mock_aai): mock_aai.return_value = json.loads(self.aai_response_data) mock_model_aai.return_value = json.loads(self.good_model_info) mock_apply_nf.return_value = None subscription = self.create_test_subs('xtraPM-All-gNB-R2B-new2', 'msrmt_grp_name-new2') subscription = json.loads(subscription)['subscription'] measurement_grp = MeasurementGroupModel('subscription_name_1', 'msrmt_grp_name', 'UNLOCKED', 15, 'pm.xml', [], []) measurement2 = self.create_measurement_grp(measurement_grp, 'meas2', 'UNLOCKED') unlocked_msgs = [measurement_grp, measurement2] mock_filter_call.return_value = NetworkFunctionFilter( **subscription["nfFilter"]) filtered_nfs = nf_service.capture_filtered_nfs( subscription["subscriptionName"]) subscription_service.apply_measurement_grp_to_nfs( filtered_nfs, unlocked_msgs) # 2 measurement group with 2 nfs each contribute 4 calls self.assertEqual(mock_apply_nf.call_count, 4)
def save_measurement_group(measurement_group, subscription_name): """ Saves the measurement_group data request Args: measurement_group (dict) : measurement group to save subscription_name (string) : subscription name to associate with measurement group. Returns: MeasurementGroupModel : measurement group saved in the database """ logger.info( f'Saving measurement group for subscription request: {subscription_name}' ) new_measurement_group = MeasurementGroupModel( subscription_name=subscription_name, measurement_group_name=measurement_group['measurementGroupName'], administrative_state=measurement_group['administrativeState'], file_based_gp=measurement_group['fileBasedGP'], file_location=measurement_group['fileLocation'], measurement_type=measurement_group['measurementTypes'], managed_object_dns_basic=measurement_group['managedObjectDNsBasic']) db.session.add(new_measurement_group) return new_measurement_group