def test_public_ips(self): ips = dict() for node in self.topology.nodes: ping.ping(node.public_ip).assert_replied() other = ips.setdefault(node.public_ip, node) if node is not other: tobiko.fail(f"Nodes {node.name} and {other.name} have the " f"same IP: {node.public_ip}")
def test_ping_with_net_mtu(self): """Test connectivity to floating IP address with MTU sized packets""" # Wait until it can reach remote port with maximum-sized packets ping.ping(self.stack.floating_ip_address, until=ping.RECEIVED, packet_size=self.observed_net_mtu, fragmentation=False).assert_replied() # Verify it can't reach remote port with over-sized packets ping.ping(self.stack.floating_ip_address, packet_size=self.observed_net_mtu + 1, fragmentation=False, count=5, check=False).assert_not_replied()
def test_ping_unreachable_address(self): result = ping.ping('1.2.3.4', count=3, check=False, **self.execute_params) self.assertIsNone(result.source) self.assertIn(result.destination, [netaddr.IPAddress('1.2.3.4'), None]) if result.destination is not None: result.assert_transmitted() result.assert_not_replied()
def test_ping_with_net_mtu(self): """Test connectivity to floating IP address""" # Wait for server instance to get ready by logging in tobiko.setup_fixture(self.stack.ssh_client) self.stack.ssh_client.connect() # Verify it can't reach secured port with maximum-sized packets ping.ping(self.stack.floating_ip_address, packet_size=self.observed_net_mtu, fragmentation=False, count=5, check=False).assert_not_replied() # Verify it can't reach secured port with over-sized packets ping.ping(self.stack.floating_ip_address, packet_size=self.observed_net_mtu + 1, fragmentation=False, count=5, check=False).assert_not_replied()
def list_port_ip_addresses(port, subnet_id=None, ip_version=None, check_connectivity=False, ssh_client=None): selected_addresses = [] for fixed_ip in port['fixed_ips']: if subnet_id and subnet_id != fixed_ip['subnet_id']: continue ip_address = netaddr.IPAddress(fixed_ip['ip_address']) if ip_version and ip_version != ip_address.version: continue if check_connectivity and not ping.ping( host=ip_address, ssh_client=ssh_client).received: continue selected_addresses.append(ip_address) return tobiko.Selection(selected_addresses)
def test_ping_invalid_ip(self): try: result = ping.ping('0.1.2.3', count=1, **self.execute_params) except ping.PingError as ex: self.assertIn(ex, [ ping.ConnectPingError(details='Invalid argument'), ping.ConnectPingError(details='Network is unreachable'), ping.SendToPingError(details='No route to host'), ]) else: self.assertIsNone(result.source) self.assertEqual(netaddr.IPAddress('0.1.2.3'), result.destination) result.assert_transmitted() result.assert_not_replied()
def _reachable_ip(self, ips, proxy_client=None, **kwargs): reachable = None if proxy_client: untested_ips = ips else: # Exclude unreachable addresses untested_ips = list() for address in ips: if address not in self._unreachable_ips: if address in self._reachable_ips: # Will take result from the first one of marked already # marked as reachable reachable = reachable or address else: # Will later search for results between the other IPs untested_ips.append(address) for address in untested_ips: if reachable is None: try: received = ping.ping(address, count=1, timeout=5., ssh_client=proxy_client, **kwargs).received except ping.PingFailed: pass else: if received: reachable = address # Mark IP as reachable self._reachable_ips.add(address) continue # Mark IP as unreachable self._unreachable_ips.add(address) return reachable
def test_ping_reachable_hostname(self): result = ping.ping('localhost', count=3, **self.execute_params) self.assertIsNone(result.source) self.assertIsNotNone(result.destination) result.assert_transmitted() result.assert_replied()
def test_ping_reachable_address(self): result = ping.ping('127.0.0.1', count=3, **self.execute_params) self.assertIsNone(result.source) self.assertEqual(netaddr.IPAddress('127.0.0.1'), result.destination) result.assert_transmitted() result.assert_replied()
def test_ping_node(self): for node in self.topology.nodes: ping.ping(node.public_ip, count=1, timeout=5.).assert_replied()
def test_ping_unreachable_address(self): result = ping.ping('1.2.3.4', count=3) self.assertIsNone(result.source) self.assertEqual(netaddr.IPAddress('1.2.3.4'), result.destination) result.assert_transmitted() result.assert_not_replied()
def test_ping_reachable_hostname(self): result = ping.ping('example.org', count=3) self.assertIsNone(result.source) # self.assertIsNotNone(result.destination) result.assert_transmitted() result.assert_replied()