Replace literals with constants
authorJose A. Lopes <jabolopes@google.com>
Fri, 30 Aug 2013 07:42:19 +0000 (09:42 +0200)
committerJose A. Lopes <jabolopes@google.com>
Mon, 9 Sep 2013 16:47:52 +0000 (18:47 +0200)
In "lib/cmdlib/node.py", in lines 1315-1316, 1354, and 1359-1370,
replace string literals with constants.  Fixes issue 558.

Signed-off-by: Jose A. Lopes <jabolopes@google.com>
Reviewed-by: Michele Tartara <mtartara@google.com>

lib/cmdlib/node.py
lib/constants.py

index 8fa1a9c..101ef05 100644 (file)
@@ -1312,8 +1312,9 @@ class LUNodeQueryvols(NoHooksLU):
   REQ_BGL = False
 
   def CheckArguments(self):
-    _CheckOutputFields(utils.FieldSet("node", "phys", "vg", "name", "size",
-                                      "instance"),
+    _CheckOutputFields(utils.FieldSet(constants.VF_NODE, constants.VF_PHYS,
+                                      constants.VF_VG, constants.VF_NAME,
+                                      constants.VF_SIZE, constants.VF_INSTANCE),
                        self.op.output_fields)
 
   def ExpandNames(self):
@@ -1351,24 +1352,24 @@ class LUNodeQueryvols(NoHooksLU):
         continue
 
       node_vols = sorted(nresult.payload,
-                         key=operator.itemgetter("dev"))
+                         key=operator.itemgetter(constants.VF_DEV))
 
       for vol in node_vols:
         node_output = []
         for field in self.op.output_fields:
-          if field == "node":
+          if field == constants.VF_NODE:
             val = self.cfg.GetNodeName(node_uuid)
-          elif field == "phys":
-            val = vol["dev"]
-          elif field == "vg":
-            val = vol["vg"]
-          elif field == "name":
-            val = vol["name"]
-          elif field == "size":
-            val = int(float(vol["size"]))
-          elif field == "instance":
-            inst = vol2inst.get((node_uuid, vol["vg"] + "/" + vol["name"]),
-                                None)
+          elif field == constants.VF_PHYS:
+            val = vol[constants.VF_DEV]
+          elif field == constants.VF_VG:
+            val = vol[constants.VF_VG]
+          elif field == constants.VF_NAME:
+            val = vol[constants.VF_NAME]
+          elif field == constants.VF_SIZE:
+            val = int(float(vol[constants.VF_SIZE]))
+          elif field == constants.VF_INSTANCE:
+            inst = vol2inst.get((node_uuid, vol[constants.VF_VG] + "/" +
+                                 vol[constants.VF_NAME]), None)
             if inst is not None:
               val = inst.name
             else:
index 87bd753..f31a84a 100644 (file)
@@ -433,6 +433,15 @@ VALID_STORAGE_OPERATIONS = {
   ST_LVM_VG: frozenset([SO_FIX_CONSISTENCY]),
   }
 
+# Volume fields
+VF_DEV = "dev"
+VF_INSTANCE = "instance"
+VF_NAME = "name"
+VF_NODE = "node"
+VF_PHYS = "phys"
+VF_SIZE = "size"
+VF_VG = "vg"
+
 # Local disk status
 # Note: Code depends on LDS_OKAY < LDS_UNKNOWN < LDS_FAULTY
 (LDS_OKAY,