On Thu, Sep 17, 2009 at 02:55:03PM +0100, Guido Trotter wrote:
> On Thu, Sep 17, 2009 at 9:42 AM, Iustin Pop <[email protected]> wrote:
> > +  def _ErrorIf(self, cond, *args, **kwargs):
> > +    """Log an error message if the passed condition is True.
> > +
> > +    """
> > +    cond = bool(cond) or self.op.debug_simulate_errors
> > +    if cond:
> > +      self._Error(*args, **kwargs)
> > +    # do not mark the operation as failed for WARN cases only
> > +    if kwargs.get("code", "ERROR") == "ERROR":
> 
> Can you use (even internal) constants here?

Here's the interdiff (I was sure someone will catch this :):

diff --git a/lib/cmdlib.py b/lib/cmdlib.py
index c3c85e6..4c8584c 100644
--- a/lib/cmdlib.py
+++ b/lib/cmdlib.py
@@ -885,6 +885,10 @@ class LUVerifyCluster(LogicalUnit):
   ENODESSH = (TNODE, "ENODESSH")
   ENODEVERSION = (TNODE, "ENODEVERSION")
 
+  ETYPE_FIELD = "code"
+  ETYPE_ERROR = "ERROR"
+  ETYPE_WARNING = "WARNING"
+
   def ExpandNames(self):
     self.needed_locks = {
       locking.LEVEL_NODE: locking.ALL_SET,
@@ -901,7 +905,7 @@ class LUVerifyCluster(LogicalUnit):
     This must be called only from Exec and functions called from Exec.
 
     """
-    ltype = kwargs.get("code", "ERROR")
+    ltype = kwargs.get(self.ETYPE_FIELD, self.ETYPE_ERROR)
     itype, etxt = ecode
     # first complete the msg
     if args:
@@ -926,7 +930,7 @@ class LUVerifyCluster(LogicalUnit):
     if cond:
       self._Error(*args, **kwargs)
     # do not mark the operation as failed for WARN cases only
-    if kwargs.get("code", "ERROR") == "ERROR":
+    if kwargs.get(self.ETYPE_FIELD, self.ETYPE_ERROR) == self.ETYPE_ERROR:
       self.bad = self.bad or cond
 
   def _VerifyNode(self, nodeinfo, file_list, local_cksum,
@@ -986,7 +990,8 @@ class LUVerifyCluster(LogicalUnit):
     self._ErrorIf(constants.RELEASE_VERSION != remote_version[1],
                   self.ENODEVERSION, node,
                   "software version mismatch: master %s, node %s",
-                  constants.RELEASE_VERSION, remote_version[1], code="WARNING")
+                  constants.RELEASE_VERSION, remote_version[1],
+                  code=self.ETYPE_WARNING)
 
     # checks vg existence and size > 20G
     if vg_name is not None:

-- 
iustin

Reply via email to