Exemplo n.º 1
0
def TestInstanceRenameAndBack(rename_source, rename_target):
    """gnt-instance rename

  This must leave the instance with the original name, not the target
  name.

  """
    CheckSsconfInstanceList(rename_source)

    # first do a rename to a different actual name, expecting it to fail
    qa_utils.AddToEtcHosts(["meeeeh-not-exists", rename_target])
    try:
        AssertCommand(["gnt-instance", "rename", rename_source, rename_target],
                      fail=True)
        CheckSsconfInstanceList(rename_source)
    finally:
        qa_utils.RemoveFromEtcHosts(["meeeeh-not-exists", rename_target])

    info = GetInstanceInfo(rename_source)

    # Check instance volume tags correctly updated. Note that this check is lvm
    # specific, so we skip it for non-lvm-based instances.
    # FIXME: This will need updating when instances will be able to have
    # different disks living on storage pools with etherogeneous storage types.
    # FIXME: This check should be put inside the disk/storage class themselves,
    # rather than explicitly called here.
    if info["storage-type"] == constants.ST_LVM_VG:
        # In the lvm world we can check for tags on the logical volume
        tags_cmd = ("lvs -o tags --noheadings %s | grep " %
                    (" ".join(info["volumes"]), ))
    else:
        # Other storage types don't have tags, so we use an always failing command,
        # to make sure it never gets executed
        tags_cmd = "false"

    # and now rename instance to rename_target...
    AssertCommand(["gnt-instance", "rename", rename_source, rename_target])
    CheckSsconfInstanceList(rename_target)
    qa_utils.RunInstanceCheck(rename_source, False)
    qa_utils.RunInstanceCheck(rename_target, False)

    # NOTE: tags might not be the exactly as the instance name, due to
    # charset restrictions; hence the test might be flaky
    if (rename_source != rename_target
            and info["storage-type"] == constants.ST_LVM_VG):
        for node in info["nodes"]:
            AssertCommand(tags_cmd + rename_source, node=node, fail=True)
            AssertCommand(tags_cmd + rename_target, node=node, fail=False)

    # and back
    AssertCommand(["gnt-instance", "rename", rename_target, rename_source])
    CheckSsconfInstanceList(rename_source)
    qa_utils.RunInstanceCheck(rename_target, False)

    if (rename_source != rename_target
            and info["storage-type"] == constants.ST_LVM_VG):
        for node in info["nodes"]:
            AssertCommand(tags_cmd + rename_source, node=node, fail=False)
            AssertCommand(tags_cmd + rename_target, node=node, fail=True)
Exemplo n.º 2
0
def TestInterClusterInstanceMove(src_instance,
                                 dest_instance,
                                 inodes,
                                 tnode,
                                 perform_checks=True):
    """Test tools/move-instance"""
    master = qa_config.GetMasterNode()

    rapi_pw_file = tempfile.NamedTemporaryFile()
    rapi_pw_file.write(_rapi_password)
    rapi_pw_file.flush()

    # Needed only if checks are to be performed
    if perform_checks:
        dest_instance.SetDiskTemplate(src_instance.disk_template)

    # TODO: Run some instance tests before moving back

    if len(inodes) > 1:
        # No disk template currently requires more than 1 secondary node. If this
        # changes, either this test must be skipped or the script must be updated.
        assert len(inodes) == 2
        snode = inodes[1]
    else:
        # instance is not redundant, but we still need to pass a node
        # (which will be ignored)
        snode = tnode
    pnode = inodes[0]
    # note: pnode:snode are the *current* nodes, so we move it first to
    # tnode:pnode, then back to pnode:snode
    for current_src_inst, current_dest_inst, target_pnode, target_snode in \
      [(src_instance.name, dest_instance.name, tnode.primary, pnode.primary),
       (dest_instance.name, src_instance.name, pnode.primary, snode.primary)]:
        cmd = [
            "../tools/move-instance",
            "--verbose",
            "--src-ca-file=%s" % _rapi_ca.name,
            "--src-username=%s" % _rapi_username,
            "--src-password-file=%s" % rapi_pw_file.name,
            "--dest-instance-name=%s" % current_dest_inst,
            "--dest-primary-node=%s" % target_pnode,
            "--dest-secondary-node=%s" % target_snode,
            "--net=0:mac=%s" % constants.VALUE_GENERATE,
            master.primary,
            master.primary,
            current_src_inst,
        ]

        # Some uses of this test might require that RAPI-only commands are used,
        # and the checks are command-line based.

        if perform_checks:
            qa_utils.RunInstanceCheck(current_dest_inst, False)

        AssertEqual(StartLocalCommand(cmd).wait(), 0)

        if perform_checks:
            qa_utils.RunInstanceCheck(current_src_inst, False)
            qa_utils.RunInstanceCheck(current_dest_inst, True)
Exemplo n.º 3
0
def TestRapiInstanceRenameAndBack(rename_source, rename_target):
    """Test renaming instance via RAPI

  This must leave the instance with the original name (in the
  non-failure case).

  """
    _WaitForRapiJob(_rapi_client.RenameInstance(rename_source, rename_target))
    qa_utils.RunInstanceCheck(rename_source, False)
    qa_utils.RunInstanceCheck(rename_target, False)
    _WaitForRapiJob(_rapi_client.RenameInstance(rename_target, rename_source))
    qa_utils.RunInstanceCheck(rename_target, False)
Exemplo n.º 4
0
def _InvokeMoveInstance(current_dest_inst,
                        current_src_inst,
                        rapi_pw_filename,
                        joint_master,
                        perform_checks,
                        target_nodes=None):
    """ Invokes the move-instance tool for testing purposes.

  """
    # Some uses of this test might require that RAPI-only commands are used,
    # and the checks are command-line based.
    if perform_checks:
        qa_utils.RunInstanceCheck(current_dest_inst, False)

    cmd = [
        "../tools/move-instance",
        "--verbose",
        "--src-ca-file=%s" % _rapi_ca.name,
        "--src-username=%s" % _rapi_username,
        "--src-password-file=%s" % rapi_pw_filename,
        "--dest-instance-name=%s" % current_dest_inst,
    ]

    if target_nodes:
        pnode, snode = target_nodes
        cmd.extend([
            "--dest-primary-node=%s" % pnode,
            "--dest-secondary-node=%s" % snode,
        ])
    else:
        cmd.extend([
            "--iallocator=%s" % constants.IALLOC_HAIL,
            "--opportunistic-tries=1",
        ])

    cmd.extend([
        "--net=0:mac=%s" % constants.VALUE_GENERATE,
        joint_master,
        joint_master,
        current_src_inst,
    ])

    AssertEqual(StartLocalCommand(cmd).wait(), 0)

    if perform_checks:
        qa_utils.RunInstanceCheck(current_src_inst, False)
        qa_utils.RunInstanceCheck(current_dest_inst, True)
Exemplo n.º 5
0
def TestInstanceAddWithPlainDisk(nodes, fail=False):
    """gnt-instance add -t plain"""
    if constants.DT_PLAIN in qa_config.GetEnabledDiskTemplates():
        instance = CreateInstanceByDiskTemplateOneNode(nodes,
                                                       constants.DT_PLAIN,
                                                       fail=fail)
        if not fail:
            qa_utils.RunInstanceCheck(instance, True)
        return instance
Exemplo n.º 6
0
def TestRapiInstanceFailover(instance):
    """Test failing over instance via RAPI"""
    if not IsFailoverSupported(instance):
        print qa_utils.FormatInfo("Instance doesn't support failover, skipping"
                                  " test")
        return
    # Move to secondary node
    _WaitForRapiJob(_rapi_client.FailoverInstance(instance.name))
    qa_utils.RunInstanceCheck(instance, True)
    # And back to previous primary
    _WaitForRapiJob(_rapi_client.FailoverInstance(instance.name))
Exemplo n.º 7
0
def TestRapiInstanceMigrate(instance):
  """Test migrating instance via RAPI"""
  if not IsMigrationSupported(instance):
    print qa_logging.FormatInfo("Instance doesn't support migration, skipping"
                                " test")
    return
  # Move to secondary node
  _WaitForRapiJob(_rapi_client.MigrateInstance(instance.name))
  qa_utils.RunInstanceCheck(instance, True)
  # And back to previous primary
  _WaitForRapiJob(_rapi_client.MigrateInstance(instance.name))
Exemplo n.º 8
0
def TestRapiInstanceReinstall(instance):
    """Test reinstalling an instance via RAPI"""
    if instance.disk_template == constants.DT_DISKLESS:
        print qa_utils.FormatInfo("Test not supported for diskless instances")
        return

    _WaitForRapiJob(_rapi_client.ReinstallInstance(instance.name))
    # By default, the instance is started again
    qa_utils.RunInstanceCheck(instance, True)

    # Reinstall again without starting
    _WaitForRapiJob(
        _rapi_client.ReinstallInstance(instance.name, no_startup=True))
Exemplo n.º 9
0
def TestInstanceFailover(instance):
    """gnt-instance failover"""
    if not IsFailoverSupported(instance):
        print qa_utils.FormatInfo("Instance doesn't support failover, skipping"
                                  " test")
        return

    cmd = ["gnt-instance", "failover", "--force", instance.name]

    # failover ...
    AssertCommand(cmd)
    qa_utils.RunInstanceCheck(instance, True)

    # ... and back
    AssertCommand(cmd)
Exemplo n.º 10
0
def TestInstanceReboot(instance):
    """gnt-instance reboot"""
    options = qa_config.get("options", {})
    reboot_types = options.get("reboot-types", constants.REBOOT_TYPES)
    name = instance.name
    for rtype in reboot_types:
        AssertCommand(["gnt-instance", "reboot", "--type=%s" % rtype, name])

    AssertCommand(["gnt-instance", "shutdown", name])
    qa_utils.RunInstanceCheck(instance, False)
    AssertCommand(["gnt-instance", "reboot", name])

    master = qa_config.GetMasterNode()
    cmd = ["gnt-instance", "list", "--no-headers", "-o", "status", name]
    result_output = qa_utils.GetCommandOutput(master.primary,
                                              utils.ShellQuoteArgs(cmd))
    AssertEqual(result_output.strip(), constants.INSTST_RUNNING)
Exemplo n.º 11
0
def TestInstanceMigrate(instance, toggle_always_failover=True):
    """gnt-instance migrate"""
    if not IsMigrationSupported(instance):
        print qa_utils.FormatInfo(
            "Instance doesn't support migration, skipping"
            " test")
        return

    cmd = ["gnt-instance", "migrate", "--force", instance.name]
    af_par = constants.BE_ALWAYS_FAILOVER
    af_field = "be/" + constants.BE_ALWAYS_FAILOVER
    af_init_val = _GetBoolInstanceField(instance.name, af_field)

    # migrate ...
    AssertCommand(cmd)
    # TODO: Verify the choice between failover and migration
    qa_utils.RunInstanceCheck(instance, True)

    # ... and back (possibly with always_failover toggled)
    if toggle_always_failover:
        AssertCommand([
            "gnt-instance", "modify", "-B",
            ("%s=%s" % (af_par, not af_init_val)), instance.name
        ])
    AssertCommand(cmd)
    # TODO: Verify the choice between failover and migration
    qa_utils.RunInstanceCheck(instance, True)
    if toggle_always_failover:
        AssertCommand([
            "gnt-instance", "modify", "-B", ("%s=%s" % (af_par, af_init_val)),
            instance.name
        ])

    # TODO: Split into multiple tests
    AssertCommand(["gnt-instance", "shutdown", instance.name])
    qa_utils.RunInstanceCheck(instance, False)
    AssertCommand(cmd, fail=True)
    AssertCommand([
        "gnt-instance", "migrate", "--force", "--allow-failover", instance.name
    ])
    AssertCommand(["gnt-instance", "start", instance.name])
    AssertCommand(cmd)
    # @InstanceCheck enforces the check that the instance is running
    qa_utils.RunInstanceCheck(instance, True)

    AssertCommand([
        "gnt-instance", "modify", "-B",
        ("%s=%s" % (constants.BE_ALWAYS_FAILOVER, constants.VALUE_TRUE)),
        instance.name
    ])

    AssertCommand(cmd)
    qa_utils.RunInstanceCheck(instance, True)
    # TODO: Verify that a failover has been done instead of a migration

    # TODO: Verify whether the default value is restored here (not hardcoded)
    AssertCommand([
        "gnt-instance", "modify", "-B",
        ("%s=%s" % (constants.BE_ALWAYS_FAILOVER, constants.VALUE_FALSE)),
        instance.name
    ])

    AssertCommand(cmd)
    qa_utils.RunInstanceCheck(instance, True)