예제 #1
0
파일: packet.py 프로젝트: atifs/fboss
def _wait_for_counter_to_stop(test, switch_thrift, counter, delay,
        max_queue_time=2.5):
    # wait for counter to stop incrementing,
    # so no old/queued packets corrupt our test data
    # 2.5 is a bit of a mgaic number because of the current
    # counter bump queuing delay of 2 seconcs as described at the
    # top of this file
    npkts_start = get_fb303_counter(switch_thrift,
                                    counter,
                                    test.log)
    start = time.time()
    while (start + delay) > time.time():
        # assume no packets queued for more than max_queue seconds
        time.sleep(max_queue_time)
        npkts_before = get_fb303_counter(switch_thrift,
                                         counter,
                                         test.log)
        if npkts_before != npkts_start:
            # need to wait longer
            npkts_start = npkts_before
        else:
            break
    test.assertEqual(npkts_before, npkts_start,
                        "Packets never stopped; test broken!?")
    return npkts_before
예제 #2
0
파일: test_ports.py 프로젝트: dhtech/fboss
 def test_port_status_matchfb303(self):
     self.test_topology.min_hosts_or_skip(1)
     mismatch_ports = []
     with self.test_topology.switch_thrift() as sw_client:
         all_port_info = sw_client.getAllPortInfo()
         for _pnum, pstate in all_port_info.items():
             is_port_up = pstate.operState == PortOperState.UP
             fb303_counter = get_fb303_counter(sw_client,
                                               '%s.up' % (pstate.name))
             fb303_is_port_up = fb303_counter == 1
             if is_port_up != fb303_is_port_up:
                 mismatch_ports.append(
                     (pstate.name, pstate.operState, fb303_counter)
                 )
     self.assertEqual(
         len(mismatch_ports),
         0,
         msg="There are %d/%d mismatch ports: %s" % (
             len(mismatch_ports), len(all_port_info), ', '.join(
                 [
                     '%s (operState: %s, fb303_counter: %s' %
                     (name, is_port_up, fb303_is_port_up)
                     for name, is_port_up, fb303_is_port_up in mismatch_ports
                 ]
             )
         )
     )
예제 #3
0
파일: packet.py 프로젝트: dhtech/fboss
def _wait_for_pkts_to_be_counted(test, switch_thrift, counter, sent_pkts,
                                 delay, npkts_before):
    # wait for counter to increment at least sent_pkts times before delay
    start = time.time()
    found = False
    while not found and (start + delay) > time.time():
        npkts_after = get_fb303_counter(switch_thrift, counter)
        if npkts_after >= npkts_before + sent_pkts:
            found = True
        else:
            time.sleep(0.5)  # sleep a little intead of busy wait
    delta = time.time() - start
    # TODO log to scuba and track time delta
    # to expose/track stats thread lag/latency -- seems to be 1-5 seconds!?
    test.log.info("Packets after: %d secs %f" % (npkts_after, delta))
    return npkts_after