コード例 #1
0
 def test_create_delete_bgp_speaker(self):
     bgp_speaker = objects.BGPSpeakerTestObj(self.neutron, self.nb_api)
     self.addCleanup(bgp_speaker.close)
     bgp_speaker.create()
     self.assertTrue(bgp_speaker.exists())
     bgp_speaker.close()
     self.assertFalse(bgp_speaker.exists())
コード例 #2
0
    def test_delete_bgp_peer_update_bgp_speaker(self):
        bgp_peer = objects.BGPPeerTestObj(self.neutron, self.nb_api)
        self.addCleanup(bgp_peer.close)
        bgp_speaker = objects.BGPSpeakerTestObj(self.neutron, self.nb_api)
        self.addCleanup(bgp_speaker.close)
        bgp_peer.create()
        bgp_speaker.create()
        bgp_speaker.add_peer(bgp_peer.peer_id)
        nb_bgp_speaker = bgp_speaker.get_nb_bgp_speaker()
        peers = [peer.id for peer in nb_bgp_speaker.peers]
        self.assertIn(bgp_peer.peer_id, peers)

        bgp_peer.close()
        nb_bgp_speaker = bgp_speaker.get_nb_bgp_speaker()
        peers = [peer.id for peer in nb_bgp_speaker.peers]
        self.assertNotIn(bgp_peer.peer_id, nb_bgp_speaker.peers)
コード例 #3
0
    def test_add_remove_bgp_peer(self):
        bgp_peer = self.store(
            objects.BGPPeerTestObj(self.neutron, self.nb_api))
        bgp_speaker = self.store(
            objects.BGPSpeakerTestObj(self.neutron, self.nb_api))
        bgp_peer.create()
        bgp_speaker.create()
        bgp_speaker.add_peer(bgp_peer.peer_id)
        nb_bgp_speaker = bgp_speaker.get_nb_bgp_speaker()
        peers = [peer.id for peer in nb_bgp_speaker.peers]
        self.assertIn(bgp_peer.peer_id, peers)

        bgp_speaker.remove_peer(bgp_peer.peer_id)
        nb_bgp_speaker = bgp_speaker.get_nb_bgp_speaker()
        peers = [peer.id for peer in nb_bgp_speaker.peers]
        self.assertNotIn(bgp_peer.peer_id, nb_bgp_speaker.peers)
コード例 #4
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)