Fix extension discovery for object_storage

Python-tempestconf assumed that swift's /info endpoint is always the
same. But it may happen that the endpoint is renamed to /swift/info
in certain situations (e.g.: when swift is on ceph).

This patch fixes the issue by trying to access the /info endpoint
first. When the connection to /info endpoint is unsuccessful then
/swift/info endpoint is used as a fallback.

Story: 43092
Change-Id: I4447e1527eae8ec75acb4fb96047c894db75620d
This commit is contained in:
lpiwowar 2021-08-26 15:22:38 +02:00
parent c9dcf15b34
commit 0398f2a6c0
1 changed files with 22 additions and 9 deletions

View File

@ -25,18 +25,31 @@ from config_tempest.services.base import Service
class ObjectStorageService(Service): class ObjectStorageService(Service):
def set_extensions(self): def set_extensions(self):
if 'v3' not in self.service_url: # it's not a v3 url if 'v3' not in self.service_url: # it's not a v3 url
try: capabilities = self.get_capabilities('info')
body = self.do_get(self.service_url, top_level=True, if not capabilities:
top_level_path="info") # Certain deploynments have /info API endpoint for
body = json.loads(body) # listing active capabilities at /swift/info instead
# Remove Swift general information from extensions list # (e.g.: when ceph is on swift)
body.pop('swift') capabilities = self.get_capabilities('swift/info')
self.extensions = body.keys()
except Exception: capabilities = json.loads(capabilities)
self.extensions = [] # Remove Swift general information from extensions list
capabilities.pop('swift', {})
self.extensions = capabilities.keys()
else: else:
self.extensions = [] self.extensions = []
def get_capabilities(self, path):
try:
body = self.do_get(self.service_url, top_level=True,
top_level_path=path)
except Exception as e:
body = '{}'
LOG.warning('Object storage %s API endpoint not discovered. '
'Error message: %s', path, e)
return body
def list_create_roles(self, conf, client): def list_create_roles(self, conf, client):
try: try:
roles = client.list_roles()['roles'] roles = client.list_roles()['roles']