Example #1
0
 def test_get_nondistributed_active_network_ports_no_candidate(self):
     self._setup_port_binding(dvr=False)
     # Register a bunch of non-L2 agents on the same host
     helpers.register_l3_agent()
     helpers.register_dhcp_agent()
     fdb_network_ports = l2pop_db.get_nondistributed_active_network_ports(
         self.ctx.session, TEST_NETWORK_ID)
     self.assertEqual(0, len(fdb_network_ports))
Example #2
0
 def test_get_nondistributed_active_network_ports_no_candidate(self):
     self._setup_port_binding(dvr=False)
     # Register a bunch of non-L2 agents on the same host
     helpers.register_l3_agent()
     helpers.register_dhcp_agent()
     fdb_network_ports = l2pop_db.get_nondistributed_active_network_ports(
         self.ctx.session, TEST_NETWORK_ID)
     self.assertEqual(0, len(fdb_network_ports))
Example #3
0
 def test_get_nondistributed_active_network_ports(self):
     self._setup_port_binding(dvr=False)
     # Register a L2 agent + A bunch of other agents on the same host
     helpers.register_l3_agent()
     helpers.register_dhcp_agent()
     helpers.register_ovs_agent()
     fdb_network_ports = l2pop_db.get_nondistributed_active_network_ports(
         self.ctx.session, TEST_NETWORK_ID)
     self.assertEqual(1, len(fdb_network_ports))
     _, agent = fdb_network_ports[0]
     self.assertEqual(constants.AGENT_TYPE_OVS, agent.agent_type)
Example #4
0
 def test_get_nondistributed_active_network_ports(self):
     self._setup_port_binding(dvr=False)
     # Register a L2 agent + A bunch of other agents on the same host
     helpers.register_l3_agent()
     helpers.register_dhcp_agent()
     helpers.register_ovs_agent()
     fdb_network_ports = l2pop_db.get_nondistributed_active_network_ports(
         self.ctx.session, TEST_NETWORK_ID)
     self.assertEqual(1, len(fdb_network_ports))
     _, agent = fdb_network_ports[0]
     self.assertEqual(constants.AGENT_TYPE_OVS, agent.agent_type)
Example #5
0
 def test_active_network_ports_with_dvr_snat_port(self):
     # Test to get agent hosting dvr snat port
     helpers.register_l3_agent()
     helpers.register_dhcp_agent()
     helpers.register_ovs_agent()
     # create DVR router
     self._create_router()
     # setup DVR snat port
     self._setup_port_binding(
         device_owner=constants.DEVICE_OWNER_ROUTER_SNAT,
         device_id=TEST_ROUTER_ID)
     helpers.register_dhcp_agent()
     fdb_network_ports = l2pop_db.get_nondistributed_active_network_ports(
         self.ctx.session, TEST_NETWORK_ID)
     self.assertEqual(1, len(fdb_network_ports))
Example #6
0
 def test_active_network_ports_with_dvr_snat_port(self):
     # Test to get agent hosting dvr snat port
     helpers.register_l3_agent()
     helpers.register_dhcp_agent()
     helpers.register_ovs_agent()
     # create DVR router
     self._create_router()
     # setup DVR snat port
     self._setup_port_binding(
         device_owner=constants.DEVICE_OWNER_ROUTER_SNAT,
         device_id=TEST_ROUTER_ID)
     helpers.register_dhcp_agent()
     fdb_network_ports = l2pop_db.get_nondistributed_active_network_ports(
         self.ctx.session, TEST_NETWORK_ID)
     self.assertEqual(1, len(fdb_network_ports))
Example #7
0
 def test_active_network_ports_with_ha_dvr_snat_port(self):
     # test to get HA agents hosting HA+DVR snat port
     helpers.register_dhcp_agent()
     helpers.register_l3_agent()
     helpers.register_ovs_agent()
     # create HA+DVR router
     self._create_ha_router()
     # setup HA snat port
     self._setup_port_binding(
         device_owner=constants.DEVICE_OWNER_ROUTER_SNAT,
         device_id=TEST_ROUTER_ID)
     fdb_network_ports = l2pop_db.get_nondistributed_active_network_ports(
         self.ctx, TEST_NETWORK_ID)
     self.assertEqual(0, len(fdb_network_ports))
     ha_ports = l2pop_db.get_ha_active_network_ports(
         self.ctx, TEST_NETWORK_ID)
     self.assertEqual(2, len(ha_ports))
Example #8
0
 def test_active_network_ports_with_ha_dvr_snat_port(self):
     # test to get HA agents hosting HA+DVR snat port
     helpers.register_dhcp_agent()
     helpers.register_l3_agent()
     helpers.register_ovs_agent()
     # create HA+DVR router
     self._create_ha_router()
     # setup HA snat port
     self._setup_port_binding(
         device_owner=constants.DEVICE_OWNER_ROUTER_SNAT,
         device_id=TEST_ROUTER_ID)
     fdb_network_ports = l2pop_db.get_nondistributed_active_network_ports(
         self.ctx, TEST_NETWORK_ID)
     self.assertEqual(0, len(fdb_network_ports))
     ha_ports = l2pop_db.get_ha_active_network_ports(
         self.ctx, TEST_NETWORK_ID)
     self.assertEqual(2, len(ha_ports))
Example #9
0
    def _create_agent_fdb(self, context, agent, segment, network_id):
        agent_fdb_entries = {network_id:
                             {'segment_id': segment['segmentation_id'],
                              'network_type': segment['network_type'],
                              'ports': {}}}
        tunnel_network_ports = (
            l2pop_db.get_distributed_active_network_ports(context, network_id))
        fdb_network_ports = (
            l2pop_db.get_nondistributed_active_network_ports(context,
                                                             network_id))
        ports = agent_fdb_entries[network_id]['ports']
        ports.update(self._get_tunnels(
            fdb_network_ports + tunnel_network_ports,
            agent.host))
        for agent_ip, fdbs in ports.items():
            for binding, agent in fdb_network_ports:
                if l2pop_db.get_agent_ip(agent) == agent_ip:
                    fdbs.extend(self._get_port_fdb_entries(binding.port))

        return agent_fdb_entries
Example #10
0
    def _create_agent_fdb(self, session, agent, segment, network_id):
        agent_fdb_entries = {network_id:
                             {'segment_id': segment['segmentation_id'],
                              'network_type': segment['network_type'],
                              'ports': {}}}
        tunnel_network_ports = (
            l2pop_db.get_distributed_active_network_ports(session, network_id))
        fdb_network_ports = (
            l2pop_db.get_nondistributed_active_network_ports(session,
                                                             network_id))
        ports = agent_fdb_entries[network_id]['ports']
        ports.update(self._get_tunnels(
            fdb_network_ports + tunnel_network_ports,
            agent.host))
        for agent_ip, fdbs in ports.items():
            for binding, agent in fdb_network_ports:
                if l2pop_db.get_agent_ip(agent) == agent_ip:
                    fdbs.extend(self._get_port_fdb_entries(binding.port))

        return agent_fdb_entries
Example #11
0
    def _create_agent_fdb(self,
                          context,
                          agent,
                          segment,
                          network_id,
                          source=None):
        exclude_host = agent.host if agent else None
        session = context.session
        agent_fdb_entries = {
            network_id: {
                'segment_id': segment['segmentation_id'],
                'network_type': segment['network_type'],
                'audit': True,
                'ports': {}
            }
        }
        physical_network = segment.get('physical_network')
        if physical_network:
            agent_fdb_entries[network_id]['physical_network'] = (
                physical_network)
        tunnel_network_ports = (l2pop_db.get_distributed_active_network_ports(
            session, network_id))
        fdb_network_ports = (l2pop_db.get_nondistributed_active_network_ports(
            session, network_id))
        ports = agent_fdb_entries[network_id]['ports']
        ports.update(
            self._get_tunnels(fdb_network_ports + tunnel_network_ports,
                              exclude_host=exclude_host,
                              physical_network=physical_network))
        for agent_ip, fdbs in ports.items():
            for binding, agent in fdb_network_ports:
                ip = l2pop_db.get_agent_ip(
                    agent, physical_network=segment.get('physical_network'))
                if ip == agent_ip:
                    fdbs.extend(self._get_port_fdb_entries(binding.port))

        return run_fdb_extend_funcs(context,
                                    network_id,
                                    agent_fdb_entries,
                                    source=source,
                                    exclude_host=exclude_host)