Repository: qpid-dispatch Updated Branches: refs/heads/crolke-DISPATCH-188-1 4ca28e396 -> 6a6b95176
Deduplicate lists of items from policy files. Tidy up doc text. Project: http://git-wip-us.apache.org/repos/asf/qpid-dispatch/repo Commit: http://git-wip-us.apache.org/repos/asf/qpid-dispatch/commit/6a6b9517 Tree: http://git-wip-us.apache.org/repos/asf/qpid-dispatch/tree/6a6b9517 Diff: http://git-wip-us.apache.org/repos/asf/qpid-dispatch/diff/6a6b9517 Branch: refs/heads/crolke-DISPATCH-188-1 Commit: 6a6b9517639b509c10f1be13cfdc263e61759ad3 Parents: 4ca28e3 Author: Chuck Rolke <[email protected]> Authored: Mon Dec 14 10:16:24 2015 -0500 Committer: Chuck Rolke <[email protected]> Committed: Mon Dec 14 10:16:24 2015 -0500 ---------------------------------------------------------------------- .../qpid_dispatch_internal/management/policy.py | 58 +++++++++++++++----- tests/system_tests_policy.py | 3 +- 2 files changed, 45 insertions(+), 16 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/qpid-dispatch/blob/6a6b9517/python/qpid_dispatch_internal/management/policy.py ---------------------------------------------------------------------- diff --git a/python/qpid_dispatch_internal/management/policy.py b/python/qpid_dispatch_internal/management/policy.py index 35baa8d..cd4d80e 100644 --- a/python/qpid_dispatch_internal/management/policy.py +++ b/python/qpid_dispatch_internal/management/policy.py @@ -62,7 +62,7 @@ External Policy: 2. CRUD Interface At the CRUD Create function the policy is represented by two strings: -- name : name of the ConfigParser section +- name : name of the ConfigParser section which is the application name - data : ConfigParser section as a string The CRUD Interface policy is created by ConfigParser.read(externalFile) @@ -71,11 +71,12 @@ and then iterating through the config parser sections. CRUD Interface Policy: ---------------------- - 'photoserver', '[('schemaVersion', '1'), - ('policyVersion', '1'), - ('roles', "{\n - 'users' : ['u1', 'u2'],\n - 'paidsubscribers' : ['p1', 'p2']\n}")]' + name: 'photoserver' + data: '[('schemaVersion', '1'), + ('policyVersion', '1'), + ('roles', "{\n + 'users' : ['u1', 'u2'],\n + 'paidsubscribers' : ['p1', 'p2']\n}")]' 3. Internal @@ -443,6 +444,9 @@ class PolicyCompiler(): errors.append("Application '%s' option '%s' policy '%s' setting '%s' must be type 'list' but is '%s'." % (name, key, pname, setting, type(sval))) return False + # deduplicate address lists + sval = list(set(sval)) + submap[pname][setting] = sval else: warnings.append("Application '%s' option '%s' policy '%s' setting '%s' is ignored." % (name, key, pname, setting)) @@ -508,9 +512,14 @@ class PolicyCompiler(): if key == "connectionOrigins": if not self.crud_compiler_v1_origins(name, submap, warnings, errors): return False - if key == "policies": + elif key == "policies": if not self.crud_compiler_v1_policies(name, submap, warnings, errors): return False + else: + # deduplicate connectionPolicy and roles lists + for k,v in submap.iteritems(): + v = list(set(v)) + submap[k] = v policy_out[key] = submap except Exception, e: errors.append("Application '%s' option '%s' error processing map: %s" % @@ -606,8 +615,8 @@ class Policy(): def policy_create(self, name, policy): """ Create named policy - @param name: policy name - @param policy: policy data + @param name: application name + @param policy: policy data in CRUD Interface format """ warnings = [] diag = [] @@ -621,22 +630,39 @@ class Policy(): self.data[name] = candidate def policy_read(self, name): - """Read named policy""" + """ + Read policy for named application + @param[in] name application name + @return policy data in Crud Interface format + """ return self.data[name] def policy_update(self, name, policy): - """Update named policy""" - pass + """ + Update named policy + @param[in] name application name + @param[in] policy data in Crud interface format + """ + if not name in self.data: + raise PolicyError("Policy '%s' does not exist" % name) + self.policy_create(name, policy) def policy_delete(self, name): - """Delete named policy""" + """ + Delete named policy + @param[in] name application name + """ + if not name in self.data: + raise PolicyError("Policy '%s' does not exist" % name) del self.data[name] # # db enumerator # def policy_db_get_names(self): - """Return a list of policy names.""" + """ + Return a list of application names in this policy + """ return self.data.keys() @@ -655,7 +681,8 @@ class Policy(): def policy_aggregate_policy_int(self, upolicy, policy, roles, settingname): """ - Pull int out of policy.policies[role] and install into upolicy if > existing + Pull int out of policy.policies[role] and install into upolicy. + Integers are set to max(new, existing) param[in,out] upolicy user policy receiving aggregations param[in] policy Internal policy holding settings to be aggregated param[in] settingname setting of interest @@ -726,6 +753,7 @@ class Policy(): sp = rpol[settingname] if settingname in upolicy: upolicy[settingname].extend( sp ) + upolicy[settingname] = list(set(upolicy[settingname])) else: # user policy doesn't have setting so force it upolicy[settingname] = sp http://git-wip-us.apache.org/repos/asf/qpid-dispatch/blob/6a6b9517/tests/system_tests_policy.py ---------------------------------------------------------------------- diff --git a/tests/system_tests_policy.py b/tests/system_tests_policy.py index 4cd880a..1775328 100644 --- a/tests/system_tests_policy.py +++ b/tests/system_tests_policy.py @@ -233,7 +233,8 @@ class PolicyFile(TestCase): self.assertTrue(upolicy['allow_anonymous_sender']) self.assertTrue(upolicy['allow_dynamic_src']) addrs = ['public', 'private','management', 'root'] - print "targets = %s" % upolicy['targets'] + self.assertTrue(len(upolicy['targets']) == 4) + self.assertTrue(len(upolicy['sources']) == 4) for s in addrs: self.assertTrue(s in upolicy['targets']) for s in addrs: self.assertTrue(s in upolicy['sources']) --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
