| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
from keystoneauth1 import fixture |
| 14 |
|
| 15 |
from keystoneclient import access |
| 16 |
from keystoneclient import exceptions |
| 17 |
from keystoneclient.tests.unit.v2_0 import client_fixtures |
| 18 |
from keystoneclient.tests.unit.v2_0 import utils |
| 19 |
|
| 20 |
|
| 21 |
class ServiceCatalogTest(utils.TestCase): |
| 22 |
def setUp(self): |
| 23 |
super(ServiceCatalogTest, self).setUp() |
| 24 |
self.AUTH_RESPONSE_BODY = client_fixtures.auth_response_body() |
| 25 |
|
| 26 |
def test_building_a_service_catalog(self): |
| 27 |
auth_ref = access.AccessInfo.factory(None, self.AUTH_RESPONSE_BODY) |
| 28 |
sc = auth_ref.service_catalog |
| 29 |
|
| 30 |
self.assertEqual(sc.url_for(service_type='compute'), |
| 31 |
"https://compute.north.host/v1/1234") |
| 32 |
self.assertEqual(sc.url_for('tenantId', '1', service_type='compute'), |
| 33 |
"https://compute.north.host/v1/1234") |
| 34 |
self.assertEqual(sc.url_for('tenantId', '2', service_type='compute'), |
| 35 |
"https://compute.north.host/v1.1/3456") |
| 36 |
|
| 37 |
self.assertRaises(exceptions.EndpointNotFound, sc.url_for, "region", |
| 38 |
"South", service_type='compute') |
| 39 |
|
| 40 |
def test_service_catalog_endpoints(self): |
| 41 |
auth_ref = access.AccessInfo.factory(None, self.AUTH_RESPONSE_BODY) |
| 42 |
sc = auth_ref.service_catalog |
| 43 |
public_ep = sc.get_endpoints(service_type='compute', |
| 44 |
endpoint_type='publicURL') |
| 45 |
self.assertEqual(public_ep['compute'][1]['tenantId'], '2') |
| 46 |
self.assertEqual(public_ep['compute'][1]['versionId'], '1.1') |
| 47 |
self.assertEqual(public_ep['compute'][1]['internalURL'], |
| 48 |
"https://compute.north.host/v1.1/3456") |
| 49 |
|
| 50 |
def test_service_catalog_regions(self): |
| 51 |
self.AUTH_RESPONSE_BODY['access']['region_name'] = "North" |
| 52 |
|
| 53 |
with self.deprecations.expect_deprecations_here(): |
| 54 |
auth_ref = access.AccessInfo.factory(None, self.AUTH_RESPONSE_BODY) |
| 55 |
sc = auth_ref.service_catalog |
| 56 |
|
| 57 |
url = sc.url_for(service_type='image', endpoint_type='publicURL') |
| 58 |
self.assertEqual(url, "https://image.north.host/v1/") |
| 59 |
|
| 60 |
self.AUTH_RESPONSE_BODY['access']['region_name'] = "South" |
| 61 |
|
| 62 |
with self.deprecations.expect_deprecations_here(): |
| 63 |
auth_ref = access.AccessInfo.factory(None, self.AUTH_RESPONSE_BODY) |
| 64 |
sc = auth_ref.service_catalog |
| 65 |
|
| 66 |
url = sc.url_for(service_type='image', endpoint_type='internalURL') |
| 67 |
self.assertEqual(url, "https://image-internal.south.host/v1/") |
| 68 |
|
| 69 |
def test_service_catalog_empty(self): |
| 70 |
self.AUTH_RESPONSE_BODY['access']['serviceCatalog'] = [] |
| 71 |
auth_ref = access.AccessInfo.factory(None, self.AUTH_RESPONSE_BODY) |
| 72 |
self.assertRaises(exceptions.EmptyCatalog, |
| 73 |
auth_ref.service_catalog.url_for, |
| 74 |
service_type='image', |
| 75 |
endpoint_type='internalURL') |
| 76 |
|
| 77 |
def test_service_catalog_get_endpoints_region_names(self): |
| 78 |
auth_ref = access.AccessInfo.factory(None, self.AUTH_RESPONSE_BODY) |
| 79 |
sc = auth_ref.service_catalog |
| 80 |
|
| 81 |
endpoints = sc.get_endpoints(service_type='image', region_name='North') |
| 82 |
self.assertEqual(len(endpoints), 1) |
| 83 |
self.assertEqual(endpoints['image'][0]['publicURL'], |
| 84 |
'https://image.north.host/v1/') |
| 85 |
|
| 86 |
endpoints = sc.get_endpoints(service_type='image', region_name='South') |
| 87 |
self.assertEqual(len(endpoints), 1) |
| 88 |
self.assertEqual(endpoints['image'][0]['publicURL'], |
| 89 |
'https://image.south.host/v1/') |
| 90 |
|
| 91 |
endpoints = sc.get_endpoints(service_type='compute') |
| 92 |
self.assertEqual(len(endpoints['compute']), 2) |
| 93 |
|
| 94 |
endpoints = sc.get_endpoints(service_type='compute', |
| 95 |
region_name='North') |
| 96 |
self.assertEqual(len(endpoints['compute']), 2) |
| 97 |
|
| 98 |
endpoints = sc.get_endpoints(service_type='compute', |
| 99 |
region_name='West') |
| 100 |
self.assertEqual(len(endpoints['compute']), 0) |
| 101 |
|
| 102 |
def test_service_catalog_url_for_region_names(self): |
| 103 |
auth_ref = access.AccessInfo.factory(None, self.AUTH_RESPONSE_BODY) |
| 104 |
sc = auth_ref.service_catalog |
| 105 |
|
| 106 |
url = sc.url_for(service_type='image', region_name='North') |
| 107 |
self.assertEqual(url, 'https://image.north.host/v1/') |
| 108 |
|
| 109 |
url = sc.url_for(service_type='image', region_name='South') |
| 110 |
self.assertEqual(url, 'https://image.south.host/v1/') |
| 111 |
|
| 112 |
url = sc.url_for(service_type='compute', |
| 113 |
region_name='North', |
| 114 |
attr='versionId', |
| 115 |
filter_value='1.1') |
| 116 |
self.assertEqual(url, 'https://compute.north.host/v1.1/3456') |
| 117 |
|
| 118 |
self.assertRaises(exceptions.EndpointNotFound, sc.url_for, |
| 119 |
service_type='image', region_name='West') |
| 120 |
|
| 121 |
def test_servcie_catalog_get_url_region_names(self): |
| 122 |
auth_ref = access.AccessInfo.factory(None, self.AUTH_RESPONSE_BODY) |
| 123 |
sc = auth_ref.service_catalog |
| 124 |
|
| 125 |
urls = sc.get_urls(service_type='image') |
| 126 |
self.assertEqual(len(urls), 2) |
| 127 |
|
| 128 |
urls = sc.get_urls(service_type='image', region_name='North') |
| 129 |
self.assertEqual(len(urls), 1) |
| 130 |
self.assertEqual(urls[0], 'https://image.north.host/v1/') |
| 131 |
|
| 132 |
urls = sc.get_urls(service_type='image', region_name='South') |
| 133 |
self.assertEqual(len(urls), 1) |
| 134 |
self.assertEqual(urls[0], 'https://image.south.host/v1/') |
| 135 |
|
| 136 |
urls = sc.get_urls(service_type='image', region_name='West') |
| 137 |
self.assertIsNone(urls) |
| 138 |
|
| 139 |
def test_service_catalog_param_overrides_body_region(self): |
| 140 |
self.AUTH_RESPONSE_BODY['access']['region_name'] = "North" |
| 141 |
|
| 142 |
with self.deprecations.expect_deprecations_here(): |
| 143 |
auth_ref = access.AccessInfo.factory(None, self.AUTH_RESPONSE_BODY) |
| 144 |
sc = auth_ref.service_catalog |
| 145 |
|
| 146 |
url = sc.url_for(service_type='image') |
| 147 |
self.assertEqual(url, 'https://image.north.host/v1/') |
| 148 |
|
| 149 |
url = sc.url_for(service_type='image', region_name='South') |
| 150 |
self.assertEqual(url, 'https://image.south.host/v1/') |
| 151 |
|
| 152 |
endpoints = sc.get_endpoints(service_type='image') |
| 153 |
self.assertEqual(len(endpoints['image']), 1) |
| 154 |
self.assertEqual(endpoints['image'][0]['publicURL'], |
| 155 |
'https://image.north.host/v1/') |
| 156 |
|
| 157 |
endpoints = sc.get_endpoints(service_type='image', region_name='South') |
| 158 |
self.assertEqual(len(endpoints['image']), 1) |
| 159 |
self.assertEqual(endpoints['image'][0]['publicURL'], |
| 160 |
'https://image.south.host/v1/') |
| 161 |
|
| 162 |
def test_service_catalog_service_name(self): |
| 163 |
auth_ref = access.AccessInfo.factory(resp=None, |
| 164 |
body=self.AUTH_RESPONSE_BODY) |
| 165 |
sc = auth_ref.service_catalog |
| 166 |
|
| 167 |
url = sc.url_for(service_name='Image Servers', endpoint_type='public', |
| 168 |
service_type='image', region_name='North') |
| 169 |
self.assertEqual('https://image.north.host/v1/', url) |
| 170 |
|
| 171 |
self.assertRaises(exceptions.EndpointNotFound, sc.url_for, |
| 172 |
service_name='Image Servers', service_type='compute') |
| 173 |
|
| 174 |
urls = sc.get_urls(service_type='image', service_name='Image Servers', |
| 175 |
endpoint_type='public') |
| 176 |
|
| 177 |
self.assertIn('https://image.north.host/v1/', urls) |
| 178 |
self.assertIn('https://image.south.host/v1/', urls) |
| 179 |
|
| 180 |
urls = sc.get_urls(service_type='image', service_name='Servers', |
| 181 |
endpoint_type='public') |
| 182 |
|
| 183 |
self.assertIsNone(urls) |
| 184 |
|
| 185 |
def test_service_catalog_multiple_service_types(self): |
| 186 |
token = fixture.V2Token() |
| 187 |
token.set_scope() |
| 188 |
|
| 189 |
for i in range(3): |
| 190 |
s = token.add_service('compute') |
| 191 |
s.add_endpoint(public='public-%d' % i, |
| 192 |
admin='admin-%d' % i, |
| 193 |
internal='internal-%d' % i, |
| 194 |
region='region-%d' % i) |
| 195 |
|
| 196 |
auth_ref = access.AccessInfo.factory(resp=None, body=token) |
| 197 |
|
| 198 |
urls = auth_ref.service_catalog.get_urls(service_type='compute', |
| 199 |
endpoint_type='publicURL') |
| 200 |
|
| 201 |
self.assertEqual(set(['public-0', 'public-1', 'public-2']), set(urls)) |
| 202 |
|
| 203 |
urls = auth_ref.service_catalog.get_urls(service_type='compute', |
| 204 |
endpoint_type='publicURL', |
| 205 |
region_name='region-1') |
| 206 |
|
| 207 |
self.assertEqual(('public-1', ), urls) |