Use hostname on restful service certificate

Force the use of hostname on getting the certificates
for restful service, instead of the IP address.
This is necessary due to the update of the Ceph version
in rook-ceph app. New Ceph version started to store the IP
number instead of the hostname in restful service infos.
We need a new function to return the hostname in order to
get the key and certificate files.

Story: 2009138
Task: 46735

Test Plan:
PASS: AIO-SX - created an image with this version of code
and use it to get service certificate

Signed-off-by: Daian Cardoso Sganderlla <Daian.CardosoSganderlla@windriver.com>
Change-Id: I06ac2b40662ef1df4b86d82d2cdf298d746d886b
This commit is contained in:
Daian Cardoso Sganderlla 2022-10-14 14:35:33 -04:00
parent 3599e8e456
commit 2617f00165

View File

@ -102,16 +102,31 @@ class CephClient(object):
raise exception.CephMgrMissingRestfulService(
status.get('services', ''))
def _get_service_hostname(self):
try:
output = subprocess.check_output(
('ceph mgr metadata '
'--connect-timeout {}').format(
CEPH_CLI_TIMEOUT_SEC),
shell=True)
except subprocess.CalledProcessError as e:
raise exception.CephMgrDumpError(str(e))
try:
status = json.loads(output)
except (KeyError, ValueError):
raise exception.CephMgrJsonError(output)
return status[0]["hostname"]
def _get_certificate(self):
self._cleanup_certificate()
url = urlparse(self.service_url)
hostname = self._get_service_hostname()
try:
certificate = subprocess.check_output(
('ceph config-key get '
'--connect-timeout {} '
'mgr/restful/{}/crt').format(
CEPH_CLI_TIMEOUT_SEC,
url.hostname),
hostname),
shell=True)
except subprocess.CalledProcessError:
return