]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
mgr/volumes/nfs: Fix mypy errors
authorVarsha Rao <varao@redhat.com>
Tue, 24 Mar 2020 18:56:56 +0000 (00:26 +0530)
committerVarsha Rao <varao@redhat.com>
Wed, 8 Apr 2020 11:51:17 +0000 (17:21 +0530)
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[<type>, <type>] = ...")
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 <varao@redhat.com>
src/pybind/mgr/volumes/fs/nfs.py
src/pybind/mgr/volumes/module.py

index 405939426c5c5adeb77164b36eae7b8238719cbc..871883281a11b0dafa55e69f123839878b5fad49 100644 (file)
@@ -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))
index eb6fe0ee9b1b4060480848eb87fe852ae71645a1..e9ced669baffb7072a891d4673e61c602a03cf2c 100644 (file)
@@ -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()