From: Guillaume Abrioux Date: Tue, 24 Oct 2023 11:28:11 +0000 (+0000) Subject: node-proxy: address mypy and flake8 errors X-Git-Tag: testing/wip-batrick-testing-20240411.154038~520^2~36 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=8343968af89c30bb6005fdbe640520d78258356b;p=ceph-ci.git node-proxy: address mypy and flake8 errors This addresses some flake8 and python typing errors. Signed-off-by: Guillaume Abrioux --- diff --git a/src/cephadm/cephadmlib/node_proxy/baseredfishsystem.py b/src/cephadm/cephadmlib/node_proxy/baseredfishsystem.py index ccf61e9cf87..c4675e5b8f0 100644 --- a/src/cephadm/cephadmlib/node_proxy/baseredfishsystem.py +++ b/src/cephadm/cephadmlib/node_proxy/baseredfishsystem.py @@ -19,7 +19,7 @@ class BaseRedfishSystem(BaseSystem): self.username: str = kw['username'] self.password: str = kw['password'] # move the following line (class attribute?) - self.client = RedFishClient(host=self.host, port=self.port, username=self.username, password=self.password) + self.client: RedFishClient = RedFishClient(host=self.host, port=self.port, username=self.username, password=self.password) self.log.logger.info(f"redfish system initialization, host: {self.host}, user: {self.username}") self.run: bool = False @@ -104,7 +104,7 @@ class BaseRedfishSystem(BaseSystem): _data = self._get_path(_path) return [self._get_path(member['@odata.id']) for member in _data['Members']] - def get_system(self) -> Dict[str, Dict[str, Dict]]: + def get_system(self) -> Dict[str, Any]: result = { 'host': self.get_host(), 'sn': self.get_sn(), diff --git a/src/cephadm/cephadmlib/node_proxy/basesystem.py b/src/cephadm/cephadmlib/node_proxy/basesystem.py index d4cda344ddb..4fb1b7b8553 100644 --- a/src/cephadm/cephadmlib/node_proxy/basesystem.py +++ b/src/cephadm/cephadmlib/node_proxy/basesystem.py @@ -10,7 +10,7 @@ class BaseSystem: self.config: Config = kw['config'] self.client: BaseClient - def get_system(self) -> Dict[str, Dict[str, Dict]]: + def get_system(self) -> Dict[str, Any]: raise NotImplementedError() def get_status(self) -> Dict[str, Dict[str, Dict]]: @@ -25,6 +25,9 @@ class BaseSystem: def get_memory(self) -> Dict[str, Dict[str, Dict]]: raise NotImplementedError() + def get_fans(self) -> Dict[str, Dict[str, Dict]]: + raise NotImplementedError() + def get_power(self) -> Dict[str, Dict[str, Dict]]: raise NotImplementedError() diff --git a/src/cephadm/cephadmlib/node_proxy/main.py b/src/cephadm/cephadmlib/node_proxy/main.py index cd36639bd1f..82f941a0851 100644 --- a/src/cephadm/cephadmlib/node_proxy/main.py +++ b/src/cephadm/cephadmlib/node_proxy/main.py @@ -6,9 +6,6 @@ from .reporter import Reporter from .util import Config, Logger from typing import Dict, Any, Optional, List from .basesystem import BaseSystem -import sys -import argparse -import json import traceback DEFAULT_CONFIG = { diff --git a/src/cephadm/cephadmlib/node_proxy/redfish_client.py b/src/cephadm/cephadmlib/node_proxy/redfish_client.py index f7ec01ae5b4..3046a634c58 100644 --- a/src/cephadm/cephadmlib/node_proxy/redfish_client.py +++ b/src/cephadm/cephadmlib/node_proxy/redfish_client.py @@ -1,8 +1,6 @@ -import time -import datetime import ssl import json -from urllib.error import HTTPError, URLError +from urllib.error import URLError from urllib.request import urlopen, Request from .baseclient import BaseClient from .util import Logger @@ -14,13 +12,13 @@ class RedFishClient(BaseClient): def __init__(self, host: str = "", - port: str = "443", + port: int = 443, username: str = "", password: str = ""): super().__init__(host, username, password) self.log: Logger = Logger(__name__) self.log.logger.info(f"Initializing redfish client {__name__}") - self.host: str = f"https://{host}:{port}" + self.host: str = f"https://{host}:{str(port)}" self.token: str = '' self.location: str = '' diff --git a/src/cephadm/cephadmlib/node_proxy/redfishdellsystem.py b/src/cephadm/cephadmlib/node_proxy/redfishdellsystem.py index 9ae370ea4a6..516272c7223 100644 --- a/src/cephadm/cephadmlib/node_proxy/redfishdellsystem.py +++ b/src/cephadm/cephadmlib/node_proxy/redfishdellsystem.py @@ -42,7 +42,6 @@ class RedfishDellSystem(BaseRedfishSystem): self.log.logger.warning(f"Could not find field: {field} in data: {data[elt]}") return normalize_dict(result) - def get_sn(self) -> str: return self._sys['SKU'] @@ -70,15 +69,15 @@ class RedfishDellSystem(BaseRedfishSystem): def get_fans(self) -> Dict[str, Dict[str, Dict]]: return self._sys['fans'] - def get_led(self) -> Dict[str, Dict[str, Dict]]: + def get_led(self) -> Dict[str, Any]: endpoint = f"/redfish/v1/{self.chassis_endpoint}" result = self.client.query(method='GET', endpoint=endpoint, timeout=10) response_json = json.loads(result[1]) mapper = { - 'true': 'on', - 'false': 'off' + 'true': 'on', + 'false': 'off' } if result[2] == 200: return {"state": mapper[str(response_json['LocationIndicatorActive']).lower()]}