コード例 #1
0
 def test_dvr_port_binding_deleted_by_port_deletion(self):
     with self.ctx.session.begin(subtransactions=True):
         self.ctx.session.add(models_v2.Network(id='network_id'))
         device_owner = constants.DEVICE_OWNER_DVR_INTERFACE
         port = models_v2.Port(
             id='port_id',
             network_id='network_id',
             mac_address='00:11:22:33:44:55',
             admin_state_up=True,
             status=constants.PORT_STATUS_ACTIVE,
             device_id='device_id',
             device_owner=device_owner)
         self.ctx.session.add(port)
         binding_kwarg = {
             'port_id': 'port_id',
             'host': 'host',
             'vif_type': portbindings.VIF_TYPE_UNBOUND,
             'vnic_type': portbindings.VNIC_NORMAL,
             'router_id': 'router_id',
             'status': constants.PORT_STATUS_DOWN
         }
         self.ctx.session.add(models.DVRPortBinding(**binding_kwarg))
         binding_kwarg['host'] = 'another-host'
         self.ctx.session.add(models.DVRPortBinding(**binding_kwarg))
     with warnings.catch_warnings(record=True) as warning_list:
         with self.ctx.session.begin(subtransactions=True):
             self.ctx.session.delete(port)
         self.assertEqual([], warning_list)
     ports = ml2_db.get_dvr_port_bindings(self.ctx.session, 'port_id')
     self.assertEqual(0, len(ports))
コード例 #2
0
 def create_network(self, context, network):
     """Handle creation of a single network."""
     # single request processing
     n = network['network']
     # NOTE(jkoelker) Get the tenant_id outside of the session to avoid
     #                unneeded db action if the operation raises
     tenant_id = self._get_tenant_id_for_create(context, n)
     with context.session.begin(subtransactions=True):
         args = {
             'tenant_id': tenant_id,
             'id': n.get('id') or uuidutils.generate_uuid(),
             'name': n['name'],
             'admin_state_up': n['admin_state_up'],
             'mtu': n.get('mtu', constants.DEFAULT_NETWORK_MTU),
             'status': n.get('status', constants.NET_STATUS_ACTIVE)
         }
         # TODO(pritesh): Move vlan_transparent to the extension module.
         # vlan_transparent here is only added if the vlantransparent
         # extension is enabled.
         if ('vlan_transparent' in n and
                 n['vlan_transparent'] != attributes.ATTR_NOT_SPECIFIED):
             args['vlan_transparent'] = n['vlan_transparent']
         network = models_v2.Network(**args)
         if n['shared']:
             entry = rbac_db.NetworkRBAC(network=network,
                                         action='access_as_shared',
                                         target_tenant='*',
                                         tenant_id=network['tenant_id'])
             context.session.add(entry)
         context.session.add(network)
     return self._make_network_dict(network,
                                    process_extensions=False,
                                    context=context)
コード例 #3
0
ファイル: test_db.py プロジェクト: dingboopt/neutron-x
    def _setup_port_binding(self, network_id='network_id', dvr=True):
        with self.ctx.session.begin(subtransactions=True):
            self.ctx.session.add(models_v2.Network(id=network_id))
            device_owner = constants.DEVICE_OWNER_DVR_INTERFACE if dvr else ''
            self.ctx.session.add(
                models_v2.Port(id='port_id',
                               network_id=network_id,
                               mac_address='00:11:22:33:44:55',
                               admin_state_up=True,
                               status=constants.PORT_STATUS_ACTIVE,
                               device_id='',
                               device_owner=device_owner))
            port_binding_cls = (models.DVRPortBinding
                                if dvr else models.PortBinding)
            binding_kwarg = {
                'port_id': 'port_id',
                'host': helpers.HOST,
                'vif_type': portbindings.VIF_TYPE_UNBOUND,
                'vnic_type': portbindings.VNIC_NORMAL
            }
            if dvr:
                binding_kwarg['router_id'] = 'router_id'
                binding_kwarg['status'] = constants.PORT_STATUS_DOWN

            self.ctx.session.add(port_binding_cls(**binding_kwarg))
コード例 #4
0
 def _make_net(self):
     with self.ctx.session.begin():
         net = models_v2.Network(name='net_net',
                                 status='ACTIVE',
                                 tenant_id='1',
                                 admin_state_up=True)
         self.ctx.session.add(net)
     return net
コード例 #5
0
 def _make_net(self):
     with db_api.context_manager.writer.using(self.ctx):
         net = models_v2.Network(name='net_net',
                                 status='ACTIVE',
                                 tenant_id='1',
                                 admin_state_up=True)
         self.ctx.session.add(net)
     return net
コード例 #6
0
ファイル: test_nsx_db.py プロジェクト: yuhui7red/neutron
 def _setup_neutron_network_and_port(self, network_id, port_id):
     with self.ctx.session.begin(subtransactions=True):
         self.ctx.session.add(models_v2.Network(id=network_id))
         port = models_v2.Port(id=port_id,
                               network_id=network_id,
                               mac_address='foo_mac_address',
                               admin_state_up=True,
                               status='ACTIVE',
                               device_id='',
                               device_owner='')
         self.ctx.session.add(port)
コード例 #7
0
ファイル: test_utils.py プロジェクト: stackhpc/neutron
    def test_1(self):
        context = n_context.Context(user_id=None,
                                    tenant_id=None,
                                    is_admin=True,
                                    overwrite=False)
        self.assertFalse(utils.is_session_active(context.session))
        with db_api.CONTEXT_WRITER.using(context):
            net = models_v2.Network(id=uuidutils.generate_uuid())
            context.session.add(net)
            self.assertTrue(utils.is_session_active(context.session))

        self.assertFalse(utils.is_session_active(context.session))
コード例 #8
0
 def _make_net(self, n, is_shared=False, is_external=False):
     session = self.context.session
     network = models_v2.Network(tenant_id='fake-tenant-id',
                                 name='test-network-{0}'.format(n),
                                 status='ACTIVE',
                                 admin_state_up=True,
                                 shared=is_shared)
     session.add(network)
     session.flush()
     if is_external:
         extnet = external_net_db.ExternalNetwork(network_id=network['id'])
         session.add(extnet)
         session.flush()
     return network
コード例 #9
0
 def _setup_neutron_network(self, network_id, port_ids):
     with self.ctx.session.begin(subtransactions=True):
         self.ctx.session.add(models_v2.Network(id=network_id))
         ports = []
         for port_id in port_ids:
             mac_address = (db_base_plugin_v2.NeutronDbPluginV2.
                            _generate_mac())
             port = models_v2.Port(id=port_id,
                                   network_id=network_id,
                                   mac_address=mac_address,
                                   admin_state_up=True,
                                   status='ACTIVE',
                                   device_id='',
                                   device_owner='')
             self.ctx.session.add(port)
             ports.append(port)
         return ports
コード例 #10
0
ファイル: test_db.py プロジェクト: fcxliang/lzf5-study
 def _create_ha_router(self, distributed=False):
     helpers.register_l3_agent(HOST_2)
     helpers.register_ovs_agent(HOST_2, tunneling_ip=HOST_2_TUNNELING_IP)
     # Register l3 agent on host3, which doesn't host any HA router.
     # Tests should test that host3 is not a HA agent host.
     helpers.register_l3_agent(HOST_3)
     helpers.register_ovs_agent(HOST_3, tunneling_ip=HOST_3_TUNNELING_IP)
     with self.ctx.session.begin(subtransactions=True):
         self.ctx.session.add(models_v2.Network(id=TEST_HA_NETWORK_ID))
         self._create_router(distributed=distributed, ha=True)
         for state, host in [(n_const.HA_ROUTER_STATE_ACTIVE, HOST),
                             (n_const.HA_ROUTER_STATE_STANDBY, HOST_2)]:
             self._setup_port_binding(
                 network_id=TEST_HA_NETWORK_ID,
                 device_owner=constants.DEVICE_OWNER_ROUTER_HA_INTF,
                 device_id=TEST_ROUTER_ID,
                 host_state=state,
                 host=host)
コード例 #11
0
    def test_network_view_mapping(self):
        # prepare grid
        self._create_default_grid()

        # prepare members
        self._create_simple_members()
        db_members = infoblox_db.get_members(self.ctx.session)
        gm_member = utils.find_one_in_list('member_type', 'GM', db_members)

        # prepare network
        network = models_v2.Network(name="Test Network", status="ON",
                                    admin_state_up=True)
        self.ctx.session.add(network)
        self.ctx.session.flush()

        # prepare network view
        netview_dict = {'hs-view-1': gm_member.member_id}
        self._create_network_views(netview_dict)

        db_network_views = infoblox_db.get_network_views(self.ctx.session)
        network_view_id = db_network_views[0].id

        # test associate network view
        network_id = network.id
        subnet_id = 'test-subnet-id'
        infoblox_db.associate_network_view(self.ctx.session, network_view_id,
                                           network_id, subnet_id)
        db_network_view_mappings = infoblox_db.get_network_view_mappings(
            self.ctx.session)
        self.assertEqual(network_id, db_network_view_mappings[0].network_id)
        self.assertEqual(subnet_id, db_network_view_mappings[0].subnet_id)

        db_network_views = infoblox_db.get_network_view_by_mapping(
            self.ctx.session,
            network_id=network_id,
            subnet_id=subnet_id)
        self.assertEqual(network_view_id, db_network_views[0].id)

        # test dissociate network view
        infoblox_db.dissociate_network_view(self.ctx.session, network_id,
                                            subnet_id)
        db_network_view_mappings = infoblox_db.get_network_view_mappings(
            self.ctx.session, network_id=network_id, subnet_id=subnet_id)
        self.assertEqual([], db_network_view_mappings)
コード例 #12
0
    def test_get_router_api(self):
        ctx = mock.Mock()
        router_id = _uuid()

        router_addr = '172.16.18.10'

        server = self._nova_client.servers.get.return_value
        server.addresses = {
            'external': [{
                'addr': router_addr,
            }]
        }

        query = ctx.session.query.return_value
        query.filter_by.return_value.one.return_value = models_v2.Network(
            name='external')

        with mock.patch.object(vyatta_client.VRouterRestAPIClient,
                               'connect') as api_connect:
            api = self.driver._get_router_api(ctx, router_id)
            self.assertIsNotNone(api)
            api_connect.assert_called_once_with(router_addr)
コード例 #13
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.context', autospec=True)
     mock_context = ctx_patcher.start()
     self.addCleanup(db_api.clear_db)
     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_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 = models_v2.Network(id=self.ext_net_id,
                                      tenant_id=self.tenant_id,
                                      admin_state_up=True,
                                      status=constants.NET_STATUS_ACTIVE)
     self.net_ext = external_net_db.ExternalNetwork(
         network_id=self.ext_net_id)
     self.context.session.add(self.network)
     # The following is to avoid complains from sqlite on
     # foreign key violations
     self.context.session.flush()
     self.context.session.add(self.net_ext)
     self.router = l3_db.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 = models_v2.Port(
         id=FAKE_GW_PORT_ID,
         tenant_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=FAKE_GW_PORT_MAC,
         network_id=self.ext_net_id)
     self.router.gw_port_id = self.router_gw_port.id
     self.context.session.add(self.router)
     self.context.session.add(self.router_gw_port)
     self.context.session.flush()
     self.fip_ext_port = models_v2.Port(
         id=FAKE_FIP_EXT_PORT_ID,
         tenant_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=FAKE_FIP_EXT_PORT_MAC,
         network_id=self.ext_net_id)
     self.context.session.add(self.fip_ext_port)
     self.context.session.flush()
     self.int_net = models_v2.Network(id=self.int_net_id,
                                      tenant_id=self.tenant_id,
                                      admin_state_up=True,
                                      status=constants.NET_STATUS_ACTIVE)
     self.int_sub = models_v2.Subnet(id=self.int_sub_id,
                                     tenant_id=self.tenant_id,
                                     ip_version=4,
                                     cidr='3.3.3.0/24',
                                     gateway_ip='3.3.3.1',
                                     network_id=self.int_net_id)
     self.router_port = models_v2.Port(
         id=FAKE_ROUTER_PORT_ID,
         tenant_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=FAKE_ROUTER_PORT_MAC,
         network_id=self.int_net_id)
     self.router_port_ip_info = models_v2.IPAllocation(
         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.context.session.add(self.int_net)
     self.context.session.add(self.int_sub)
     self.context.session.add(self.router_port)
     self.context.session.add(self.router_port_ip_info)
     self.context.session.flush()
     self.fip_int_port = models_v2.Port(id=FAKE_FIP_INT_PORT_ID,
                                        tenant_id=self.tenant_id,
                                        admin_state_up=True,
                                        device_id='something',
                                        device_owner='compute:nova',
                                        status=constants.PORT_STATUS_ACTIVE,
                                        mac_address=FAKE_FIP_INT_PORT_MAC,
                                        network_id=self.int_net_id)
     self.fip_int_ip_info = models_v2.IPAllocation(
         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_db.FloatingIP(id=_uuid(),
                                 floating_ip_address='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.context.session.add(self.fip_int_port)
     self.context.session.add(self.fip_int_ip_info)
     self.context.session.add(self.fip)
     self.context.session.flush()
     self.fip_request = {
         'port_id': FAKE_FIP_INT_PORT_ID,
         'tenant_id': self.tenant_id
     }
コード例 #14
0
 def _setup_neutron_network(self, network_id):
     with self.ctx.session.begin(subtransactions=True):
         self.ctx.session.add(models_v2.Network(id=network_id))
コード例 #15
0
 def _save_network(self, network_id):
     ctx = context.get_admin_context()
     with ctx.session.begin(subtransactions=True):
         ctx.session.add(models_v2.Network(id=network_id))
     network = ctx.session.query(models_v2.Network).one()
     return network.standard_attr_id
コード例 #16
0
ファイル: test_db.py プロジェクト: fcxliang/lzf5-study
 def _create_network(self, network_id=TEST_NETWORK_ID):
     with self.ctx.session.begin(subtransactions=True):
         self.ctx.session.add(models_v2.Network(id=network_id))
コード例 #17
0
 def _save_networks(self, networks):
     ctx = context.get_admin_context()
     for network_id in networks:
         with ctx.session.begin(subtransactions=True):
             ctx.session.add(models_v2.Network(id=network_id))
コード例 #18
0
 def _save_networks(self, networks):
     for network_id in networks:
         with self.ctx.session.begin(subtransactions=True):
             self.ctx.session.add(models_v2.Network(id=network_id))