示例#1
0
    def test_parse_no_packet_line_match(self):
        output = textwrap.dedent('''
        PING google.com (172.217.3.206) 56(84) bytes of data.
        64 bytes from sea15s12-in-f206.1e100.net (172.217.3.206): icmp_seq=1 ttl=63 time=27.3 ms
        64 bytes from sea15s12-in-f206.1e100.net (172.217.3.206): icmp_seq=2 ttl=63 time=26.7 ms
        64 bytes from sea15s12-in-f206.1e100.net (172.217.3.206): icmp_seq=3 ttl=63 time=27.8 ms
        64 bytes from sea15s12-in-f206.1e100.net (172.217.3.206): icmp_seq=4 ttl=63 time=29.0 ms

        --- google.com ping statistics ---
        4 packets transmitted, b received, 0% packet loss, time 3008ms
        rtt min/avg/max/mdev = 26.780/27.731/29.014/0.832 ms
        ''').strip().encode('ascii')
        packet_line = '4 packets transmitted, b received, ' \
                      '0% packet loss, time 3008ms'
        expected_error_msg = 'Could not parse packet line:' \
                             '\n{packet_line}'.format(packet_line=packet_line)

        expected = ping.PingCommandResult(
            error=expected_error_msg,
            host_or_ip='google.com',
            num_packets=4,
            stats=None,
        )
        actual = ping.parse_ping_output(output, '', self.param)
        self.assertEqual(expected, actual)
示例#2
0
 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)
示例#3
0
    def test_parse_deadline_reached_no_results(self):
        output = textwrap.dedent('''
        PING google.com (172.217.3.206) 56(84) bytes of data.

        --- google.com ping statistics ---
        1 packets transmitted, 0 received, 100% packet loss, time 0ms
        ''').strip().encode('ascii')
        expected_error_msg = 'Not enough output lines in ping output. ' \
                             'The ping may have timed out.'

        expected = ping.PingCommandResult(
            error=expected_error_msg,
            host_or_ip='google.com',
            num_packets=4,
            stats=None,
        )
        actual = ping.parse_ping_output(output, '', self.param)
        self.assertEqual(expected, actual)
示例#4
0
    def test_parse_no_header_line(self):
        output = textwrap.dedent('''
        PING google.com (172.217.3.206) 56(84) bytes of data.
        64 bytes from sea15s12-in-f206.1e100.net (172.217.3.206): icmp_seq=1 ttl=63 time=27.3 ms
        64 bytes from sea15s12-in-f206.1e100.net (172.217.3.206): icmp_seq=2 ttl=63 time=26.7 ms
        64 bytes from sea15s12-in-f206.1e100.net (172.217.3.206): icmp_seq=3 ttl=63 time=27.8 ms
        64 bytes from sea15s12-in-f206.1e100.net (172.217.3.206): icmp_seq=4 ttl=63 time=29.0 ms

        4 packets transmitted, 4 received, 0% packet loss, time 3008ms
        rtt min/avg/max/mdev = 26.780/27.731/29.014/0.832 ms
        ''').strip().encode('ascii')

        expected = ping.PingCommandResult(
            error='Could not find statistics header in ping output',
            host_or_ip='google.com',
            num_packets=4,
            stats=None,
        )
        actual = ping.parse_ping_output(output, '', self.param)
        self.assertEqual(expected, actual)
示例#5
0
    def test_parse_good_output(self):
        output = textwrap.dedent('''
        PING google.com (172.217.3.206) 56(84) bytes of data.
        64 bytes from sea15s12-in-f206.1e100.net (172.217.3.206): icmp_seq=1 ttl=63 time=27.3 ms
        64 bytes from sea15s12-in-f206.1e100.net (172.217.3.206): icmp_seq=2 ttl=63 time=26.7 ms
        64 bytes from sea15s12-in-f206.1e100.net (172.217.3.206): icmp_seq=3 ttl=63 time=27.8 ms
        64 bytes from sea15s12-in-f206.1e100.net (172.217.3.206): icmp_seq=4 ttl=63 time=29.0 ms

        --- google.com ping statistics ---
        4 packets transmitted, 4 received, 0% packet loss, time 3008ms
        rtt min/avg/max/mdev = 26.780/27.731/29.014/0.832 ms
        ''').strip().encode('ascii')

        actual = ping.parse_ping_output(output, '', self.param)
        self.assertEqual(4, actual.stats.packets_transmitted)
        self.assertEqual(4, actual.stats.packets_received)
        self.assertEqual(0, actual.stats.packet_loss_pct)
        self.assertEqual(26.780, actual.stats.rtt_min)
        self.assertEqual(27.731, actual.stats.rtt_avg)
        self.assertEqual(29.014, actual.stats.rtt_max)
        self.assertEqual(0.832, actual.stats.rtt_mdev)