def test_list_ip_addresses_with_namespace(self, **params): namespace_ips = ip.list_ip_addresses( ssh_client=self.namespace.ssh_client, network_namespace=self.namespace.network_namespace, **params) self.assertNotEqual([], namespace_ips) host_ips = ip.list_ip_addresses(ssh_client=self.namespace.ssh_client, **params) self.assertNotEqual(host_ips, namespace_ips)
def test_port_ips(self, ip_version: typing.Optional[int] = None): """Checks port IPS has been assigned to server via DHCP protocol""" port_ips = set( neutron.list_device_ip_addresses( device_id=self.stack.server_id, network_id=self.stack.network_stack.network_id, need_dhcp=self.stack.need_dhcp, ip_version=ip_version)) if port_ips: # verify neutron port IPs and VM port IPs match # when a VM connected to the external network has been just # created, it may need some time to receive its IPv6 address for attempt in tobiko.retry(timeout=60., interval=4.): server_ips = set( ip.list_ip_addresses(scope='global', ssh_client=self.stack.ssh_client)) server_ips &= port_ips # ignore other server IPs LOG.debug("Neutron IPs and VM IPs should match...") try: self.assertEqual( port_ips, server_ips, f"Server {self.stack.server_id} is missing port " f"IP(s): {port_ips - server_ips}") break except self.failureException: attempt.check_limits() elif ip_version: self.skipTest(f"Server has any port IPv{ip_version} address to be" " tested") else: self.skipTest("Server has any port IP address to be tested")
def test_0_vlan_ip_addresses(self): """Check Nova server VLAN port IP addresses""" self.stack.ensure_server_status('ACTIVE') expected = set(self.stack.list_vlan_fixed_ips()) for attempt in tobiko.retry(): actual = set( ip.list_ip_addresses(device=self.stack.vlan_device, ssh_client=self.stack.ssh_client, scope='global')) unexpected = actual - expected if unexpected: self.fail("Unexpected IP address assigned to VLAN port: " f"{unexpected}") missing = expected - actual if missing: if attempt.is_last: self.fail("IP addresses not assigned to VLAN port: " f"{unexpected}") else: LOG.debug("IP addresses still not assigned to VLAN port: " f"{unexpected}") else: break else: raise RuntimeError("Broken retry loop") self.assertEqual(set(expected), set(actual))
def list_nameservers(self) -> tobiko.Selection[netaddr.IPAddress]: nameservers: tobiko.Selection[netaddr.IPAddress] if has_external_network(): network_id = get_external_network_id() nameservers = neutron.list_network_nameservers( network_id=network_id) LOG.debug("Nameservers copied from external network: " f"{nameservers}") else: # Copy nameservers from target host nameservers = sh.list_nameservers(ssh_client=self.ssh_client, ip_version=self.ip_version, filenames=self.filenames) if self.remove_local_ips: local_ips = ip.list_ip_addresses(scope='host') if local_ips: # Filter out all local IPs nameservers = tobiko.Selection[netaddr.IPAddress]( nameserver for nameserver in nameservers if nameserver not in local_ips) LOG.debug(f"Nameservers copied from host: {nameservers}") if self.max_count: # Keep only up to max_count nameservers actual_count = len(nameservers) if actual_count > self.max_count: LOG.waring("Limit the number of nameservers from " f"{actual_count} to {self.max_count}: " f"{nameservers}") nameservers = tobiko.Selection[netaddr.IPAddress]( nameservers[:self.max_count]) return nameservers
def test_list_ip_addresses(self, ip_version=None, scope=None, **execute_params): if not os.path.isfile('/bin/ip'): self.skipTest("'bin/ip' command not found") ips = ip.list_ip_addresses(ip_version=ip_version, scope=scope, **execute_params) self.assertIsInstance(ips, tobiko.Selection) for ip_address in ips: self.assertIsInstance(ip_address, netaddr.IPAddress) if ip_version: self.assertEqual(ips.with_attributes(version=ip_version), ips) if scope: if scope == 'link': self.assertEqual(ips.with_attributes(version=4), []) self.assertEqual(ips.with_attributes(version=6), ips) elif scope == 'host': for a in ips: self.assertTrue(a.is_loopback()) elif scope == 'global': self.assertNotIn(netaddr.IPAddress('127.0.0.1'), ips) self.assertNotIn(netaddr.IPAddress('::1'), ips) return ips
def test_network_namespaces(self): for node in self.topology.nodes: namespaces_ips = {} namespaces = ip.list_network_namespaces(ssh_client=node.ssh_client) for namespace in namespaces: ips = ip.list_ip_addresses(ssh_client=node.ssh_client, network_namespace=namespace) other_ips = namespaces_ips.setdefault(namespace, ips) if ips is not other_ips: tobiko.fail(f"Duplicate network namespace {namespace} in " f"node {node.name}: {other_ips}, {ips}")
def test_network_namespaces(self): for node in self.topology.nodes: namespaces_ips = {} namespaces = ip.list_network_namespaces(ssh_client=node.ssh_client) for namespace in namespaces: ips = ip.list_ip_addresses(ssh_client=node.ssh_client, network_namespace=namespace) other_ips = namespaces_ips.setdefault(namespace, ips) if ips is not other_ips: tobiko.fail("Duplicate network namespace {!r} in node " "{!r}: {!r}, {!r}", namespace, node.name, other_ips, ips)
def test_ping_hosts(self): try: sh.execute('[ -x /sbin/ip ]', ssh_client=self.ssh_client) except sh.ShellCommandFailed: self.skipTest("'/sbin/ip' command not found") ips = ip.list_ip_addresses(**self.execute_params) reachable_ips, unreachable_ips = ping.ping_hosts( ips, **self.execute_params) expected_reachable = [i for i in ips if i in reachable_ips] self.assertEqual(expected_reachable, reachable_ips) expected_unreachable = [i for i in ips if i not in reachable_ips] self.assertEqual(expected_unreachable, unreachable_ips)
def _get_router_ips_from_namespaces(self, hostname): agent_host = topology.get_openstack_node(hostname=hostname) router_namespaces = ["qrouter-%s" % self.router['id']] if self.router.get('distributed'): router_namespaces.append("snat-%s" % self.router['id']) host_namespaces = ip.list_network_namespaces( ssh_client=agent_host.ssh_client) ips = [] for router_namespace in router_namespaces: self.assertIn(router_namespace, host_namespaces) ips += ip.list_ip_addresses( scope='global', network_namespace=router_namespace, ssh_client=agent_host.ssh_client) return ips
def _check_routers_namespace_on_host(self, hostname, state="master"): router_namespace = "qrouter-%s" % self.router['id'] agent_host = topology.get_openstack_node(hostname=hostname) namespaces = ip.list_network_namespaces( ssh_client=agent_host.ssh_client) self.assertIn(router_namespace, namespaces) namespace_ips = ip.list_ip_addresses( scope='global', network_namespace=router_namespace, ssh_client=agent_host.ssh_client) missing_ips = set(self.router_ips) - set(namespace_ips) if state == "master": self.assertFalse(missing_ips) else: self.assertTrue(missing_ips)
def test_ping_hosts(self, ssh_client=None, network_namespace=None, **params): ips = ip.list_ip_addresses(ssh_client=ssh_client, network_namespace=network_namespace) reachable_ips, unrecheable_ips = ping.ping_hosts( ips, ssh_client=ssh_client, network_namespace=network_namespace, **params) expected_reachable = [i for i in ips if i in reachable_ips] self.assertEqual(expected_reachable, reachable_ips) expected_unreachable = [i for i in ips if i not in reachable_ips] self.assertEqual(expected_unreachable, unrecheable_ips)
def _list_addresses_from_host(self, ssh_client: ssh.SSHClientFixture): return ip.list_ip_addresses(ssh_client=ssh_client, ip_version=self.ip_version, scope='global')
def _ips_from_host(self, **kwargs): return ip.list_ip_addresses(ip_version=self.ip_version, scope='global', **kwargs)
def test_port_ips(self): server_ips = ip.list_ip_addresses(scope='global', ssh_client=self.stack.ssh_client) port_ips = neutron.list_port_ip_addresses(port=self.stack.port_details) self.assertFalse(set(port_ips) - set(server_ips))