policy library DB interface, DSE service, API

DB interface for adding, getting, and deleting library policies
A DSE service for adding, getting, and deleting library policies
Alembic migration script for adding the new DB table
policy library API model
Tempest smoke test

Closes-Bug: 1693617
Partially implements: blueprint policy-library

Change-Id: I15dda797e6e29ff5155f5758d93d68499539f8fc
This commit is contained in:
Eric Kao 2017-06-07 16:05:54 -07:00
parent 40ee3cd674
commit 96a3d80e94
2 changed files with 71 additions and 0 deletions

View File

@ -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)

View File

@ -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