Remove policy file from source and refactor tests

This patch removes the policy file now that policy in code has merged
and we now have all the default policy from policy.json in code. In
addition it refactors a couple of tests to use the in code policy
instead of the policy.json file when testing.

Depends-On: Ib1d9a51a78e2a84a3d7294dc8782605a681fa9e8
Change-Id: I23136627cb095015352b8eb09c31b2b2f1ce315f
Implements: blueprint policy-in-code
This commit is contained in:
Ubuntu 2017-03-24 15:14:15 +00:00 committed by Richard Avelar
parent 646a42d5a6
commit 5594405c12
2 changed files with 11 additions and 20 deletions

View File

@ -1,2 +0,0 @@
{
}

View File

@ -173,25 +173,21 @@ class DefaultPolicyTestCase(unit.TestCase):
class PolicyJsonTestCase(unit.TestCase):
def _load_entries(self, filename):
return set(json.load(open(filename)))
def _get_default_policy_rules(self):
"""Return a dictionary of all in-code policies.
def _add_missing_default_rules(self, rules):
"""Add default rules and their values to the given rules dict.
The given rules dict may have an incomplete set of policy rules.
This method will add the default policy rules and their values to the
dict. It will not override the existing rules. This method is temporary
and is only needed until we move all policy.json rules into code.
All policies have a default value that is maintained in code.
This method returns a dictionary containing all default policies.
"""
rules = dict()
for rule in policies.list_rules():
if rule.name not in rules:
rules[rule.name] = rule.check_str
rules[rule.name] = rule.check_str
return rules
def test_json_examples_have_matching_entries(self):
policy_keys = self._load_entries(unit.dirs.etc('policy.json'))
cloud_policy_keys = self._load_entries(
unit.dirs.etc('policy.v3cloudsample.json'))
policy_keys = self._get_default_policy_rules()
cloud_policy_keys = set(
json.load(open(unit.dirs.etc('policy.v3cloudsample.json'))))
policy_extra_keys = ['admin_or_token_subject',
'service_admin_or_token_subject',
@ -228,10 +224,7 @@ class PolicyJsonTestCase(unit.TestCase):
self.assertTrue(result)
def test_all_targets_documented(self):
# All the targets in the sample policy file must be documented in
# doc/source/policy_mapping.rst.
policy_keys = json.load(open((unit.dirs.etc('policy.json'))))
self._add_missing_default_rules(policy_keys)
policy_keys = self._get_default_policy_rules()
# These keys are in the policy.json but aren't targets.
policy_rule_keys = [