summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLukasz Rajewski <lukasz.rajewski@orange.com>2020-05-11 17:38:06 +0200
committerLukasz Rajewski <lukasz.rajewski@orange.com>2020-05-11 20:03:16 +0200
commit76efb65c4fffbd5b940a75c36329a2e0409be382 (patch)
treed8185fa040174641728c1dbbdd66085733c736dd
parent1b493a741b87880181a027fe102d295fcbd6f7cb (diff)
Fix for remote policy filtering
Changed a way of processing policies by scope. Before filtering was resulting with None type access exception. Change-Id: Ide6515b4b18a2dc7344e92b32a76d00ba48d4301 Issue-ID: OPTFRA-755 Signed-off-by: Lukasz Rajewski <lukasz.rajewski@orange.com>
-rw-r--r--config/common_config.yaml2
-rw-r--r--osdf/adapters/policy/interface.py9
-rw-r--r--test/test_PolicyCalls.py2
3 files changed, 7 insertions, 6 deletions
diff --git a/config/common_config.yaml b/config/common_config.yaml
index 97bfcca..0f2dc96 100644
--- a/config/common_config.yaml
+++ b/config/common_config.yaml
@@ -38,7 +38,7 @@ osdf_temp: # special configuration required for "workarounds" or testing
placement_policy_files_vfw_td:
- vnfPolicy_vFW_TD.json
- vnfPolicy_vPGN_TD.json
- - affinity_vFW_TD.json
+ - Affinity_vFW_TD.json
- QueryPolicy_vFW_TD.json
slice_selection_policy_dir_urllc_1: "./test/policy-local-files/"
slice_selection_policy_files_urllc_1:
diff --git a/osdf/adapters/policy/interface.py b/osdf/adapters/policy/interface.py
index ccbd3dc..1e7d2cd 100644
--- a/osdf/adapters/policy/interface.py
+++ b/osdf/adapters/policy/interface.py
@@ -76,9 +76,10 @@ def get_by_scope(rest_client, req, config_local, type_service):
keys = scope_fields.keys() & policies[policyName]['properties'].keys()
policy = {}
policy[policyName] = policies[policyName]
- scope_policies.append(policy for k in keys
- if set(policies.get(policyName, {}).get('properties',{}).get(k)) >= set(scope_fields[k])
- and policy not in scope_policies)
+ for k in keys:
+ if set(policies.get(policyName, {}).get('properties',{}).get(k)) >= set(scope_fields[k])\
+ and policy not in scope_policies:
+ scope_policies.append(policy)
return scope_policies
@@ -146,7 +147,7 @@ def remote_api(req_json, osdf_config, service_type="placement"):
policies = get_by_scope(rc, req_json, osdf_config.core, service_type)
formatted_policies = []
- for x in itertools.chain(*policies):
+ for x in policies:
if x[list(x.keys())[0]].get('properties') is None:
raise BusinessException("Properties not found for policy with name %s" % x[list(x.keys()[0])])
else:
diff --git a/test/test_PolicyCalls.py b/test/test_PolicyCalls.py
index d4dc37f..1ca14dc 100644
--- a/test/test_PolicyCalls.py
+++ b/test/test_PolicyCalls.py
@@ -92,7 +92,7 @@ class TestPolicyCalls(unittest.TestCase):
policy_config_file = yaml.load(yaml_file2)
with patch('osdf.utils.interfaces.RestClient.request', return_value=req_json_obj2):
policies_list = interface.get_by_scope(RestClient, req_json_obj, policy_config_file, 'placement')
- self.assertTrue(policies_list, 'is null')
+ self.assertFalse(policies_list)
self.assertRaises(Exception)
def test_gen_demands(self):