]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/nfs: move write_block func to file level format_block
authorJohn Mulligan <jmulligan@redhat.com>
Fri, 4 Mar 2022 20:04:56 +0000 (15:04 -0500)
committerAdam King <adking@redhat.com>
Sat, 21 May 2022 23:01:55 +0000 (19:01 -0400)
The method was an unnecessary use of staticmethod as well as a
confusingly named function. Move the file and rename it for clarity.

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

src/pybind/mgr/nfs/export.py
src/pybind/mgr/nfs/ganesha_conf.py

index cd2c7fa5d66f70bed937a247be74d27700a723c2..6f129e55c528204944e54772ba5673f163b9a593 100644 (file)
@@ -24,7 +24,8 @@ from .ganesha_conf import (
     Export,
     GaneshaConfParser,
     RGWFSAL,
-    RawBlock)
+    RawBlock,
+    format_block)
 from .exception import NFSException, NFSInvalidOperation, FSNotFound
 from .utils import (
     CONF_PREFIX,
@@ -119,7 +120,7 @@ class NFSRados:
                       self.pool, self.namespace, obj)
 
             # Add created obj url to common config obj
-            ioctx.append(config_obj, GaneshaConfParser.write_block(
+            ioctx.append(config_obj, format_block(
                          self._create_url_block(obj)).encode('utf-8'))
             _check_rados_notify(ioctx, config_obj)
             log.debug("Added %s url to %s", obj, config_obj)
@@ -310,7 +311,7 @@ class ExportMgr:
     def _save_export(self, cluster_id: str, export: Export) -> None:
         self.exports[cluster_id].append(export)
         self._rados(cluster_id).write_obj(
-            GaneshaConfParser.write_block(export.to_export_block()),
+            format_block(export.to_export_block()),
             export_obj_name(export.export_id),
             conf_obj_name(export.cluster_id)
         )
@@ -361,7 +362,7 @@ class ExportMgr:
                        need_nfs_service_restart: bool) -> None:
         self.exports[cluster_id].append(export)
         self._rados(cluster_id).update_obj(
-            GaneshaConfParser.write_block(export.to_export_block()),
+            format_block(export.to_export_block()),
             export_obj_name(export.export_id), conf_obj_name(export.cluster_id),
             should_notify=not need_nfs_service_restart)
         if need_nfs_service_restart:
index 67bee5b44148ad0bf74460531d52c9b5eba0ee0f..0db9559b5385621238a5c56146bd77c8c86e1701 100644 (file)
@@ -149,33 +149,6 @@ class GaneshaConfParser:
             blocks.append(self.parse_block_or_section())
         return blocks
 
-    @staticmethod
-    def write_block_body(block: RawBlock, depth: int = 0) -> str:
-        conf_str = ""
-        for blo in block.blocks:
-            conf_str += GaneshaConfParser.write_block(blo, depth)
-
-        for key, val in block.values.items():
-            if val is not None:
-                conf_str += _indentation(depth)
-                fval = _format_val(block.block_name, key, val)
-                conf_str += '{} = {};\n'.format(key, fval)
-        return conf_str
-
-    @staticmethod
-    def write_block(block: RawBlock, depth: int = 0) -> str:
-        if block.block_name == "%url":
-            return '%url "{}"\n\n'.format(block.values['value'])
-
-        conf_str = ""
-        conf_str += _indentation(depth)
-        conf_str += format(block.block_name)
-        conf_str += " {\n"
-        conf_str += GaneshaConfParser.write_block_body(block, depth + 1)
-        conf_str += _indentation(depth)
-        conf_str += "}\n"
-        return conf_str
-
 
 class FSAL(object):
     def __init__(self, name: str) -> None:
@@ -518,3 +491,33 @@ class Export:
         if not isinstance(other, Export):
             return False
         return self.to_dict() == other.to_dict()
+
+
+def _format_block_body(block: RawBlock, depth: int = 0) -> str:
+    conf_str = ""
+    for blo in block.blocks:
+        conf_str += format_block(blo, depth)
+
+    for key, val in block.values.items():
+        if val is not None:
+            conf_str += _indentation(depth)
+            fval = _format_val(block.block_name, key, val)
+            conf_str += '{} = {};\n'.format(key, fval)
+    return conf_str
+
+
+def format_block(block: RawBlock, depth: int = 0) -> str:
+    """Format a raw block object into text suitable as a ganesha configuration
+    block.
+    """
+    if block.block_name == "%url":
+        return '%url "{}"\n\n'.format(block.values['value'])
+
+    conf_str = ""
+    conf_str += _indentation(depth)
+    conf_str += format(block.block_name)
+    conf_str += " {\n"
+    conf_str += _format_block_body(block, depth + 1)
+    conf_str += _indentation(depth)
+    conf_str += "}\n"
+    return conf_str