Пример #1
0
    def _initialize_objs(self):
        self.qos_policies = []
        self.ports = []
        self.networks = []
        self.fips = []
        self.router_fips, self.fips_network = self._create_one_router()
        self.fips_ports = []
        self.routers = []
        self.router_networks = []
        fip_cidr = netaddr.IPNetwork('10.10.0.0/24')

        for net_idx in range(2):
            qos_policy = policy_obj.QosPolicy(self.ctx,
                                              id=uuidutils.generate_uuid(),
                                              project_id=self.project_id)
            qos_policy.create()
            self.qos_policies.append(qos_policy)

            # Any QoS policy should have at least one rule, in order to have
            # the port dictionary extended with the QoS policy information; see
            # QoSPlugin._extend_port_resource_request
            qos_rule = rule_obj.QosDscpMarkingRule(
                self.ctx,
                dscp_mark=20,
                id=uuidutils.generate_uuid(),
                qos_policy_id=qos_policy.id)
            qos_rule.create()

            self.fips_ports.append(
                self._create_one_port(1000 + net_idx, self.fips_network.id))
            fip_ip = str(netaddr.IPAddress(fip_cidr.ip + net_idx + 1))
            fip = router_obj.FloatingIP(
                self.ctx,
                id=uuidutils.generate_uuid(),
                project_id=self.project_id,
                floating_ip_address=fip_ip,
                floating_network_id=self.fips_network.id,
                floating_port_id=self.fips_ports[-1].id)
            fip.create()
            self.fips.append(fip)

            network = network_obj.Network(self.ctx,
                                          id=uuidutils.generate_uuid(),
                                          project_id=self.project_id)
            network.create()
            self.networks.append(network)

            for port_idx in range(3):
                self.ports.append(
                    self._create_one_port(net_idx * 16 + port_idx, network.id))

            router, router_network = self._create_one_router()
            self.routers.append(router)
            self.router_networks.append(router_network)
Пример #2
0
    def setUp(self):
        super(PortForwardingExtensionBaseTestCase, self).setUp()

        self.fip_pf_ext = pf.PortForwardingAgentExtension()

        self.context = context.get_admin_context()
        self.connection = mock.Mock()
        self.floatingip2 = router.FloatingIP(context=None, id=_uuid(),
                                             floating_ip_address='172.24.6.12',
                                             floating_network_id=_uuid(),
                                             router_id=_uuid(),
                                             status='ACTIVE')
        self.portforwarding1 = pf_obj.PortForwarding(
            context=None, id=_uuid(), floatingip_id=self.floatingip2.id,
            external_port=1111, protocol='tcp', internal_port_id=_uuid(),
            external_port_range='1111:1111',
            internal_port_range='11111:11111',
            internal_ip_address='1.1.1.1', internal_port=11111,
            floating_ip_address=self.floatingip2.floating_ip_address,
            router_id=self.floatingip2.router_id)

        self.agent = l3_agent.L3NATAgent(HOSTNAME, self.conf)
        self.ex_gw_port = {'id': _uuid()}
        self.fip = {'id': _uuid(),
                    'floating_ip_address': TEST_FIP,
                    'fixed_ip_address': '192.168.0.1',
                    'floating_network_id': _uuid(),
                    'port_id': _uuid(),
                    'host': HOSTNAME}
        self.router = {'id': self.floatingip2.router_id,
                       'gw_port': self.ex_gw_port,
                       'ha': False,
                       'distributed': False,
                       lib_const.FLOATINGIP_KEY: [self.fip]}
        self.router_info = l3router.RouterInfo(
            self.agent, self.floatingip2.router_id, self.router,
            **self.ri_kwargs)
        self.centralized_port_forwarding_fip_set = set(
            [str(self.floatingip2.floating_ip_address) + '/32'])
        self.pf_managed_fips = [self.floatingip2.id]
        self.router_info.ex_gw_port = self.ex_gw_port
        self.router_info.fip_managed_by_port_forwardings = self.pf_managed_fips
        self.agent.router_info[self.router['id']] = self.router_info

        self.get_router_info = mock.patch(
            'neutron.agent.l3.l3_agent_extension_api.'
            'L3AgentExtensionAPI.get_router_info').start()
        self.get_router_info.return_value = self.router_info

        self.agent_api = l3_ext_api.L3AgentExtensionAPI(None, None)
        self.fip_pf_ext.consume_api(self.agent_api)

        self.port_forwardings = [self.portforwarding1]
Пример #3
0
 def _create_test_fip_id_for_port_forwarding(self):
     fake_fip = '172.23.3.0'
     ext_net_id = self._create_external_network_id()
     router_id = self._create_test_router_id()
     values = {
         'floating_ip_address': netaddr.IPAddress(fake_fip),
         'floating_network_id': ext_net_id,
         'floating_port_id':
         self._create_test_port_id(network_id=ext_net_id),
         'router_id': router_id,
     }
     fip_obj = router.FloatingIP(self.context, **values)
     fip_obj.create()
     return fip_obj.id
Пример #4
0
 def test__check_and_get_fip_assoc_with_extra_association_no_change(self):
     fip = {'extra_key': 'value'}
     context = mock.MagicMock()
     floatingip_obj = l3_obj.FloatingIP(
         context,
         id=uuidutils.generate_uuid(),
         floating_network_id=uuidutils.generate_uuid(),
         floating_ip_address=netaddr.IPAddress('8.8.8.8'),
         fixed_port_id=uuidutils.generate_uuid(),
         floating_port_id=uuidutils.generate_uuid())
     with mock.patch.object(l3_db.L3_NAT_dbonly_mixin,
                            '_get_assoc_data',
                            return_value=('1', '2',
                                          '3')) as mock_get_assoc_data:
         self.db._check_and_get_fip_assoc(context, fip, floatingip_obj)
         context.session.query.assert_not_called()
         mock_get_assoc_data.assert_called_once_with(
             mock.ANY, fip, floatingip_obj)
Пример #5
0
 def setUp(self):
     super(TestL3GwModeMixin, self).setUp()
     plugin = __name__ + '.' + TestDbIntPlugin.__name__
     self.setup_coreplugin(plugin)
     self.target_object = TestDbIntPlugin()
     # Patch the context
     ctx_patcher = mock.patch('neutron_lib.context', autospec=True)
     mock_context = ctx_patcher.start()
     self.context = mock_context.get_admin_context()
     # This ensure also calls to elevated work in unit tests
     self.context.elevated.return_value = self.context
     self.context.session = db_api.get_writer_session()
     # Create sample data for tests
     self.ext_net_id = _uuid()
     self.int_net_id = _uuid()
     self.int_sub_id = _uuid()
     self.tenant_id = 'the_tenant'
     self.network = net_obj.Network(
         self.context,
         id=self.ext_net_id,
         project_id=self.tenant_id,
         admin_state_up=True,
         status=constants.NET_STATUS_ACTIVE)
     self.net_ext = net_obj.ExternalNetwork(
         self.context, network_id=self.ext_net_id)
     self.network.create()
     self.net_ext.create()
     self.router = l3_models.Router(
         id=_uuid(),
         name=None,
         tenant_id=self.tenant_id,
         admin_state_up=True,
         status=constants.NET_STATUS_ACTIVE,
         enable_snat=True,
         gw_port_id=None)
     self.context.session.add(self.router)
     self.context.session.flush()
     self.router_gw_port = port_obj.Port(
         self.context,
         id=FAKE_GW_PORT_ID,
         project_id=self.tenant_id,
         device_id=self.router.id,
         device_owner=l3_db.DEVICE_OWNER_ROUTER_GW,
         admin_state_up=True,
         status=constants.PORT_STATUS_ACTIVE,
         mac_address=netaddr.EUI(FAKE_GW_PORT_MAC),
         network_id=self.ext_net_id)
     self.router_gw_port.create()
     self.router.gw_port_id = self.router_gw_port.id
     self.context.session.add(self.router)
     self.context.session.flush()
     self.fip_ext_port = port_obj.Port(
         self.context,
         id=FAKE_FIP_EXT_PORT_ID,
         project_id=self.tenant_id,
         admin_state_up=True,
         device_id=self.router.id,
         device_owner=l3_db.DEVICE_OWNER_FLOATINGIP,
         status=constants.PORT_STATUS_ACTIVE,
         mac_address=netaddr.EUI(FAKE_FIP_EXT_PORT_MAC),
         network_id=self.ext_net_id)
     self.fip_ext_port.create()
     self.context.session.flush()
     self.int_net = net_obj.Network(
         self.context,
         id=self.int_net_id,
         project_id=self.tenant_id,
         admin_state_up=True,
         status=constants.NET_STATUS_ACTIVE)
     self.int_sub = subnet_obj.Subnet(self.context,
         id=self.int_sub_id,
         project_id=self.tenant_id,
         ip_version=constants.IP_VERSION_4,
         cidr=net_utils.AuthenticIPNetwork('3.3.3.0/24'),
         gateway_ip=netaddr.IPAddress('3.3.3.1'),
         network_id=self.int_net_id)
     self.router_port = port_obj.Port(
         self.context,
         id=FAKE_ROUTER_PORT_ID,
         project_id=self.tenant_id,
         admin_state_up=True,
         device_id=self.router.id,
         device_owner=l3_db.DEVICE_OWNER_ROUTER_INTF,
         status=constants.PORT_STATUS_ACTIVE,
         mac_address=netaddr.EUI(FAKE_ROUTER_PORT_MAC),
         network_id=self.int_net_id)
     self.router_port_ip_info = port_obj.IPAllocation(self.context,
         port_id=self.router_port.id,
         network_id=self.int_net.id,
         subnet_id=self.int_sub_id,
         ip_address='3.3.3.1')
     self.int_net.create()
     self.int_sub.create()
     self.router_port.create()
     self.router_port_ip_info.create()
     self.context.session.flush()
     self.fip_int_port = port_obj.Port(
         self.context,
         id=FAKE_FIP_INT_PORT_ID,
         project_id=self.tenant_id,
         admin_state_up=True,
         device_id='something',
         device_owner=constants.DEVICE_OWNER_COMPUTE_PREFIX + 'nova',
         status=constants.PORT_STATUS_ACTIVE,
         mac_address=netaddr.EUI(FAKE_FIP_INT_PORT_MAC),
         network_id=self.int_net_id)
     self.fip_int_ip_info = port_obj.IPAllocation(self.context,
         port_id=self.fip_int_port.id,
         network_id=self.int_net.id,
         subnet_id=self.int_sub_id,
         ip_address='3.3.3.3')
     self.fip = l3_obj.FloatingIP(
         self.context,
         id=_uuid(),
         floating_ip_address=netaddr.IPAddress('1.1.1.2'),
         floating_network_id=self.ext_net_id,
         floating_port_id=FAKE_FIP_EXT_PORT_ID,
         fixed_port_id=None,
         fixed_ip_address=None,
         router_id=None)
     self.fip_int_port.create()
     self.fip_int_ip_info.create()
     self.fip.create()
     self.context.session.flush()
     self.context.session.expire_all()
     self.fip_request = {'port_id': FAKE_FIP_INT_PORT_ID,
                         'tenant_id': self.tenant_id}