NEC plugin: Rename quantum_id column to neutron_id
ID mapping tables in NEC plugin had columns named quantum_id. This commit renames them to neutron following project renaming. Closes-Bug: #1287432 Change-Id: I0669defba7189d5b8259365d88d67db51a28c764
This commit is contained in:
parent
f1c7054309
commit
dba196702b
@ -0,0 +1,65 @@
|
||||
# Copyright 2014 OpenStack Foundation
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
#
|
||||
|
||||
"""NEC Rename quantum_id to neutron_id
|
||||
|
||||
Revision ID: 538732fa21e1
|
||||
Revises: 2447ad0e9585
|
||||
Create Date: 2014-03-04 05:43:33.660601
|
||||
|
||||
"""
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = '538732fa21e1'
|
||||
down_revision = '2447ad0e9585'
|
||||
|
||||
# Change to ['*'] if this migration applies to all plugins
|
||||
|
||||
migration_for_plugins = [
|
||||
'neutron.plugins.nec.nec_plugin.NECPluginV2'
|
||||
]
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
from neutron.db import migration
|
||||
|
||||
|
||||
def upgrade(active_plugins=None, options=None):
|
||||
if not migration.should_run(active_plugins, migration_for_plugins):
|
||||
return
|
||||
|
||||
for table in ['ofctenantmappings', 'ofcnetworkmappings',
|
||||
'ofcportmappings', 'ofcfiltermappings',
|
||||
'ofcroutermappings',
|
||||
]:
|
||||
op.alter_column(table, 'quantum_id',
|
||||
new_column_name='neutron_id',
|
||||
existing_type=sa.String(length=36),
|
||||
existing_nullable=False)
|
||||
|
||||
|
||||
def downgrade(active_plugins=None, options=None):
|
||||
if not migration.should_run(active_plugins, migration_for_plugins):
|
||||
return
|
||||
|
||||
for table in ['ofctenantmappings', 'ofcnetworkmappings',
|
||||
'ofcportmappings', 'ofcfiltermappings',
|
||||
'ofcroutermappings',
|
||||
]:
|
||||
op.alter_column(table, 'neutron_id',
|
||||
new_column_name='quantum_id',
|
||||
existing_type=sa.String(length=36),
|
||||
existing_nullable=False)
|
@ -1 +1 @@
|
||||
2447ad0e9585
|
||||
538732fa21e1
|
||||
|
@ -15,8 +15,6 @@
|
||||
# under the License.
|
||||
# @author: Ryota MIBU
|
||||
|
||||
# TODO(amotoki): bug 1287432: Rename quantum_id column in ID mapping tables.
|
||||
|
||||
import sqlalchemy as sa
|
||||
|
||||
from neutron.db import api as db
|
||||
@ -57,7 +55,7 @@ def get_ofc_item(session, resource, neutron_id):
|
||||
if not model:
|
||||
return
|
||||
try:
|
||||
return session.query(model).filter_by(quantum_id=neutron_id).one()
|
||||
return session.query(model).filter_by(neutron_id=neutron_id).one()
|
||||
except sa.orm.exc.NoResultFound:
|
||||
return
|
||||
|
||||
@ -90,7 +88,7 @@ def find_ofc_item(session, resource, ofc_id):
|
||||
def add_ofc_item(session, resource, neutron_id, ofc_id):
|
||||
try:
|
||||
model = _get_resource_model(resource)
|
||||
params = dict(quantum_id=neutron_id, ofc_id=ofc_id)
|
||||
params = dict(neutron_id=neutron_id, ofc_id=ofc_id)
|
||||
item = model(**params)
|
||||
with session.begin(subtransactions=True):
|
||||
session.add(item)
|
||||
@ -105,7 +103,7 @@ def del_ofc_item(session, resource, neutron_id):
|
||||
try:
|
||||
model = _get_resource_model(resource)
|
||||
with session.begin(subtransactions=True):
|
||||
item = session.query(model).filter_by(quantum_id=neutron_id).one()
|
||||
item = session.query(model).filter_by(neutron_id=neutron_id).one()
|
||||
session.delete(item)
|
||||
return True
|
||||
except sa.orm.exc.NoResultFound:
|
||||
@ -154,12 +152,12 @@ def get_active_ports_on_ofc(context, network_id, port_id=None):
|
||||
"""
|
||||
query = context.session.query(nmodels.OFCPortMapping)
|
||||
query = query.join(models_v2.Port,
|
||||
nmodels.OFCPortMapping.quantum_id == models_v2.Port.id)
|
||||
nmodels.OFCPortMapping.neutron_id == models_v2.Port.id)
|
||||
query = query.filter(models_v2.Port.network_id == network_id)
|
||||
if port_id:
|
||||
query = query.filter(nmodels.OFCPortMapping.quantum_id == port_id)
|
||||
query = query.filter(nmodels.OFCPortMapping.neutron_id == port_id)
|
||||
|
||||
return [(p['quantum_id'], p['ofc_id']) for p in query]
|
||||
return [(p['neutron_id'], p['ofc_id']) for p in query]
|
||||
|
||||
|
||||
def get_port_from_device(port_id):
|
||||
|
@ -31,8 +31,8 @@ class OFCId(object):
|
||||
|
||||
|
||||
class NeutronId(object):
|
||||
"""Logical ID on Quantum."""
|
||||
quantum_id = sa.Column(sa.String(36), primary_key=True)
|
||||
"""Logical ID on Neutron."""
|
||||
neutron_id = sa.Column(sa.String(36), primary_key=True)
|
||||
|
||||
|
||||
class OFCTenantMapping(model_base.BASEV2, NeutronId, OFCId):
|
||||
|
@ -202,20 +202,18 @@ class PacketFilterDbMixin(object):
|
||||
|
||||
It returns a list of tuple (neutron filter_id, OFC id).
|
||||
"""
|
||||
# TODO(amotoki): bug 1287432
|
||||
# Rename quantum_id column in ID mapping tables.
|
||||
query = (context.session.query(nmodels.OFCFilterMapping)
|
||||
.join(PacketFilter,
|
||||
nmodels.OFCFilterMapping.quantum_id == PacketFilter.id)
|
||||
nmodels.OFCFilterMapping.neutron_id == PacketFilter.id)
|
||||
.filter(PacketFilter.admin_state_up == True))
|
||||
|
||||
network_id = port['network_id']
|
||||
net_pf_query = (query.filter(PacketFilter.network_id == network_id)
|
||||
.filter(PacketFilter.in_port == None))
|
||||
net_filters = [(pf['quantum_id'], pf['ofc_id']) for pf in net_pf_query]
|
||||
net_filters = [(pf['neutron_id'], pf['ofc_id']) for pf in net_pf_query]
|
||||
|
||||
port_pf_query = query.filter(PacketFilter.in_port == port['id'])
|
||||
port_filters = [(pf['quantum_id'], pf['ofc_id'])
|
||||
port_filters = [(pf['neutron_id'], pf['ofc_id'])
|
||||
for pf in port_pf_query]
|
||||
|
||||
return net_filters + port_filters
|
||||
|
@ -62,7 +62,7 @@ class NECPluginV2DBOfcMappingTest(NECPluginV2DBTestBase):
|
||||
o, q, n = self.get_ofc_item_random_params()
|
||||
tenant = ndb.add_ofc_item(self.session, 'ofc_tenant', q, o)
|
||||
self.assertEqual(tenant.ofc_id, o)
|
||||
self.assertEqual(tenant.quantum_id, q)
|
||||
self.assertEqual(tenant.neutron_id, q)
|
||||
|
||||
def test_add_ofc_item_duplicate_entry(self):
|
||||
o, q, n = self.get_ofc_item_random_params()
|
||||
@ -76,7 +76,7 @@ class NECPluginV2DBOfcMappingTest(NECPluginV2DBTestBase):
|
||||
ndb.add_ofc_item(self.session, 'ofc_tenant', q, o)
|
||||
tenant = ndb.get_ofc_item(self.session, 'ofc_tenant', q)
|
||||
self.assertEqual(tenant.ofc_id, o)
|
||||
self.assertEqual(tenant.quantum_id, q)
|
||||
self.assertEqual(tenant.neutron_id, q)
|
||||
|
||||
def test_get_ofc_item_for_nonexisting_entry(self):
|
||||
self.assertIsNone(
|
||||
@ -108,7 +108,7 @@ class NECPluginV2DBOfcMappingTest(NECPluginV2DBTestBase):
|
||||
ndb.add_ofc_item(self.session, 'ofc_tenant', q, o)
|
||||
tenant = ndb.find_ofc_item(self.session, 'ofc_tenant', o)
|
||||
self.assertEqual(tenant.ofc_id, o)
|
||||
self.assertEqual(tenant.quantum_id, q)
|
||||
self.assertEqual(tenant.neutron_id, q)
|
||||
|
||||
def test_find_ofc_item_for_nonexisting_entry(self):
|
||||
self.assertIsNone(
|
||||
|
Loading…
Reference in New Issue
Block a user