efiacor | 0080fa4 | 2020-09-08 16:26:50 +0100 | [diff] [blame] | 1 | # ============LICENSE_START=================================================== |
ajay_dp001 | 053579b | 2021-08-25 13:53:27 +0530 | [diff] [blame] | 2 | # Copyright (C) 2020-2021 Nordix Foundation. |
efiacor | 0080fa4 | 2020-09-08 16:26:50 +0100 | [diff] [blame] | 3 | # ============================================================================ |
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | # you may not use this file except in compliance with the License. |
| 6 | # You may obtain a copy of the License at |
| 7 | # |
| 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | # |
| 10 | # Unless required by applicable law or agreed to in writing, software |
| 11 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | # See the License for the specific language governing permissions and |
| 14 | # limitations under the License. |
| 15 | # |
| 16 | # SPDX-License-Identifier: Apache-2.0 |
| 17 | # ============LICENSE_END===================================================== |
raviteja.karumuri | 86f4eb2 | 2021-11-09 17:30:03 +0000 | [diff] [blame] | 18 | import copy |
efiacor | 0080fa4 | 2020-09-08 16:26:50 +0100 | [diff] [blame] | 19 | import json |
| 20 | import os |
| 21 | from unittest import TestCase |
| 22 | from unittest.mock import patch, MagicMock |
| 23 | |
| 24 | from mod import create_app, db |
SagarS | adcbd37 | 2021-12-09 16:59:51 +0000 | [diff] [blame] | 25 | from mod.api.db_models import NetworkFunctionFilterModel, MeasurementGroupModel, \ |
raviteja.karumuri | c77c6d9 | 2021-12-02 19:13:27 +0000 | [diff] [blame^] | 26 | SubscriptionModel, NetworkFunctionModel, NfSubRelationalModel |
shivasubedi | 9aa0b66 | 2021-01-18 13:59:18 +0000 | [diff] [blame] | 27 | from mod.network_function import NetworkFunctionFilter |
efiacor | 0080fa4 | 2020-09-08 16:26:50 +0100 | [diff] [blame] | 28 | from mod.pmsh_utils import AppConfig |
ajay_dp001 | 053579b | 2021-08-25 13:53:27 +0530 | [diff] [blame] | 29 | from mod.pmsh_config import AppConfig as NewAppConfig |
efiacor | 0080fa4 | 2020-09-08 16:26:50 +0100 | [diff] [blame] | 30 | |
| 31 | |
shivasubedi | 9aa0b66 | 2021-01-18 13:59:18 +0000 | [diff] [blame] | 32 | def get_pmsh_config(file_path='data/cbs_data_1.json'): |
raviteja.karumuri | 7e30421 | 2021-11-24 13:10:09 +0000 | [diff] [blame] | 33 | """ |
| 34 | Gets PMSH config from the JSON file |
| 35 | |
| 36 | Args: |
| 37 | file_path (String): Name of the file with path |
| 38 | |
| 39 | Returns |
| 40 | dict: Dictionary representation of the the service configuration |
| 41 | """ |
shivasubedi | 9aa0b66 | 2021-01-18 13:59:18 +0000 | [diff] [blame] | 42 | with open(os.path.join(os.path.dirname(__file__), file_path), 'r') as data: |
efiacor | 0080fa4 | 2020-09-08 16:26:50 +0100 | [diff] [blame] | 43 | return json.load(data) |
| 44 | |
| 45 | |
raviteja.karumuri | 7e30421 | 2021-11-24 13:10:09 +0000 | [diff] [blame] | 46 | def create_subscription_data(subscription_name): |
| 47 | """ |
| 48 | Creates subscription model object |
| 49 | |
| 50 | Args: |
| 51 | subscription_name (String): Name of the Subscription |
| 52 | |
| 53 | Returns |
| 54 | SubscriptionModel: single subscription model object |
| 55 | """ |
raviteja.karumuri | 86f4eb2 | 2021-11-09 17:30:03 +0000 | [diff] [blame] | 56 | nf_filter = NetworkFunctionFilterModel(subscription_name, '{^pnf.*,^vnf.*}', |
| 57 | '{}', '{}', '{}') |
| 58 | mg_first = MeasurementGroupModel(subscription_name, 'MG1', 'UNLOCKED', 15, '/pm/pm.xml', |
| 59 | '[{ "measurementType": "countera" }, ' |
| 60 | '{ "measurementType": "counterb" }]', |
| 61 | '[{ "DN":"dna"},{"DN":"dnb"}]') |
| 62 | mg_second = copy.deepcopy(mg_first) |
| 63 | mg_second.measurement_group_name = 'MG2' |
| 64 | mg_second.administrative_state = 'LOCKED' |
| 65 | mg_list = [mg_first, mg_second] |
| 66 | subscription_model = SubscriptionModel(subscription_name, 'pmsh_operational_policy', |
| 67 | 'pmsh_control_loop_name', 'LOCKED') |
| 68 | subscription_model.network_filter = nf_filter |
| 69 | subscription_model.measurement_groups = mg_list |
egernug | 15dde94 | 2021-12-06 13:11:15 +0000 | [diff] [blame] | 70 | nf1 = NfSubRelationalModel(subscription_name, "pnf_101", "LOCKED") |
| 71 | nf2 = NfSubRelationalModel(subscription_name, "pnf_102", "LOCKED") |
| 72 | subscription_model.nfs = [nf1, nf2] |
raviteja.karumuri | 86f4eb2 | 2021-11-09 17:30:03 +0000 | [diff] [blame] | 73 | return subscription_model |
| 74 | |
| 75 | |
raviteja.karumuri | 7e30421 | 2021-11-24 13:10:09 +0000 | [diff] [blame] | 76 | def create_multiple_subscription_data(subscription_names): |
| 77 | """ |
| 78 | Creates a list of subscription model objects |
| 79 | |
| 80 | Args: |
| 81 | subscription_names (List): Name of the Subscriptions |
| 82 | |
| 83 | Returns |
| 84 | list (SubscriptionModel): of subscription model objects |
| 85 | """ |
| 86 | subscriptions = [] |
| 87 | for subscription_name in subscription_names: |
| 88 | subscriptions.append(create_subscription_data(subscription_name)) |
| 89 | return subscriptions |
| 90 | |
| 91 | |
raviteja.karumuri | c77c6d9 | 2021-12-02 19:13:27 +0000 | [diff] [blame^] | 92 | def create_multiple_network_function_data(nf_name_list): |
| 93 | """ |
| 94 | Creates list of network function model objects |
| 95 | |
| 96 | Args: |
| 97 | nf_name_list (list): Network function names |
| 98 | |
| 99 | Returns |
| 100 | list: of network function model objects |
| 101 | """ |
| 102 | nf_list = [] |
| 103 | for nf_name in nf_name_list: |
| 104 | nf = NetworkFunctionModel(nf_name, '10.10.10.32', '2001:0db8:0:0:0:0:1428:57ab', |
| 105 | '687kj45-d396-4efb-af02-6b83499b12f8', |
| 106 | 'e80a6ae3-cafd-4d24-850d-e14c084a5ca9', |
| 107 | 'model_name', 'pm_control', '1.0.2') |
| 108 | nf_list.append(nf) |
| 109 | return nf_list |
| 110 | |
| 111 | |
efiacor | 0080fa4 | 2020-09-08 16:26:50 +0100 | [diff] [blame] | 112 | class BaseClassSetup(TestCase): |
| 113 | app = None |
| 114 | app_context = None |
| 115 | |
| 116 | @classmethod |
| 117 | @patch('mod.get_db_connection_url', MagicMock(return_value='sqlite://')) |
| 118 | @patch('mod.update_logging_config', MagicMock()) |
| 119 | def setUpClass(cls): |
| 120 | os.environ['LOGGER_CONFIG'] = os.path.join(os.path.dirname(__file__), 'log_config.yaml') |
| 121 | os.environ['LOGS_PATH'] = '.' |
| 122 | cls.app = create_app() |
| 123 | cls.app_context = cls.app.app_context() |
| 124 | cls.app_context.push() |
| 125 | |
| 126 | @patch('mod.pmsh_utils.AppConfig._get_pmsh_config', MagicMock(return_value=get_pmsh_config())) |
| 127 | def setUp(self): |
| 128 | os.environ['AAI_SERVICE_PORT'] = '8443' |
| 129 | db.create_all() |
| 130 | self.app_conf = AppConfig() |
shivasubedi | 9aa0b66 | 2021-01-18 13:59:18 +0000 | [diff] [blame] | 131 | self.app_conf.nf_filter = NetworkFunctionFilter(**self.app_conf.subscription.nfFilter) |
efiacor | 0080fa4 | 2020-09-08 16:26:50 +0100 | [diff] [blame] | 132 | |
ajay_dp001 | 053579b | 2021-08-25 13:53:27 +0530 | [diff] [blame] | 133 | @patch('mod.pmsh_config.AppConfig._get_config', MagicMock(return_value=get_pmsh_config())) |
| 134 | def setUpAppConf(self): |
| 135 | self.pmsh_app_conf = NewAppConfig() |
| 136 | |
efiacor | 0080fa4 | 2020-09-08 16:26:50 +0100 | [diff] [blame] | 137 | def tearDown(self): |
| 138 | db.drop_all() |
| 139 | |
| 140 | @classmethod |
| 141 | def tearDownClass(cls): |
| 142 | db.session.remove() |