Exemple #1
0
    def test_get_routing_table(self):
        attr = self.generate_device_details(
            ip_cidrs=["%s/24" % TEST_IP, "fd00::1/64"])
        device = self.manage_device(attr)
        device_ip = attr.ip_cidrs[0].split('/')[0]
        destination = '8.8.8.0/24'
        device.route.add_route(destination, device_ip)

        destination6 = 'fd01::/64'
        device.route.add_route(destination6, "fd00::2")

        expected_routes = [{
            'nexthop': device_ip,
            'device': attr.name,
            'destination': destination,
            'scope': 'universe'
        }, {
            'nexthop':
            None,
            'device':
            attr.name,
            'destination':
            str(netaddr.IPNetwork(attr.ip_cidrs[0]).cidr),
            'scope':
            'link'
        }]

        routes = ip_lib.get_routing_table(4, namespace=attr.namespace)
        self.assertItemsEqual(expected_routes, routes)
        self.assertIsInstance(routes, list)

        expected_routes6 = [{
            'nexthop': "fd00::2",
            'device': attr.name,
            'destination': destination6,
            'scope': 'universe'
        }, {
            'nexthop':
            None,
            'device':
            attr.name,
            'destination':
            str(netaddr.IPNetwork(attr.ip_cidrs[1]).cidr),
            'scope':
            'universe'
        }]
        routes6 = ip_lib.get_routing_table(6, namespace=attr.namespace)
        self.assertItemsEqual(expected_routes6, routes6)
        self.assertIsInstance(routes6, list)
    def _assert_extra_routes(self, router):
        routes = ip_lib.get_routing_table(self.root_helper, router.ns_name)
        routes = [{'nexthop': route['nexthop'],
                   'destination': route['destination']} for route in routes]

        for extra_route in router.router['routes']:
            self.assertIn(extra_route, routes)
Exemple #3
0
    def test_get_routing_table(self):
        attr = self.generate_device_details()
        device = self.manage_device(attr)
        device_ip = attr.ip_cidrs[0].split('/')[0]
        destination = '8.8.8.0/24'
        device.route.add_route(destination, device_ip)

        expected_routes = [{
            'nexthop': device_ip,
            'device': attr.name,
            'destination': destination,
            'scope': None
        }, {
            'nexthop':
            None,
            'device':
            attr.name,
            'destination':
            str(netaddr.IPNetwork(attr.ip_cidrs[0]).cidr),
            'scope':
            'link'
        }]

        routes = ip_lib.get_routing_table(4, namespace=attr.namespace)
        self.assertEqual(expected_routes, routes)
    def _assert_extra_routes(self, router):
        routes = ip_lib.get_routing_table(4, namespace=router.ns_name)
        routes = [{'nexthop': route['nexthop'],
                   'destination': route['destination']} for route in routes]

        for extra_route in router.router['routes']:
            self.assertIn(extra_route, routes)
Exemple #5
0
    def _assert_extra_routes(self, router, namespace=None):
        if namespace is None:
            namespace = router.ns_name
        routes = ip_lib.get_routing_table(4, namespace=namespace)
        routes = [{'nexthop': route['nexthop'],
                   'destination': route['destination']} for route in routes]

        for extra_route in router.router['routes']:
            self.assertIn(extra_route, routes)
Exemple #6
0
 def _assert_onlink_subnet_routes(
         self, router, ip_versions, namespace=None):
     ns_name = namespace or router.ns_name
     routes = []
     for ip_version in ip_versions:
         _routes = ip_lib.get_routing_table(ip_version,
                                            namespace=ns_name)
         routes.extend(_routes)
     routes = set(route['destination'] for route in routes)
     extra_subnets = router.get_ex_gw_port()['extra_subnets']
     for extra_subnet in (route['cidr'] for route in extra_subnets):
         self.assertIn(extra_subnet, routes)
Exemple #7
0
 def _assert_onlink_subnet_routes(
         self, router, ip_versions, namespace=None):
     ns_name = namespace or router.ns_name
     routes = []
     for ip_version in ip_versions:
         _routes = ip_lib.get_routing_table(ip_version,
                                            namespace=ns_name)
         routes.extend(_routes)
     routes = set(route['destination'] for route in routes)
     extra_subnets = router.get_ex_gw_port()['extra_subnets']
     for extra_subnet in (route['cidr'] for route in extra_subnets):
         self.assertIn(extra_subnet, routes)
Exemple #8
0
    def test_get_routing_table(self):
        attr = self.generate_device_details(
            ip_cidrs=["%s/24" % TEST_IP, "fd00::1/64"]
        )
        device = self.manage_device(attr)
        device_ip = attr.ip_cidrs[0].split('/')[0]
        destination = '8.8.8.0/24'
        device.route.add_route(destination, device_ip)

        destination6 = 'fd01::/64'
        device.route.add_route(destination6, "fd00::2")

        expected_routes = [{'nexthop': device_ip,
                            'device': attr.name,
                            'destination': destination,
                            'scope': 'universe'},
                           {'nexthop': None,
                            'device': attr.name,
                            'destination': str(
                                netaddr.IPNetwork(attr.ip_cidrs[0]).cidr),
                            'scope': 'link'}]

        routes = ip_lib.get_routing_table(4, namespace=attr.namespace)
        self.assertItemsEqual(expected_routes, routes)
        self.assertIsInstance(routes, list)

        expected_routes6 = [{'nexthop': "fd00::2",
                             'device': attr.name,
                             'destination': destination6,
                             'scope': 'universe'},
                            {'nexthop': None,
                             'device': attr.name,
                             'destination': str(
                                 netaddr.IPNetwork(attr.ip_cidrs[1]).cidr),
                             'scope': 'universe'}]
        routes6 = ip_lib.get_routing_table(6, namespace=attr.namespace)
        self.assertItemsEqual(expected_routes6, routes6)
        self.assertIsInstance(routes6, list)
Exemple #9
0
    def test_get_routing_table(self):
        attr = self.generate_device_details()
        device = self.manage_device(attr)
        device_ip = attr.ip_cidrs[0].split('/')[0]
        destination = '8.8.8.0/24'
        device.route.add_route(destination, device_ip)

        expected_routes = [{'nexthop': device_ip,
                            'device': attr.name,
                            'destination': destination},
                           {'nexthop': None,
                            'device': attr.name,
                            'destination': str(
                                netaddr.IPNetwork(attr.ip_cidrs[0]).cidr)}]

        routes = ip_lib.get_routing_table(namespace=attr.namespace)
        self.assertEqual(expected_routes, routes)
Exemple #10
0
    def test_get_routing_table(self):
        attr = self.generate_device_details()
        device = self.manage_device(attr)
        device_ip = attr.ip_cidrs[0].split("/")[0]
        destination = "8.8.8.0/24"
        device.route.add_route(destination, device_ip)

        expected_routes = [
            {"nexthop": device_ip, "device": attr.name, "destination": destination, "scope": None},
            {
                "nexthop": None,
                "device": attr.name,
                "destination": str(netaddr.IPNetwork(attr.ip_cidrs[0]).cidr),
                "scope": "link",
            },
        ]

        routes = ip_lib.get_routing_table(4, namespace=attr.namespace)
        self.assertEqual(expected_routes, routes)
Exemple #11
0
 def test_get_routing_table_no_namespace(self):
     with testtools.ExpectedException(ip_lib.NetworkNamespaceNotFound):
         ip_lib.get_routing_table(4, namespace="nonexistent-netns")
Exemple #12
0
 def test_get_routing_table_no_namespace(self):
     with testtools.ExpectedException(ip_lib.NetworkNamespaceNotFound):
         ip_lib.get_routing_table(4, namespace="nonexistent-netns")