예제 #1
0
def _RetrieveSecret(instance, pnode):
    """Retrieves the DRBD secret given an instance object and the primary node.

  @type instance: L{qa_config._QaInstance}
  @type pnode: L{qa_config._QaNode}

  @rtype: string

  """
    instance_info = GetInstanceInfo(instance.name)

    # We are interested in only the first disk on the primary
    drbd_minor = instance_info["drbd-minors"][pnode.primary][0]

    # This form should work for all DRBD versions
    drbd_command = ("drbdsetup show %d; drbdsetup %d show || true" %
                    (drbd_minor, drbd_minor))
    instance_drbd_info = \
      qa_utils.GetCommandOutput(pnode.primary, drbd_command)

    match_obj = _DRBD_SECRET_RE.search(instance_drbd_info)
    if match_obj is None:
        raise qa_error.Error(
            "Could not retrieve DRBD secret for instance %s from"
            " node %s." % (instance.name, pnode.primary))

    return match_obj.groups(0)[0]
예제 #2
0
def IsExclusiveStorageInstanceTestEnabled():
    test_name = "exclusive-storage-instance-tests"
    if qa_config.TestEnabled(test_name):
        vgname = qa_config.get("vg-name", constants.DEFAULT_VG)
        vgscmd = utils.ShellQuoteArgs([
            "vgs",
            "--noheadings",
            "-o",
            "pv_count",
            vgname,
        ])
        nodes = qa_config.GetConfig()["nodes"]
        for node in nodes:
            try:
                pvnum = int(qa_utils.GetCommandOutput(node.primary, vgscmd))
            except Exception, e:
                msg = (
                    "Cannot get the number of PVs on %s, needed by '%s': %s" %
                    (node.primary, test_name, e))
                raise qa_error.Error(msg)
            if pvnum < 2:
                raise qa_error.Error(
                    "Node %s has not enough PVs (%s) to run '%s'" %
                    (node.primary, pvnum, test_name))
        res = True
예제 #3
0
def _CheckFileOnAllNodes(filename, content):
    """Verifies the content of the given file on all nodes.

  """
    cmd = utils.ShellQuoteArgs(["cat", filename])
    for node in qa_config.get("nodes"):
        AssertEqual(qa_utils.GetCommandOutput(node.primary, cmd), content)
예제 #4
0
def _AssertOobCall(verify_path, expected_args):
  """Assert the OOB call was performed with expetected args."""
  master = qa_config.GetMasterNode()

  verify_output_cmd = utils.ShellQuoteArgs(["cat", verify_path])
  output = qa_utils.GetCommandOutput(master.primary, verify_output_cmd,
                                     tty=False)

  AssertEqual(expected_args, output.strip())
예제 #5
0
def _TestInstanceUserDown(instance, master, hv_shutdown_fn):
    # Shutdown instance and bring instance status to 'USER_down'
    hv_shutdown_fn()

    cmd = [
        "gnt-instance", "list", "--no-headers", "-o", "status", instance.name
    ]
    result_output = qa_utils.GetCommandOutput(master.primary,
                                              utils.ShellQuoteArgs(cmd))
    AssertEqual(result_output.strip(), constants.INSTST_USERDOWN)

    # Fail to bring instance status to 'running'
    AssertCommand(["gnt-instance", "start", instance.name], fail=True)

    cmd = [
        "gnt-instance", "list", "--no-headers", "-o", "status", instance.name
    ]
    result_output = qa_utils.GetCommandOutput(master.primary,
                                              utils.ShellQuoteArgs(cmd))
    AssertEqual(result_output.strip(), constants.INSTST_USERDOWN)

    # Bring instance status to 'ADMIN_down'
    AssertCommand(["gnt-instance", "shutdown", instance.name])

    cmd = [
        "gnt-instance", "list", "--no-headers", "-o", "status", instance.name
    ]
    result_output = qa_utils.GetCommandOutput(master.primary,
                                              utils.ShellQuoteArgs(cmd))
    AssertEqual(result_output.strip(), constants.INSTST_ADMINDOWN)

    # Bring instance status to 'running'
    AssertCommand(["gnt-instance", "start", instance.name])

    cmd = [
        "gnt-instance", "list", "--no-headers", "-o", "status", instance.name
    ]
    result_output = qa_utils.GetCommandOutput(master.primary,
                                              utils.ShellQuoteArgs(cmd))
    AssertEqual(result_output.strip(), constants.INSTST_RUNNING)

    # Bring instance status to 'ADMIN_down' forcibly
    AssertCommand(["gnt-instance", "shutdown", "-f", instance.name])

    cmd = [
        "gnt-instance", "list", "--no-headers", "-o", "status", instance.name
    ]
    result_output = qa_utils.GetCommandOutput(master.primary,
                                              utils.ShellQuoteArgs(cmd))
    AssertEqual(result_output.strip(), constants.INSTST_ADMINDOWN)

    # Bring instance status to 'running'
    AssertCommand(["gnt-instance", "start", instance.name])

    cmd = [
        "gnt-instance", "list", "--no-headers", "-o", "status", instance.name
    ]
    result_output = qa_utils.GetCommandOutput(master.primary,
                                              utils.ShellQuoteArgs(cmd))
    AssertEqual(result_output.strip(), constants.INSTST_RUNNING)
예제 #6
0
def ReloadCertificates(ensure_presence=True):
    """Reloads the client RAPI certificate with the one present on the node.

  If the QA is set up to use a specific certificate using the
  "rapi-files-location" parameter, it will be put in place prior to retrieving
  it.

  """
    if ensure_presence:
        _EnsureRapiFilesPresence()

    if _rapi_username is None or _rapi_password is None:
        raise qa_error.Error("RAPI username and password have to be set before"
                             " attempting to reload a certificate.")

    # pylint: disable=W0603
    # due to global usage
    global _rapi_ca
    global _rapi_client

    master = qa_config.GetMasterNode()

    # Load RAPI certificate from master node
    cmd = [
        "openssl", "x509", "-in",
        qa_utils.MakeNodePath(master, pathutils.RAPI_CERT_FILE)
    ]

    # Write to temporary file
    _rapi_ca = tempfile.NamedTemporaryFile()
    _rapi_ca.write(
        qa_utils.GetCommandOutput(master.primary, utils.ShellQuoteArgs(cmd)))
    _rapi_ca.flush()

    port = qa_config.get("rapi-port", default=constants.DEFAULT_RAPI_PORT)
    cfg_curl = rapi.client.GenericCurlConfig(cafile=_rapi_ca.name, proxy="")

    if qa_config.UseVirtualCluster():
        # TODO: Implement full support for RAPI on virtual clusters
        print qa_logging.FormatWarning(
            "RAPI tests are not yet supported on"
            " virtual clusters and will be disabled")

        assert _rapi_client is None
    else:
        _rapi_client = rapi.client.GanetiRapiClient(master.primary,
                                                    port=port,
                                                    username=_rapi_username,
                                                    password=_rapi_password,
                                                    curl_config_fn=cfg_curl)

        print "RAPI protocol version: %s" % _rapi_client.GetVersion()
예제 #7
0
def _ReadSsconfInstanceList():
    """Reads ssconf_instance_list from the master node.

  """
    master = qa_config.GetMasterNode()

    ssconf_path = utils.PathJoin(pathutils.DATA_DIR,
                                 "ssconf_%s" % constants.SS_INSTANCE_LIST)

    cmd = ["cat", qa_utils.MakeNodePath(master, ssconf_path)]

    return qa_utils.GetCommandOutput(master.primary,
                                     utils.ShellQuoteArgs(cmd)).splitlines()
예제 #8
0
def _GetInstanceField(instance, field):
    """Get the value of a field of an instance.

  @type instance: string
  @param instance: Instance name
  @type field: string
  @param field: Name of the field
  @rtype: string

  """
    master = qa_config.GetMasterNode()
    infocmd = utils.ShellQuoteArgs([
        "gnt-instance", "list", "--no-headers", "--units", "m", "-o", field,
        instance
    ])
    return qa_utils.GetCommandOutput(master.primary, infocmd).strip()
예제 #9
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)
예제 #10
0
파일: qa_rapi.py 프로젝트: kawamuray/ganeti
def Setup(username, password):
    """Configures the RAPI client.

  """
    # pylint: disable=W0603
    # due to global usage
    global _rapi_ca
    global _rapi_client
    global _rapi_username
    global _rapi_password

    _rapi_username = username
    _rapi_password = password

    master = qa_config.GetMasterNode()

    # Load RAPI certificate from master node
    cmd = ["cat", qa_utils.MakeNodePath(master, pathutils.RAPI_CERT_FILE)]

    # Write to temporary file
    _rapi_ca = tempfile.NamedTemporaryFile()
    _rapi_ca.write(
        qa_utils.GetCommandOutput(master.primary, utils.ShellQuoteArgs(cmd)))
    _rapi_ca.flush()

    port = qa_config.get("rapi-port", default=constants.DEFAULT_RAPI_PORT)
    cfg_curl = rapi.client.GenericCurlConfig(cafile=_rapi_ca.name, proxy="")

    if qa_config.UseVirtualCluster():
        # TODO: Implement full support for RAPI on virtual clusters
        print qa_logging.FormatWarning(
            "RAPI tests are not yet supported on"
            " virtual clusters and will be disabled")

        assert _rapi_client is None
    else:
        _rapi_client = rapi.client.GanetiRapiClient(master.primary,
                                                    port=port,
                                                    username=username,
                                                    password=password,
                                                    curl_config_fn=cfg_curl)

        print "RAPI protocol version: %s" % _rapi_client.GetVersion()

    return _rapi_client
예제 #11
0
def LookupRapiSecret(rapi_user):
  """Find the RAPI secret for the given user.

  @param rapi_user: Login user
  @return: Login secret for the user

  """
  CTEXT = "{CLEARTEXT}"
  master = qa_config.GetMasterNode()
  cmd = ["cat", qa_utils.MakeNodePath(master, pathutils.RAPI_USERS_FILE)]
  file_content = qa_utils.GetCommandOutput(master.primary,
                                           utils.ShellQuoteArgs(cmd))
  users = ParsePasswordFile(file_content)
  entry = users.get(rapi_user)
  if not entry:
    raise qa_error.Error("User %s not found in RAPI users file" % rapi_user)
  secret = entry.password
  if secret.upper().startswith(CTEXT):
    secret = secret[len(CTEXT):]
  elif secret.startswith("{"):
    raise qa_error.Error("Unsupported password schema for RAPI user %s:"
                         " not a clear text password" % rapi_user)
  return secret
예제 #12
0
def TestNodeStorage():
  """gnt-node storage"""
  master = qa_config.GetMasterNode()

  # FIXME: test all storage_types in constants.STORAGE_TYPES
  # as soon as they are implemented.
  enabled_storage_types = qa_config.GetEnabledStorageTypes()
  testable_storage_types = list(set(enabled_storage_types).intersection(
      set([constants.ST_FILE, constants.ST_LVM_VG, constants.ST_LVM_PV])))

  for storage_type in testable_storage_types:

    cmd = ["gnt-node", "list-storage", "--storage-type", storage_type]

    # Test simple list
    AssertCommand(cmd)

    # Test all storage fields
    cmd = ["gnt-node", "list-storage", "--storage-type", storage_type,
           "--output=%s" % ",".join(list(constants.VALID_STORAGE_FIELDS))]
    AssertCommand(cmd)

    # Get list of valid storage devices
    cmd = ["gnt-node", "list-storage", "--storage-type", storage_type,
           "--output=node,name,allocatable", "--separator=|",
           "--no-headers"]
    output = qa_utils.GetCommandOutput(master.primary,
                                       utils.ShellQuoteArgs(cmd))

    # Test with up to two devices
    testdevcount = 2

    for line in output.splitlines()[:testdevcount]:
      (node_name, st_name, st_allocatable) = line.split("|")

      # Dummy modification without any changes
      cmd = ["gnt-node", "modify-storage", node_name, storage_type, st_name]
      AssertCommand(cmd)

      # Make sure we end up with the same value as before
      if st_allocatable.lower() == "y":
        test_allocatable = ["no", "yes"]
      else:
        test_allocatable = ["yes", "no"]

      fail = (constants.SF_ALLOCATABLE not in
              constants.MODIFIABLE_STORAGE_FIELDS.get(storage_type, []))

      for i in test_allocatable:
        AssertCommand(["gnt-node", "modify-storage", "--allocatable", i,
                       node_name, storage_type, st_name], fail=fail)

        # Verify list output
        cmd = ["gnt-node", "list-storage", "--storage-type", storage_type,
               "--output=name,allocatable", "--separator=|",
               "--no-headers", node_name]
        listout = qa_utils.GetCommandOutput(master.primary,
                                            utils.ShellQuoteArgs(cmd))
        for line in listout.splitlines():
          (vfy_name, vfy_allocatable) = line.split("|")
          if vfy_name == st_name and not fail:
            AssertEqual(vfy_allocatable, i[0].upper())
          else:
            AssertEqual(vfy_allocatable, st_allocatable)

      # Test repair functionality
      fail = (constants.SO_FIX_CONSISTENCY not in
              constants.VALID_STORAGE_OPERATIONS.get(storage_type, []))
      AssertCommand(["gnt-node", "repair-storage", node_name,
                     storage_type, st_name], fail=fail)
예제 #13
0
파일: qa_os.py 프로젝트: nh2/ganeti-test-1
def _TestOs(mode, rapi_cb):
    """Generic function for OS definition testing

  """
    master = qa_config.GetMasterNode()

    name = _TEMP_OS_NAME
    variant = "default"
    fullname = "%s+%s" % (name, variant)
    dirname = _TEMP_OS_PATH

    # Ensure OS is usable
    cmd = ["gnt-os", "modify", "--hidden=no", "--blacklisted=no", name]
    AssertCommand(cmd)

    nodes = []
    try:
        for i, node in enumerate(qa_config.get("nodes")):
            nodes.append(node)
            if mode == _ALL_INVALID:
                valid = False
            elif mode == _ALL_VALID:
                valid = True
            elif mode == _PARTIALLY_VALID:
                valid = bool(i % 2)
            else:
                raise AssertionError("Unknown mode %s" % mode)
            _SetupTempOs(node, dirname, variant, valid)

        # TODO: Use Python 2.6's itertools.permutations
        for (hidden, blacklisted) in [(False, False), (True, False),
                                      (False, True), (True, True)]:
            # Change OS' visibility
            cmd = [
                "gnt-os", "modify", "--hidden", ["no", "yes"][int(hidden)],
                "--blacklisted", ["no", "yes"][int(blacklisted)], name
            ]
            AssertCommand(cmd)

            # Diagnose, checking exit status
            AssertCommand(["gnt-os", "diagnose"], fail=(mode != _ALL_VALID))

            # Diagnose again, ignoring exit status
            output = qa_utils.GetCommandOutput(master.primary,
                                               "gnt-os diagnose || :")
            for line in output.splitlines():
                if line.startswith("OS: %s [global status:" % name):
                    break
            else:
                raise qa_error.Error(
                    "Didn't find OS '%s' in 'gnt-os diagnose'" % name)

            # Check info for all
            cmd = ["gnt-os", "info"]
            output = qa_utils.GetCommandOutput(master.primary,
                                               utils.ShellQuoteArgs(cmd))
            AssertIn("%s:" % name, output.splitlines())

            # Check info for OS
            cmd = ["gnt-os", "info", name]
            output = qa_utils.GetCommandOutput(
                master.primary, utils.ShellQuoteArgs(cmd)).splitlines()
            AssertIn("%s:" % name, output)
            for (field, value) in [("valid", mode == _ALL_VALID),
                                   ("hidden", hidden),
                                   ("blacklisted", blacklisted)]:
                AssertIn("  - %s: %s" % (field, value), output)

            # Only valid OSes should be listed
            cmd = ["gnt-os", "list", "--no-headers"]
            output = qa_utils.GetCommandOutput(master.primary,
                                               utils.ShellQuoteArgs(cmd))
            if mode == _ALL_VALID and not (hidden or blacklisted):
                assert_fn = AssertIn
            else:
                assert_fn = AssertNotIn
            assert_fn(fullname, output.splitlines())

            # Check via RAPI
            if rapi_cb:
                assert_fn(fullname, rapi_cb())
    finally:
        for node in nodes:
            _RemoveTempOs(node, dirname)