def test_function(self): actual = traceroute._get_traceroute_command_args_list( traceroute.TracerouteParams( host_or_ip='google.com', max_hops=10, bytes_per_packet=30, ), ) self.assertEqual(['traceroute', '-m', '10', 'google.com', '30'], actual) actual = traceroute._get_traceroute_command_args_list( traceroute.TracerouteParams(host_or_ip='google.com', max_hops=None, bytes_per_packet=None)) self.assertEqual(['traceroute', '-m', '30', 'google.com', '60'], actual)
def __traceroute_specified_hosts(traceroute_param_protos): def create_result_proto(result): if result.error: return magmad_pb2.TracerouteResult( error=result.error, host_or_ip=result.host_or_ip, ) else: return magmad_pb2.TracerouteResult( host_or_ip=result.host_or_ip, hops=create_hop_protos(result.stats.hops), ) def create_hop_protos(hops): hop_protos = [] for hop in hops: hop_protos.append( magmad_pb2.TracerouteHop( idx=hop.idx, probes=create_probe_protos(hop.probes), ), ) return hop_protos def create_probe_protos(probes): return [ magmad_pb2.TracerouteProbe( hostname=probe.hostname, ip=probe.ip_addr, rtt_ms=probe.rtt_ms, ) for probe in probes ] traceroutes_to_exec = [ traceroute.TracerouteParams( host_or_ip=param.host_or_ip, max_hops=param.max_hops, bytes_per_packet=param.bytes_per_packet, ) for param in traceroute_param_protos ] traceroute_results = traceroute.traceroute(traceroutes_to_exec) return map(create_result_proto, traceroute_results)
def setUp(self): self.param = traceroute.TracerouteParams( host_or_ip='google.com', max_hops=30, bytes_per_packet=60, )