#!/usr/bin/env python3
#
# Determine the duration of a specified test.
#

import datetime
import sys

import pscheduler


spec = pscheduler.json_load(exit_on_error=True)['spec']

# TODO: Make sure the type is one we like
# TODO: Validate the spec

#
# Trace time
#

# Tracepath does a hardwaired maximum of 31 hops with what looks like
# a timeout of 3 seconds.

total = datetime.timedelta(seconds=93)


#
# DNS Resolution
#

try:
    hostnames = spec['hostnames']
except KeyError:
    hostnames = True

# Some time for DNS, which will be done in parallel.
# TODO: Should probably ask the DNS module for the timeout.
if hostnames:
    total += datetime.timedelta(seconds=2)


#
# AS Resolution
#

try:
    ases = spec['as']
except KeyError:
    ases = True

# Some time for AS, which will be done in parallel.
# TODO: Should probably ask the AS module for the timeout.
if ases:
    total += datetime.timedelta(seconds=4)


#
# Slop
#

total += datetime.timedelta(seconds=2)

pscheduler.succeed_json({
        "duration": pscheduler.timedelta_as_iso8601(total)
})
