Merge "policy library DB interface, DSE service, API"
This commit is contained in:
commit
4d21599164
|
@ -31,6 +31,9 @@ class PolicyClient(rest_client.RestClient):
|
|||
policies = '/v1/policies'
|
||||
policies_status = '/v1/policies/%s/status'
|
||||
policy_action = '/v1/policies/%s?%s'
|
||||
library_policy = '/v1/librarypolicies'
|
||||
library_policy_path = '/v1/librarypolicies/%s'
|
||||
library_policies = '/v1/librarypolicies'
|
||||
datasources = '/v1/data-sources'
|
||||
datasource_path = '/v1/data-sources/%s'
|
||||
datasource_tables = '/v1/data-sources/%s/tables'
|
||||
|
@ -63,6 +66,22 @@ class PolicyClient(rest_client.RestClient):
|
|||
self.policy_path % policy)
|
||||
return self._resp_helper(resp, body)
|
||||
|
||||
def create_library_policy(self, body):
|
||||
body = json.dumps(body)
|
||||
resp, body = self.post(
|
||||
self.library_policy, body=body)
|
||||
return self._resp_helper(resp, body)
|
||||
|
||||
def delete_library_policy(self, policy):
|
||||
resp, body = self.delete(
|
||||
self.library_policy_path % policy)
|
||||
return self._resp_helper(resp, body)
|
||||
|
||||
def show_library_policy(self, policy):
|
||||
resp, body = self.get(
|
||||
self.library_policy_path % policy)
|
||||
return self._resp_helper(resp, body)
|
||||
|
||||
def create_policy_rule(self, policy_name, body=None):
|
||||
body = json.dumps(body)
|
||||
resp, body = self.post(
|
||||
|
@ -95,6 +114,10 @@ class PolicyClient(rest_client.RestClient):
|
|||
resp, body = self.get(self.policies)
|
||||
return self._resp_helper(resp, body)
|
||||
|
||||
def list_library_policy(self):
|
||||
resp, body = self.get(self.library_policies)
|
||||
return self._resp_helper(resp, body)
|
||||
|
||||
def list_policy_tables(self, policy_name):
|
||||
resp, body = self.get(self.policy_tables % (policy_name))
|
||||
return self._resp_helper(resp, body)
|
||||
|
|
|
@ -190,6 +190,54 @@ class TestPolicyBasicOps(manager_congress.ScenarioPolicyBase):
|
|||
self.assertEqual(f(), meta_data)
|
||||
|
||||
|
||||
class TestPolicyLibraryBasicOps(manager_congress.ScenarioPolicyBase):
|
||||
@decorators.attr(type='smoke')
|
||||
def test_policy_library_basic_op(self):
|
||||
response = self.admin_manager.congress_client.list_library_policy()
|
||||
initial_state = response['results']
|
||||
|
||||
test_policy = {
|
||||
"name": "test_policy",
|
||||
"description": "test policy description",
|
||||
"kind": "nonrecursive",
|
||||
"abbreviation": "abbr",
|
||||
"rules": [{"rule": "p(x) :- q(x)", "comment": "test comment",
|
||||
"name": "test name"},
|
||||
{"rule": "p(x) :- q2(x)", "comment": "test comment2",
|
||||
"name": "test name2"}]
|
||||
}
|
||||
response = self.admin_manager.congress_client.create_library_policy(
|
||||
test_policy)
|
||||
policy_id = response['id']
|
||||
test_policy['id'] = policy_id
|
||||
|
||||
def delete_if_found(id_):
|
||||
try:
|
||||
self.admin_manager.congress_client.delete_library_policy(id_)
|
||||
except exceptions.NotFound:
|
||||
pass
|
||||
|
||||
self.addCleanup(delete_if_found, policy_id)
|
||||
|
||||
response = self.admin_manager.congress_client.list_library_policy()
|
||||
new_state = response['results']
|
||||
|
||||
self.assertEqual(len(initial_state) + 1, len(new_state),
|
||||
'new library policy not reflected in list results')
|
||||
self.assertIn(test_policy, new_state,
|
||||
'new library policy not reflected in list results')
|
||||
|
||||
self.admin_manager.congress_client.delete_library_policy(policy_id)
|
||||
|
||||
response = self.admin_manager.congress_client.list_library_policy()
|
||||
new_state = response['results']
|
||||
|
||||
self.assertEqual(len(initial_state), len(new_state),
|
||||
'library policy delete not reflected in list results')
|
||||
self.assertNotIn(test_policy, new_state,
|
||||
'library policy delete not reflected in list results')
|
||||
|
||||
|
||||
class TestCongressDataSources(manager_congress.ScenarioPolicyBase):
|
||||
|
||||
@classmethod
|
||||
|
|
Loading…
Reference in New Issue