From 2617f00165d513c03a87dd43f36b1460ff836758 Mon Sep 17 00:00:00 2001 From: Daian Cardoso Sganderlla Date: Fri, 14 Oct 2022 14:35:33 -0400 Subject: [PATCH] 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 Change-Id: I06ac2b40662ef1df4b86d82d2cdf298d746d886b --- .../python-cephclient/cephclient/client.py | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/ceph/python-cephclient/python-cephclient/cephclient/client.py b/ceph/python-cephclient/python-cephclient/cephclient/client.py index 336983fc..21903c8d 100644 --- a/ceph/python-cephclient/python-cephclient/cephclient/client.py +++ b/ceph/python-cephclient/python-cephclient/cephclient/client.py @@ -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