| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
import uuid |
| 14 |
|
| 15 |
from keystoneauth1.exceptions import http |
| 16 |
|
| 17 |
from keystoneclient.tests.functional import base |
| 18 |
from keystoneclient.tests.functional.v3 import client_fixtures as fixtures |
| 19 |
|
| 20 |
|
| 21 |
class EndpointGroupsTestMixin(object): |
| 22 |
|
| 23 |
def check_endpoint_group(self, endpoint_group, endpoint_group_ref=None): |
| 24 |
self.assertIsNotNone(endpoint_group.id) |
| 25 |
self.assertIn('self', endpoint_group.links) |
| 26 |
self.assertIn('/endpoint_groups/' + endpoint_group.id, |
| 27 |
endpoint_group.links['self']) |
| 28 |
|
| 29 |
if endpoint_group_ref: |
| 30 |
self.assertEqual(endpoint_group_ref['name'], endpoint_group.name) |
| 31 |
self.assertEqual(endpoint_group_ref['filters'], |
| 32 |
endpoint_group.filters) |
| 33 |
|
| 34 |
|
| 35 |
if hasattr(endpoint_group_ref, 'description'): |
| 36 |
self.assertEqual(endpoint_group_ref['description'], |
| 37 |
endpoint_group.description) |
| 38 |
else: |
| 39 |
|
| 40 |
self.assertIsNotNone(endpoint_group.name) |
| 41 |
self.assertIsNotNone(endpoint_group.filters) |
| 42 |
|
| 43 |
|
| 44 |
class EndpointGroupsTestCase(base.V3ClientTestCase, EndpointGroupsTestMixin): |
| 45 |
|
| 46 |
def test_create_endpoint_group(self): |
| 47 |
endpoint_group_ref = { |
| 48 |
'name': fixtures.RESOURCE_NAME_PREFIX + uuid.uuid4().hex, |
| 49 |
'filters': {'interface': 'internal'}, |
| 50 |
'description': uuid.uuid4().hex} |
| 51 |
endpoint_group = self.client.endpoint_groups.create( |
| 52 |
**endpoint_group_ref) |
| 53 |
|
| 54 |
self.addCleanup(self.client.endpoint_groups.delete, endpoint_group) |
| 55 |
self.check_endpoint_group(endpoint_group, endpoint_group_ref) |
| 56 |
|
| 57 |
def test_get_endpoint_group(self): |
| 58 |
endpoint_group = fixtures.EndpointGroup(self.client) |
| 59 |
self.useFixture(endpoint_group) |
| 60 |
|
| 61 |
endpoint_ret = self.client.endpoint_groups.get(endpoint_group.id) |
| 62 |
self.check_endpoint_group(endpoint_ret, endpoint_group.ref) |
| 63 |
|
| 64 |
self.assertRaises(http.NotFound, |
| 65 |
self.client.endpoint_groups.get, |
| 66 |
uuid.uuid4().hex) |
| 67 |
|
| 68 |
def test_check_endpoint_group(self): |
| 69 |
endpoint_group = fixtures.EndpointGroup(self.client) |
| 70 |
self.useFixture(endpoint_group) |
| 71 |
|
| 72 |
self.client.endpoint_groups.check(endpoint_group.id) |
| 73 |
self.assertRaises(http.NotFound, |
| 74 |
self.client.endpoint_groups.check, |
| 75 |
uuid.uuid4().hex) |
| 76 |
|
| 77 |
def test_list_endpoint_groups(self): |
| 78 |
endpoint_group_one = fixtures.EndpointGroup(self.client) |
| 79 |
self.useFixture(endpoint_group_one) |
| 80 |
|
| 81 |
endpoint_group_two = fixtures.EndpointGroup(self.client) |
| 82 |
self.useFixture(endpoint_group_two) |
| 83 |
|
| 84 |
endpoint_groups = self.client.endpoint_groups.list() |
| 85 |
|
| 86 |
|
| 87 |
for endpoint_group in endpoint_groups: |
| 88 |
self.check_endpoint_group(endpoint_group) |
| 89 |
|
| 90 |
self.assertIn(endpoint_group_one.entity, endpoint_groups) |
| 91 |
self.assertIn(endpoint_group_two.entity, endpoint_groups) |
| 92 |
|
| 93 |
def test_update_endpoint_group(self): |
| 94 |
endpoint_group = fixtures.EndpointGroup(self.client) |
| 95 |
self.useFixture(endpoint_group) |
| 96 |
|
| 97 |
new_name = fixtures.RESOURCE_NAME_PREFIX + uuid.uuid4().hex |
| 98 |
new_filters = {'interface': 'public'} |
| 99 |
new_description = uuid.uuid4().hex |
| 100 |
|
| 101 |
endpoint_group_ret = self.client.endpoint_groups.update( |
| 102 |
endpoint_group, |
| 103 |
name=new_name, |
| 104 |
filters=new_filters, |
| 105 |
description=new_description) |
| 106 |
|
| 107 |
endpoint_group.ref.update({'name': new_name, 'filters': new_filters, |
| 108 |
'description': new_description}) |
| 109 |
self.check_endpoint_group(endpoint_group_ret, endpoint_group.ref) |
| 110 |
|
| 111 |
def test_delete_endpoint_group(self): |
| 112 |
endpoint_group = self.client.endpoint_groups.create( |
| 113 |
name=fixtures.RESOURCE_NAME_PREFIX + uuid.uuid4().hex, |
| 114 |
filters={'interface': 'admin'}, |
| 115 |
description=uuid.uuid4().hex) |
| 116 |
|
| 117 |
self.client.endpoint_groups.delete(endpoint_group.id) |
| 118 |
self.assertRaises(http.NotFound, |
| 119 |
self.client.endpoint_groups.check, |
| 120 |
endpoint_group.id) |
| 121 |
self.assertRaises(http.NotFound, |
| 122 |
self.client.endpoint_groups.get, |
| 123 |
endpoint_group.id) |