1AUTHOR = "gps@google.com (Gregory P. Smith)"
2TIME = "SHORT"
3NAME = "barrier_2client"
4TEST_CATEGORY = "Functional"
5TEST_CLASS = 'Network'
6TEST_TYPE = "Server"
7SYNC_COUNT = 2
8DOC = """
9A functional test of autotest's Barrier mechanisms for synchronizing
10events between two clients without the help of the server.
11"""
12
13from autotest_lib.server import utils
14
15def run(pair):
16    logging.info('Running on %s and %s', pair[0], pair[1])
17    host_objs = [hosts.create_host(machine) for machine in pair]
18    host_at_objs = [autotest.Autotest(host) for host in host_objs]
19
20    client_control_template = """
21import logging, platform, socket, traceback
22try:
23    client_hostnames = %r
24    master_hostname = client_hostnames[0]
25    client_hostname = client_hostnames[1]
26
27    logging.info('Testing hostname only barrier')
28    barrier = job.barrier(platform.node(), 'barriertest_2client', 120)
29    logging.info('rendezvous-ing')
30    barrier.rendezvous(master_hostname, client_hostname)
31    logging.info('done.')
32
33    logging.info('Testing local identifier barrier')
34    barrier = job.barrier(platform.node() + '#id0', 'barriertest_2client', 120)
35    logging.info('rendezvous-ing')
36    barrier.rendezvous(master_hostname + '#id0',
37                       client_hostname + '#id0')
38    logging.info('done.')
39
40    logging.info('Testing IP@ barrier')
41    barrier = job.barrier(socket.gethostbyname(platform.node()),
42                          'barriertest_2client', 120)
43    logging.info('rendezvous-ing')
44    barrier.rendezvous(socket.gethostbyname(master_hostname),
45                       socket.gethostbyname(client_hostname))
46    logging.info('done.')
47
48    logging.info('Testing IP@ barrier with ids')
49    barrier = job.barrier(socket.gethostbyname(platform.node()) + '#42',
50                          'barriertest_2client', 120)
51    logging.info('rendezvous-ing')
52    barrier.rendezvous(socket.gethostbyname(master_hostname) + '#42',
53                       socket.gethostbyname(client_hostname) + '#42')
54    logging.info('done.')
55except:
56    traceback.print_exc()
57    raise
58"""
59    client_controls = [client_control_template % (pair,) for host in host_objs]
60
61    subcommand_list = []
62    for host, host_at, control in zip(host_objs, host_at_objs, client_controls):
63        subcommand_list.append(subcommand(host_at.run,
64                                          (control, host.hostname)))
65
66    parallel(subcommand_list)
67
68
69# grab the pairs (and failures)
70(pairs, failures) = utils.form_ntuples_from_machines(machines, 2)
71
72# log the failures
73for failure in failures:
74    job.record("FAIL", failure[0], "barrier_2client", failure[1])
75
76# now run through each pair and run
77job.parallel_simple(run, pairs, log=False)
78