From 1269c617ddb82bd2a5d713e7b4c1da2359c33855 Mon Sep 17 00:00:00 2001 From: Rao Adnan Khan Date: Sat, 1 Apr 2017 01:42:46 -0500 Subject: [PATCH] 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 --- ...olicy-client-library-b8279c18335588c9.yaml | 6 + .../services/identity/v3/policies_client.py | 112 ++++++++++++++++++ .../identity/v3/test_policies_client.py | 88 ++++++++++++++ 3 files changed, 206 insertions(+) create mode 100644 releasenotes/notes/add-additional-methods-to-policy-client-library-b8279c18335588c9.yaml diff --git a/releasenotes/notes/add-additional-methods-to-policy-client-library-b8279c18335588c9.yaml b/releasenotes/notes/add-additional-methods-to-policy-client-library-b8279c18335588c9.yaml new file mode 100644 index 0000000000..cd5284dd89 --- /dev/null +++ b/releasenotes/notes/add-additional-methods-to-policy-client-library-b8279c18335588c9.yaml @@ -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. diff --git a/tempest/lib/services/identity/v3/policies_client.py b/tempest/lib/services/identity/v3/policies_client.py index d4560e2fdb..ca8dbbd2fa 100644 --- a/tempest/lib/services/identity/v3/policies_client.py +++ b/tempest/lib/services/identity/v3/policies_client.py @@ -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) diff --git a/tempest/tests/lib/services/identity/v3/test_policies_client.py b/tempest/tests/lib/services/identity/v3/test_policies_client.py index 66c3d6540d..0237475609 100644 --- a/tempest/tests/lib/services/identity/v3/test_policies_client.py +++ b/tempest/tests/lib/services/identity/v3/test_policies_client.py @@ -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)