def __ping_specified_hosts(ping_param_protos): def create_ping_result_proto(ping_result): if ping_result.error: return magmad_pb2.PingResult( error=ping_result.error, host_or_ip=ping_result.host_or_ip, num_packets=ping_result.num_packets, ) else: return magmad_pb2.PingResult( host_or_ip=ping_result.host_or_ip, num_packets=ping_result.num_packets, packets_transmitted=ping_result.stats.packets_transmitted, packets_received=ping_result.stats.packets_received, avg_response_ms=ping_result.stats.rtt_avg, ) pings_to_exec = [ ping.PingCommandParams( host_or_ip=p.host_or_ip, num_packets=p.num_packets, timeout_secs=None, ) for p in ping_param_protos ] ping_results = ping.ping(pings_to_exec) return map(create_ping_result_proto, ping_results)
def test_function(self): actual = ping._get_ping_command_args_list( ping.PingCommandParams( host_or_ip='google.com', num_packets=4, timeout_secs=5, )) self.assertEqual(['ping', 'google.com', '-c', '4', '-w', '5'], actual) actual = ping._get_ping_command_args_list( ping.PingCommandParams( host_or_ip='google.com', num_packets=None, timeout_secs=None, )) self.assertEqual(['ping', 'google.com', '-c', '4', '-w', '20'], actual)
def _get_ping_params(config): ping_params = [] if 'ping_config' in config and 'hosts' in config['ping_config']: ping_params = [ ping.PingCommandParams(host, config['ping_config']['num_packets'], config['ping_config']['timeout_secs']) for host in config['ping_config']['hosts'] ] return ping_params
def test_parse_with_errors(self): param = ping.PingCommandParams(host_or_ip='localhost', num_packets=None, timeout_secs=None) actual = ping.parse_ping_output('test', 'test', param) expected = ping.PingCommandResult(error='test', host_or_ip='localhost', num_packets=ping.DEFAULT_NUM_PACKETS, stats=None) self.assertEqual(expected, actual)
def __init__( self, loop: asyncio.AbstractEventLoop, config: Dict[str, str], mconfig: LinkstatsMconfig, ) -> None: super().__init__(self.UPDATE_PERIOD, loop) self.config = config self.mconfig = mconfig self._state: Dict[str, str] = {} # protects _frozen_state self._lock = RLock() self._frozen_state: Dict[str, str] = {} self._ping_params: ping.PingCommandParams = [] # ping parameters if self.mconfig.ping_host_list: self._ping_params = [ ping.PingCommandParams(host, self.mconfig.ping_num_packets, self.mconfig.ping_timeout_secs) for host in self.mconfig.ping_host_list ]
def setUp(self): self.param = ping.PingCommandParams( host_or_ip='google.com', num_packets=4, timeout_secs=None, )