示例#1
0
def TestNetworkConnect():
    """gnt-network connect/disconnect"""
    (group1, ) = qa_utils.GetNonexistentGroups(1)
    (network1, ) = GetNonexistentNetworks(1)

    default_mode = "bridged"
    default_link = "xen-br0"
    nicparams = qa_config.get("default-nicparams")
    if nicparams:
        mode = nicparams.get("mode", default_mode)
        link = nicparams.get("link", default_link)
    else:
        mode = default_mode
        link = default_link

    AssertCommand(["gnt-group", "add", group1])
    AssertCommand(
        ["gnt-network", "add", "--network", "192.0.2.0/24", network1])

    AssertCommand(["gnt-network", "connect", network1, mode, link, group1])

    TestNetworkList()

    AssertCommand(["gnt-network", "disconnect", network1, group1])

    AssertCommand(["gnt-group", "remove", group1])
    AssertCommand(["gnt-network", "remove", network1])
示例#2
0
def TestRapiNodeGroups():
    """Test several node group operations using RAPI.

  """
    (group1, group2, group3) = qa_utils.GetNonexistentGroups(3)

    # Create a group with no attributes
    body = {
        "name": group1,
    }

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

    _WaitForRapiJob(job_id)

    # Create a group specifying alloc_policy
    body = {
        "name": group2,
        "alloc_policy": constants.ALLOC_POLICY_UNALLOCABLE,
    }

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

    _WaitForRapiJob(job_id)

    # Modify alloc_policy
    body = {
        "alloc_policy": constants.ALLOC_POLICY_UNALLOCABLE,
    }

    (job_id, ) = _DoTests([
        ("/2/groups/%s/modify" % group1, _VerifyReturnsJob, "PUT", body),
    ])

    _WaitForRapiJob(job_id)

    # Rename a group
    body = {
        "new_name": group3,
    }

    (job_id, ) = _DoTests([
        ("/2/groups/%s/rename" % group2, _VerifyReturnsJob, "PUT", body),
    ])

    _WaitForRapiJob(job_id)

    # Delete groups
    for group in [group1, group3]:
        (job_id, ) = _DoTests([
            ("/2/groups/%s" % group, _VerifyReturnsJob, "DELETE", None),
        ])

        _WaitForRapiJob(job_id)
示例#3
0
def TestGroupAddWithOptions():
  """gnt-group add with options"""
  (group1, ) = qa_utils.GetNonexistentGroups(1)

  AssertCommand(["gnt-group", "add", "--alloc-policy", "notvalid", group1],
                fail=True)

  AssertCommand(["gnt-group", "add", "--alloc-policy", "last_resort",
                 "--node-parameters", "oob_program=/bin/true", group1])

  AssertCommand(["gnt-group", "remove", group1])
示例#4
0
def TestAssignNodesIncludingSplit(orig_group, node1, node2):
  """gnt-group assign-nodes --force

  Expects node1 and node2 to be primary and secondary for a common instance.

  """
  assert node1 != node2

  (other_group, ) = qa_utils.GetNonexistentGroups(1)

  master_node = qa_config.GetMasterNode().primary

  def AssertInGroup(group, nodes):
    real_output = GetCommandOutput(master_node,
                                   "gnt-node list --no-headers -o group " +
                                   utils.ShellQuoteArgs(nodes))
    AssertEqual(real_output.splitlines(), [group] * len(nodes))

  AssertInGroup(orig_group, [node1, node2])
  AssertCommand(["gnt-group", "add", other_group])

  try:
    AssertCommand(["gnt-group", "assign-nodes", other_group, node1, node2])
    AssertInGroup(other_group, [node1, node2])

    # This should fail because moving node1 to orig_group would leave their
    # common instance split between orig_group and other_group.
    AssertCommand(["gnt-group", "assign-nodes", orig_group, node1], fail=True)
    AssertInGroup(other_group, [node1, node2])

    AssertCommand(["gnt-group", "assign-nodes", "--force", orig_group, node1])
    AssertInGroup(orig_group, [node1])
    AssertInGroup(other_group, [node2])

    AssertCommand(["gnt-group", "assign-nodes", orig_group, node2])
    AssertInGroup(orig_group, [node1, node2])
  finally:
    AssertCommand(["gnt-group", "remove", other_group])
示例#5
0
def TestGroupAddRemoveRename():
  """gnt-group add/remove/rename"""
  existing_group_with_nodes = GetDefaultGroup()

  (group1, group2, group3) = qa_utils.GetNonexistentGroups(3)

  AssertCommand(["gnt-group", "add", group1])
  AssertCommand(["gnt-group", "add", group2])
  AssertCommand(["gnt-group", "add", group2], fail=True)
  AssertCommand(["gnt-group", "add", existing_group_with_nodes], fail=True)

  AssertCommand(["gnt-group", "rename", group1, group2], fail=True)
  AssertCommand(["gnt-group", "rename", group1, group3])

  try:
    AssertCommand(["gnt-group", "rename", existing_group_with_nodes, group1])

    AssertCommand(["gnt-group", "remove", group2])
    AssertCommand(["gnt-group", "remove", group3])
    AssertCommand(["gnt-group", "remove", group1], fail=True)
  finally:
    # Try to ensure idempotency re groups that already existed.
    AssertCommand(["gnt-group", "rename", group1, existing_group_with_nodes])
示例#6
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])
示例#7
0
def TestRapiNodeGroups():
    """Test several node group operations using RAPI.

  """
    (group1, group2, group3) = qa_utils.GetNonexistentGroups(3)

    # Create a group with no attributes
    body = {
        "name": group1,
    }

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

    _WaitForRapiJob(job_id)

    # Create a group specifying alloc_policy
    body = {
        "name": group2,
        "alloc_policy": constants.ALLOC_POLICY_UNALLOCABLE,
    }

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

    _WaitForRapiJob(job_id)

    # Modify alloc_policy
    body = {
        "alloc_policy": constants.ALLOC_POLICY_UNALLOCABLE,
    }

    (job_id, ) = _DoTests([
        ("/2/groups/%s/modify" % group1, _VerifyReturnsJob, "PUT", body),
    ])

    _WaitForRapiJob(job_id)

    # Rename a group
    body = {
        "new_name": group3,
    }

    (job_id, ) = _DoTests([
        ("/2/groups/%s/rename" % group2, _VerifyReturnsJob, "PUT", body),
    ])

    _WaitForRapiJob(job_id)

    # Test for get/set symmetry

    # Identifying the node - RAPI provides these itself
    IDENTIFIERS = ["group_name"]
    # As the name states, not exposed yet
    NOT_EXPOSED_YET = ["hv_state", "disk_state"]

    # The parameters we do not want to get and set (as that sets the
    # group-specific params to the filled ones)
    FILLED_PARAMS = ["ndparams", "ipolicy", "diskparams"]

    # The aliases that we can use to perform this test with the group-specific
    # params
    CUSTOM_PARAMS = ["custom_ndparams", "custom_ipolicy", "custom_diskparams"]

    _DoGetPutTests("/2/groups/%s" % group3,
                   "/2/groups/%s/modify" % group3,
                   opcodes.OpGroupSetParams.OP_PARAMS,
                   rapi_only_aliases=CUSTOM_PARAMS,
                   exceptions=(IDENTIFIERS + NOT_EXPOSED_YET),
                   set_exceptions=FILLED_PARAMS)

    # Delete groups
    for group in [group1, group3]:
        (job_id, ) = _DoTests([
            ("/2/groups/%s" % group, _VerifyReturnsJob, "DELETE", None),
        ])

        _WaitForRapiJob(job_id)
示例#8
0
 def __enter__(self):
   (self._group, ) = qa_utils.GetNonexistentGroups(1)
   AssertCommand(["gnt-group", "add", self._group])
   return self._group