From b87f6fc0fd1cdc5803166a2f92ce5152d5495999 Mon Sep 17 00:00:00 2001 From: Varsha Rao Date: Wed, 25 Mar 2020 00:26:56 +0530 Subject: [PATCH] mgr/volumes/nfs: Fix mypy errors This patch fixes the following mypy errors: volumes/module.py:9: note: In module imported here, volumes/__init__.py:2: note: ... from here: volumes/fs/nfs.py: note: In member "validate_path" of class "CephFSFSal": volumes/fs/nfs.py:80: error: Name 're' is not defined volumes/fs/nfs.py: note: In member "create_path" of class "CephFSFSal": volumes/fs/nfs.py:83: error: Name 'CephFS' is not defined volumes/fs/nfs.py: note: In member "_persist_daemon_configuration" of class "GaneshaConf": volumes/fs/nfs.py:259: error: Need type annotation for 'daemon_map' (hint: "daemon_map: Dict[, ] = ...") volumes/fs/nfs.py: note: In member "create_instance" of class "NFSConfig": volumes/fs/nfs.py:386: error: Incompatible types in assignment (expression has type "GaneshaConf", variable has type "str") volumes/fs/nfs.py: note: In member "create_export" of class "NFSConfig": volumes/fs/nfs.py:389: error: "str" has no attribute "create_export" volumes/fs/nfs.py: note: In member "delete_export" of class "NFSConfig": volumes/fs/nfs.py:404: error: "str" has no attribute "has_export" volumes/fs/nfs.py:407: error: "str" has no attribute "remove_export" volumes/fs/nfs.py:408: error: "str" has no attribute "reload_daemons" volumes/__init__.py:2: note: In module imported here: volumes/module.py: note: In member "_cmd_fs_nfs_export_create" of class "Module": volumes/module.py:406: error: "str" has no attribute "check_fsal_valid" volumes/module.py:407: error: "str" has no attribute "create_instance" volumes/module.py:408: error: "str" has no attribute "create_export" volumes/module.py: note: In member "_cmd_fs_nfs_export_delete" of class "Module": volumes/module.py:412: error: "str" has no attribute "delete_export" volumes/module.py: note: In member "_cmd_fs_nfs_cluster_create" of class "Module": volumes/module.py:415: error: Incompatible types in assignment (expression has type "NFSConfig", variable has type "str") volumes/module.py:416: error: "str" has no attribute "create_nfs_cluster" Signed-off-by: Varsha Rao --- src/pybind/mgr/volumes/fs/nfs.py | 19 +++++++++---------- src/pybind/mgr/volumes/module.py | 5 +++-- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/pybind/mgr/volumes/fs/nfs.py b/src/pybind/mgr/volumes/fs/nfs.py index 405939426c5c5..871883281a11b 100644 --- a/src/pybind/mgr/volumes/fs/nfs.py +++ b/src/pybind/mgr/volumes/fs/nfs.py @@ -1,5 +1,9 @@ import json import logging +try: + from typing import Dict, List, Optional +except ImportError: + pass import cephfs import orchestrator @@ -75,14 +79,6 @@ class CephFSFSal(): self.sec_label_xattr = sec_label_xattr self.cephx_key = cephx_key - @classmethod - def validate_path(cls, path): - return re.match(r'^/[^><|&()?]*$', path) - - def create_path(self, path): - cfs = CephFS(self.fs_name) - cfs.mk_dirs(path) - @classmethod def from_fsal_block(cls, fsal_block): return cls(fsal_block['name'], @@ -256,7 +252,7 @@ class GaneshaConf(object): return nid def _persist_daemon_configuration(self): - daemon_map = {} + daemon_map = {} # type: Dict[str, List[Dict[str, str]]] """ for daemon_id in self.list_daemons(): daemon_map[daemon_id] = [] @@ -327,7 +323,7 @@ class NFSConfig(object): self.pool_name = 'nfs-ganesha' self.pool_ns = cluster_id self.mgr = mgr - self.ganeshaconf = '' + self.ganeshaconf = None # type: Optional[GaneshaConf] self.key = '' def update_user_caps(self): @@ -383,9 +379,11 @@ class NFSConfig(object): self.pool_name, self.pool_ns, nodeid, result) def create_instance(self): + assert self.ganeshaconf is not None self.ganeshaconf = GaneshaConf(self) def create_export(self): + assert self.ganeshaconf is not None ex_id = self.ganeshaconf.create_export({ 'path': "/", 'pseudo': "/cephfs", @@ -401,6 +399,7 @@ class NFSConfig(object): return 0, "", "Export Created Successfully" def delete_export(self, ex_id): + assert self.ganeshaconf is not None if not self.ganeshaconf.has_export(ex_id): return 0, "No exports available","" log.info("Export detected for id:{}".format(ex_id)) diff --git a/src/pybind/mgr/volumes/module.py b/src/pybind/mgr/volumes/module.py index eb6fe0ee9b1b4..e9ced669baffb 100644 --- a/src/pybind/mgr/volumes/module.py +++ b/src/pybind/mgr/volumes/module.py @@ -1,11 +1,12 @@ import errno import json +from typing import Optional + from mgr_module import MgrModule import orchestrator from .fs.volume import VolumeClient -#from .fs.nfs import check_fsal_valid, create_instance, create_export, delete_export from .fs.nfs import NFSConfig class Module(orchestrator.OrchestratorClientMixin, MgrModule): @@ -257,7 +258,7 @@ class Module(orchestrator.OrchestratorClientMixin, MgrModule): def __init__(self, *args, **kwargs): super(Module, self).__init__(*args, **kwargs) self.vc = VolumeClient(self) - self.nfs_obj = "" + self.nfs_obj = None # type: Optional[NFSConfig] def __del__(self): self.vc.shutdown() -- 2.39.5