Ejemplo n.º 1
0
def RunExportImportTests(instance, inodes):
    """Tries to export and import the instance.

  @type inodes: list of nodes
  @param inodes: current nodes of the instance

  """
    # FIXME: export explicitly bails out on file based storage. other non-lvm
    # based storage types are untested, though. Also note that import could still
    # work, but is deeply embedded into the "export" case.
    if qa_config.TestEnabled("instance-export"):
        RunTest(qa_instance.TestInstanceExportNoTarget, instance)

        pnode = inodes[0]
        expnode = qa_config.AcquireNode(exclude=pnode)
        try:
            name = RunTest(qa_instance.TestInstanceExport, instance, expnode)

            RunTest(qa_instance.TestBackupList, expnode)

            if qa_config.TestEnabled("instance-import"):
                newinst = qa_config.AcquireInstance()
                try:
                    RunTest(qa_instance.TestInstanceImport, newinst, pnode,
                            expnode, name)
                    # Check if starting the instance works
                    RunTest(qa_instance.TestInstanceStartup, newinst)
                    RunTest(qa_instance.TestInstanceRemove, newinst)
                finally:
                    newinst.Release()
        finally:
            expnode.Release()

    # FIXME: inter-cluster-instance-move crashes on file based instances :/
    # See Issue 414.
    if (qa_config.TestEnabled([qa_rapi.Enabled,
                               "inter-cluster-instance-move"])):
        newinst = qa_config.AcquireInstance()
        try:
            tnode = qa_config.AcquireNode(exclude=inodes)
            try:
                RunTest(qa_rapi.TestInterClusterInstanceMove, instance,
                        newinst, inodes, tnode)
            finally:
                tnode.Release()
        finally:
            newinst.Release()
Ejemplo n.º 2
0
def _AcquireAllInstances():
  """Generator for acquiring all instances in the QA config.

  """
  try:
    while True:
      instance = qa_config.AcquireInstance()
      yield instance
  except qa_error.OutOfInstancesError:
    pass
Ejemplo n.º 3
0
def TestRapiInstanceMultiAlloc(node):
    """Test adding two new instances via the RAPI instance-multi-alloc method"""
    if not qa_config.IsTemplateSupported(constants.DT_PLAIN):
        return

    JOBS_KEY = "jobs"

    instance_one = qa_config.AcquireInstance()
    instance_two = qa_config.AcquireInstance()
    instance_list = [instance_one, instance_two]
    try:
        rapi_dicts = [
            _GenInstanceAllocationDict(node, i) for i in instance_list
        ]

        job_id = _rapi_client.InstancesMultiAlloc(rapi_dicts)

        results, = _WaitForRapiJob(job_id)

        if JOBS_KEY not in results:
            raise qa_error.Error("RAPI instance-multi-alloc did not deliver "
                                 "information about created jobs")

        if len(results[JOBS_KEY]) != len(instance_list):
            raise qa_error.Error(
                "RAPI instance-multi-alloc failed to return the "
                "desired number of jobs!")

        for success, job in results[JOBS_KEY]:
            if success:
                _WaitForRapiJob(job)
            else:
                raise qa_error.Error("Failed to create instance in "
                                     "instance-multi-alloc call")
    except:
        # Note that although released, it may be that some of the instance creations
        # have in fact succeeded. Handling this in a better way may be possible, but
        # is not necessary as the QA has already failed at this point.
        for instance in instance_list:
            instance.Release()
        raise

    return (instance_one, instance_two)
Ejemplo n.º 4
0
  def testAcquireInstanceTooMany(self):
    # Acquire all instances
    for _ in range(len(self.config["instances"])):
      inst = qa_config.AcquireInstance(_cfg=self.config)
      self.assertTrue(inst.used)
      self.assertTrue(inst.disk_template is None)

    # The next acquisition must fail
    self.assertRaises(qa_error.OutOfInstancesError,
                      qa_config.AcquireInstance, _cfg=self.config)
Ejemplo n.º 5
0
def TestRapiInstanceAdd(node, use_client):
    """Test adding a new instance via RAPI"""
    if not qa_config.IsTemplateSupported(constants.DT_PLAIN):
        return
    instance = qa_config.AcquireInstance()
    instance.SetDiskTemplate(constants.DT_PLAIN)
    try:
        disks = [{
            "size": utils.ParseUnit(d.get("size")),
            "name": str(d.get("name"))
        } for d in qa_config.GetDiskOptions()]
        nic0_mac = instance.GetNicMacAddr(0, constants.VALUE_GENERATE)
        nics = [{
            constants.INIC_MAC: nic0_mac,
        }]

        beparams = {
            constants.BE_MAXMEM:
            utils.ParseUnit(qa_config.get(constants.BE_MAXMEM)),
            constants.BE_MINMEM:
            utils.ParseUnit(qa_config.get(constants.BE_MINMEM)),
        }

        if use_client:
            job_id = _rapi_client.CreateInstance(constants.INSTANCE_CREATE,
                                                 instance.name,
                                                 constants.DT_PLAIN,
                                                 disks,
                                                 nics,
                                                 os=qa_config.get("os"),
                                                 pnode=node.primary,
                                                 beparams=beparams)
        else:
            body = {
                "__version__": 1,
                "mode": constants.INSTANCE_CREATE,
                "name": instance.name,
                "os_type": qa_config.get("os"),
                "disk_template": constants.DT_PLAIN,
                "pnode": node.primary,
                "beparams": beparams,
                "disks": disks,
                "nics": nics,
            }

            (job_id, ) = _DoTests([
                ("/2/instances", _VerifyReturnsJob, "POST", body),
            ])

        _WaitForRapiJob(job_id)

        return instance
    except:
        instance.Release()
        raise
Ejemplo n.º 6
0
  def testAcquireAndReleaseInstance(self):
    self.assertFalse(compat.any(i.used for i in self.config["instances"]))

    inst = qa_config.AcquireInstance(_cfg=self.config)
    self.assertTrue(inst.used)
    self.assertTrue(inst.disk_template is None)

    inst.Release()

    self.assertFalse(inst.used)
    self.assertTrue(inst.disk_template is None)

    self.assertFalse(compat.any(i.used for i in self.config["instances"]))
Ejemplo n.º 7
0
def TestParallelInstanceRename(instance):
  """PERFORMANCE: Instance rename with parallel instance creation.

  """
  # instance rename requires the instance to be down
  qa_utils.AssertCommand(["gnt-instance", "stop", instance.name])

  new_instance = qa_config.AcquireInstance()
  try:
    _TestInstanceOperationInParallelToInstanceCreation(
      ["gnt-instance", "rename", "--submit", instance.name, new_instance.name],
      ["gnt-instance", "rename", "--submit", new_instance.name, instance.name])
  finally:
    new_instance.Release()

  qa_utils.AssertCommand(["gnt-instance", "start", instance.name])
    def testAcquireAndReleaseInstance(self):
        self.assertFalse(
            compat.any(
                map(operator.attrgetter("used"), self.config["instances"])))

        inst = qa_config.AcquireInstance(_cfg=self.config)
        self.assertTrue(inst.used)
        self.assertTrue(inst.disk_template is None)

        inst.Release()

        self.assertFalse(inst.used)
        self.assertTrue(inst.disk_template is None)

        self.assertFalse(
            compat.any(
                map(operator.attrgetter("used"), self.config["instances"])))
Ejemplo n.º 9
0
def _CreateInstanceByDiskTemplateRaw(nodes_spec, disk_template, fail=False):
  """Creates an instance with the given disk template on the given nodes(s).
     Note that this function does not check if enough nodes are given for
     the respective disk template.

  @type nodes_spec: string
  @param nodes_spec: string specification of one node (by node name) or several
                     nodes according to the requirements of the disk template
  @type disk_template: string
  @param disk_template: the disk template to be used by the instance
  @return: the created instance

  """
  instance = qa_config.AcquireInstance()
  try:
    cmd = (["gnt-instance", "add",
            "--os-type=%s" % qa_config.get("os"),
            "--disk-template=%s" % disk_template,
            "--node=%s" % nodes_spec] +
           GetGenericAddParameters(instance, disk_template))
    cmd.append(instance.name)

    AssertCommand(cmd, fail=fail)

    if not fail:
      CheckSsconfInstanceList(instance.name)
      instance.SetDiskTemplate(disk_template)

      return instance
  except:
    instance.Release()
    raise

  # Handle the case where creation is expected to fail
  assert fail
  instance.Release()
  return None
Ejemplo n.º 10
0
def RunCommonInstanceTests(instance, inst_nodes):
    """Runs a few tests that are common to all disk types.

  """
    RunTestIf("instance-shutdown", qa_instance.TestInstanceShutdown, instance)
    RunTestIf(["instance-shutdown", "instance-console", qa_rapi.Enabled],
              qa_rapi.TestRapiStoppedInstanceConsole, instance)
    RunTestIf(["instance-shutdown", "instance-modify"],
              qa_instance.TestInstanceStoppedModify, instance)
    RunTestIf("instance-shutdown", qa_instance.TestInstanceStartup, instance)

    # Test shutdown/start via RAPI
    RunTestIf(["instance-shutdown", qa_rapi.Enabled],
              qa_rapi.TestRapiInstanceShutdown, instance)
    RunTestIf(["instance-shutdown", qa_rapi.Enabled],
              qa_rapi.TestRapiInstanceStartup, instance)

    RunTestIf("instance-list", qa_instance.TestInstanceList)

    RunTestIf("instance-info", qa_instance.TestInstanceInfo, instance)

    RunTestIf("instance-modify", qa_instance.TestInstanceModify, instance)
    RunTestIf(["instance-modify", qa_rapi.Enabled],
              qa_rapi.TestRapiInstanceModify, instance)

    RunTestIf("instance-console", qa_instance.TestInstanceConsole, instance)
    RunTestIf(["instance-console", qa_rapi.Enabled],
              qa_rapi.TestRapiInstanceConsole, instance)

    RunTestIf("instance-device-names", qa_instance.TestInstanceDeviceNames,
              instance)
    DOWN_TESTS = qa_config.Either([
        "instance-reinstall",
        "instance-rename",
        "instance-grow-disk",
    ])

    # shutdown instance for any 'down' tests
    RunTestIf(DOWN_TESTS, qa_instance.TestInstanceShutdown, instance)

    # now run the 'down' state tests
    RunTestIf("instance-reinstall", qa_instance.TestInstanceReinstall,
              instance)
    RunTestIf(["instance-reinstall", qa_rapi.Enabled],
              qa_rapi.TestRapiInstanceReinstall, instance)

    if qa_config.TestEnabled("instance-rename"):
        tgt_instance = qa_config.AcquireInstance()
        try:
            rename_source = instance.name
            rename_target = tgt_instance.name
            # perform instance rename to the same name
            RunTest(qa_instance.TestInstanceRenameAndBack, rename_source,
                    rename_source)
            RunTestIf(qa_rapi.Enabled, qa_rapi.TestRapiInstanceRenameAndBack,
                      rename_source, rename_source)
            if rename_target is not None:
                # perform instance rename to a different name, if we have one configured
                RunTest(qa_instance.TestInstanceRenameAndBack, rename_source,
                        rename_target)
                RunTestIf(qa_rapi.Enabled,
                          qa_rapi.TestRapiInstanceRenameAndBack, rename_source,
                          rename_target)
        finally:
            tgt_instance.Release()

    RunTestIf(["instance-grow-disk"], qa_instance.TestInstanceGrowDisk,
              instance)

    # and now start the instance again
    RunTestIf(DOWN_TESTS, qa_instance.TestInstanceStartup, instance)

    RunTestIf("instance-reboot", qa_instance.TestInstanceReboot, instance)

    RunTestIf("tags", qa_tags.TestInstanceTags, instance)

    if instance.disk_template == constants.DT_DRBD8:
        RunTestIf("cluster-verify",
                  qa_cluster.TestClusterVerifyDisksBrokenDRBD, instance,
                  inst_nodes)
    RunTestIf("cluster-verify", qa_cluster.TestClusterVerify)

    RunTestIf(qa_rapi.Enabled, qa_rapi.TestInstance, instance)

    # Lists instances, too
    RunTestIf("node-list", qa_node.TestNodeList)

    # Some jobs have been run, let's test listing them
    RunTestIf("job-list", qa_job.TestJobList)