Commit 01ab7ec9 authored by Niklas Hambuechen's avatar Niklas Hambuechen

QA for job filtering

Includes QA for RAPI filter management and gnt_filter.

System tests (adding/removing filters, observing their effects)
are done with gnt_filter.
Signed-off-by: default avatarNiklas Hambuechen <niklash@google.com>
Reviewed-by: default avatarKlaus Aehlig <aehlig@google.com>
parent 226455df
......@@ -1193,6 +1193,7 @@ qa_scripts = \
qa/qa_daemon.py \
qa/qa_env.py \
qa/qa_error.py \
qa/qa_filters.py \
qa/qa_group.py \
qa/qa_instance.py \
qa/qa_instance_utils.py \
......
......@@ -46,6 +46,7 @@ import qa_config
import qa_daemon
import qa_env
import qa_error
import qa_filters
import qa_group
import qa_instance
import qa_iptables
......@@ -429,6 +430,23 @@ def RunNetworkTests():
RunTestIf(["network", "tags"], qa_network.TestNetworkTags)
def RunFilterTests():
"""Run tests for job filter management.
"""
RunTestIf("filters", qa_filters.TestFilterList)
RunTestIf("filters", qa_filters.TestFilterListFields)
RunTestIf("filters", qa_filters.TestFilterAddRemove)
RunTestIf("filters", qa_filters.TestFilterReject)
RunTestIf("filters", qa_filters.TestFilterOpCode)
RunTestIf("filters", qa_filters.TestFilterReasonChain)
RunTestIf("filters", qa_filters.TestFilterContinue)
RunTestIf("filters", qa_filters.TestFilterAcceptPause)
RunTestIf("filters", qa_filters.TestFilterWatermark)
RunTestIf("filters", qa_filters.TestFilterRateLimit)
RunTestIf("filters", qa_filters.TestAdHocReasonRateLimit)
def RunGroupRwTests():
"""Run tests for adding/removing/renaming groups.
......@@ -948,6 +966,7 @@ def RunQa():
RunTestBlock(RunGroupListTests)
RunTestBlock(RunGroupRwTests)
RunTestBlock(RunNetworkTests)
RunTestBlock(RunFilterTests)
# The master shouldn't be readded or put offline; "delay" needs a non-master
# node to test
......@@ -1032,6 +1051,9 @@ def RunQa():
finally:
pnode.Release()
if qa_rapi.Enabled():
RunTestIf("filters", qa_rapi.TestFilters)
RunTestIf("cluster-upgrade", qa_cluster.TestUpgrade)
RunTestBlock(RunExclusiveStorageTests)
......
......@@ -60,6 +60,7 @@ def TestGanetiCommands():
["gnt-node", "--version"],
["gnt-os", "--version"],
["gnt-storage", "--version"],
["gnt-filter", "--version"],
["ganeti-noded", "--version"],
["ganeti-rapi", "--version"],
["ganeti-watcher", "--version"],
......
This diff is collapsed.
......@@ -32,11 +32,13 @@
"""
import copy
import functools
import itertools
import random
import re
import tempfile
import uuid as uuid_module
from ganeti import cli
from ganeti import compat
......@@ -168,6 +170,15 @@ JOB_FIELDS = compat.UniqueFrozenset([
"received_ts", "start_ts", "end_ts",
])
FILTER_FIELDS = compat.UniqueFrozenset([
"watermark",
"priority",
"predicates",
"action",
"reason_trail",
"uuid",
])
LIST_FIELDS = ("id", "uri")
......@@ -320,6 +331,11 @@ def TestEmptyCluster():
for field in GROUP_FIELDS:
AssertIn(field, group)
def _VerifyFiltersBulk(data):
for group in data:
for field in FILTER_FIELDS:
AssertIn(field, group)
_DoTests([
("/", None, "GET", None),
("/2/info", _VerifyInfo, "GET", None),
......@@ -331,6 +347,8 @@ def TestEmptyCluster():
("/2/instances", [], "GET", None),
("/2/instances?bulk=1", [], "GET", None),
("/2/os", None, "GET", None),
("/2/filters", [], "GET", None),
("/2/filters?bulk=1", _VerifyFiltersBulk, "GET", None),
])
# Test HTTP Not Found
......@@ -1097,3 +1115,51 @@ def TestInterClusterInstanceMove(src_instance, dest_instance,
_InvokeMoveInstance(src_instance.name, dest_instance.name, rapi_pw_file.name,
master.primary, perform_checks,
target_nodes=(pnode.primary, snode.primary))
def TestFilters():
"""Testing filter management via the remote API.
"""
body = {
"priority": 10,
"predicates": [],
"action": "CONTINUE",
"reason": [(constants.OPCODE_REASON_SRC_USER,
"reason1",
utils.EpochNano())],
}
body1 = copy.deepcopy(body)
body1["priority"] = 20
# Query filters
_DoTests([("/2/filters", [], "GET", None)])
# Add a filter via POST and delete it again
uuid = _DoTests([("/2/filters", None, "POST", body)])[0]
uuid_module.UUID(uuid) # Check if uuid is a valid UUID
_DoTests([("/2/filters/%s" % uuid, lambda r: r is None, "DELETE", None)])
_DoTests([
# Check PUT-inserting a nonexistent filter with given UUID
("/2/filters/%s" % uuid, lambda u: u == uuid, "PUT", body),
# Check PUT-inserting an existent filter with given UUID
("/2/filters/%s" % uuid, lambda u: u == uuid, "PUT", body1),
# Check that the update changed the filter
("/2/filters/%s" % uuid, lambda f: f["priority"] == 20, "GET", None),
# Delete it again
("/2/filters/%s" % uuid, lambda r: r is None, "DELETE", None),
])
# Add multiple filters, query and delete them
uuids = _DoTests([
("/2/filters", None, "POST", body),
("/2/filters", None, "POST", body),
("/2/filters", None, "POST", body),
])
_DoTests([("/2/filters", lambda rs: [r["uuid"] for r in rs] == uuids,
"GET", None)])
for u in uuids:
_DoTests([("/2/filters/%s" % u, lambda r: r is None, "DELETE", None)])
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment