Revision c2e22e7b

b/qa/qa_config.py
702 702
  return instance
703 703

  
704 704

  
705
def AcquireManyInstances(num, _cfg=None):
706
  """Return instances that are not in use.
707

  
708
  @type num: int
709
  @param num: Number of instances; can be 0.
710
  @rtype: list of instances
711
  @return: C{num} different instances
712

  
713
  """
714

  
715
  if _cfg is None:
716
    cfg = GetConfig()
717
  else:
718
    cfg = _cfg
719

  
720
  # Filter out unwanted instances
721
  instances = filter(lambda inst: not inst.used, cfg["instances"])
722

  
723
  if len(instances) < num:
724
    raise qa_error.OutOfInstancesError(
725
      "Not enough instances left (%d needed, %d remaining)" %
726
      (num, len(instances))
727
    )
728

  
729
  instances = []
730

  
731
  try:
732
    for _ in range(0, num):
733
      n = AcquireInstance(_cfg=cfg)
734
      instances.append(n)
735
  except qa_error.OutOfInstancesError:
736
    ReleaseManyInstances(instances)
737
    raise
738

  
739
  return instances
740

  
741

  
742
def ReleaseManyInstances(instances):
743
  for instance in instances:
744
    instance.Release()
745

  
746

  
705 747
def SetExclusiveStorage(value):
706 748
  """Wrapper for L{_QaConfig.SetExclusiveStorage}.
707 749

  
b/qa/rapi-workload.py
31 31
import types
32 32

  
33 33
import ganeti.constants as constants
34
from ganeti.rapi.client import GanetiApiError
34
from ganeti.rapi.client import GanetiApiError, NODE_EVAC_PRI, NODE_EVAC_SEC
35 35

  
36 36
import qa_config
37 37
import qa_node
......
632 632
  Finish(client, client.DeleteNetwork, NETWORK_NAME)
633 633

  
634 634

  
635
def CreateDRBDInstance(client, node_one, node_two, instance_name):
636
  """ Creates a DRBD-enabled instance on the given nodes.
637

  
638
  """
639
  Finish(client, client.CreateInstance,
640
         "create", instance_name, "drbd", [{"size": "1000"}], [{}],
641
         os="debian-image", pnode=node_one, snode=node_two)
642

  
643

  
644
def TestInstanceMigrations(client, node_one, node_two, node_three,
645
                           instance_name):
646
  """ Test various operations related to migrating instances.
647

  
648
  @type node_one string
649
  @param node_one The name of a node in the cluster.
650
  @type node_two string
651
  @param node_two The name of another node in the cluster.
652
  @type node_three string
653
  @param node_three The name of yet another node in the cluster.
654
  @type instance_name string
655
  @param instance_name An instance name that can be used.
656

  
657
  """
658

  
659
  CreateDRBDInstance(client, node_one, node_two, instance_name)
660
  Finish(client, client.FailoverInstance, instance_name)
661
  Finish(client, client.DeleteInstance, instance_name)
662

  
663
  CreateDRBDInstance(client, node_one, node_two, instance_name)
664
  Finish(client, client.EvacuateNode,
665
         node_two, early_release=False, mode=NODE_EVAC_SEC,
666
         remote_node=node_three)
667
  Finish(client, client.DeleteInstance, instance_name)
668

  
669
  CreateDRBDInstance(client, node_one, node_two, instance_name)
670
  Finish(client, client.EvacuateNode,
671
         node_one, early_release=False, mode=NODE_EVAC_PRI, iallocator="hail")
672
  Finish(client, client.DeleteInstance, instance_name)
673

  
674
  CreateDRBDInstance(client, node_one, node_two, instance_name)
675
  Finish(client, client.MigrateInstance,
676
         instance_name, cleanup=True, target_node=node_two)
677
  Finish(client, client.DeleteInstance, instance_name)
678

  
679
  CreateDRBDInstance(client, node_one, node_two, instance_name)
680
  Finish(client, client.MigrateNode,
681
         node_one, iallocator="hail", mode="non-live")
682
  Finish(client, client.DeleteInstance, instance_name)
683

  
684
  CreateDRBDInstance(client, node_one, node_two, instance_name)
685
  Finish(client, client.MigrateNode,
686
         node_one, target_node=node_two, mode="non-live")
687
  Finish(client, client.DeleteInstance, instance_name)
688

  
689

  
635 690
def Workload(client):
636 691
  """ The actual RAPI workload used for tests.
637 692

  
......
661 716
  RemoveAllInstances(client)
662 717

  
663 718
  nodes = qa_config.AcquireManyNodes(2)
664
  instance_one = qa_config.AcquireInstance()
665
  instance_two = qa_config.AcquireInstance()
666
  TestSingleInstance(client, instance_one.name, instance_two.name,
719
  instances = qa_config.AcquireManyInstances(2)
720
  TestSingleInstance(client, instances[0].name, instances[1].name,
667 721
                     nodes[0].primary, nodes[1].primary)
668
  instance_two.Release()
669
  instance_one.Release()
722
  qa_config.ReleaseManyInstances(instances)
670 723
  qa_config.ReleaseManyNodes(nodes)
671 724

  
672 725
  # Test all the queries which involve resources that do not have functions
......
686 739

  
687 740
  TestNetworks(client)
688 741

  
742
  nodes = qa_config.AcquireManyNodes(3)
743
  instance = qa_config.AcquireInstance()
744
  TestInstanceMigrations(client, nodes[0].primary, nodes[1].primary,
745
                         nodes[2].primary, instance.name)
746
  instance.Release()
747
  qa_config.ReleaseManyNodes(nodes)
748

  
689 749

  
690 750
def Usage():
691 751
  sys.stderr.write("Usage:\n\trapi-workload.py qa-config-file")

Also available in: Unified diff