def test_add_ipv6_address_with_gateway(self): ip = address.IPv6(address=IPV6_ADDRESS, gateway=IPV6_GATEWAY, defaultRoute=True) with dummy_device() as nic: with preserve_default_route(): address.add(nic, ipv4=None, ipv6=ip) self.assertTrue(routes.is_ipv6_default_route(IPV6_GATEWAY))
def test_add_ipv6_address_with_gateway(self): ip = address.IPv6(address=IPV6_A_WITH_PREFIXLEN, gateway=IPV6_GATEWAY, defaultRoute=True) with dummy_device() as nic: with preserve_default_route(): address.add(nic, ipv4=None, ipv6=ip) self.assertTrue(routes.is_ipv6_default_route(IPV6_GATEWAY))
def test_add_ipv6_gateway_given_existing_ipv4_and_ipv6_gateways( self, nic0, ipv4_address, ipv6_address): with preserve_default_route(): address.add(nic0, ipv4=ipv4_address, ipv6=None) address.add(nic0, ipv4=None, ipv6=ipv6_address) address.add(nic0, ipv4=None, ipv6=ipv6_address) assert routes.is_default_route(IPV4_GATEWAY, routes.get_routes()) assert routes.is_ipv6_default_route(IPV6_GATEWAY)
def test_add_ipv4_and_ipv6_address_with_gateways(self): ipv4 = address.IPv4(address=IPV4_ADDRESS, netmask=IPV4_NETMASK, gateway=IPV4_GATEWAY, defaultRoute=True) ipv6 = address.IPv6(address=IPV6_ADDRESS, gateway=IPV6_GATEWAY, defaultRoute=True) with dummy_device() as nic: with preserve_default_route(): address.add(nic, ipv4=ipv4, ipv6=ipv6) addr, netmask, _, ipv6addresses = address.addrs_info(nic) self.assertTrue(routes.is_default_route(IPV4_GATEWAY)) self.assertTrue(routes.is_ipv6_default_route(IPV6_GATEWAY))
def test_add_ipv6_gateway_given_existing_ipv4_and_ipv6_gateways(self): ipv4 = address.IPv4(address=IPV4_ADDRESS, netmask=IPV4_NETMASK, gateway=IPV4_GATEWAY, defaultRoute=True) ipv6 = address.IPv6(address=IPV6_ADDRESS, gateway=IPV6_GATEWAY, defaultRoute=True) with dummy_device() as nic: with preserve_default_route(): address.add(nic, ipv4=ipv4, ipv6=None) address.add(nic, ipv4=None, ipv6=ipv6) address.add(nic, ipv4=None, ipv6=ipv6) self.assertTrue(routes.is_default_route(IPV4_GATEWAY)) self.assertTrue(routes.is_ipv6_default_route(IPV6_GATEWAY))
def test_add_ipv4_and_ipv6_address_with_gateways(self): ipv4 = address.IPv4(address=IPV4_A_ADDRESS, netmask=IPV4_NETMASK, gateway=IPV4_GATEWAY, defaultRoute=True) ipv6 = address.IPv6(address=IPV6_A_WITH_PREFIXLEN, gateway=IPV6_GATEWAY, defaultRoute=True) with dummy_device() as nic: with preserve_default_route(): address.add(nic, ipv4=ipv4, ipv6=ipv6) addr, netmask, _, ipv6addresses = address.addrs_info(nic) self.assertTrue(routes.is_default_route(IPV4_GATEWAY)) self.assertTrue(routes.is_ipv6_default_route(IPV6_GATEWAY))
def preserve_default_route(): ipv4_dg_data = routes.getDefaultGateway() ipv4_gateway = ipv4_dg_data.via if ipv4_dg_data else None ipv4_device = ipv4_dg_data.device if ipv4_dg_data else None ipv6_dg_data = routes.ipv6_default_gateway() ipv6_gateway = ipv6_dg_data.via if ipv6_dg_data else None ipv6_device = ipv6_dg_data.device if ipv6_dg_data else None try: yield finally: if ipv4_gateway and not routes.is_default_route(ipv4_gateway): address.set_default_route(ipv4_gateway, family=4, dev=ipv4_device) if ipv6_gateway and not routes.is_ipv6_default_route(ipv6_gateway): address.set_default_route(ipv6_gateway, family=6, dev=ipv6_device)
def test_add_ipv4_and_ipv6_address_with_gateways(self, nic0, ipv4_address, ipv6_address): with preserve_default_route(): address.add(nic0, ipv4=ipv4_address, ipv6=ipv6_address) assert routes.is_default_route(IPV4_GATEWAY, routes.get_routes()) assert routes.is_ipv6_default_route(IPV6_GATEWAY)
def test_add_ipv6_address_with_gateway(self, nic0, ipv6_address): with preserve_default_route(): address.add(nic0, ipv4=None, ipv6=ipv6_address) assert routes.is_ipv6_default_route(IPV6_GATEWAY)