Bump version to 2.5.0~rc1
[ganeti-local] / lib / client / gnt_cluster.py
index f06f5f8..04fda73 100644 (file)
@@ -20,7 +20,7 @@
 
 """Cluster related commands"""
 
-# pylint: disable-msg=W0401,W0613,W0614,C0103
+# pylint: disable=W0401,W0613,W0614,C0103
 # W0401: Wildcard import ganeti.cli
 # W0613: Unused argument, since all functions follow the same API
 # W0614: Unused import %s from wildcard import (since we need cli)
@@ -455,40 +455,46 @@ def VerifyCluster(opts, args):
   @return: the desired exit code
 
   """
-  simulate = opts.simulate_errors
   skip_checks = []
 
-  if opts.nodegroup is None:
-    # Verify cluster config.
-    op = opcodes.OpClusterVerifyConfig(verbose=opts.verbose,
-                                       error_codes=opts.error_codes,
-                                       debug_simulate_errors=simulate)
-
-    success, all_groups = SubmitOpCode(op, opts=opts)
-  else:
-    success = True
-    all_groups = [opts.nodegroup]
-
   if opts.skip_nplusone_mem:
     skip_checks.append(constants.VERIFY_NPLUSONE_MEM)
 
-  jex = JobExecutor(opts=opts, verbose=False)
+  cl = GetClient()
+
+  op = opcodes.OpClusterVerify(verbose=opts.verbose,
+                               error_codes=opts.error_codes,
+                               debug_simulate_errors=opts.simulate_errors,
+                               skip_checks=skip_checks,
+                               group_name=opts.nodegroup)
+  result = SubmitOpCode(op, cl=cl, opts=opts)
+
+  # Keep track of submitted jobs
+  jex = JobExecutor(cl=cl, opts=opts)
 
-  for group in all_groups:
-    op = opcodes.OpClusterVerifyGroup(group_name=group,
-                                      skip_checks=skip_checks,
-                                      verbose=opts.verbose,
-                                      error_codes=opts.error_codes,
-                                      debug_simulate_errors=simulate)
-    jex.QueueJob("group " + group, op)
+  for (status, job_id) in result[constants.JOB_IDS_KEY]:
+    jex.AddJobId(None, status, job_id)
 
   results = jex.GetResults()
-  success &= compat.all(r[1][0] for r in results)
 
-  if success:
-    return constants.EXIT_SUCCESS
+  (bad_jobs, bad_results) = \
+    map(len,
+        # Convert iterators to lists
+        map(list,
+            # Count errors
+            map(compat.partial(itertools.ifilterfalse, bool),
+                # Convert result to booleans in a tuple
+                zip(*((job_success, len(op_results) == 1 and op_results[0])
+                      for (job_success, op_results) in results)))))
+
+  if bad_jobs == 0 and bad_results == 0:
+    rcode = constants.EXIT_SUCCESS
   else:
-    return constants.EXIT_FAILURE
+    rcode = constants.EXIT_FAILURE
+    if bad_jobs > 0:
+      ToStdout("%s job(s) failed while verifying the cluster.", bad_jobs)
+
+  return rcode
 
 
 def VerifyDisks(opts, args):
@@ -616,7 +622,7 @@ def MasterPing(opts, args):
     cl = GetClient()
     cl.QueryClusterInfo()
     return 0
-  except Exception: # pylint: disable-msg=W0703
+  except Exception: # pylint: disable=W0703
     return 1
 
 
@@ -679,14 +685,14 @@ def _RenewCrypto(new_cluster_cert, new_rapi_cert, rapi_cert_filename,
 
       OpenSSL.crypto.load_certificate(OpenSSL.crypto.FILETYPE_PEM,
                                       rapi_cert_pem)
-    except Exception, err: # pylint: disable-msg=W0703
+    except Exception, err: # pylint: disable=W0703
       ToStderr("Can't load new RAPI certificate from %s: %s" %
                (rapi_cert_filename, str(err)))
       return 1
 
     try:
       OpenSSL.crypto.load_privatekey(OpenSSL.crypto.FILETYPE_PEM, rapi_cert_pem)
-    except Exception, err: # pylint: disable-msg=W0703
+    except Exception, err: # pylint: disable=W0703
       ToStderr("Can't load new RAPI private key from %s: %s" %
                (rapi_cert_filename, str(err)))
       return 1
@@ -697,7 +703,7 @@ def _RenewCrypto(new_cluster_cert, new_rapi_cert, rapi_cert_filename,
   if cds_filename:
     try:
       cds = utils.ReadFile(cds_filename)
-    except Exception, err: # pylint: disable-msg=W0703
+    except Exception, err: # pylint: disable=W0703
       ToStderr("Can't load new cluster domain secret from %s: %s" %
                (cds_filename, str(err)))
       return 1