Exemplo n.º 1
0
 def test_create_router_interface(self):
     router = self.store(objects.RouterTestObj(self.neutron, self.nb_api))
     network = self.store(objects.NetworkTestObj(self.neutron, self.nb_api))
     network_id = network.create()
     self.assertTrue(network.exists())
     subnet = self.store(objects.SubnetTestObj(
         self.neutron,
         self.nb_api,
         network_id,
     ))
     subnet_id = subnet.create()
     router_id = router.create()
     self.assertTrue(router.exists())
     subnet_msg = {'subnet_id': subnet_id}
     port = self.neutron.add_interface_router(router_id, body=subnet_msg)
     port2 = self.nb_api.get_logical_port(port['port_id'])
     self.assertIsNotNone(port2)
     router.close()
     utils.wait_until_none(
         lambda: self.nb_api.get_logical_port(port['port_id']),
         exception=Exception('Port was not deleted')
     )
     subnet.close()
     network.close()
     self.assertFalse(router.exists())
     self.assertFalse(network.exists())
Exemplo n.º 2
0
    def test_router_version(self):
        network = objects.NetworkTestObj(self.neutron, self.nb_api)
        self.addCleanup(network.close)
        network_id = network.create()
        self.assertTrue(network.exists())
        subnet = objects.SubnetTestObj(self.neutron, self.nb_api, network_id)
        self.addCleanup(subnet.close)
        subnet_id = subnet.create()
        self.assertTrue(subnet.exists())
        router = objects.RouterTestObj(self.neutron, self.nb_api)
        self.addCleanup(router.close)
        router_id = router.create()
        self.assertTrue(router.exists())
        prev_version = self.nb_api.get(l3.LogicalRouter(id=router_id)).version

        subnet_msg = {'subnet_id': subnet_id}
        self.neutron.add_interface_router(router_id, body=subnet_msg)
        version = self.nb_api.get(l3.LogicalRouter(id=router_id)).version
        self.assertGreater(version, prev_version)
        prev_version = version

        self.neutron.remove_interface_router(router_id, body=subnet_msg)
        version = self.nb_api.get(l3.LogicalRouter(id=router_id)).version
        self.assertGreater(version, prev_version)

        router.close()
        self.assertFalse(router.exists())
        subnet.close()
        self.assertFalse(subnet.exists())
        network.close()
        self.assertFalse(network.exists())
Exemplo n.º 3
0
 def __init__(self, topology, router_id, subnet_ids):
     """Create a router in the topology. Add router interfaces for each
     subnet.
     :param topology:   The topology to which the router belongs
     :type topology:    Topology
     :param router_id:  The ID of the router. Created in Topology.
     :type router_id:   Number (opaque)
     :param subnet_ids: List of subnets to which the router is connected
     :type subnet_ids:  List
     """
     self.topology = topology
     self.router_id = router_id
     self.subnet_ids = subnet_ids
     self.router = objects.RouterTestObj(
         self.topology.neutron,
         self.topology.nb_api,
     )
     self.router.create(router={
         'admin_state_up': True
     })
     self.router_interfaces = {}
     for subnet_id in self.subnet_ids:
         subnet = self.topology.subnets[subnet_id]
         subnet_uuid = subnet.subnet.subnet_id
         router_interface = self.router.add_interface(subnet_id=subnet_uuid)
         self.router_interfaces[subnet_id] = router_interface
Exemplo n.º 4
0
 def test_create_router_interface(self):
     ovs = utils.OvsFlowsParser()
     flows_before_change = ovs.dump(self.integration_bridge)
     router = self.store(objects.RouterTestObj(self.neutron, self.nb_api))
     network = self.store(objects.NetworkTestObj(self.neutron, self.nb_api))
     network_id = network.create()
     subnet = {
         'network_id': network_id,
         'cidr': '10.30.0.0/24',
         'gateway_ip': '10.30.0.1',
         'ip_version': 4,
         'name': 'subnet-test',
         'enable_dhcp': True
     }
     subnet = self.neutron.create_subnet({'subnet': subnet})
     subnet_id = subnet['subnet']['id']
     router_id = router.create()
     self.assertTrue(router.exists())
     subnet_msg = {'subnet_id': subnet_id}
     time.sleep(const.DEFAULT_RESOURCE_READY_TIMEOUT)
     self.neutron.add_interface_router(router_id, body=subnet_msg)
     dhcp_ip = utils.wait_until_is_and_return(
         lambda: self.get_dhcp_ip(network_id, subnet_id),
         exception=Exception('DHCP IP was not generated'))
     flows_after_change = ovs.dump(self.integration_bridge)
     self.assertFalse(self.check_dhcp_rule(flows_before_change, dhcp_ip))
     self.assertTrue(self.check_dhcp_rule(flows_after_change, dhcp_ip))
     self.neutron.remove_interface_router(router_id, body=subnet_msg)
     router.close()
     network.close()
     utils.wait_until_none(
         lambda: self.check_dhcp_rule(ovs.dump(self.integration_bridge),
                                      dhcp_ip),
         exception=Exception('DHCP IP was not removed from OpenFlow rules'),
         timeout=30)
Exemplo n.º 5
0
    def test_router_version(self):
        router = self.store(objects.RouterTestObj(self.neutron, self.nb_api))
        network = self.store(objects.NetworkTestObj(self.neutron, self.nb_api))
        network_id = network.create()
        self.assertTrue(network.exists())
        subnet = self.store(
            objects.SubnetTestObj(
                self.neutron,
                self.nb_api,
                network_id,
            ))
        subnet_id = subnet.create()
        self.assertTrue(subnet.exists())
        router_id = router.create()
        self.assertTrue(router.exists())
        version = self.nb_api.get_router(router_id).get_version()
        self.assertEqual(version, 0)

        subnet_msg = {'subnet_id': subnet_id}
        self.neutron.add_interface_router(router_id, body=subnet_msg)
        version = self.nb_api.get_router(router_id).get_version()
        self.assertEqual(version, 1)

        self.neutron.remove_interface_router(router_id, body=subnet_msg)
        version = self.nb_api.get_router(router_id).get_version()
        self.assertEqual(version, 2)

        router.close()
        self.assertFalse(router.exists())
        subnet.close()
        self.assertFalse(subnet.exists())
        network.close()
        self.assertFalse(network.exists())
Exemplo n.º 6
0
    def test_disassociate_floatingip(self):
        with self._prepare_ext_net() as external_network_id:
            router = self.store(
                objects.RouterTestObj(self.neutron, self.nb_api))
            fip = self.store(
                objects.FloatingipTestObj(self.neutron, self.nb_api))

            router_para = {
                'name': 'myrouter1', 'admin_state_up': True,
                'external_gateway_info': {"network_id": external_network_id}}
            router.create(router=router_para)
            self.assertTrue(router.exists())

            # private network
            private_network = self.store(
                objects.NetworkTestObj(self.neutron, self.nb_api))
            private_network_id = private_network.create()
            self.assertTrue(private_network.exists())
            # private subnet
            priv_subnet = self.store(objects.SubnetTestObj(
                self.neutron,
                self.nb_api,
                private_network_id,
            ))
            private_subnet_para = {'cidr': '10.0.0.0/24',
                                   'ip_version': 4,
                                   'network_id': private_network_id}
            priv_subnet_id = priv_subnet.create(private_subnet_para)
            self.assertTrue(priv_subnet.exists())
            router_interface = router.add_interface(subnet_id=priv_subnet_id)
            router_lport = self.nb_api.get(
                l2.LogicalPort(id=router_interface['port_id']))
            self.assertIsNotNone(router_lport)

            port = self.store(
                objects.PortTestObj(self.neutron,
                                    self.nb_api, private_network_id))
            port_id = port.create()
            self.assertIsNotNone(port.get_logical_port())

            fip_para = {'floating_network_id': external_network_id,
                        'port_id': port_id}
            # create
            fip.create(fip_para)
            self.assertTrue(fip.exists())

            # disassociate with port
            fip.update({})
            fip_obj = fip.get_floatingip()
            self.assertIsNone(fip_obj.lport)

            fip.close()
            self.assertFalse(fip.exists())
            port.close()
            self.assertFalse(port.exists())
            router.close()
            self.assertFalse(router.exists())
            priv_subnet.close()
            self.assertFalse(priv_subnet.exists())
Exemplo n.º 7
0
 def test_create_delete_router(self):
     router = self.store(objects.RouterTestObj(self.neutron, self.nb_api))
     router_id = router.create()
     self.assertTrue(router.exists())
     version1 = self.nb_api.get_router(router_id).get_version()
     router.update()
     self.assertTrue(router.exists())
     version2 = self.nb_api.get_router(router_id).get_version()
     self.assertTrue(version1 != version2)
     router.close()
     self.assertFalse(router.exists())
Exemplo n.º 8
0
 def test_create_delete_router(self):
     router = objects.RouterTestObj(self.neutron, self.nb_api)
     self.addCleanup(router.close)
     router_id = router.create()
     self.assertTrue(router.exists())
     version1 = self.nb_api.get(l3.LogicalRouter(id=router_id)).version
     router.update()
     self.assertTrue(router.exists())
     version2 = self.nb_api.get(l3.LogicalRouter(id=router_id)).version
     self.assertTrue(version1 != version2)
     router.close()
     self.assertFalse(router.exists())
Exemplo n.º 9
0
    def test_delete_router_interface_port(self):
        router = self.store(objects.RouterTestObj(self.neutron, self.nb_api))
        network = self.store(objects.NetworkTestObj(self.neutron, self.nb_api))
        network_id = network.create()
        self.assertTrue(network.exists())
        subnet = self.store(
            objects.SubnetTestObj(
                self.neutron,
                self.nb_api,
                network_id,
            ))
        subnet_id = subnet.create({
            'cidr': '91.126.188.0/24',
            'ip_version': 4,
            'network_id': network_id
        })
        router_id = router.create()
        self.assertTrue(router.exists())
        interface_msg = {'subnet_id': subnet_id}
        router_l = self.neutron.add_interface_router(router_id,
                                                     body=interface_msg)
        routers = self.nb_api.get_all(l3.LogicalRouter)
        router2 = None
        for r in routers:
            if r.id == router_l['id']:
                router2 = r
                break
        self.assertIsNotNone(router2)
        interface_port = self.neutron.show_port(router_l['port_id'])
        self.assertRaises(n_exc.Conflict, self.neutron.delete_port,
                          interface_port['port']['id'])
        self.assertIsNotNone(
            self.nb_api.get(l2.LogicalPort(id=interface_port['port']['id'])))

        self.neutron.remove_interface_router(router.router_id,
                                             body=interface_msg)
        port2 = self.nb_api.get(
            l2.LogicalPort(id=interface_port['port']['id']))
        self.assertIsNone(port2)
        subnet.close()
        router.close()
        network.close()
        self.assertFalse(router.exists())
        self.assertFalse(network.exists())
Exemplo n.º 10
0
 def test_create_delete_router(self):
     router = self.store(objects.RouterTestObj(self.neutron, self.nb_api))
     router.create()
     self.assertTrue(router.exists())
     router.close()
     self.assertFalse(router.exists())
Exemplo n.º 11
0
    def test_icmp_responder(self):
        """
        Add a VM. Verify the icmp flow is there.
        """
        network = self.store(objects.NetworkTestObj(self.neutron, self.nb_api))
        network_id = network.create(network={'name': 'icmp_responder_test'})
        subnet_obj = self.store(objects.SubnetTestObj(
            self.neutron,
            self.nb_api,
            network_id,
        ))

        subnet = {'network_id': network_id,
                  'cidr': '10.10.10.0/24',
                  'gateway_ip': '10.10.10.1',
                  'ip_version': 4,
                  'name': 'arp_responder_test',
                  'enable_dhcp': True}
        subnet_id = subnet_obj.create(subnet)

        flows_before = self._get_l3_lookup_table_flows()

        router = self.store(objects.RouterTestObj(self.neutron, self.nb_api))
        router_id = router.create()
        subnet_msg = {'subnet_id': subnet_id}
        interface = self.neutron.add_interface_router(router_id,
                                                      body=subnet_msg)
        port_id = interface['port_id']
        router_port = self.neutron.list_ports(id=port_id)['ports'][0]
        router_ip = None
        for ip in router_port['fixed_ips']:
            if ip['subnet_id'] == subnet_id:
                router_ip = ip['ip_address']
                break

        vm = self.store(objects.VMTestObj(self, self.neutron))
        vm.create(network=network)
        ip = vm.get_first_ipv4()
        self.assertIsNotNone(ip)

        flows_middle = self._get_l3_lookup_table_flows()

        vm.close()
        router.close()
        time.sleep(test_const.DEFAULT_RESOURCE_READY_TIMEOUT)

        flows_delta = [flow for flow in flows_middle
                       if flow not in flows_before]

        self.assertIsNotNone(
            self._find_icmp_responder_flow_by_ip(flows_delta, router_ip)
        )
        condition = lambda: self._check_icmp_flow_removal(router_ip)
        try:
            test_utils.wait_until_true(
                condition, timeout=test_const.DEFAULT_RESOURCE_READY_TIMEOUT,
                sleep=1,
                exception=RuntimeError(
                    "Timed out waiting for icmp responder flow from %(ip)s"
                    " to be removed" % {'ip': router_ip}))
        except Exception as e:
            self.assertIsNone(e)
        finally:
            network.close()
Exemplo n.º 12
0
    def test_add_remove_bgp_network(self):
        bgp_speaker = objects.BGPSpeakerTestObj(self.neutron, self.nb_api)
        self.addCleanup(bgp_speaker.close)
        bgp_speaker.create()
        address_scope = objects.AddressScopeTestObj(self.neutron, self.nb_api)
        self.addCleanup(address_scope.close)
        as_id = address_scope.create()
        private_subnetpool = objects.SubnetPoolTestObj(self.neutron,
                                                       self.nb_api)
        self.addCleanup(private_subnetpool.close)
        private_sp_id = private_subnetpool.create(
            subnetpool={
                'name': "private_sp",
                'default_prefixlen': 24,
                'prefixes': ["20.0.0.0/8"],
                'address_scope_id': as_id
            })
        public_subnetpool = objects.SubnetPoolTestObj(self.neutron,
                                                      self.nb_api)
        self.addCleanup(public_subnetpool.close)
        public_sp_id = public_subnetpool.create(
            subnetpool={
                'name': "public_sp",
                'default_prefixlen': 24,
                'prefixes': ["172.24.4.0/24"],
                'address_scope_id': as_id
            })
        public_network = objects.NetworkTestObj(self.neutron, self.nb_api)
        self.addCleanup(public_network.close)
        public_network_id = public_network.create(network={
            'name': 'public',
            'router:external': True
        })
        public_subnet = objects.SubnetTestObj(self.neutron, self.nb_api,
                                              public_network_id)
        self.addCleanup(public_subnet.close)
        public_subnet.create(
            subnet={
                'ip_version': 4,
                'network_id': public_network_id,
                'subnetpool_id': public_sp_id
            })
        private_network = objects.NetworkTestObj(self.neutron, self.nb_api)
        self.addCleanup(private_network.close)
        private_network_id = private_network.create(network={'name': "public"})
        private_subnet = objects.SubnetTestObj(self.neutron, self.nb_api,
                                               private_network_id)
        self.addCleanup(private_subnet.close)
        private_sn_id = private_subnet.create(
            subnet={
                'ip_version': 4,
                'network_id': private_network_id,
                'subnetpool_id': private_sp_id
            })
        bgp_speaker.add_network(public_network_id)
        router = objects.RouterTestObj(self.neutron, self.nb_api)
        self.addCleanup(router.close)
        router_id = router.create()
        self.neutron.add_interface_router(router_id,
                                          body={'subnet_id': private_sn_id})
        self.neutron.add_gateway_router(router_id,
                                        body={'network_id': public_network_id})
        # Finnally, verify the route has been set in nb db.
        nb_bgp_speaker = bgp_speaker.get_nb_bgp_speaker()
        self.assertEqual(1, len(nb_bgp_speaker.prefix_routes))

        vm = objects.VMTestObj(self, self.neutron)
        self.addCleanup(vm.close)
        vm_id = vm.create(network=private_network)
        vm_port = self.neutron.list_ports(device_id=vm_id).get('ports')[0]
        vm_port_id = vm_port.get('id')
        fip = objects.FloatingipTestObj(self.neutron, self.nb_api)
        self.addCleanup(fip.close)
        fip.create({
            'floating_network_id': public_network_id,
            'port_id': vm_port_id
        })
        fip_addr = fip.get_floatingip().floating_ip_address
        nb_bgp_speaker = bgp_speaker.get_nb_bgp_speaker()
        self.assertEqual(1, len(nb_bgp_speaker.host_routes))
        self.assertIn(
            host_route.HostRoute(destination=netaddr.IPNetwork(fip_addr),
                                 nexthop='172.24.4.100'),
            nb_bgp_speaker.host_routes)

        fip.update({'port_id': None})
        nb_bgp_speaker = bgp_speaker.get_nb_bgp_speaker()
        self.assertFalse(nb_bgp_speaker.host_routes)

        bgp_speaker.remove_network(public_network_id)
        nb_bgp_speaker = bgp_speaker.get_nb_bgp_speaker()
        self.assertFalse(nb_bgp_speaker.prefix_routes)
Exemplo n.º 13
0
    def test_floatingip_version(self):
        with self._prepare_ext_net() as external_network_id:
            private_network = self.store(
                objects.NetworkTestObj(self.neutron, self.nb_api))
            private_network_id = private_network.create(
                network={'name': 'private'})
            self.assertTrue(private_network.exists())
            priv_subnet = self.store(
                objects.SubnetTestObj(
                    self.neutron,
                    self.nb_api,
                    private_network_id,
                ))
            router = self.store(
                objects.RouterTestObj(self.neutron, self.nb_api))
            port = self.store(
                objects.PortTestObj(self.neutron, self.nb_api,
                                    private_network_id))
            fip = self.store(
                objects.FloatingipTestObj(self.neutron, self.nb_api))

            router_para = {
                'name': 'myrouter1',
                'admin_state_up': True,
                'external_gateway_info': {
                    "network_id": external_network_id
                }
            }
            router.create(router=router_para)
            self.assertTrue(router.exists())

            private_subnet_para = {
                'cidr': '10.0.0.0/24',
                'ip_version': 4,
                'network_id': private_network_id
            }
            priv_subnet_id = priv_subnet.create(private_subnet_para)
            self.assertTrue(priv_subnet.exists())
            router_interface = router.add_interface(subnet_id=priv_subnet_id)
            router_lport = self.nb_api.get_logical_port(
                router_interface['port_id'])
            self.assertIsNotNone(router_lport)

            port_id = port.create()
            self.assertIsNotNone(port.get_logical_port())

            fip_para = {'floating_network_id': external_network_id}
            # create
            new_fip = fip.create(fip_para)
            self.assertTrue(fip.exists())
            fip_id = new_fip['id']
            prev_version = self.nb_api.get_floatingip(fip_id).get_version()

            # associate with port
            fip.update({'port_id': port_id})
            fip_obj = fip.get_floatingip()
            self.assertEqual(fip_obj.get_lport_id(), port_id)
            version = self.nb_api.get_floatingip(fip_id).get_version()
            self.assertGreater(version, prev_version)
            prev_version = version

            fip.update({})
            fip_obj = fip.get_floatingip()
            self.assertIsNone(fip_obj.get_lport_id())
            version = self.nb_api.get_floatingip(fip_id).get_version()
            self.assertGreater(version, prev_version)

            fip.close()
            self.assertFalse(fip.exists())
            port.close()
            self.assertFalse(port.exists())
            router.close()
            self.assertFalse(router.exists())
            priv_subnet.close()
            self.assertFalse(priv_subnet.exists())