summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xconfig/osdf_config.yaml7
-rw-r--r--osdf/adapters/aaf/aaf_authentication.py34
-rw-r--r--osdf/adapters/policy/interface.py30
-rw-r--r--osdf/optimizers/pciopt/pci_opt_processor.py45
-rw-r--r--osdf/optimizers/pciopt/solver/min_confusion_inl.mzn140
-rw-r--r--osdf/optimizers/pciopt/solver/optimizer.py62
-rwxr-xr-xosdfapp.py20
-rwxr-xr-xtest/config/osdf_config.yaml5
-rw-r--r--test/functest/simulators/configdb/response-payloads/getCellList-2000.json1
-rw-r--r--test/functest/simulators/configdb/response-payloads/getNbrList-cell20.json14
-rw-r--r--test/functest/simulators/configdb/response-payloads/getNbrList-cell21.json6
-rw-r--r--test/functest/simulators/configdb/response-payloads/getNbrList-cell22.json6
-rw-r--r--test/functest/simulators/configdb/response-payloads/getNbrList-cell23.json6
-rw-r--r--test/functest/simulators/configdb/response-payloads/getNbrList-cell24.json6
-rw-r--r--test/pci-optimization-tests/pci_anr_request.json29
-rw-r--r--test/pci-optimization-tests/request.json2
-rw-r--r--test/test_aaf_authentication.py9
-rw-r--r--test/test_process_pci_anr_opt.py79
18 files changed, 460 insertions, 41 deletions
diff --git a/config/osdf_config.yaml b/config/osdf_config.yaml
index 8c6d9f1..2abc651 100755
--- a/config/osdf_config.yaml
+++ b/config/osdf_config.yaml
@@ -20,6 +20,8 @@ conductorMinorVersion: 0
# Policy Platform -- requires ClientAuth, Authorization, and Environment
policyPlatformUrl: http://policy.api.simpledemo.onap.org:8081/pdp/api/getConfig # Policy Dev platform URL
policyPlatformEnv: TEST # Environment for policy platform
+# URL for policy model uploading
+policyPlatformUrlForModelUploading: http://policy.api.simpledemo.onap.org:8081/policy/api/v1/policytypes
# Config for DMaaP
messageReaderHosts: NA
@@ -31,10 +33,11 @@ sdcONAPInstanceID: NA
# AAF Authentication config
is_aaf_enabled: False
-aaf_cache_expiry_hrs: 3
+aaf_cache_expiry_mins: 5
aaf_url: https://aaftest.simpledemo.onap.org:8095
aaf_user_roles:
- - /api/oof/v1/placement:org.onap.osdf.access|*|read ALL
+ - '/placement:org.onap.oof.access|*|read ALL'
+ - '/pci:org.onap.oof.access|*|read ALL'
# Secret Management Service from AAF
aaf_sms_url: https://aaf-sms.onap:10443
diff --git a/osdf/adapters/aaf/aaf_authentication.py b/osdf/adapters/aaf/aaf_authentication.py
index 26eac29..2a72c30 100644
--- a/osdf/adapters/aaf/aaf_authentication.py
+++ b/osdf/adapters/aaf/aaf_authentication.py
@@ -43,7 +43,6 @@ def authenticate(uid, passwd):
return has_valid_role(perms)
except Exception as exp:
error_log.error("Error Authenticating the user {} : {}: ".format(uid, exp))
- pass
return False
@@ -57,27 +56,38 @@ else return false
def has_valid_role(perms):
aaf_user_roles = deploy_config['aaf_user_roles']
+ aaf_roles = get_role_list(perms)
+
for roles in aaf_user_roles:
path_perm = roles.split(':')
uri = path_perm[0]
- role = path_perm[1].split('|')[0]
- if re.search(uri, request.path) and perms:
- roles = perms.get('roles')
- if roles:
- perm_list = roles.get('perm')
- for p in perm_list:
- if role == p['type']:
- return True
+ perm = path_perm[1].split('|')
+ p = (perm[0], perm[1], perm[2].split()[0])
+ if re.search(uri, request.path) and p in aaf_roles:
+ return True
return False
+
"""
-Make the remote aaf api call if user is not in the cache.
+Build a list of roles tuples from the AAF response.
-Return the perms
"""
+
+
+def get_role_list(perms):
+ role_list = []
+ if perms:
+ roles = perms.get('roles')
+ if roles:
+ perm = roles.get('perm', [])
+ for p in perm:
+ role_list.append((p['type'], p['instance'], p['action']))
+ return role_list
+
+
def get_aaf_permissions(uid, passwd):
key = base64.b64encode(bytes("{}_{}".format(uid, passwd), "ascii"))
- time_delta = timedelta(hours=deploy_config.get('aaf_cache_expiry_hrs', 3))
+ time_delta = timedelta(minutes=deploy_config.get('aaf_cache_expiry_mins', 5))
perms = perm_cache.get(key)
diff --git a/osdf/adapters/policy/interface.py b/osdf/adapters/policy/interface.py
index a7839c6..0f20667 100644
--- a/osdf/adapters/policy/interface.py
+++ b/osdf/adapters/policy/interface.py
@@ -19,6 +19,9 @@
import base64
import itertools
import json
+import yaml
+import os
+import uuid
from requests import RequestException
@@ -190,3 +193,30 @@ def get_policies(request_json, service_type):
policies = remote_api(request_json, osdf_config, service_type)
return policies
+
+def upload_policy_models():
+ """Upload all the policy models reside in the folder"""
+ model_path = "../../models/policy/placement/tosca"
+ requestId = uuid.uuid4()
+ config = osdf_config.deployment
+ uid, passwd = config['policyPlatformUsername'], config['policyPlatformPassword']
+ pcuid, pcpasswd = config['policyClientUsername'], config['policyClientPassword']
+ headers = {"ClientAuth": base64.b64encode(bytes("{}:{}".format(pcuid, pcpasswd), "ascii"))}
+ headers.update({'Environment': config['policyPlatformEnv']})
+ headers.update({'X-ONAP-RequestID': requestId})
+ url = config['policyPlatformUrlForModelUploading']
+ rc = RestClient(userid=uid, passwd=passwd, headers=headers, url=url, log_func=debug_log.debug)
+
+ for file in os.listdir(model_path):
+ if not file.endswith(".yml"):
+ continue
+ with open(file) as f:
+ file_converted = json.dumps(yaml.load(f))
+ response = rc.request(json=file_converted, ok_codes=(200))
+ if not response:
+ success = False
+ audit_log.warn("Policy model %s uploading failed!" % file)
+ if not success:
+ return "Policy model uploading success!"
+ else:
+ return "Policy model uploading not success!"
diff --git a/osdf/optimizers/pciopt/pci_opt_processor.py b/osdf/optimizers/pciopt/pci_opt_processor.py
index da87b83..7a640aa 100644
--- a/osdf/optimizers/pciopt/pci_opt_processor.py
+++ b/osdf/optimizers/pciopt/pci_opt_processor.py
@@ -67,7 +67,7 @@ def process_pci_optimation(request_json, osdf_config, flat_policies):
def get_solutions(cell_info_list, network_cell_info, request_json):
- status, solutions = build_solution_list(cell_info_list, network_cell_info, request_json)
+ status, pci_solutions, anr_solutions = build_solution_list(cell_info_list, network_cell_info, request_json)
return {
"transactionId": request_json['requestInfo']['transactionId'],
"requestId": request_json["requestInfo"]["requestId"],
@@ -76,28 +76,45 @@ def get_solutions(cell_info_list, network_cell_info, request_json):
"solutions": [
{
'networkId': request_json['cellInfo']['networkId'],
- 'pciSolutions': solutions
+ 'pciSolutions': pci_solutions,
+ 'anrSolutions': anr_solutions
}
]
}
def build_solution_list(cell_info_list, network_cell_info, request_json):
- solution_list = []
status = "success"
req_id = request_json["requestInfo"]["requestId"]
try:
- opt_solution = optimize(network_cell_info, cell_info_list)
- sol = opt_solution[0]['pci']
- for k, v in sol.items():
- old_pci = get_pci_value(network_cell_info, k)
- if old_pci != v:
- response = {
- 'cellId': get_cell_id(network_cell_info, k),
- 'pci': v
- }
- solution_list.append(response)
+ opt_solution = optimize(network_cell_info, cell_info_list, request_json)
+ pci_solutions = build_pci_solution(network_cell_info, opt_solution['pci'])
+ anr_solutions = build_anr_solution(network_cell_info, opt_solution.get('removables', {}))
except RuntimeError:
error_log.error("Failed finding solution for {} {}".format(req_id, traceback.format_exc()))
status = "failed"
- return status, solution_list
+ return status, pci_solutions, anr_solutions
+
+
+def build_pci_solution(network_cell_info, pci_solution):
+ pci_solutions = []
+ for k, v in pci_solution.items():
+ old_pci = get_pci_value(network_cell_info, k)
+ if old_pci != v:
+ response = {
+ 'cellId': get_cell_id(network_cell_info, k),
+ 'pci': v
+ }
+ pci_solutions.append(response)
+ return pci_solutions
+
+
+def build_anr_solution(network_cell_info, removables):
+ anr_solutions = []
+ for k, v in removables.items():
+ response = {
+ 'cellId': get_cell_id(network_cell_info, k),
+ 'removeableNeighbors': list(map(lambda x: get_cell_id(network_cell_info, x), v))
+ }
+ anr_solutions.append(response)
+ return anr_solutions
diff --git a/osdf/optimizers/pciopt/solver/min_confusion_inl.mzn b/osdf/optimizers/pciopt/solver/min_confusion_inl.mzn
new file mode 100644
index 0000000..0f0fc91
--- /dev/null
+++ b/osdf/optimizers/pciopt/solver/min_confusion_inl.mzn
@@ -0,0 +1,140 @@
+% -------------------------------------------------------------------------
+% 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.
+%
+% -------------------------------------------------------------------------
+%
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% Parameters and its assertions
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+% Number of cells/radios.
+int: NUM_NODES;
+
+% Maximum number of Physical Cell Identifiers to be assigned to the nodes.
+int: NUM_PCIS;
+
+% Number of edges between neighbor nodes. There is a edge (i,j) if and only
+% if nodes i and j are neighbors, i.e., an user equipment (UE) can make
+% handoff between i and j. Such edges are used to avoid **COLLISION**, i.e.,
+% to guarantee that nodes i and j have different PCIs.
+int: NUM_NEIGHBORS;
+
+% Each line represents an edge between direct neighbors as defined before.
+array[1..NUM_NEIGHBORS, 1..2] of int: NEIGHBORS;
+
+% Number of undirect neighbor pairs (j, k) such that both j and k are direct
+% neighbors of node i, i.e., (j, k) exits if and only if exists (i, j) and
+% (i, k). Nodes (i, k) can generate "confunsions" in the network if they have
+% the same PCI. Such edges are used to avoid/minimize **CONFUSIONS**.
+int: NUM_SECOND_LEVEL_NEIGHBORS;
+
+% Each line represents an edge between undirect neighbors as defined before.
+array[1..NUM_SECOND_LEVEL_NEIGHBORS, 1..2] of int: SECOND_LEVEL_NEIGHBORS;
+
+% Number of ignorable neighbor links. Such links can be ignored during
+% optimization if needed.
+int: NUM_IGNORABLE_NEIGHBOR_LINKS;
+
+% The links that can be ignored if needed. Each line represents the two ends
+% of the links, like the previous structures.
+array[1..NUM_IGNORABLE_NEIGHBOR_LINKS, 1..2] of int: IGNORABLE_NEIGHBOR_LINKS;
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% Decision variables
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+% Defines the PCI for each node.
+array[0..NUM_NODES-1] of var 0..NUM_PCIS-1: pci;
+
+array[1..NUM_IGNORABLE_NEIGHBOR_LINKS] of var 0..1: used_ignorables;
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% Constraints
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+% Direct neighbors must have different PCIs for avoid **COLLISION**.
+% Forced links.
+constraint
+forall(i in 1..NUM_NEIGHBORS, j in 1..NUM_IGNORABLE_NEIGHBOR_LINKS
+ where
+ NEIGHBORS[i, 1] != IGNORABLE_NEIGHBOR_LINKS[j, 1] \/
+ NEIGHBORS[i, 2] != IGNORABLE_NEIGHBOR_LINKS[j, 2]
+)(
+ pci[NEIGHBORS[i, 1]] != pci[NEIGHBORS[i, 2]]
+);
+
+
+% Ignorable links.
+constraint
+forall(i in 1..NUM_NEIGHBORS, j in 1..NUM_IGNORABLE_NEIGHBOR_LINKS
+ where
+ NEIGHBORS[i, 1] == IGNORABLE_NEIGHBOR_LINKS[j, 1] /\
+ NEIGHBORS[i, 2] == IGNORABLE_NEIGHBOR_LINKS[j, 2]
+)(
+ used_ignorables[j] >= bool2int(pci[NEIGHBORS[i, 1]] == pci[NEIGHBORS[i, 2]])
+);
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% Objective function
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+% Total number of confusions.
+var int: total_confusions =
+ sum([bool2int(pci[SECOND_LEVEL_NEIGHBORS[i, 1]] ==
+ pci[SECOND_LEVEL_NEIGHBORS[i, 2]])
+ | i in 1..NUM_SECOND_LEVEL_NEIGHBORS]);
+
+% Total number of used ignorables links.
+var int: total_used_ignorables = sum(used_ignorables);
+
+solve :: int_search(pci, smallest, indomain_min, complete)
+
+% Minimize the total number of confusions.
+%minimize total_confusions;
+
+% Minimize the total number of confusions first,
+% then the number of used ignorables links.
+minimize (2 * NUM_IGNORABLE_NEIGHBOR_LINKS * total_confusions) +
+ total_used_ignorables;
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% Output
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+output
+["PCI assigment"] ++
+["\nnode,pci"] ++
+[
+ "\n" ++ show(node) ++ "," ++ show(pci[node])
+| node in 0..NUM_NODES-1
+] ++
+["\n\nTotal used ignorables links: " ++ show(total_used_ignorables)] ++
+["\nUsed ignorables links: "] ++
+[
+ "\n" ++ show(IGNORABLE_NEIGHBOR_LINKS[i, 1]) ++
+ "," ++ show(IGNORABLE_NEIGHBOR_LINKS[i, 2])
+ | i in 1..NUM_IGNORABLE_NEIGHBOR_LINKS where fix(used_ignorables[i] > 0)
+] ++
+["\n\nConfusions"] ++
+["\nTotal confusions: " ++ show(total_confusions)] ++
+["\nConfusion pairs"] ++
+[
+ "\n" ++ show(SECOND_LEVEL_NEIGHBORS[i, 1]) ++ "," ++
+ show(SECOND_LEVEL_NEIGHBORS[i, 2])
+ | i in 1..NUM_SECOND_LEVEL_NEIGHBORS where
+ fix(pci[SECOND_LEVEL_NEIGHBORS[i, 1]] == pci[SECOND_LEVEL_NEIGHBORS[i, 2]])
+]
+
diff --git a/osdf/optimizers/pciopt/solver/optimizer.py b/osdf/optimizers/pciopt/solver/optimizer.py
index 2825536..9b2e9d9 100644
--- a/osdf/optimizers/pciopt/solver/optimizer.py
+++ b/osdf/optimizers/pciopt/solver/optimizer.py
@@ -18,18 +18,44 @@
import itertools
import os
+from collections import defaultdict
import pymzn
from .pci_utils import get_id
BASE_DIR = os.path.dirname(__file__)
-MZN_FILE_NAME = os.path.join(BASE_DIR, 'no_conflicts_no_confusion.mzn')
-def pci_optimize(network_cell_info, cell_info_list):
+def pci_optimize(network_cell_info, cell_info_list, request_json):
neighbor_edges = get_neighbor_list(network_cell_info)
second_level_edges = get_second_level_neighbor(network_cell_info)
+ ignorable_links = get_ignorable_links(network_cell_info, request_json)
+ anr_flag = is_anr(request_json)
+
+ dzn_data = build_dzn_data(cell_info_list, ignorable_links, neighbor_edges, second_level_edges, anr_flag)
+
+ return build_pci_solution(dzn_data, ignorable_links, anr_flag)
+
+
+def build_pci_solution(dzn_data, ignorable_links, anr_flag):
+ mzn_solution = solve(get_mzn_model(anr_flag), dzn_data)
+
+ solution = {'pci': mzn_solution[0]['pci']}
+
+ if anr_flag:
+ removables = defaultdict(list)
+ used_ignorables = mzn_solution[0]['used_ignorables']
+ index = 0
+ for i in ignorable_links:
+ if used_ignorables[index] > 0:
+ removables[i[0]].append(i[1])
+ index += 1
+ solution['removables'] = removables
+ return solution
+
+
+def build_dzn_data(cell_info_list, ignorable_links, neighbor_edges, second_level_edges, anr_flag):
dzn_data = {
'NUM_NODES': len(cell_info_list),
'NUM_PCIS': len(cell_info_list),
@@ -38,8 +64,22 @@ def pci_optimize(network_cell_info, cell_info_list):
'NUM_SECOND_LEVEL_NEIGHBORS': len(second_level_edges),
'SECOND_LEVEL_NEIGHBORS': get_list(second_level_edges)
}
+ if anr_flag:
+ dzn_data['NUM_IGNORABLE_NEIGHBOR_LINKS'] = len(ignorable_links)
+ dzn_data['IGNORABLE_NEIGHBOR_LINKS'] = get_list(ignorable_links)
+ return dzn_data
+
+
+def get_mzn_model(anr_flag):
+ if anr_flag:
+ mzn_model = os.path.join(BASE_DIR, 'min_confusion_inl.mzn')
+ else:
+ mzn_model = os.path.join(BASE_DIR, 'no_conflicts_no_confusion.mzn')
+ return mzn_model
- return solve(dzn_data)
+
+def is_anr(request_json):
+ return 'pci-anr' in request_json["requestInfo"]["optimizers"]
def get_list(edge_list):
@@ -49,8 +89,8 @@ def get_list(edge_list):
return sorted(array_list)
-def solve(dzn_data):
- return pymzn.minizinc(MZN_FILE_NAME, data=dzn_data)
+def solve(mzn_model, dzn_data):
+ return pymzn.minizinc(mzn=mzn_model, data=dzn_data)
def get_neighbor_list(network_cell_info):
@@ -83,3 +123,15 @@ def build_second_level_list(network_cell_info, cell):
for nbr in cell.get('nbr_list', []):
second_nbr_list.append(get_id(network_cell_info, nbr['cellId']))
return [list(elem) for elem in list(itertools.combinations(second_nbr_list, 2))]
+
+
+def get_ignorable_links(network_cell_info, request_json):
+ ignorable_list = set()
+ anr_input_list = request_json["cellInfo"].get('anrInputList', [])
+ if anr_input_list:
+ for anr_info in anr_input_list:
+ cell_id = get_id(network_cell_info, anr_info['cellId'])
+ anr_removable = anr_info.get('removeableNeighbors', [])
+ for anr in anr_removable:
+ ignorable_list.add((cell_id, get_id(network_cell_info, anr)))
+ return ignorable_list
diff --git a/osdfapp.py b/osdfapp.py
index a83adb7..b8afbf4 100755
--- a/osdfapp.py
+++ b/osdfapp.py
@@ -21,6 +21,7 @@ OSDF Manager Main Flask Application
"""
import json
+import ssl
import sys
import traceback
from optparse import OptionParser
@@ -34,6 +35,7 @@ from schematics.exceptions import DataError
import osdf.adapters.aaf.sms as sms
import osdf.operation.responses
from osdf.adapters.policy.interface import get_policies
+from osdf.adapters.policy.interface import upload_policy_models
from osdf.config.base import osdf_config
from osdf.logging.osdf_logging import MH, audit_log, error_log, debug_log
from osdf.models.api.pciOptimizationRequest import PCIOptimizationAPI
@@ -101,6 +103,15 @@ def do_osdf_health_check():
return "OK"
+@app.route("/api/oof/loadmodels/v1", methods=["GET"])
+def do_osdf_load_policies():
+ audit_log.info("Uploading policy models")
+ """Upload policy models"""
+ response = upload_policy_models()
+ audit_log.info(response)
+ return "OK"
+
+
@app.route("/api/oof/v1/placement", methods=["POST"])
@auth_basic.login_required
def do_placement_opt():
@@ -192,6 +203,13 @@ def get_options(argv):
return opts
+def build_ssl_context():
+ ssl_context = ssl.SSLContext(ssl.PROTOCOL_TLSv1_2)
+ ssl_context.set_ciphers('ECDHE-RSA-AES128-SHA256:EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH')
+ ssl_context.load_cert_chain(sys_conf['ssl_context'][0], sys_conf['ssl_context'][1])
+ return ssl_context
+
+
if __name__ == "__main__":
sys_conf = osdf_config['core']['osdf_system']
@@ -203,7 +221,7 @@ if __name__ == "__main__":
ssl_opts = sys_conf.get('ssl_context')
if ssl_opts:
- common_app_opts.update({'ssl_context': tuple(ssl_opts)})
+ common_app_opts.update({'ssl_context': build_ssl_context()})
opts = get_options(sys.argv)
# Load secrets from SMS
diff --git a/test/config/osdf_config.yaml b/test/config/osdf_config.yaml
index 8cff1d5..eaa31ff 100755
--- a/test/config/osdf_config.yaml
+++ b/test/config/osdf_config.yaml
@@ -48,10 +48,11 @@ osdfPlacementUsername: "test"
osdfPlacementPassword: "testpwd"
is_aaf_enabled: False
-aaf_cache_expiry_hrs: 3
+aaf_cache_expiry_mins: 5
aaf_url: https://aaftest.simpledemo.onap.org:8095
aaf_user_roles:
- - /api/oof/v1/placement:org.onap.osdf.access|*|read ALL
+ - '/placement:org.onap.oof.access|*|read ALL'
+ - '/pci:org.onap.oof.access|*|read ALL'
# Secret Management Service from AAF
aaf_sms_url: https://aaf-sms.onap:10443
diff --git a/test/functest/simulators/configdb/response-payloads/getCellList-2000.json b/test/functest/simulators/configdb/response-payloads/getCellList-2000.json
new file mode 100644
index 0000000..77cf7db
--- /dev/null
+++ b/test/functest/simulators/configdb/response-payloads/getCellList-2000.json
@@ -0,0 +1 @@
+["cell20","cell21","cell22","cell23","cell24"] \ No newline at end of file
diff --git a/test/functest/simulators/configdb/response-payloads/getNbrList-cell20.json b/test/functest/simulators/configdb/response-payloads/getNbrList-cell20.json
new file mode 100644
index 0000000..86c7d2c
--- /dev/null
+++ b/test/functest/simulators/configdb/response-payloads/getNbrList-cell20.json
@@ -0,0 +1,14 @@
+[
+ {
+ "cellId": "cell21",
+ "pciValue": 0
+ },
+ {
+ "cellId": "cell22",
+ "pciValue": 1
+ },
+ {
+ "cellId": "cell23",
+ "pciValue": 2
+ }
+] \ No newline at end of file
diff --git a/test/functest/simulators/configdb/response-payloads/getNbrList-cell21.json b/test/functest/simulators/configdb/response-payloads/getNbrList-cell21.json
new file mode 100644
index 0000000..490c15f
--- /dev/null
+++ b/test/functest/simulators/configdb/response-payloads/getNbrList-cell21.json
@@ -0,0 +1,6 @@
+[
+ {
+ "cellId": "cell20",
+ "pciValue":0
+ }
+] \ No newline at end of file
diff --git a/test/functest/simulators/configdb/response-payloads/getNbrList-cell22.json b/test/functest/simulators/configdb/response-payloads/getNbrList-cell22.json
new file mode 100644
index 0000000..426e13b
--- /dev/null
+++ b/test/functest/simulators/configdb/response-payloads/getNbrList-cell22.json
@@ -0,0 +1,6 @@
+[
+ {
+ "cellId": "cell20",
+ "pciValue": 0
+ }
+] \ No newline at end of file
diff --git a/test/functest/simulators/configdb/response-payloads/getNbrList-cell23.json b/test/functest/simulators/configdb/response-payloads/getNbrList-cell23.json
new file mode 100644
index 0000000..de582eb
--- /dev/null
+++ b/test/functest/simulators/configdb/response-payloads/getNbrList-cell23.json
@@ -0,0 +1,6 @@
+[
+ {
+ "cellId": "cell24",
+ "pciValue": 0
+ }
+] \ No newline at end of file
diff --git a/test/functest/simulators/configdb/response-payloads/getNbrList-cell24.json b/test/functest/simulators/configdb/response-payloads/getNbrList-cell24.json
new file mode 100644
index 0000000..8d8d3fb
--- /dev/null
+++ b/test/functest/simulators/configdb/response-payloads/getNbrList-cell24.json
@@ -0,0 +1,6 @@
+[
+ {
+ "cellId": "cell23",
+ "pciValue": 2
+ }
+] \ No newline at end of file
diff --git a/test/pci-optimization-tests/pci_anr_request.json b/test/pci-optimization-tests/pci_anr_request.json
new file mode 100644
index 0000000..e8947b1
--- /dev/null
+++ b/test/pci-optimization-tests/pci_anr_request.json
@@ -0,0 +1,29 @@
+{
+ "requestInfo": {
+ "transactionId": "xxx-xxx-xxxx",
+ "requestId": "yyy-yyy-yyyy",
+ "callbackUrl": "https://wiki.onap.org:5000/callbackUrl/",
+ "sourceId": "SO",
+ "requestType": "create",
+ "numSolutions": 1,
+ "optimizers": [
+ "pci-anr"
+ ],
+ "timeout": 600
+ },
+ "cellInfo": {
+ "networkId": "2000",
+ "cellIdList": [
+ "cell20"
+ ]
+ },
+ "anrInputList": [
+ {
+ "cellId": "cell20",
+ "removeableNeighbors": [
+ "cell23"
+ ]
+ }
+ ],
+ "trigger": "NbrListChange"
+} \ No newline at end of file
diff --git a/test/pci-optimization-tests/request.json b/test/pci-optimization-tests/request.json
index 7ec9ab5..517ee10 100644
--- a/test/pci-optimization-tests/request.json
+++ b/test/pci-optimization-tests/request.json
@@ -7,7 +7,7 @@
"requestType": "create",
"numSolutions": 1,
"optimizers": [
- "placement"
+ "pci"
],
"timeout": 600
},
diff --git a/test/test_aaf_authentication.py b/test/test_aaf_authentication.py
index f20a860..6911337 100644
--- a/test/test_aaf_authentication.py
+++ b/test/test_aaf_authentication.py
@@ -16,6 +16,7 @@
# -------------------------------------------------------------------------
#
import os
+
from flask import Flask
from mock import mock
@@ -33,7 +34,7 @@ class TestAafAuthentication():
def mock_aaf_response(*args, **kwargs):
return {"perm": [{"instance": "menu_ecd", "action": "*", "type": "org.onap.oof.controller.dev.menu"},
- {"instance": "*", "action": "*", "type": "org.onap.osdf.access"},
+ {"instance": "*", "action": "read", "type": "org.onap.oof.access"},
{"instance": "aaf", "action": "request", "type": "org.onap.osdf.certman"},
{"instance": "*", "action": "*", "type": "org.onap.osdf.dev.access"},
{"instance": ":*:*", "action": "*", "type": "org.onap.osdf.dev.k8"},
@@ -48,8 +49,8 @@ class TestAafAuthentication():
auth.clear_cache()
def mock_aaf_response(*args, **kwargs):
- return {"perm": [{"instance": "menu_ecd", "action": "*", "type": "org.onap.oof.controller.dev.menu"},
- {"instance": "*", "action": "*", "type": "org.onap.osdf.access"},
+ return {"perm": [{"instance": "menu_ecd", "action": "*", "type": "org.onap.osdf.controller.dev.menu"},
+ {"instance": "*", "action": "read", "type": "org.onap.oof.access"},
{"instance": "aaf", "action": "request", "type": "org.onap.osdf.certman"},
{"instance": "*", "action": "*", "type": "org.onap.osdf.dev.access"},
{"instance": ":*:*", "action": "*", "type": "org.onap.osdf.dev.k8"},
@@ -77,7 +78,7 @@ class TestAafAuthentication():
def mock_aaf_response(*args, **kwargs):
return {"perm": [{"instance": "menu_ecd", "action": "*", "type": "org.onap.oof.controller.dev.menu"},
- {"instance": "*", "action": "*", "type": "org.onap.osdf.access"},
+ {"instance": "*", "action": "*", "type": "org.onap.oof.access"},
{"instance": "aaf", "action": "request", "type": "org.onap.osdf.certman"},
{"instance": "*", "action": "*", "type": "org.onap.osdf.dev.access"},
{"instance": ":*:*", "action": "*", "type": "org.onap.osdf.dev.k8"},
diff --git a/test/test_process_pci_anr_opt.py b/test/test_process_pci_anr_opt.py
new file mode 100644
index 0000000..8c6a34c
--- /dev/null
+++ b/test/test_process_pci_anr_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, 3: 3, 4: 0}, 'used_ignorables': [0]}]
+
+ 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_anr_opt_solutions(self):
+ main_dir = ""
+ parameter_data_file = main_dir + "test/pci-optimization-tests/pci_anr_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()
+