Revision 9a8ae794 test/ganeti.rapi.client_unittest.py

b/test/ganeti.rapi.client_unittest.py
510 510
    self.assertQuery("static", ["1"])
511 511

  
512 512
  def testCreateInstanceOldVersion(self):
513
    # No NICs
513
    # The old request format, version 0, is no longer supported
514 514
    self.rapi.AddResponse(None, code=404)
515 515
    self.assertRaises(client.GanetiApiError, self.client.CreateInstance,
516 516
                      "create", "inst1.example.com", "plain", [], [])
517 517
    self.assertEqual(self.rapi.CountPending(), 0)
518 518

  
519
    # More than one NIC
520
    self.rapi.AddResponse(None, code=404)
521
    self.assertRaises(client.GanetiApiError, self.client.CreateInstance,
522
                      "create", "inst1.example.com", "plain", [],
523
                      [{}, {}, {}])
524
    self.assertEqual(self.rapi.CountPending(), 0)
525

  
526
    # Unsupported NIC fields
527
    self.rapi.AddResponse(None, code=404)
528
    self.assertRaises(client.GanetiApiError, self.client.CreateInstance,
529
                      "create", "inst1.example.com", "plain", [],
530
                      [{"x": True, "y": False}])
531
    self.assertEqual(self.rapi.CountPending(), 0)
532

  
533
    # Unsupported disk fields
534
    self.rapi.AddResponse(None, code=404)
535
    self.assertRaises(client.GanetiApiError, self.client.CreateInstance,
536
                      "create", "inst1.example.com", "plain",
537
                      [{}, {"moo": "foo",}], [{}])
538
    self.assertEqual(self.rapi.CountPending(), 0)
539

  
540
    # Unsupported fields
541
    self.rapi.AddResponse(None, code=404)
542
    self.assertRaises(client.GanetiApiError, self.client.CreateInstance,
543
                      "create", "inst1.example.com", "plain", [], [{}],
544
                      hello_world=123)
545
    self.assertEqual(self.rapi.CountPending(), 0)
546

  
547
    self.rapi.AddResponse(None, code=404)
548
    self.assertRaises(client.GanetiApiError, self.client.CreateInstance,
549
                      "create", "inst1.example.com", "plain", [], [{}],
550
                      memory=128)
551
    self.assertEqual(self.rapi.CountPending(), 0)
552

  
553
    # Normal creation
554
    testnics = [
555
      [{}],
556
      [{ "mac": constants.VALUE_AUTO, }],
557
      [{ "ip": "192.0.2.99", "mode": constants.NIC_MODE_ROUTED, }],
558
      ]
559

  
560
    testdisks = [
561
      [],
562
      [{ "size": 128, }],
563
      [{ "size": 321, }, { "size": 4096, }],
564
      ]
565

  
566
    for idx, nics in enumerate(testnics):
567
      for disks in testdisks:
568
        beparams = {
569
          constants.BE_MEMORY: 512,
570
          constants.BE_AUTO_BALANCE: False,
571
          }
572
        hvparams = {
573
          constants.HV_MIGRATION_PORT: 9876,
574
          constants.HV_VNC_TLS: True,
575
          }
576

  
577
        self.rapi.AddResponse(None, code=404)
578
        self.rapi.AddResponse(serializer.DumpJson(3122617 + idx))
579
        job_id = self.client.CreateInstance("create", "inst1.example.com",
580
                                            "plain", disks, nics,
581
                                            pnode="node99", dry_run=True,
582
                                            hvparams=hvparams,
583
                                            beparams=beparams)
584
        self.assertEqual(job_id, 3122617 + idx)
585
        self.assertHandler(rlib2.R_2_instances)
586
        self.assertDryRun()
587
        self.assertEqual(self.rapi.CountPending(), 0)
588

  
589
        data = serializer.LoadJson(self.rapi.GetLastRequestData())
590
        self.assertEqual(data["name"], "inst1.example.com")
591
        self.assertEqual(data["disk_template"], "plain")
592
        self.assertEqual(data["pnode"], "node99")
593
        self.assertEqual(data[constants.BE_MEMORY], 512)
594
        self.assertEqual(data[constants.BE_AUTO_BALANCE], False)
595
        self.assertEqual(data[constants.HV_MIGRATION_PORT], 9876)
596
        self.assertEqual(data[constants.HV_VNC_TLS], True)
597
        self.assertEqual(data["disks"], [disk["size"] for disk in disks])
598

  
599 519
  def testCreateInstance(self):
600 520
    self.rapi.AddResponse(serializer.DumpJson([rlib2._INST_CREATE_REQV1]))
601 521
    self.rapi.AddResponse("23030")

Also available in: Unified diff