]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/vol: re-write for better readability
authorRishabh Dave <ridave@redhat.com>
Sun, 19 Nov 2023 10:56:16 +0000 (16:26 +0530)
committerRishabh Dave <ridave@redhat.com>
Fri, 22 Mar 2024 16:57:35 +0000 (22:27 +0530)
Instead of writing like this  -

  if abcd1.abcd2(abcd3) and abcd4 == abcd5
print('efgh6')
  if abcd7.abcd8(abcd9) and abcd4 == abcd5
print('efgh10')

Write like this because it easier to read, especially in case of the
patch where condition under is really long -

  if abcd4 == abcd5:
    if abcd1.abcd2(abcd3):
print('abcd4')
    if abcd5.abcd8(abcd9):
print('abcd5')

Signed-off-by: Rishabh Dave <ridave@redhat.com>
(cherry picked from commit e0034e5ed5f41d89ce88e8956adc88c48d3ccf8a)

src/pybind/mgr/volumes/fs/operations/versions/subvolume_v1.py
src/pybind/mgr/volumes/fs/operations/versions/subvolume_v2.py

index 4667653f2d1e6d811b2bf009b56a6ae6d3efcd37..90f35a4c90b39e6523c9bd816bc8c1d9f7056ddb 100644 (file)
@@ -684,16 +684,16 @@ class SubvolumeV1(SubvolumeBase, SubvolumeTemplate):
     def status(self):
         state = SubvolumeStates.from_value(self.metadata_mgr.get_global_option(MetadataManager.GLOBAL_META_KEY_STATE))
         subvolume_type = self.subvol_type
-        subvolume_status = {
-            'state' : state.value
-        }
-        if not SubvolumeOpSm.is_complete_state(state) and subvolume_type == SubvolumeTypes.TYPE_CLONE:
-            subvolume_status["source"] = self._get_clone_source()
-        if SubvolumeOpSm.is_failed_state(state) and subvolume_type == SubvolumeTypes.TYPE_CLONE:
-            try:
-                subvolume_status["failure"] = self._get_clone_failure()
-            except MetadataMgrException:
-                pass
+        subvolume_status = {'state' : state.value}
+
+        if subvolume_type == SubvolumeTypes.TYPE_CLONE:
+            if not SubvolumeOpSm.is_complete_state(state):
+                subvolume_status["source"] = self._get_clone_source()
+            if SubvolumeOpSm.is_failed_state(state):
+                try:
+                    subvolume_status["failure"] = self._get_clone_failure()
+                except MetadataMgrException:
+                    pass
 
         return subvolume_status
 
index 17955d3020f8d7094ab15887d86a98e78f0522c5..55d7f945b7750631f7dadf4ad4b4ec6e0868f54a 100644 (file)
@@ -307,13 +307,17 @@ class SubvolumeV2(SubvolumeV1):
                                       op_type.value, self.subvolname, etype.value))
 
             estate = self.state
-            if op_type not in self.allowed_ops_by_state(estate) and estate == SubvolumeStates.STATE_RETAINED:
-                raise VolumeException(-errno.ENOENT, "subvolume '{0}' is removed and has only snapshots retained".format(
-                                      self.subvolname))
-
-            if op_type not in self.allowed_ops_by_state(estate) and estate != SubvolumeStates.STATE_RETAINED:
-                raise VolumeException(-errno.EAGAIN, "subvolume '{0}' is not ready for operation {1}".format(
-                                      self.subvolname, op_type.value))
+            if op_type not in self.allowed_ops_by_state(estate):
+                if estate == SubvolumeStates.STATE_RETAINED:
+                    raise VolumeException(
+                        -errno.ENOENT,
+                        f'subvolume "{self.subvolname}" is removed and has '
+                        'only snapshots retained')
+                else:
+                    raise VolumeException(
+                        -errno.EAGAIN,
+                        f'subvolume "{self.subvolname}" is not ready for '
+                        f'operation "{op_type.value}"')
 
             if estate != SubvolumeStates.STATE_RETAINED:
                 subvol_path = self.path