Revision bf93ae69 lib/cmdlib.py

b/lib/cmdlib.py
1254 1254

  
1255 1255

  
1256 1256
def _VerifyCertificate(filename):
1257
  """Verifies a certificate for LUClusterVerify.
1257
  """Verifies a certificate for LUClusterVerifyConfig.
1258 1258

  
1259 1259
  @type filename: string
1260 1260
  @param filename: Path to PEM file
......
1264 1264
    cert = OpenSSL.crypto.load_certificate(OpenSSL.crypto.FILETYPE_PEM,
1265 1265
                                           utils.ReadFile(filename))
1266 1266
  except Exception, err: # pylint: disable-msg=W0703
1267
    return (LUClusterVerify.ETYPE_ERROR,
1267
    return (LUClusterVerifyConfig.ETYPE_ERROR,
1268 1268
            "Failed to load X509 certificate %s: %s" % (filename, err))
1269 1269

  
1270 1270
  (errcode, msg) = \
......
1279 1279
  if errcode is None:
1280 1280
    return (None, fnamemsg)
1281 1281
  elif errcode == utils.CERT_WARNING:
1282
    return (LUClusterVerify.ETYPE_WARNING, fnamemsg)
1282
    return (LUClusterVerifyConfig.ETYPE_WARNING, fnamemsg)
1283 1283
  elif errcode == utils.CERT_ERROR:
1284
    return (LUClusterVerify.ETYPE_ERROR, fnamemsg)
1284
    return (LUClusterVerifyConfig.ETYPE_ERROR, fnamemsg)
1285 1285

  
1286 1286
  raise errors.ProgrammerError("Unhandled certificate error code %r" % errcode)
1287 1287

  
......
1368 1368
      self.bad = self.bad or cond
1369 1369

  
1370 1370

  
1371
class LUClusterVerify(LogicalUnit, _VerifyErrors):
1372
  """Verifies the cluster status.
1371
class LUClusterVerifyConfig(NoHooksLU, _VerifyErrors):
1372
  """Verifies the cluster config.
1373 1373

  
1374 1374
  """
1375

  
1376
  REQ_BGL = False
1377

  
1378
  def ExpandNames(self):
1379
    self.all_group_info = self.cfg.GetAllNodeGroupsInfo()
1380
    self.needed_locks = {}
1381

  
1382
  def Exec(self, feedback_fn):
1383
    """Verify integrity of cluster, performing various test on nodes.
1384

  
1385
    """
1386
    self.bad = False
1387
    self._feedback_fn = feedback_fn
1388

  
1389
    feedback_fn("* Verifying cluster config")
1390

  
1391
    for msg in self.cfg.VerifyConfig():
1392
      self._ErrorIf(True, self.ECLUSTERCFG, None, msg)
1393

  
1394
    feedback_fn("* Verifying cluster certificate files")
1395

  
1396
    for cert_filename in constants.ALL_CERT_FILES:
1397
      (errcode, msg) = _VerifyCertificate(cert_filename)
1398
      self._ErrorIf(errcode, self.ECLUSTERCERT, None, msg, code=errcode)
1399

  
1400
    return (not self.bad, [g.name for g in self.all_group_info.values()])
1401

  
1402

  
1403
class LUClusterVerifyGroup(LogicalUnit, _VerifyErrors):
1404
  """Verifies the status of a node group.
1405

  
1406
  """
1407

  
1375 1408
  HPATH = "cluster-verify"
1376 1409
  HTYPE = constants.HTYPE_CLUSTER
1377 1410
  REQ_BGL = False
......
1429 1462
      self.oslist = {}
1430 1463

  
1431 1464
  def ExpandNames(self):
1465
    # This raises errors.OpPrereqError on its own:
1466
    self.group_uuid = self.cfg.LookupNodeGroup(self.op.group_name)
1467

  
1468
    all_node_info = self.cfg.GetAllNodesInfo()
1469
    all_inst_info = self.cfg.GetAllInstancesInfo()
1470

  
1471
    node_names = set(node.name
1472
                     for node in all_node_info.values()
1473
                     if node.group == self.group_uuid)
1474

  
1475
    inst_names = [inst.name
1476
                  for inst in all_inst_info.values()
1477
                  if inst.primary_node in node_names]
1478

  
1432 1479
    self.needed_locks = {
1433
      locking.LEVEL_NODE: locking.ALL_SET,
1434
      locking.LEVEL_INSTANCE: locking.ALL_SET,
1480
      locking.LEVEL_NODEGROUP: [self.group_uuid],
1481
      locking.LEVEL_NODE: list(node_names),
1482
      locking.LEVEL_INSTANCE: inst_names,
1435 1483
    }
1484

  
1436 1485
    self.share_locks = dict.fromkeys(locking.LEVELS, 1)
1437 1486

  
1438 1487
  def CheckPrereq(self):
1439 1488
    self.all_node_info = self.cfg.GetAllNodesInfo()
1440 1489
    self.all_inst_info = self.cfg.GetAllInstancesInfo()
1441
    self.my_node_names = utils.NiceSort(list(self.all_node_info))
1442
    self.my_node_info = self.all_node_info
1443
    self.my_inst_names = utils.NiceSort(list(self.all_inst_info))
1444
    self.my_inst_info = self.all_inst_info
1490

  
1491
    group_nodes = set(node.name
1492
                      for node in self.all_node_info.values()
1493
                      if node.group == self.group_uuid)
1494

  
1495
    group_instances = set(inst.name
1496
                          for inst in self.all_inst_info.values()
1497
                          if inst.primary_node in group_nodes)
1498

  
1499
    unlocked_nodes = \
1500
        group_nodes.difference(self.glm.list_owned(locking.LEVEL_NODE))
1501

  
1502
    unlocked_instances = \
1503
        group_instances.difference(self.glm.list_owned(locking.LEVEL_INSTANCE))
1504

  
1505
    if unlocked_nodes:
1506
      raise errors.OpPrereqError("missing lock for nodes: %s" %
1507
                                 utils.CommaJoin(unlocked_nodes))
1508

  
1509
    if unlocked_instances:
1510
      raise errors.OpPrereqError("missing lock for instances: %s" %
1511
                                 utils.CommaJoin(unlocked_instances))
1512

  
1513
    self.my_node_names = utils.NiceSort(group_nodes)
1514
    self.my_inst_names = utils.NiceSort(group_instances)
1515

  
1516
    self.my_node_info = dict((name, self.all_node_info[name])
1517
                             for name in self.my_node_names)
1518

  
1519
    self.my_inst_info = dict((name, self.all_inst_info[name])
1520
                             for name in self.my_inst_names)
1445 1521

  
1446 1522
  def _VerifyNode(self, ninfo, nresult):
1447 1523
    """Perform some basic validation on data returned from a node.
......
2241 2317
    return ([], self.my_node_names)
2242 2318

  
2243 2319
  def Exec(self, feedback_fn):
2244
    """Verify integrity of cluster, performing various test on nodes.
2320
    """Verify integrity of the node group, performing various test on nodes.
2245 2321

  
2246 2322
    """
2247 2323
    # This method has too many local variables. pylint: disable-msg=R0914
......
2249 2325
    _ErrorIf = self._ErrorIf # pylint: disable-msg=C0103
2250 2326
    verbose = self.op.verbose
2251 2327
    self._feedback_fn = feedback_fn
2252
    feedback_fn("* Verifying global settings")
2253
    for msg in self.cfg.VerifyConfig():
2254
      _ErrorIf(True, self.ECLUSTERCFG, None, msg)
2255

  
2256
    # Check the cluster certificates
2257
    for cert_filename in constants.ALL_CERT_FILES:
2258
      (errcode, msg) = _VerifyCertificate(cert_filename)
2259
      _ErrorIf(errcode, self.ECLUSTERCERT, None, msg, code=errcode)
2260 2328

  
2261 2329
    vg_name = self.cfg.GetVGName()
2262 2330
    drbd_helper = self.cfg.GetDRBDHelper()

Also available in: Unified diff