from utils.resources import File
from utils.schedule import at, after, shell, trigger, notify

create_model('client-server')

add_host('client')
add_host('server')

create_schedule('client-server-test')

test_end_policy('complete', setup_phase_delay=0.0)
create_trigger('kill-server', 1)

add_resource(File('serverdist', 'Server.py', chmod='+x'))
add_resource(File('clientdist', 'Client.py', name='Client', chmod='+x'))
add_resource(File('testfile', 'datafile.txt'))

append_schedule('client', [
    ('client',  at(1),                  shell('./@{clientdist.name} @{server.ip} 6666 @{testfile.name} dest_path', use_resources=['clientdist', 'testfile'], check_executable=False)),
    ('md5sum',  after('client'),        shell('md5sum @{testfile.name}')),
    ('notify',  after('md5sum'),        notify('kill-server'))
])

append_schedule('server', [
    ('server',  at(0),                  shell('./@{serverdist.name} 0.0.0.0 6666', use_resources=['serverdist'], check_executable=False)),
    ('ls',      after('server'),        shell('ls dest_path')),
    ('md5sum',  after('ls'),            shell('md5sum dest_path')),
    ('rm',      after('md5sum'),        shell('rm -f dest_path')),
    ('trigger', trigger('kill-server'), shell('kill @{server.pid}'))
])

# vim: ft=python
