]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/nfs: lift _format_val function to file level
authorJohn Mulligan <jmulligan@redhat.com>
Fri, 4 Mar 2022 19:53:38 +0000 (14:53 -0500)
committerAdam King <adking@redhat.com>
Sat, 21 May 2022 23:01:49 +0000 (19:01 -0400)
There's no advantage to having this function as a closure and it makes
reading the code (and testing it) more challenging.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
(cherry picked from commit 1a7b7e35b261c9e227f0540ae5310e68a7e8bfe4)

src/pybind/mgr/nfs/ganesha_conf.py

index 382b91827e3a110fe7c8d27b1b498d330755b89c..67bee5b44148ad0bf74460531d52c9b5eba0ee0f 100644 (file)
@@ -14,6 +14,17 @@ def _indentation(depth: int, size: int = 4) -> str:
     return " " * (depth * size)
 
 
+def _format_val(block_name: str, key: str, val: str) -> str:
+    if isinstance(val, list):
+        return ', '.join([_format_val(block_name, key, v) for v in val])
+    if isinstance(val, bool):
+        return str(val).lower()
+    if isinstance(val, int) or (block_name == 'CLIENT'
+                                and key == 'clients'):
+        return '{}'.format(val)
+    return '"{}"'.format(val)
+
+
 class RawBlock():
     def __init__(self, block_name: str, blocks: List['RawBlock'] = [], values: Dict[str, Any] = {}):
         if not values:  # workaround mutable default argument
@@ -140,16 +151,6 @@ class GaneshaConfParser:
 
     @staticmethod
     def write_block_body(block: RawBlock, depth: int = 0) -> str:
-        def format_val(key: str, val: str) -> str:
-            if isinstance(val, list):
-                return ', '.join([format_val(key, v) for v in val])
-            if isinstance(val, bool):
-                return str(val).lower()
-            if isinstance(val, int) or (block.block_name == 'CLIENT'
-                                        and key == 'clients'):
-                return '{}'.format(val)
-            return '"{}"'.format(val)
-
         conf_str = ""
         for blo in block.blocks:
             conf_str += GaneshaConfParser.write_block(blo, depth)
@@ -157,7 +158,8 @@ class GaneshaConfParser:
         for key, val in block.values.items():
             if val is not None:
                 conf_str += _indentation(depth)
-                conf_str += '{} = {};\n'.format(key, format_val(key, val))
+                fval = _format_val(block.block_name, key, val)
+                conf_str += '{} = {};\n'.format(key, fval)
         return conf_str
 
     @staticmethod