Fix for remote policy filtering 82/107482/2
authorLukasz Rajewski <lukasz.rajewski@orange.com>
Mon, 11 May 2020 15:38:06 +0000 (17:38 +0200)
committerLukasz Rajewski <lukasz.rajewski@orange.com>
Mon, 11 May 2020 18:03:16 +0000 (20:03 +0200)
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>
config/common_config.yaml
osdf/adapters/policy/interface.py
test/test_PolicyCalls.py

index 97bfcca..0f2dc96 100644 (file)
@@ -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:
index ccbd3dc..1e7d2cd 100644 (file)
@@ -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:
index d4dc37f..1ca14dc 100644 (file)
@@ -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):