Keystone v3-ext/OS-ENDPOINT-POLICY endpoints implementation.

Existing policy client is missing policy association API calls
for the endpoints, services and regions. These are supported API,
as mentioned on the wiki given below:

https://developer.openstack.org/api-ref/identity/v3-ext/index.html#associate-policy-and-endpoint

Closes-Bug: #1682641
Change-Id: I4af1e4862a17216d65446e8c29bd1b886f5d8c24
This commit is contained in:
Rao Adnan Khan 2017-04-01 01:42:46 -05:00 committed by Felipe Monteiro
parent 4207dbedad
commit 1269c617dd
3 changed files with 206 additions and 0 deletions

View File

@ -0,0 +1,6 @@
---
features:
- |
Add ``v3-ext/OS-ENDPOINT-POLICY`` API calls to support creation, deletion and
retrieval of associations between service endpoints and policies. Such associations
enable an endpoint to request its policy.

View File

@ -73,3 +73,115 @@ class PoliciesClient(rest_client.RestClient):
resp, body = self.delete(url)
self.expected_success(204, resp.status)
return rest_client.ResponseBody(resp, body)
def update_policy_association_for_endpoint(self, policy_id, endpoint_id):
"""Create policy association with endpoint.
For a full list of available parameters, please refer to the official
API reference:
https://developer.openstack.org/api-ref/identity/v3-ext/index.html#associate-policy-and-endpoint
"""
url = "policies/{0}/OS-ENDPOINT-POLICY/endpoints/{1}"\
.format(policy_id, endpoint_id)
resp, body = self.put(url, '{}')
self.expected_success(204, resp.status)
return rest_client.ResponseBody(resp, body)
def show_policy_association_for_endpoint(self, policy_id, endpoint_id):
"""Get policy association of endpoint.
API reference:
https://developer.openstack.org/api-ref/identity/v3-ext/index.html#verify-a-policy-and-endpoint-association
"""
url = "policies/{0}/OS-ENDPOINT-POLICY/endpoints/{1}"\
.format(policy_id, endpoint_id)
resp, body = self.get(url)
self.expected_success(204, resp.status)
return rest_client.ResponseBody(resp, body)
def delete_policy_association_for_endpoint(self, policy_id, endpoint_id):
"""Delete policy association with endpoint.
API reference:
https://developer.openstack.org/api-ref/identity/v3-ext/index.html#delete-a-policy-and-endpoint-association
"""
url = "policies/{0}/OS-ENDPOINT-POLICY/endpoints/{1}"\
.format(policy_id, endpoint_id)
resp, body = self.delete(url)
self.expected_success(204, resp.status)
return rest_client.ResponseBody(resp, body)
def update_policy_association_for_service(self, policy_id, service_id):
"""Create policy association with service.
API reference:
https://developer.openstack.org/api-ref/identity/v3-ext/index.html#associate-policy-and-service-type-endpoint
"""
url = "policies/{0}/OS-ENDPOINT-POLICY/services/{1}"\
.format(policy_id, service_id)
resp, body = self.put(url, '{}')
self.expected_success(204, resp.status)
return rest_client.ResponseBody(resp, body)
def show_policy_association_for_service(self, policy_id, service_id):
"""Get policy association of service.
API Reference:
https://developer.openstack.org/api-ref/identity/v3-ext/index.html#verify-a-policy-and-service-type-endpoint-association
"""
url = "policies/{0}/OS-ENDPOINT-POLICY/services/{1}"\
.format(policy_id, service_id)
resp, body = self.get(url)
self.expected_success(204, resp.status)
return rest_client.ResponseBody(resp, body)
def delete_policy_association_for_service(self, policy_id, service_id):
"""Delete policy association with service.
API reference:
https://developer.openstack.org/api-ref/identity/v3-ext/index.html#delete-a-policy-and-service-type-endpoint-association
"""
url = "policies/{0}/OS-ENDPOINT-POLICY/services/{1}"\
.format(policy_id, service_id)
resp, body = self.delete(url)
self.expected_success(204, resp.status)
return rest_client.ResponseBody(resp, body)
def update_policy_association_for_region_and_service(
self, policy_id, service_id, region_id):
"""Create policy association with service and region.
API reference:
https://developer.openstack.org/api-ref/identity/v3-ext/index.html#associate-policy-and-service-type-endpoint-in-a-region
"""
url = "policies/{0}/OS-ENDPOINT-POLICY/services/{1}/regions/{2}"\
.format(policy_id, service_id, region_id)
resp, body = self.put(url, '{}')
self.expected_success(204, resp.status)
return rest_client.ResponseBody(resp, body)
def show_policy_association_for_region_and_service(
self, policy_id, service_id, region_id):
"""Get policy association of service and region.
API reference:
https://developer.openstack.org/api-ref/identity/v3-ext/index.html#verify-a-policy-and-service-type-endpoint-in-a-region-association
"""
url = "policies/{0}/OS-ENDPOINT-POLICY/services/{1}/regions/{2}"\
.format(policy_id, service_id, region_id)
resp, body = self.get(url)
self.expected_success(204, resp.status)
return rest_client.ResponseBody(resp, body)
def delete_policy_association_for_region_and_service(
self, policy_id, service_id, region_id):
"""Delete policy association with service and region.
API reference:
https://developer.openstack.org/api-ref/identity/v3-ext/index.html#delete-a-policy-and-service-type-endpoint-in-a-region-association
"""
url = "policies/{0}/OS-ENDPOINT-POLICY/services/{1}/regions/{2}"\
.format(policy_id, service_id, region_id)
resp, body = self.delete(url)
self.expected_success(204, resp.status)
return rest_client.ResponseBody(resp, body)

View File

@ -81,6 +81,10 @@ class TestPoliciesClient(base.BaseServiceTest):
}
]
}
FAKE_ENDPOINT_ID = "234789"
FAKE_SERVICE_ID = "556782"
FAKE_POLICY_ID = "717273"
FAKE_REGION_ID = "73"
def setUp(self):
super(TestPoliciesClient, self).setUp()
@ -150,3 +154,87 @@ class TestPoliciesClient(base.BaseServiceTest):
{},
policy_id="717273",
status=204)
def test_update_policy_association_for_endpoint(self):
self.check_service_client_function(
self.client.update_policy_association_for_endpoint,
'tempest.lib.common.rest_client.RestClient.put',
{},
policy_id=self.FAKE_POLICY_ID,
endpoint_id=self.FAKE_ENDPOINT_ID,
status=204)
def test_show_policy_association_for_endpoint(self):
self.check_service_client_function(
self.client.show_policy_association_for_endpoint,
'tempest.lib.common.rest_client.RestClient.get',
{},
policy_id=self.FAKE_POLICY_ID,
endpoint_id=self.FAKE_ENDPOINT_ID,
status=204)
def test_delete_policy_association_for_endpoint(self):
self.check_service_client_function(
self.client.delete_policy_association_for_endpoint,
'tempest.lib.common.rest_client.RestClient.delete',
{},
policy_id=self.FAKE_POLICY_ID,
endpoint_id=self.FAKE_ENDPOINT_ID,
status=204)
def test_update_policy_association_for_service(self):
self.check_service_client_function(
self.client.update_policy_association_for_service,
'tempest.lib.common.rest_client.RestClient.put',
{},
policy_id=self.FAKE_POLICY_ID,
service_id=self.FAKE_SERVICE_ID,
status=204)
def test_show_policy_association_for_service(self):
self.check_service_client_function(
self.client.show_policy_association_for_service,
'tempest.lib.common.rest_client.RestClient.get',
{},
policy_id=self.FAKE_POLICY_ID,
service_id=self.FAKE_SERVICE_ID,
status=204)
def test_delete_policy_association_for_service(self):
self.check_service_client_function(
self.client.delete_policy_association_for_service,
'tempest.lib.common.rest_client.RestClient.delete',
{},
policy_id=self.FAKE_POLICY_ID,
service_id=self.FAKE_SERVICE_ID,
status=204)
def test_update_policy_association_for_region_and_service(self):
self.check_service_client_function(
self.client.update_policy_association_for_region_and_service,
'tempest.lib.common.rest_client.RestClient.put',
{},
policy_id=self.FAKE_POLICY_ID,
service_id=self.FAKE_SERVICE_ID,
region_id=self.FAKE_REGION_ID,
status=204)
def test_show_policy_association_for_region_and_service(self):
self.check_service_client_function(
self.client.show_policy_association_for_region_and_service,
'tempest.lib.common.rest_client.RestClient.get',
{},
policy_id=self.FAKE_POLICY_ID,
service_id=self.FAKE_SERVICE_ID,
region_id=self.FAKE_REGION_ID,
status=204)
def test_delete_policy_association_for_region_and_service(self):
self.check_service_client_function(
self.client.delete_policy_association_for_region_and_service,
'tempest.lib.common.rest_client.RestClient.delete',
{},
policy_id=self.FAKE_POLICY_ID,
service_id=self.FAKE_SERVICE_ID,
region_id=self.FAKE_REGION_ID,
status=204)