]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
node-proxy: address mypy and flake8 errors
authorGuillaume Abrioux <gabrioux@ibm.com>
Tue, 24 Oct 2023 11:28:11 +0000 (11:28 +0000)
committerGuillaume Abrioux <gabrioux@ibm.com>
Thu, 25 Jan 2024 15:07:20 +0000 (15:07 +0000)
This addresses some flake8 and python typing errors.

Signed-off-by: Guillaume Abrioux <gabrioux@ibm.com>
src/cephadm/cephadmlib/node_proxy/baseredfishsystem.py
src/cephadm/cephadmlib/node_proxy/basesystem.py
src/cephadm/cephadmlib/node_proxy/main.py
src/cephadm/cephadmlib/node_proxy/redfish_client.py
src/cephadm/cephadmlib/node_proxy/redfishdellsystem.py

index ccf61e9cf87951a6681c07d1de15829783c299cf..c4675e5b8f03d529e8d28846b143157c8f569787 100644 (file)
@@ -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(),
index d4cda344ddbf49415173209b232db546d2ff1e45..4fb1b7b855347d901bbf22fe16a7f30cf42d7dfb 100644 (file)
@@ -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()
 
index cd36639bd1fe3daa907b2bd5c3a51abb37ca374f..82f941a085125d8dc93343ca24c5897d524db642 100644 (file)
@@ -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 = {
index f7ec01ae5b42fadfc9543d15fe77cb92448cbb9c..3046a634c58e50607f3928e6a3bb8c9707e39182 100644 (file)
@@ -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 = ''
 
index 9ae370ea4a6d6243a1b56d4f6abefa051dc923cd..516272c7223e8741f9c237323079661e0f95a36d 100644 (file)
@@ -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()]}