Home | History | Annotate | Download | only in barriertest
      1 # This is used directly by server/tests/barriertest/control.srv
      2 
      3 import logging, time
      4 from autotest_lib.client.bin import test
      5 from autotest_lib.client.common_lib import barrier, error
      6 
      7 
      8 class barriertest(test.test):
      9     version = 2
     10 
     11 
     12     def run_once(self, our_addr, hostnames, master, timeout=120):
     13         # A reusable local server as we're using multiple barriers in one test.
     14         server = barrier.listen_server()
     15 
     16         # Basic barrier rendezvous test.
     17         self.job.barrier(our_addr, 'First', timeout=timeout,
     18                          listen_server=server).rendezvous(*hostnames)
     19         logging.info('1. rendezvous "First" complete.')
     20         time.sleep(2)
     21 
     22         # A rendezvous_servers using a different master than the default.
     23         self.job.barrier(our_addr, 'Second', timeout=timeout,
     24                          listen_server=server
     25                          ).rendezvous_servers(hostnames[-1], *hostnames[:-1])
     26         logging.info('2. rendezvous_servers "Second" complete.')
     27         time.sleep(2)
     28 
     29         # A regular rendezvous, this time testing the abort functionality.
     30         try:
     31             self.job.barrier(our_addr, 'WillAbort', timeout=timeout,
     32                              listen_server=server
     33                              ).rendezvous(abort=True, *hostnames)
     34         except error.BarrierAbortError:
     35             pass
     36         except error.BarrierError, e:
     37             # We did get an error from the barrier, but was is acceptable or
     38             # not?  Site code may not be able to indicate an explicit abort.
     39             self.job.record('WARN', None, 'barriertest',
     40                             'BarrierError %s instead of BarrierAbortError.' % e)
     41         else:
     42             raise error.TestFail('Explicit barrier rendezvous abort failed.')
     43         logging.info('3. rendezvous(abort=True) complete.')
     44         time.sleep(2)
     45 
     46         # Now attempt a rendezvous_servers that also includes the server.
     47         self.job.barrier(our_addr, 'FinalSync', timeout=timeout,
     48                          listen_server=server
     49                          ).rendezvous_servers(master, *hostnames)
     50         logging.info('4. rendezvous_servers "FinalSync" complete.')
     51         time.sleep(2)
     52 
     53         # rendezvous_servers, aborted from the master.
     54         try:
     55             self.job.barrier(our_addr, 'WillAbortServers', timeout=timeout,
     56                              listen_server=server
     57                              ).rendezvous_servers(master, *hostnames)
     58         except error.BarrierAbortError:
     59             pass
     60         except error.BarrierError, e:
     61             # We did get an error from the barrier, but was is acceptable or
     62             # not?  Site code may not be able to indicate an explicit abort.
     63             self.job.record('WARN', None, 'barriertest',
     64                             'BarrierError %s instead of BarrierAbortError.' % e)
     65         else:
     66             raise error.TestFail('Explicit barrier rendezvous abort failed.')
     67         logging.info('5. rendezvous_servers(abort=True) complete.')
     68         time.sleep(2)
     69 
     70         server.close()
     71