#!/usr/bin/env python3
#
# Checker for 's3throughput' task limits
#

import pscheduler

from validate import spec_is_valid
from validate import limit_is_valid

#
# Load and validate everything
#

try:
    json = pscheduler.json_load() # from stdin?
except ValueError as ex:
    pscheduler.fail("Invalid JSON %s" % str(ex))

spec = json["spec"]
valid, message = spec_is_valid(spec)
if not valid:
    raise ValueError("Invalid test spec: %s" % message)

limit = json["limit"]
valid, message = limit_is_valid(limit)
if not valid:
    raise ValueError("Invalid limit: %s" % message)


#
# Evaluate everything
#

errors = []

# Here, check through the 'limit' json data and determine whether or not it
# Has anything which conflicts with the 'spec'. All errors found should be
# appended to the 'errors' array.

"""
For Example:
for value in [ "host", "host-node", "testtype", "timeout" ]:
    try:
        test = limit[value]
    except KeyError:
        continue
    if test == "something I want to limit!":
        errors.append("Limit was matched.")
        """


#
# Finish up
#

result = { "passes": not errors }

if errors:
    result["errors"] = errors

pscheduler.succeed_json(result)
