summaryrefslogtreecommitdiffstats
path: root/test/adapters/dcae
diff options
context:
space:
mode:
authorkrishnaa96 <krishna.moorthy6@wipro.com>2020-09-14 19:15:25 +0530
committerkrishnaa96 <krishna.moorthy6@wipro.com>2020-09-17 14:48:46 +0530
commit716ad1f32fc10181d2826d1f345f5a8b81bd0106 (patch)
tree8bd569c1aa863a6cb439d4f250b143ebf14fde6c /test/adapters/dcae
parent7b4619e523dbeb519eed3b141a0359108c614f55 (diff)
Add ML based optimization to PCI opt
Add DCAE DES adapter to the adapters Add a simple ML model in PCI opt app Issue-ID: OPTFRA-769 Signed-off-by: krishnaa96 <krishna.moorthy6@wipro.com> Change-Id: I144887e1be1ac6be4d27eeec22f9669c71f2c2bb
Diffstat (limited to 'test/adapters/dcae')
-rw-r--r--test/adapters/dcae/des_response.json47
-rw-r--r--test/adapters/dcae/test_des.py69
2 files changed, 116 insertions, 0 deletions
diff --git a/test/adapters/dcae/des_response.json b/test/adapters/dcae/des_response.json
new file mode 100644
index 0000000..c8595eb
--- /dev/null
+++ b/test/adapters/dcae/des_response.json
@@ -0,0 +1,47 @@
+{
+ "result": [
+ {
+ "additionalMeasurements": [
+ {
+ "hashMap":{
+ "networkId":"plmnid1",
+ "InterEnbOutAtt_X2HO":"300",
+ "InterEnbOutSucc_X2HO":"290"
+ },
+ "name":"Chn0004"
+ },
+ {
+ "hashMap":{
+ "InterEnbOutAtt_X2HO":"250",
+ "InterEnbOutSucc_X2HO":"170"
+ },
+ "name":"Chn0001"
+ }
+ ]
+ },
+ {
+ "additionalMeasurements": [
+ {
+ "hashMap":{
+ "networkId":"plmnid1",
+ "InterEnbOutAtt_X2HO":"300",
+ "InterEnbOutSucc_X2HO":"290"
+ },
+ "name":"Chn0004"
+ },
+ {
+ "hashMap":{
+ "InterEnbOutAtt_X2HO":"250",
+ "InterEnbOutSucc_X2HO":"170"
+ },
+ "name":"Chn0001"
+ }
+ ]
+ }
+ ],
+ "request": {
+ "cell_id": "Chn0002",
+ "interval": 2
+ },
+ "result_count": 2
+} \ No newline at end of file
diff --git a/test/adapters/dcae/test_des.py b/test/adapters/dcae/test_des.py
new file mode 100644
index 0000000..6daa29b
--- /dev/null
+++ b/test/adapters/dcae/test_des.py
@@ -0,0 +1,69 @@
+# -------------------------------------------------------------------------
+# Copyright (C) 2020 Wipro Limited.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+# -------------------------------------------------------------------------
+#
+
+import mock
+from mock import patch
+from requests import RequestException
+import unittest
+from osdf.adapters.dcae import des
+from osdf.adapters.dcae.des import DESException
+import osdf.config.loader as config_loader
+from osdf.utils.interfaces import json_from_file
+from osdf.utils.programming_utils import DotDict
+
+
+class TestDes(unittest.TestCase):
+
+ def setUp(self):
+ self.config_spec = {
+ "deployment": "config/osdf_config.yaml",
+ "core": "config/common_config.yaml"
+ }
+ self.osdf_config = DotDict(config_loader.all_configs(**self.config_spec))
+
+ def tearDown(self):
+ pass
+
+ def test_extract_data(self):
+ response_file = 'test/adapters/dcae/des_response.json'
+ response_json = json_from_file(response_file)
+
+ des_config = self.osdf_config.core['PCI']['DES']
+ service_id = des_config['service_id']
+ data = des_config['filter']
+ expected = response_json['result']
+ response = mock.MagicMock()
+ response.status_code = 200
+ response.ok = True
+ response.json.return_value = response_json
+ self.patcher_req = patch('requests.post', return_value=response)
+ self.Mock_req = self.patcher_req.start()
+ self.assertEqual(expected, des.extract_data(service_id, data))
+ self.patcher_req.stop()
+
+ response = mock.MagicMock()
+ response.status_code = 404
+ self.patcher_req = patch('requests.post', return_value=response)
+ self.Mock_req = self.patcher_req.start()
+ self.assertRaises(DESException, des.extract_data, service_id, data)
+ self.patcher_req.stop()
+
+ self.patcher_req = patch('requests.post', side_effect=RequestException("error"))
+ self.Mock_req = self.patcher_req.start()
+ self.assertRaises(DESException, des.extract_data, service_id, data)
+ self.patcher_req.stop()