示例#1
0
def TestClusterReservedLvs():
    """gnt-cluster reserved lvs"""
    # if no lvm-based templates are supported, skip the test
    if not qa_config.IsStorageTypeSupported(constants.ST_LVM_VG):
        return
    vgname = qa_config.get("vg-name", constants.DEFAULT_VG)
    lvname = _QA_LV_PREFIX + "test"
    lvfullname = "/".join([vgname, lvname])

    # Clean cluster
    AssertClusterVerify()

    AssertCommand(["gnt-cluster", "modify", "--reserved-lvs", ""])
    AssertCommand(["lvcreate", "-L1G", "-n", lvname, vgname])
    AssertClusterVerify(fail=False, warnings=[constants.CV_ENODEORPHANLV])

    AssertCommand([
        "gnt-cluster", "modify", "--reserved-lvs",
        "%s,.*/other-test" % lvfullname
    ])
    AssertClusterVerify(no_warnings=[constants.CV_ENODEORPHANLV])

    AssertCommand(
        ["gnt-cluster", "modify", "--reserved-lvs",
         ".*/%s.*" % _QA_LV_PREFIX])
    AssertClusterVerify(no_warnings=[constants.CV_ENODEORPHANLV])

    AssertCommand(["gnt-cluster", "modify", "--reserved-lvs", ""])
    AssertClusterVerify(fail=False, warnings=[constants.CV_ENODEORPHANLV])

    AssertCommand(["lvremove", "-f", lvfullname])
    AssertClusterVerify()
示例#2
0
def TestRapiInstanceRemove(instance, use_client):
  """Test removing instance via RAPI"""
  # FIXME: this does not work if LVM is not enabled. Find out if this is a bug
  # in RAPI or in the test
  if not qa_config.IsStorageTypeSupported(constants.ST_LVM_VG):
    return

  if use_client:
    job_id = _rapi_client.DeleteInstance(instance.name)
  else:
    (job_id, ) = _DoTests([
      ("/2/instances/%s" % instance.name, _VerifyReturnsJob, "DELETE", None),
      ])

  _WaitForRapiJob(job_id)
示例#3
0
def TestGroupModify():
  """gnt-group modify"""
  # This tests assumes LVM to be enabled, thus it should skip if
  # this is not the case
  if not qa_config.IsStorageTypeSupported(constants.ST_LVM_VG):
    return
  (group1, ) = qa_utils.GetNonexistentGroups(1)

  AssertCommand(["gnt-group", "add", group1])

  try:
    _TestGroupModifyIPolicy(group1)
    AssertCommand(["gnt-group", "modify", "--alloc-policy", "unallocable",
                   "--node-parameters", "oob_program=/bin/false", group1])
    AssertCommand(["gnt-group", "modify",
                   "--alloc-policy", "notvalid", group1], fail=True)
    AssertCommand(["gnt-group", "modify",
                   "--node-parameters", "spindle_count=10", group1])
    if qa_config.TestEnabled("htools"):
      AssertCommand(["hbal", "-L", "-G", group1])
    AssertCommand(["gnt-group", "modify",
                   "--node-parameters", "spindle_count=default", group1])
  finally:
    AssertCommand(["gnt-group", "remove", group1])
示例#4
0
def TestRapiQuery():
    """Testing resource queries via remote API.

  """
    # FIXME: the tests are failing if no LVM is enabled, investigate
    # if it is a bug in the QA or in the code
    if not qa_config.IsStorageTypeSupported(constants.ST_LVM_VG):
        return

    master_name = qa_utils.ResolveNodeName(qa_config.GetMasterNode())
    rnd = random.Random(7818)

    for what in constants.QR_VIA_RAPI:
        namefield = {
            constants.QR_JOB: "id",
            constants.QR_EXPORT: "export",
            constants.QR_FILTER: "uuid",
        }.get(what, "name")

        all_fields = query.ALL_FIELDS[what].keys()
        rnd.shuffle(all_fields)

        # No fields, should return everything
        result = _rapi_client.QueryFields(what)
        qresult = objects.QueryFieldsResponse.FromDict(result)
        AssertEqual(len(qresult.fields), len(all_fields))

        # One field
        result = _rapi_client.QueryFields(what, fields=[namefield])
        qresult = objects.QueryFieldsResponse.FromDict(result)
        AssertEqual(len(qresult.fields), 1)

        # Specify all fields, order must be correct
        result = _rapi_client.QueryFields(what, fields=all_fields)
        qresult = objects.QueryFieldsResponse.FromDict(result)
        AssertEqual(len(qresult.fields), len(all_fields))
        AssertEqual([fdef.name for fdef in qresult.fields], all_fields)

        # Unknown field
        result = _rapi_client.QueryFields(what, fields=["_unknown!"])
        qresult = objects.QueryFieldsResponse.FromDict(result)
        AssertEqual(len(qresult.fields), 1)
        AssertEqual(qresult.fields[0].name, "_unknown!")
        AssertEqual(qresult.fields[0].kind, constants.QFT_UNKNOWN)

        # Try once more, this time without the client
        _DoTests([
            ("/2/query/%s/fields" % what, None, "GET", None),
            ("/2/query/%s/fields?fields=%s,%s,%s" %
             (what, namefield, namefield, all_fields[0]), None, "GET", None),
        ])

        # Try missing query argument
        try:
            _DoTests([
                ("/2/query/%s" % what, None, "GET", None),
            ])
        except rapi.client.GanetiApiError, err:
            AssertEqual(err.code, 400)
        else:
            raise qa_error.Error(
                "Request missing 'fields' parameter didn't fail")

        def _Check(exp_fields, data):
            qresult = objects.QueryResponse.FromDict(data)
            AssertEqual([fdef.name for fdef in qresult.fields], exp_fields)
            if not isinstance(qresult.data, list):
                raise qa_error.Error("Query did not return a list")

        _DoTests([
            # Specify fields in query
            ("/2/query/%s?fields=%s" % (what, ",".join(all_fields)),
             compat.partial(_Check, all_fields), "GET", None),
            ("/2/query/%s?fields=%s" % (what, namefield),
             compat.partial(_Check, [namefield]), "GET", None),

            # Note the spaces
            ("/2/query/%s?fields=%s,%%20%s%%09,%s%%20" %
             (what, namefield, namefield, namefield),
             compat.partial(_Check, [namefield] * 3), "GET", None)
        ])

        if what in constants.QR_VIA_RAPI_PUT:
            _DoTests([
                # PUT with fields in query
                ("/2/query/%s?fields=%s" % (what, namefield),
                 compat.partial(_Check, [namefield]), "PUT", {}),
                ("/2/query/%s" % what, compat.partial(_Check, [namefield] * 4),
                 "PUT", {
                     "fields": [namefield] * 4,
                 }),
                ("/2/query/%s" % what, compat.partial(_Check,
                                                      all_fields), "PUT", {
                                                          "fields": all_fields,
                                                      }),
                ("/2/query/%s" % what, compat.partial(_Check, [namefield] * 4),
                 "PUT", {
                     "fields": [namefield] * 4
                 })
            ])

        if what in constants.QR_VIA_RAPI_PUT:
            trivial_filter = {
                constants.QR_JOB: [qlang.OP_GE, namefield, 0],
            }.get(what, [qlang.OP_REGEXP, namefield, ".*"])

            _DoTests([
                # With filter
                ("/2/query/%s" % what, compat.partial(_Check,
                                                      all_fields), "PUT", {
                                                          "fields": all_fields,
                                                          "filter":
                                                          trivial_filter
                                                      }),
            ])

        if what == constants.QR_NODE:
            # Test with filter
            (nodes, ) = _DoTests([("/2/query/%s" % what,
                                   compat.partial(_Check, ["name", "master"]),
                                   "PUT", {
                                       "fields": ["name", "master"],
                                       "filter": [qlang.OP_TRUE, "master"],
                                   })])
            qresult = objects.QueryResponse.FromDict(nodes)
            AssertEqual(qresult.data, [
                [[constants.RS_NORMAL, master_name],
                 [constants.RS_NORMAL, True]],
            ])