From 89720800802b98458f50634ec9d723d97abf434f Mon Sep 17 00:00:00 2001 From: Sebastian Wagner Date: Wed, 12 Feb 2020 11:34:40 +0100 Subject: [PATCH] python-common: add py.typed (PEP 561) Bugs found: * Fixed documentation of how `mgr/Orchestrator.create_osds` is called * mgr/Rook.create_osds: Added missing `.path` when querying paths. * mgr/Rook.create_osds: Fixed progress message * mgr/RookCluster.create_osds: Empty list instead of `None` * python-common: use empty objects instead of `None` Signed-off-by: Sebastian Wagner --- src/pybind/mgr/cephadm/module.py | 5 +++-- src/pybind/mgr/orchestrator.py | 2 +- src/pybind/mgr/requirements.txt | 2 +- src/pybind/mgr/rook/module.py | 6 +++--- src/pybind/mgr/rook/rook_cluster.py | 4 ++-- src/python-common/ceph/deployment/drive_group.py | 2 +- src/python-common/ceph/deployment/inventory.py | 4 ++-- src/python-common/ceph/py.typed | 1 + 8 files changed, 14 insertions(+), 12 deletions(-) create mode 100644 src/python-common/ceph/py.typed diff --git a/src/pybind/mgr/cephadm/module.py b/src/pybind/mgr/cephadm/module.py index 99f2010b98a69..5d14f2c5a5dd3 100644 --- a/src/pybind/mgr/cephadm/module.py +++ b/src/pybind/mgr/cephadm/module.py @@ -24,7 +24,7 @@ import shutil import subprocess from ceph.deployment import inventory, translate -from ceph.deployment.drive_group import DriveGroupSpecs +from ceph.deployment.drive_group import DriveGroupSpec from ceph.deployment.drive_selection import selector from mgr_module import MgrModule @@ -1514,11 +1514,12 @@ class CephadmOrchestrator(MgrModule, orchestrator.OrchestratorClientMixin): return self.get_inventory().then(call_create) def create_osds(self, drive_groups): + # type: (List[DriveGroupSpec]) -> AsyncCompletion return self.get_hosts().then(lambda hosts: self.call_inventory(hosts, drive_groups)) def _prepare_deployment(self, all_hosts, # type: List[orchestrator.InventoryNode] - drive_groups, # type: List[DriveGroupSpecs] + drive_groups, # type: List[DriveGroupSpec] inventory_list # type: List[orchestrator.InventoryNode] ): # type: (...) -> orchestrator.Completion diff --git a/src/pybind/mgr/orchestrator.py b/src/pybind/mgr/orchestrator.py index 90e9685baaffe..0700317f7ad7e 100644 --- a/src/pybind/mgr/orchestrator.py +++ b/src/pybind/mgr/orchestrator.py @@ -890,7 +890,7 @@ class Orchestrator(object): raise NotImplementedError() def create_osds(self, drive_groups): - # type: (DriveGroupSpec) -> Completion + # type: (List[DriveGroupSpec]) -> Completion """ Create one or more OSDs within a single Drive Group. diff --git a/src/pybind/mgr/requirements.txt b/src/pybind/mgr/requirements.txt index f14efb8cd80d5..4281f47e8c1dd 100644 --- a/src/pybind/mgr/requirements.txt +++ b/src/pybind/mgr/requirements.txt @@ -1,7 +1,7 @@ pytest-cov==2.7.1 mock; python_version <= '3.3' ipaddress; python_version < '3.3' -../../python-common +-e../../python-common kubernetes requests-mock pyyaml diff --git a/src/pybind/mgr/rook/module.py b/src/pybind/mgr/rook/module.py index a8970c7e0cdab..eb7e23f8085ad 100644 --- a/src/pybind/mgr/rook/module.py +++ b/src/pybind/mgr/rook/module.py @@ -387,8 +387,8 @@ class RookOrchestrator(MgrModule, orchestrator.Orchestrator): drive_group = drive_groups[0] targets = [] # type: List[str] - if drive_group.data_devices: - targets += drive_group.data_devices.paths + if drive_group.data_devices and drive_group.data_devices.paths: + targets += [d.path for d in drive_group.data_devices.paths] if drive_group.data_directories: targets += drive_group.data_directories @@ -409,7 +409,7 @@ class RookOrchestrator(MgrModule, orchestrator.Orchestrator): return orchestrator.Completion.with_progress( message="Creating OSD on {0}:{1}".format( - drive_group.hosts(drive_group.host_pattern), + drive_group.hosts(all_hosts), targets), mgr=self, on_complete=lambda _:self.rook_cluster.add_osds(drive_group, all_hosts), diff --git a/src/pybind/mgr/rook/rook_cluster.py b/src/pybind/mgr/rook/rook_cluster.py index 0fa724e5ae4f5..bb667f0703f0f 100644 --- a/src/pybind/mgr/rook/rook_cluster.py +++ b/src/pybind/mgr/rook/rook_cluster.py @@ -494,7 +494,7 @@ class RookCluster(object): Rook currently (0.8) can only do single-drive OSDs, so we treat all drive groups as just a list of individual OSDs. """ - block_devices = drive_group.data_devices.paths if drive_group.data_devices else None + block_devices = drive_group.data_devices.paths if drive_group.data_devices else [] directories = drive_group.data_directories assert drive_group.objectstore in ("bluestore", "filestore") @@ -525,7 +525,7 @@ class RookCluster(object): if drive_group.hosts(all_hosts)[0] not in [n['name'] for n in current_nodes]: pd = { "name": drive_group.hosts(all_hosts)[0], - "config": { "storeType": drive_group.objectstore }} + "config": { "storeType": drive_group.objectstore }} # type: dict if block_devices: pd["devices"] = [{'name': d.path} for d in block_devices] diff --git a/src/python-common/ceph/deployment/drive_group.py b/src/python-common/ceph/deployment/drive_group.py index 138f7d49e3870..8d4ab95b3d196 100644 --- a/src/python-common/ceph/deployment/drive_group.py +++ b/src/python-common/ceph/deployment/drive_group.py @@ -113,7 +113,7 @@ class DriveGroupSpecs(object): def __init__(self, drive_group_json): # type: (dict) -> None self.drive_group_json = drive_group_json - self.drive_groups = list() # type: list + self.drive_groups = list() # type: List[DriveGroupSpec] self.build_drive_groups() def build_drive_groups(self): diff --git a/src/python-common/ceph/deployment/inventory.py b/src/python-common/ceph/deployment/inventory.py index 22109c567fc56..361adf3c36845 100644 --- a/src/python-common/ceph/deployment/inventory.py +++ b/src/python-common/ceph/deployment/inventory.py @@ -51,9 +51,9 @@ class Device(object): device_id=None, # type: Optional[str] ): self.path = path - self.sys_api = sys_api + self.sys_api = sys_api if sys_api is not None else {} # type: Dict[str, Any] self.available = available - self.rejected_reasons = rejected_reasons + self.rejected_reasons = rejected_reasons if rejected_reasons is not None else [] self.lvs = lvs self.device_id = device_id diff --git a/src/python-common/ceph/py.typed b/src/python-common/ceph/py.typed new file mode 100644 index 0000000000000..444b02d774e4f --- /dev/null +++ b/src/python-common/ceph/py.typed @@ -0,0 +1 @@ +# Marker file for PEP 561. This package uses inline types. \ No newline at end of file -- 2.39.5