From: Guillaume Abrioux Date: Mon, 12 Feb 2024 12:22:41 +0000 (+0000) Subject: node-proxy: improve http error handling in fetch_oob_details X-Git-Tag: v18.2.4~275^2~3 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=a5d4b5044a71d0b35f2db8c560821bd67d4fb1d8;p=ceph.git node-proxy: improve http error handling in fetch_oob_details This makes the daemon handle the error nicer in fetch_oob_details() Signed-off-by: Guillaume Abrioux (cherry picked from commit 7bfe445e690d13eec8552f2ba88c9ff25ed3cf92) --- diff --git a/src/ceph-node-proxy/ceph_node_proxy/main.py b/src/ceph-node-proxy/ceph_node_proxy/main.py index 2a6479c4238e9..9a449ecf88456 100644 --- a/src/ceph-node-proxy/ceph_node_proxy/main.py +++ b/src/ceph-node-proxy/ceph_node_proxy/main.py @@ -2,6 +2,7 @@ from ceph_node_proxy.redfishdellsystem import RedfishDellSystem from ceph_node_proxy.api import NodeProxyApi from ceph_node_proxy.reporter import Reporter from ceph_node_proxy.util import Config, get_logger, http_req, write_tmp_file, CONFIG +from urllib.error import HTTPError from typing import Dict, Any, Optional import argparse @@ -33,6 +34,8 @@ class NodeProxyManager: self.cephx = {'cephx': {'name': self.cephx_name, 'secret': self.cephx_secret}} self.config = Config('/etc/ceph/node-proxy.yml', config=CONFIG) + self.username: str = '' + self.password: str = '' def run(self) -> None: self.init() @@ -44,15 +47,16 @@ class NodeProxyManager: self.init_api() def fetch_oob_details(self) -> Dict[str, str]: - headers, result, status = http_req(hostname=self.mgr_host, - port=self.mgr_agent_port, - data=json.dumps(self.cephx), - endpoint='/node-proxy/oob', - ssl_ctx=self.ssl_ctx) - if status != 200: - msg = f'No out of band tool details could be loaded: {status}, {result}' + try: + headers, result, status = http_req(hostname=self.mgr_host, + port=self.mgr_agent_port, + data=json.dumps(self.cephx), + endpoint='/node-proxy/oob', + ssl_ctx=self.ssl_ctx) + except HTTPError as e: + msg = f'No out of band tool details could be loaded: {e.code}, {e.reason}' self.log.debug(msg) - raise RuntimeError(msg) + raise result_json = json.loads(result) oob_details: Dict[str, str] = { @@ -64,9 +68,13 @@ class NodeProxyManager: return oob_details def init_system(self) -> None: - oob_details = self.fetch_oob_details() - self.username: str = oob_details['username'] - self.password: str = oob_details['password'] + try: + oob_details = self.fetch_oob_details() + self.username = oob_details['username'] + self.password = oob_details['password'] + except HTTPError: + self.log.warning('No oob details could be loaded, exiting...') + raise SystemExit(1) try: self.system = RedfishDellSystem(host=oob_details['host'], port=oob_details['port'],