summaryrefslogtreecommitdiff
path: root/utils/req-res-log-validator.py
diff options
context:
space:
mode:
Diffstat (limited to 'utils/req-res-log-validator.py')
-rwxr-xr-xutils/req-res-log-validator.py47
1 files changed, 24 insertions, 23 deletions
diff --git a/utils/req-res-log-validator.py b/utils/req-res-log-validator.py
index e2b9d4f8d..46c110019 100755
--- a/utils/req-res-log-validator.py
+++ b/utils/req-res-log-validator.py
@@ -12,7 +12,6 @@ import argparse
import multiprocessing
import collections
import io
-import signal
import traceback
from datetime import timedelta
from functools import partial
@@ -44,7 +43,9 @@ Future validations:
1. Fail the script if one or more of the branches of the reply schema (e.g. oneOf, anyOf) was not hit.
"""
-IGNORED_COMMANDS = [
+IGNORED_COMMANDS = {
+ # Commands that don't work in a req-res manner (see logreqres.c)
+ "debug", # because of DEBUG SEGFAULT
"sync",
"psync",
"monitor",
@@ -54,11 +55,10 @@ IGNORED_COMMANDS = [
"sunsubscribe",
"psubscribe",
"punsubscribe",
- "debug",
+ # Commands to which we decided not write a reply schema
"pfdebug",
"lolwut",
-]
-
+}
class Request(object):
"""
@@ -169,7 +169,7 @@ class Response(object):
value = Response(f, line_counter)
self.json[field] = value.json
if line[0] == '|':
- # We don't care abou the attributes, read the real response
+ # We don't care about the attributes, read the real response
real_res = Response(f, line_counter)
self.__dict__.update(real_res.__dict__)
@@ -180,7 +180,7 @@ class Response(object):
def process_file(docs, path):
"""
- This function processes a single filegenerated by logreqres.c
+ This function processes a single file generated by logreqres.c
"""
line_counter = [0] # A list with one integer: to force python to pass it by reference
command_counter = dict()
@@ -190,7 +190,7 @@ def process_file(docs, path):
# Convert file to StringIO in order to minimize IO operations
with open(path, "r", newline="\r\n", encoding="latin-1") as f:
content = f.read()
-
+
with io.StringIO(content) as fakefile:
while True:
try:
@@ -217,6 +217,9 @@ def process_file(docs, path):
if res.error or res.queued:
continue
+ if req.command in IGNORED_COMMANDS:
+ continue
+
try:
jsonschema.validate(instance=res.json, schema=req.schema, cls=schema_validator)
except (jsonschema.ValidationError, jsonschema.exceptions.SchemaError) as err:
@@ -244,7 +247,7 @@ def fetch_schemas(cli, port, args, docs):
break
except Exception as e:
time.sleep(0.1)
- pass
+
print('Connected')
cli_proc = subprocess.Popen([cli, '-p', str(port), '--json', 'command', 'docs'], stdout=subprocess.PIPE)
@@ -287,16 +290,6 @@ if __name__ == '__main__':
fetch_schemas(args.cli, args.port, redis_args, docs)
- missing_schema = [k for k, v in docs.items()
- if "reply_schema" not in v and k not in IGNORED_COMMANDS]
- if missing_schema:
- print("WARNING! The following commands are missing a reply_schema:")
- for k in sorted(missing_schema):
- print(f" {k}")
- if args.fail_missing_reply_schemas:
- print("ERROR! at least one command does not have a reply_schema")
- sys.exit(1)
-
# Fetch schemas from a sentinel
print('Starting Redis sentinel')
@@ -308,9 +301,19 @@ if __name__ == '__main__':
fetch_schemas(args.cli, args.port, sentinel_args, docs)
os.unlink(config_file)
+ missing_schema = [k for k, v in docs.items()
+ if "reply_schema" not in v and k not in IGNORED_COMMANDS]
+ if missing_schema:
+ print("WARNING! The following commands are missing a reply_schema:")
+ for k in sorted(missing_schema):
+ print(f" {k}")
+ if args.fail_missing_reply_schemas:
+ print("ERROR! at least one command does not have a reply_schema")
+ sys.exit(1)
+
start = time.time()
- # Obtain all the files toprocesses
+ # Obtain all the files to processes
paths = []
for path in glob.glob('%s/tmp/*/*.reqres' % testdir):
paths.append(path)
@@ -335,9 +338,7 @@ if __name__ == '__main__':
print("Hits per command:")
for k, v in sorted(command_counter.items()):
print(f" {k}: {v}")
- # We don't care about SENTINEL commands
- not_hit = set(filter(lambda x: not x.startswith("sentinel"),
- set(docs.keys()) - set(command_counter.keys()) - set(IGNORED_COMMANDS)))
+ not_hit = set(set(docs.keys()) - set(command_counter.keys()) - set(IGNORED_COMMANDS))
if not_hit:
if args.verbose:
print("WARNING! The following commands were not hit at all:")