#!/usr/bin/env python3
#
# Determine the duration of an Ethr test
#

import pscheduler

from ethr_defaults import *
from ethr_utils import *

logger = pscheduler.Log(prefix='tool-ethr', quiet=True)

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


# Setup:  How long it takes to connect and set up the test
setup = setup_time(json.get('link-rtt'))


# Duration: How long the test should run

duration = json.get('duration', None)
if duration:
    delta = pscheduler.iso8601_as_timedelta(duration)
    duration = int(pscheduler.timedelta_as_seconds(delta))
else:
    duration = DEFAULT_DURATION


full_duration = setup + duration + DEFAULT_WAIT_SLEEP + DEFAULT_SERVER_SHUTDOWN
logger.debug(f'final duration = {full_duration}s')

pscheduler.succeed_json({
        'duration': f'PT{full_duration}S'
})
