aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorVarma, Vikas <vv8305@att.com>2018-09-19 00:39:03 -0400
committerVikas Varma <vv8305@att.com>2018-09-19 05:00:05 +0000
commit276119f2d54b2e8f49b8595ecfcc6545aeb77fef (patch)
treefd39c9b061e00a79d867e860a030020f7b0af571 /test
parentce6ac9833b9d91dfe9fdd4a0346a641c0c246d90 (diff)
Initial checkin for pci optimization code
Change-Id: I6fe8ad471f8ad68a964664b910f02bd8a9766639 Signed-off-by: Varma, Vikas <vv8305@att.com> Issue-ID: OPTFRA-342
Diffstat (limited to 'test')
-rw-r--r--test/configdb/test_configdb_calls.py46
-rw-r--r--test/functest/simulators/configdb/response-payloads/getCellList-1000.json1
-rw-r--r--test/functest/simulators/configdb/response-payloads/getNbrList-cell0.json10
-rw-r--r--test/functest/simulators/configdb/response-payloads/getNbrList-cell1.json10
-rw-r--r--test/functest/simulators/configdb/response-payloads/getNbrList-cell2.json10
-rwxr-xr-xtest/functest/simulators/oof_dependencies_simulators.py19
-rwxr-xr-xtest/functest/simulators/simulated-config/osdf_config.yaml12
-rw-r--r--test/pci-optimization-tests/request.json22
-rw-r--r--test/test_process_pci_opt.py79
9 files changed, 208 insertions, 1 deletions
diff --git a/test/configdb/test_configdb_calls.py b/test/configdb/test_configdb_calls.py
new file mode 100644
index 0000000..eb799e7
--- /dev/null
+++ b/test/configdb/test_configdb_calls.py
@@ -0,0 +1,46 @@
+# -------------------------------------------------------------------------
+# Copyright (c) 2018 AT&T Intellectual Property
+#
+# 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.
+#
+# -------------------------------------------------------------------------
+#
+
+from osdf.optimizers.pciopt.configdb import request
+import osdf.config.loader as config_loader
+from osdf.utils.interfaces import json_from_file
+from osdf.utils.programming_utils import DotDict
+from osdf.adapters.policy import interface as pol
+
+
+class TestConfigDbCalls():
+
+ def setUp(self):
+ self.config_spec = {
+ "deployment": "test/functest/simulators/simulated-config/osdf_config.yaml",
+ "core": "test/functest/simulators/simulated-config/common_config.yaml"
+ }
+ self.osdf_config = DotDict(config_loader.all_configs(**self.config_spec))
+ self.lp = self.osdf_config.core.get('osdf_temp', {}).get('local_policies', {}
+ ).get('placement_policy_files_vcpe')
+
+ def tearDown(self):
+ pass
+
+ def test_request(self):
+ self.setUp()
+ req_json = json_from_file("./test/pci-optimization-tests/request.json")
+ policies = pol.get_local_policies("test/policy-local-files/", self.lp)
+ cell_list = request(req_json, self.osdf_config, policies)
+
+
diff --git a/test/functest/simulators/configdb/response-payloads/getCellList-1000.json b/test/functest/simulators/configdb/response-payloads/getCellList-1000.json
new file mode 100644
index 0000000..df23f6e
--- /dev/null
+++ b/test/functest/simulators/configdb/response-payloads/getCellList-1000.json
@@ -0,0 +1 @@
+["cell0","cell1","cell2"] \ No newline at end of file
diff --git a/test/functest/simulators/configdb/response-payloads/getNbrList-cell0.json b/test/functest/simulators/configdb/response-payloads/getNbrList-cell0.json
new file mode 100644
index 0000000..e0986d8
--- /dev/null
+++ b/test/functest/simulators/configdb/response-payloads/getNbrList-cell0.json
@@ -0,0 +1,10 @@
+[
+ {
+ "cellId": "cell1",
+ "pciValue": 1
+ },
+ {
+ "cellId": "cell2",
+ "pciValue": 2
+ }
+] \ No newline at end of file
diff --git a/test/functest/simulators/configdb/response-payloads/getNbrList-cell1.json b/test/functest/simulators/configdb/response-payloads/getNbrList-cell1.json
new file mode 100644
index 0000000..d6ed353
--- /dev/null
+++ b/test/functest/simulators/configdb/response-payloads/getNbrList-cell1.json
@@ -0,0 +1,10 @@
+[
+ {
+ "cellId": "cell0",
+ "pciValue": 0
+ },
+ {
+ "cellId": "cell2",
+ "pciValue": 2
+ }
+] \ No newline at end of file
diff --git a/test/functest/simulators/configdb/response-payloads/getNbrList-cell2.json b/test/functest/simulators/configdb/response-payloads/getNbrList-cell2.json
new file mode 100644
index 0000000..1ea80be
--- /dev/null
+++ b/test/functest/simulators/configdb/response-payloads/getNbrList-cell2.json
@@ -0,0 +1,10 @@
+[
+ {
+ "cellId": "cell0",
+ "pciValue": 0
+ },
+ {
+ "cellId": "cell1",
+ "pciValue": 1
+ }
+] \ No newline at end of file
diff --git a/test/functest/simulators/oof_dependencies_simulators.py b/test/functest/simulators/oof_dependencies_simulators.py
index bdb552d..9c20e79 100755
--- a/test/functest/simulators/oof_dependencies_simulators.py
+++ b/test/functest/simulators/oof_dependencies_simulators.py
@@ -20,9 +20,9 @@
Simulators for dependencies of OSDF (e.g. HAS-API, Policy, SO-callback, etc.)
"""
import glob
+from flask import Flask, jsonify, request
from osdf.utils.interfaces import json_from_file
-from flask import Flask, jsonify, request
app = Flask(__name__)
@@ -80,5 +80,22 @@ def get_policies(sub_component):
return jsonify([json_from_file(x) for x in files])
+@app.route("/simulated/configdb/getCellList", methods=["GET"])
+def get_cell_list():
+ data, status = get_payload_for_simulated_component('configdb',
+ 'getCellList-' + request.args.get('networkId') + '.json')
+ if not status:
+ return jsonify(data)
+ return jsonify(data), 503
+
+
+@app.route("/simulated/configdb/getNbrList", methods=["GET"])
+def get_nbr_list():
+ data, status = get_payload_for_simulated_component('configdb', 'getNbrList-' + request.args.get('cellId') + '.json')
+ if not status:
+ return jsonify(data)
+ return jsonify(data), 503
+
+
if __name__ == "__main__":
app.run(debug=True)
diff --git a/test/functest/simulators/simulated-config/osdf_config.yaml b/test/functest/simulators/simulated-config/osdf_config.yaml
index 0a77fe2..dbdcc91 100755
--- a/test/functest/simulators/simulated-config/osdf_config.yaml
+++ b/test/functest/simulators/simulated-config/osdf_config.yaml
@@ -32,3 +32,15 @@ sdcONAPInstanceID: ONAP-OSDF
osdfPlacementUrl: "http://127.0.0.1:24699/osdf/api/v2/placement"
osdfPlacementUsername: "test"
osdfPlacementPassword: "testpwd"
+
+# config db api
+configDbUrl: http://127.0.0.1:5000/simulated/configdb
+configDbUserName: osdf
+configDbPassword: passwd
+configDbGetCellListUrl: 'getCellList'
+configDbGetNbrListUrl: 'getNbrList'
+
+# Credentials for PCIHandler
+pciHMSUsername: "" # pcihandler username for call back.
+pciHMSPassword: "" # pcihandler password for call back.
+
diff --git a/test/pci-optimization-tests/request.json b/test/pci-optimization-tests/request.json
new file mode 100644
index 0000000..79c98c3
--- /dev/null
+++ b/test/pci-optimization-tests/request.json
@@ -0,0 +1,22 @@
+{
+ "requestInfo": {
+ "transactionId": "xxx-xxx-xxxx",
+ "requestId": "yyy-yyy-yyyy",
+ "callbackUrl": "https://wiki.onap.org:5000/callbackUrl/",
+ "sourceId": "SO",
+ "requestType": "create",
+ "numSolutions": 1,
+ "optimizers": [
+ "placement"
+ ],
+ "timeout": 600
+ },
+ "cellInfo": {
+ "networkId": "1000",
+ "cellIdList": [
+ {
+ "cellId": "cell0"
+ }
+ ]
+ }
+} \ No newline at end of file
diff --git a/test/test_process_pci_opt.py b/test/test_process_pci_opt.py
new file mode 100644
index 0000000..31aa5fb
--- /dev/null
+++ b/test/test_process_pci_opt.py
@@ -0,0 +1,79 @@
+# -------------------------------------------------------------------------
+# Copyright (c) 2018 AT&T Intellectual Property
+#
+# 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
+import unittest
+
+from flask import Response
+from mock import patch
+from osdf.adapters.local_data import local_policies
+from osdf.optimizers.pciopt.pci_opt_processor import process_pci_optimation
+import osdf.config.loader as config_loader
+from osdf.utils.interfaces import json_from_file
+from osdf.utils.programming_utils import DotDict
+
+
+class TestProcessPlacementOpt(unittest.TestCase):
+
+ def setUp(self):
+ mock_req_accept_message = Response("Accepted Request", content_type='application/json; charset=utf-8')
+ self.patcher_req = patch('osdf.optimizers.pciopt.configdb.request',
+ return_value={"solutionInfo": {"placementInfo": "dummy"}})
+ self.patcher_req_accept = patch('osdf.operation.responses.osdf_response_for_request_accept',
+ return_value=mock_req_accept_message)
+ self.patcher_callback = patch(
+ 'osdf.optimizers.pciopt.pci_opt_processor.process_pci_optimation',
+ return_value=mock_req_accept_message)
+
+ mock_mzn_response = [{'pci': {0: 0, 1: 1, 2: 2}}]
+
+ self.patcher_minizinc_callback = patch(
+ 'osdf.optimizers.pciopt.solver.optimizer.solve',
+ return_value=mock_mzn_response )
+ self.patcher_RestClient = patch(
+ 'osdf.utils.interfaces.RestClient', return_value=mock.MagicMock())
+ self.Mock_req = self.patcher_req.start()
+ self.Mock_req_accept = self.patcher_req_accept.start()
+ self.Mock_callback = self.patcher_callback.start()
+ self.Mock_RestClient = self.patcher_RestClient.start()
+ self.Mock_mzn_callback = self.patcher_minizinc_callback.start()
+
+ def tearDown(self):
+ patch.stopall()
+
+ def test_process_pci_opt_solutions(self):
+ main_dir = ""
+ parameter_data_file = main_dir + "test/pci-optimization-tests/request.json"
+ policy_data_path = main_dir + "test/policy-local-files/"
+ self.config_spec = {
+ "deployment": "test/functest/simulators/simulated-config/osdf_config.yaml",
+ "core": "test/functest/simulators/simulated-config/common_config.yaml"
+ }
+ self.osdf_config = DotDict(config_loader.all_configs(**self.config_spec))
+
+ valid_policies_list_file = policy_data_path + '/' + 'meta-valid-policies.txt'
+ valid_policies_files = local_policies.get_policy_names_from_file(valid_policies_list_file)
+
+ request_json = json_from_file(parameter_data_file)
+ policies = [json_from_file(policy_data_path + '/' + name) for name in valid_policies_files]
+
+ templ_string = process_pci_optimation(request_json, self.osdf_config,policies)
+
+
+if __name__ == "__main__":
+ unittest.main()
+