예제 #1
0
    def test_add_centralized_floatingip(self,
                                        super_add_centralized_floatingip):
        agent = l3_agent.L3NATAgent(HOSTNAME, self.conf)
        agent.conf.agent_mode = lib_constants.L3_AGENT_MODE_DVR_SNAT
        router = l3_test_common.prepare_router_data(num_internal_ports=2)
        router['gw_port_host'] = HOSTNAME
        self.mock_driver.unplug.reset_mock()
        self._set_ri_kwargs(agent, router['id'], router)
        fip = {'id': _uuid()}
        fip_cidr = '11.22.33.44/24'

        ri = dvr_edge_ha_rtr.DvrEdgeHaRouter(HOSTNAME, [], **self.ri_kwargs)
        ri.is_router_master = mock.Mock(return_value=False)
        ri._add_vip = mock.Mock()
        interface_name = ri.get_snat_external_device_interface_name(
            ri.get_ex_gw_port())
        ri.add_centralized_floatingip(fip, fip_cidr)
        ri._add_vip.assert_called_once_with(fip_cidr, interface_name)
        super_add_centralized_floatingip.assert_not_called()

        ri1 = dvr_edge_ha_rtr.DvrEdgeHaRouter(HOSTNAME, [], **self.ri_kwargs)
        ri1.is_router_master = mock.Mock(return_value=True)
        ri1._add_vip = mock.Mock()
        interface_name = ri1.get_snat_external_device_interface_name(
            ri1.get_ex_gw_port())
        ri1.add_centralized_floatingip(fip, fip_cidr)
        ri1._add_vip.assert_called_once_with(fip_cidr, interface_name)
        super_add_centralized_floatingip.assert_called_once_with(fip, fip_cidr)
예제 #2
0
파일: agent.py 프로젝트: zxt2012bs/neutron
    def _create_router(self, router_id, router):
        args = []
        kwargs = {
            'agent': self,
            'router_id': router_id,
            'router': router,
            'use_ipv6': self.use_ipv6,
            'agent_conf': self.conf,
            'interface_driver': self.driver,
        }

        if router.get('distributed'):
            kwargs['host'] = self.host

        if router.get('distributed') and router.get('ha'):
            if self.conf.agent_mode == lib_const.L3_AGENT_MODE_DVR_SNAT:
                kwargs['state_change_callback'] = self.enqueue_state_change
                return dvr_edge_ha_router.DvrEdgeHaRouter(*args, **kwargs)

        if router.get('distributed'):
            if self.conf.agent_mode == lib_const.L3_AGENT_MODE_DVR_SNAT:
                return dvr_router.DvrEdgeRouter(*args, **kwargs)
            else:
                return dvr_local_router.DvrLocalRouter(*args, **kwargs)

        if router.get('ha'):
            kwargs['state_change_callback'] = self.enqueue_state_change
            return ha_router.HaRouter(*args, **kwargs)

        return legacy_router.LegacyRouter(*args, **kwargs)
예제 #3
0
    def test_initialize_dvr_ha_router_reset_state(self):
        agent = l3_agent.L3NATAgent(HOSTNAME, self.conf)
        agent.conf.agent_mode = lib_constants.L3_AGENT_MODE_DVR_SNAT
        router = l3_test_common.prepare_router_data(num_internal_ports=2,
                                                    enable_ha=True)
        router['gw_port_host'] = HOSTNAME
        router[lib_constants.HA_INTERFACE_KEY]['status'] = 'ACTIVE'
        self.mock_driver.unplug.reset_mock()
        self._set_ri_kwargs(agent, router['id'], router)

        ri = dvr_edge_ha_rtr.DvrEdgeHaRouter(HOSTNAME, **self.ri_kwargs)
        ri._ha_state_path = self.get_temp_file_path('router_ha_state')

        with open(ri._ha_state_path, "w") as f:
            f.write("primary")

        ri._create_snat_namespace = mock.Mock()
        ri._plug_external_gateway = mock.Mock()
        with mock.patch(
                "neutron.agent.linux.keepalived."
                "KeepalivedManager.check_processes",
                return_value=False):
            ri.initialize(mock.Mock())
            with open(ri._ha_state_path, "r") as f:
                state = f.readline()
                self.assertEqual("backup", state)
예제 #4
0
    def test_remove_centralized_floatingip(
            self, super_remove_centralized_floatingip):
        agent = l3_agent.L3NATAgent(HOSTNAME, self.conf)
        agent.conf.agent_mode = lib_constants.L3_AGENT_MODE_DVR_SNAT
        router = l3_test_common.prepare_router_data(num_internal_ports=2)
        router['gw_port_host'] = HOSTNAME
        self.mock_driver.unplug.reset_mock()
        self._set_ri_kwargs(agent, router['id'], router)
        fip_cidr = '11.22.33.44/24'

        ri = dvr_edge_ha_rtr.DvrEdgeHaRouter(HOSTNAME, **self.ri_kwargs)
        ri.is_router_primary = mock.Mock(return_value=False)
        ri._remove_vip = mock.Mock()
        ri.remove_centralized_floatingip(fip_cidr)
        ri._remove_vip.assert_called_once_with(fip_cidr)
        super_remove_centralized_floatingip.assert_not_called()

        ri1 = dvr_edge_ha_rtr.DvrEdgeHaRouter(HOSTNAME, **self.ri_kwargs)
        ri1.is_router_primary = mock.Mock(return_value=True)
        ri1._remove_vip = mock.Mock()
        ri1.remove_centralized_floatingip(fip_cidr)
        ri1._remove_vip.assert_called_once_with(fip_cidr)
        super_remove_centralized_floatingip.assert_called_once_with(fip_cidr)
예제 #5
0
 def test_initialize_dvr_ha_router_snat_ns_once(self):
     agent = l3_agent.L3NATAgent(HOSTNAME, self.conf)
     agent.conf.agent_mode = lib_constants.L3_AGENT_MODE_DVR_SNAT
     router = l3_test_common.prepare_router_data(num_internal_ports=2,
                                                 enable_ha=True)
     router['gw_port_host'] = HOSTNAME
     router[lib_constants.HA_INTERFACE_KEY]['status'] = 'ACTIVE'
     self.mock_driver.unplug.reset_mock()
     self._set_ri_kwargs(agent, router['id'], router)
     ri = dvr_edge_ha_rtr.DvrEdgeHaRouter(HOSTNAME, **self.ri_kwargs)
     ri._create_snat_namespace = mock.Mock()
     ri._plug_external_gateway = mock.Mock()
     ri.initialize(mock.Mock())
     ri._create_dvr_gateway(mock.Mock(), mock.Mock())
     ri._create_snat_namespace.assert_called_once_with()
예제 #6
0
    def _create_router(self, router_id, router):
        args = []
        kwargs = {
            'agent': self,
            'router_id': router_id,
            'router': router,
            'use_ipv6': self.use_ipv6,
            'agent_conf': self.conf,
            'interface_driver': self.driver,
        }

        if router.get('distributed'):
            kwargs['host'] = self.host

        if router.get('distributed') and router.get('ha'):
            # Case 1: If the router contains information about the HA interface
            # and if the requesting agent is a DVR_SNAT agent then go ahead
            # and create a HA router.
            # Case 2: If the router does not contain information about the HA
            # interface this means that this DVR+HA router needs to host only
            # the edge side of it, typically because it's landing on a node
            # that needs to provision a router namespace because of a DVR
            # service port (e.g. DHCP). So go ahead and create a regular DVR
            # edge router.
            if (self.conf.agent_mode == lib_const.L3_AGENT_MODE_DVR_SNAT
                    and router.get(lib_const.HA_INTERFACE_KEY) is not None):
                kwargs['state_change_callback'] = self.enqueue_state_change
                return dvr_edge_ha_router.DvrEdgeHaRouter(*args, **kwargs)

        if router.get('distributed'):
            if self.conf.agent_mode == lib_const.L3_AGENT_MODE_DVR_SNAT:
                return dvr_router.DvrEdgeRouter(*args, **kwargs)
            else:
                return dvr_local_router.DvrLocalRouter(*args, **kwargs)

        if router.get('ha'):
            kwargs['state_change_callback'] = self.enqueue_state_change
            return ha_router.HaRouter(*args, **kwargs)

        return legacy_router.LegacyRouter(*args, **kwargs)