Exemple #1
0
def Enabled():
    """Return whether remote API tests should be run.

  """
    # TODO: Implement RAPI tests for virtual clusters
    return (qa_config.TestEnabled("rapi")
            and not qa_config.UseVirtualCluster())
Exemple #2
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()
Exemple #3
0
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