]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/orchestrator: fix typing on lsm_data components
authorPaul Cuzner <pcuzner@redhat.com>
Tue, 1 Sep 2020 04:39:35 +0000 (16:39 +1200)
committerNathan Cutler <ncutler@suse.com>
Tue, 6 Oct 2020 09:40:32 +0000 (11:40 +0200)
Resolves mypy issues

Signed-off-by: Paul Cuzner <pcuzner@redhat.com>
(cherry picked from commit 3a2430fed9846251926a179989829812f9d74d99)

src/pybind/mgr/orchestrator/module.py
src/python-common/ceph/deployment/inventory.py

index 4fbe6166d5e89fc3f0fefbc9fe6a01088b46f0d0..e29e6e5b57459d48b3763c17bff2d2d54645c442 100644 (file)
@@ -370,7 +370,7 @@ class OrchestratorCli(OrchestratorClientMixin, MgrModule):
         "name=wide,type=CephBool,req=false",
         'List devices on a host')
     def _list_devices(self, hostname=None, format='plain', refresh=False, wide=False):
-        # type: (Optional[List[str]], str, bool) -> HandleCommandResult
+        # type: (Optional[List[str]], str, bool, bool) -> HandleCommandResult
         """
         Provide information about storage devices present in cluster hosts
 
@@ -400,12 +400,14 @@ class OrchestratorCli(OrchestratorClientMixin, MgrModule):
             out = []
             if wide:
                 table = PrettyTable(
-                    ['Hostname', 'Path', 'Type', 'Transport', 'RPM', 'Vendor', 'Model', 'Serial', 'Size', 'Health',
-                     'Ident', 'Fault', 'Available', 'Reject Reasons'],
+                    ['Hostname', 'Path', 'Type', 'Transport', 'RPM', 'Vendor', 'Model',
+                     'Serial', 'Size', 'Health', 'Ident', 'Fault', 'Available',
+                     'Reject Reasons'],
                     border=False)
             else:
                 table = PrettyTable(
-                    ['Hostname', 'Path', 'Type', 'Serial', 'Size', 'Health', 'Ident', 'Fault', 'Available'],
+                    ['Hostname', 'Path', 'Type', 'Serial', 'Size',
+                     'Health', 'Ident', 'Fault', 'Available'],
                     border=False)
             table.align = 'l'
             table._align['SIZE'] = 'r'
@@ -420,6 +422,11 @@ class OrchestratorCli(OrchestratorClientMixin, MgrModule):
                         led_ident = d.lsm_data['ledSupport']['IDENTstatus']
                         led_fail = d.lsm_data['ledSupport']['FAILstatus']
 
+                    if d.device_id is not None:
+                        fallback_serial = d.device_id.split('_')[-1]
+                    else:
+                        fallback_serial = ""
+
                     if wide:
                         table.add_row(
                             (
@@ -430,7 +437,7 @@ class OrchestratorCli(OrchestratorClientMixin, MgrModule):
                                 d.lsm_data.get('rpm', 'Unknown'),
                                 d.sys_api.get('vendor') or 'N/A',
                                 d.sys_api.get('model') or 'N/A',
-                                d.lsm_data.get('serialNum', d.device_id.split('_')[-1]),
+                                d.lsm_data.get('serialNum', fallback_serial),
                                 format_dimless(d.sys_api.get('size', 0), 5),
                                 d.lsm_data.get('health', 'Unknown'),
                                 display_map[led_ident],
@@ -445,7 +452,7 @@ class OrchestratorCli(OrchestratorClientMixin, MgrModule):
                                 host_.name,
                                 d.path,
                                 d.human_readable_type,
-                                d.lsm_data.get('serialNum', d.device_id.split('_')[-1]),
+                                d.lsm_data.get('serialNum', fallback_serial),
                                 format_dimless(d.sys_api.get('size', 0), 5),
                                 d.lsm_data.get('health', 'Unknown'),
                                 display_map[led_ident],
index 9bea5c8cdf0e6d1a69450255df26a5483f8b317e..eb9852426c44cba344eed4c7cdd582b403be111d 100644 (file)
@@ -51,7 +51,7 @@ class Device(object):
                  rejected_reasons=None,  # type: Optional[List[str]]
                  lvs=None,  # type: Optional[List[str]]
                  device_id=None,  # type: Optional[str]
-                 lsm_data=None,  # type: Optional[str]
+                 lsm_data={},  # type: Dict[str, Dict[str, str]]
                  ):
         self.path = path
         self.sys_api = sys_api if sys_api is not None else {}  # type: Dict[str, Any]