Create runtime descriptor for new service

Instead of explicitly creating proxy for any new service added with 
connection.add_service fill a "run-time" descriptor.
This avoids going into service discovery for each new service (when 
there are multiple of those added in a "init"-like function the overall 
start time increases heavily.

Change-Id: I114ff0ee170244978a1949dc9c7258f373023ab6
This commit is contained in:
Artem Goncharov 2019-03-18 12:03:02 +01:00
parent 6dcf92fca1
commit e8622646e4
2 changed files with 18 additions and 7 deletions

View File

@ -333,11 +333,19 @@ class Connection(six.with_metaclass(_meta.ConnectionMeta,
# we get an adapter.
if isinstance(service, six.string_types):
service = service_description.ServiceDescription(service)
service_proxy = service._make_proxy(self)
# Register the proxy class with every known alias
# Directly invoke descriptor of the ServiceDescription
def getter(self):
return service.__get__(self, service)
# Register the ServiceDescription class (as property)
# with every known alias for a "runtime descriptor"
for attr_name in service.all_types:
setattr(self, attr_name.replace('-', '_'), service_proxy)
setattr(
self.__class__,
attr_name.replace('-', '_'),
property(fget=getter)
)
def authorize(self):
"""Authorize this Connection

View File

@ -260,6 +260,13 @@ class TestNewService(base.TestCase):
self.use_keystone_v3(catalog='catalog-v3-fake-v1.json')
conn = self.cloud
service = fake_service.FakeService('fake')
conn.add_service(service)
# Ensure no discovery calls made
self.assertEqual(0, len(self.adapter.request_history))
self.register_uris([
dict(method='GET',
uri='https://fake.example.com',
@ -272,10 +279,6 @@ class TestNewService(base.TestCase):
status_code=404),
])
service = fake_service.FakeService('fake')
conn.add_service(service)
self.assertEqual(
'openstack.tests.unit.fake.v1._proxy',
conn.fake.__class__.__module__)