From 49a0eac16462c04c285125686fb235c22c9ad607 Mon Sep 17 00:00:00 2001 From: "Patel, Ankitkumar" Date: Tue, 29 May 2018 11:31:55 -0400 Subject: Fixed case sensitive resource matching Fixed the case sensitive matching for resources between policy and request. Issue-ID: OPTFRA-247 Change-Id: Ic031f6c950b6c6b44bd2e4231a9ef672beea994b Signed-off-by: Patel, Ankitkumar --- osdf/adapters/policy/interface.py | 1 + osdf/optimizers/placementopt/conductor/api_builder.py | 5 ++--- osdf/optimizers/placementopt/conductor/conductor.py | 3 ++- osdf/optimizers/placementopt/conductor/translation.py | 11 +++++++---- 4 files changed, 12 insertions(+), 8 deletions(-) (limited to 'osdf') diff --git a/osdf/adapters/policy/interface.py b/osdf/adapters/policy/interface.py index 6a6cbb3..dbbf122 100644 --- a/osdf/adapters/policy/interface.py +++ b/osdf/adapters/policy/interface.py @@ -64,6 +64,7 @@ def get_by_scope(rest_client, req, config_local, type_service): scope_fields.extend([get_scope_fields(field, references, req, list_flatten(scope_policies)) if 'get_param' in field else field]) scope_fields = set(list_flatten(scope_fields)) + scope_fields = set([x.lower() for x in scope_fields]) for scope in scope_fields: policies.extend(policy_api_call(rest_client, primary_scope, scope)) scope_policies.append([policy for policy in policies diff --git a/osdf/optimizers/placementopt/conductor/api_builder.py b/osdf/optimizers/placementopt/conductor/api_builder.py index 209aa3b..8123726 100644 --- a/osdf/optimizers/placementopt/conductor/api_builder.py +++ b/osdf/optimizers/placementopt/conductor/api_builder.py @@ -40,12 +40,11 @@ def conductor_api_builder(request_json, flat_policies: list, local_config, demand_vnf_name_list = [] for placementDemand in request_json['placementInfo']['placementDemands']: - demand_vnf_name_list.append(placementDemand['resourceModuleName']) - + demand_vnf_name_list.append(placementDemand['resourceModuleName'].lower()) demand_list = tr.gen_demands(request_json, gp['vnfPolicy']) attribute_policy_list = tr.gen_attribute_policy(demand_vnf_name_list, gp['attribute']) distance_to_location_policy_list = tr.gen_distance_to_location_policy( - demand_vnf_name_list, gp['distance_to_location']) + demand_vnf_name_list, gp['distancePolicy']) inventory_policy_list = tr.gen_inventory_group_policy(demand_vnf_name_list, gp['inventory_group']) resource_instance_policy_list = tr.gen_resource_instance_policy( demand_vnf_name_list, gp['instance_fit']) diff --git a/osdf/optimizers/placementopt/conductor/conductor.py b/osdf/optimizers/placementopt/conductor/conductor.py index c872e5a..9f680c3 100644 --- a/osdf/optimizers/placementopt/conductor/conductor.py +++ b/osdf/optimizers/placementopt/conductor/conductor.py @@ -154,7 +154,8 @@ def conductor_response_processor(conductor_response, raw_response, req_id): debug_log.debug("The key[{}] is not mapped and will not be returned in assignment info".format(key)) composite_solutions.append(solution) - request_status = conductor_response['plans'][0]['status'] + request_status = "completed" if conductor_response['plans'][0]['status'] == "done" \ + else conductor_response['plans'][0]['status'] transaction_id = raw_response.headers.get('transaction_id', "") status_message = conductor_response.get('plans')[0].get('message', "") diff --git a/osdf/optimizers/placementopt/conductor/translation.py b/osdf/optimizers/placementopt/conductor/translation.py index 4206276..f1c12c8 100644 --- a/osdf/optimizers/placementopt/conductor/translation.py +++ b/osdf/optimizers/placementopt/conductor/translation.py @@ -77,11 +77,13 @@ def get_matching_vnfs(resources, vnf_list, match_type="intersection"): :param match_type: "intersection" or "all" or "any" (any => send all_vnfs if there is any intersection) :return: List of matching VNFs """ + resources_lcase = [x.lower() for x in resources] if match_type == "all": # don't bother with any comparisons - return resources if set(resources) <= set(vnf_list) else None - common_vnfs = set(vnf_list) & set(resources) + return resources if set(resources_lcase) <= set(vnf_list) else None + common_vnfs = set(vnf_list) & set(resources_lcase) + common_resources = [x for x in resources if x.lower() in common_vnfs] if match_type == "intersection": # specifically requested intersection - return list(common_vnfs) + return list(common_resources) return resources if common_vnfs else None # "any" match => all resources to be returned @@ -209,7 +211,8 @@ def get_candidates_demands(demand): def get_policy_properties(demand, policies): """Get policy_properties for cases where there is a match with the demand""" for policy in policies: - if demand['resourceModuleName'] not in set(policy['content'].get('resources', [])): + policy_demands = set([x.lower() for x in policy['content'].get('resources', [])]) + if demand['resourceModuleName'].lower() not in policy_demands: continue # no match for this policy for policy_property in policy['content']['vnfProperties']: yield policy_property -- cgit 1.2.3-korg