From b2fbea479179f9393263b367ba6bdbcfe1ac791e Mon Sep 17 00:00:00 2001 From: "Jose A. Lopes" Date: Fri, 30 Aug 2013 09:42:19 +0200 Subject: [PATCH] Replace literals with constants 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 Reviewed-by: Michele Tartara --- lib/cmdlib/node.py | 31 ++++++++++++++++--------------- lib/constants.py | 9 +++++++++ 2 files changed, 25 insertions(+), 15 deletions(-) diff --git a/lib/cmdlib/node.py b/lib/cmdlib/node.py index 8fa1a9c..101ef05 100644 --- a/lib/cmdlib/node.py +++ b/lib/cmdlib/node.py @@ -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: diff --git a/lib/constants.py b/lib/constants.py index 87bd753..f31a84a 100644 --- a/lib/constants.py +++ b/lib/constants.py @@ -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, -- 1.7.10.4