Revision 1c3231aa test/py/ganeti.cmdlib_unittest.py

b/test/py/ganeti.cmdlib_unittest.py
306 306
    if cond:
307 307
      errors.append((item, msg))
308 308

  
309
  _VerifyFiles = cluster.LUClusterVerifyGroup._VerifyFiles
310

  
311 309
  def test(self):
312 310
    errors = []
313
    master_name = "master.example.com"
314 311
    nodeinfo = [
315
      objects.Node(name=master_name, offline=False, vm_capable=True),
316
      objects.Node(name="node2.example.com", offline=False, vm_capable=True),
317
      objects.Node(name="node3.example.com", master_candidate=True,
312
      objects.Node(name="master.example.com",
313
                   uuid="master-uuid",
314
                   offline=False,
315
                   vm_capable=True),
316
      objects.Node(name="node2.example.com",
317
                   uuid="node2-uuid",
318
                   offline=False,
319
                   vm_capable=True),
320
      objects.Node(name="node3.example.com",
321
                   uuid="node3-uuid",
322
                   master_candidate=True,
318 323
                   vm_capable=False),
319
      objects.Node(name="node4.example.com", offline=False, vm_capable=True),
320
      objects.Node(name="nodata.example.com", offline=False, vm_capable=True),
321
      objects.Node(name="offline.example.com", offline=True),
324
      objects.Node(name="node4.example.com",
325
                   uuid="node4-uuid",
326
                   offline=False,
327
                   vm_capable=True),
328
      objects.Node(name="nodata.example.com",
329
                   uuid="nodata-uuid",
330
                   offline=False,
331
                   vm_capable=True),
332
      objects.Node(name="offline.example.com",
333
                   uuid="offline-uuid",
334
                   offline=True),
322 335
      ]
323
    cluster = objects.Cluster(modify_etc_hosts=True,
324
                              enabled_hypervisors=[constants.HT_XEN_HVM])
325 336
    files_all = set([
326 337
      pathutils.CLUSTER_DOMAIN_SECRET_FILE,
327 338
      pathutils.RAPI_CERT_FILE,
......
341 352
      pathutils.VNC_PASSWORD_FILE,
342 353
      ])
343 354
    nvinfo = {
344
      master_name: rpc.RpcResult(data=(True, {
355
      "master-uuid": rpc.RpcResult(data=(True, {
345 356
        constants.NV_FILELIST: {
346 357
          pathutils.CLUSTER_CONF_FILE: "82314f897f38b35f9dab2f7c6b1593e0",
347 358
          pathutils.RAPI_CERT_FILE: "babbce8f387bc082228e544a2146fee4",
......
349 360
          hv_xen.XEND_CONFIG_FILE: "b4a8a824ab3cac3d88839a9adeadf310",
350 361
          hv_xen.XL_CONFIG_FILE: "77935cee92afd26d162f9e525e3d49b9"
351 362
        }})),
352
      "node2.example.com": rpc.RpcResult(data=(True, {
363
      "node2-uuid": rpc.RpcResult(data=(True, {
353 364
        constants.NV_FILELIST: {
354 365
          pathutils.RAPI_CERT_FILE: "97f0356500e866387f4b84233848cc4a",
355 366
          hv_xen.XEND_CONFIG_FILE: "b4a8a824ab3cac3d88839a9adeadf310",
356 367
          }
357 368
        })),
358
      "node3.example.com": rpc.RpcResult(data=(True, {
369
      "node3-uuid": rpc.RpcResult(data=(True, {
359 370
        constants.NV_FILELIST: {
360 371
          pathutils.RAPI_CERT_FILE: "97f0356500e866387f4b84233848cc4a",
361 372
          pathutils.CLUSTER_DOMAIN_SECRET_FILE: "cds-47b5b3f19202936bb4",
362 373
          }
363 374
        })),
364
      "node4.example.com": rpc.RpcResult(data=(True, {
375
      "node4-uuid": rpc.RpcResult(data=(True, {
365 376
        constants.NV_FILELIST: {
366 377
          pathutils.RAPI_CERT_FILE: "97f0356500e866387f4b84233848cc4a",
367 378
          pathutils.CLUSTER_CONF_FILE: "conf-a6d4b13e407867f7a7b4f0f232a8f527",
......
370 381
          hv_xen.XL_CONFIG_FILE: "77935cee92afd26d162f9e525e3d49b9"
371 382
          }
372 383
        })),
373
      "nodata.example.com": rpc.RpcResult(data=(True, {})),
374
      "offline.example.com": rpc.RpcResult(offline=True),
384
      "nodata-uuid": rpc.RpcResult(data=(True, {})),
385
      "offline-uuid": rpc.RpcResult(offline=True),
375 386
      }
376
    assert set(nvinfo.keys()) == set(map(operator.attrgetter("name"), nodeinfo))
387
    assert set(nvinfo.keys()) == set(map(operator.attrgetter("uuid"), nodeinfo))
388

  
389
    verify_lu = cluster.LUClusterVerifyGroup(mocks.FakeProc(),
390
                                             opcodes.OpClusterVerify(),
391
                                             mocks.FakeContext(),
392
                                             None)
393

  
394
    verify_lu._ErrorIf = compat.partial(self._FakeErrorIf, errors)
395

  
396
    # TODO: That's a bit hackish to mock only this single method. We should
397
    # build a better FakeConfig which provides such a feature already.
398
    def GetNodeName(node_uuid):
399
      for node in nodeinfo:
400
        if node.uuid == node_uuid:
401
          return node.name
402
      return None
403

  
404
    verify_lu.cfg.GetNodeName = GetNodeName
377 405

  
378
    self._VerifyFiles(compat.partial(self._FakeErrorIf, errors), nodeinfo,
379
                      master_name, nvinfo,
380
                      (files_all, files_opt, files_mc, files_vm))
406
    verify_lu._VerifyFiles(nodeinfo, "master-uuid", nvinfo,
407
                           (files_all, files_opt, files_mc, files_vm))
381 408
    self.assertEqual(sorted(errors), sorted([
382 409
      (None, ("File %s found with 2 different checksums (variant 1 on"
383 410
              " node2.example.com, node3.example.com, node4.example.com;"
......
1417 1444

  
1418 1445

  
1419 1446
class _ConfigForDiskWipe:
1420
  def __init__(self, exp_node):
1421
    self._exp_node = exp_node
1447
  def __init__(self, exp_node_uuid):
1448
    self._exp_node_uuid = exp_node_uuid
1422 1449

  
1423
  def SetDiskID(self, device, node):
1450
  def SetDiskID(self, device, node_uuid):
1424 1451
    assert isinstance(device, objects.Disk)
1425
    assert node == self._exp_node
1452
    assert node_uuid == self._exp_node_uuid
1453

  
1454
  def GetNodeName(self, node_uuid):
1455
    assert node_uuid == self._exp_node_uuid
1456
    return "name.of.expected.node"
1426 1457

  
1427 1458

  
1428 1459
class _RpcForDiskWipe:
......
1517 1548
    return (False, None)
1518 1549

  
1519 1550
  def testFailingWipe(self):
1520
    node_name = "node13445.example.com"
1551
    node_uuid = "node13445-uuid"
1521 1552
    pt = _DiskPauseTracker()
1522 1553

  
1523
    lu = _FakeLU(rpc=_RpcForDiskWipe(node_name, pt, self._FailingWipeCb),
1524
                 cfg=_ConfigForDiskWipe(node_name))
1554
    lu = _FakeLU(rpc=_RpcForDiskWipe(node_uuid, pt, self._FailingWipeCb),
1555
                 cfg=_ConfigForDiskWipe(node_uuid))
1525 1556

  
1526 1557
    disks = [
1527 1558
      objects.Disk(dev_type=constants.LD_LV, logical_id="disk0",
......
1532 1563
      ]
1533 1564

  
1534 1565
    inst = objects.Instance(name="inst562",
1535
                            primary_node=node_name,
1566
                            primary_node=node_uuid,
1536 1567
                            disk_template=constants.DT_PLAIN,
1537 1568
                            disks=disks)
1538 1569

  

Also available in: Unified diff