]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
NEC plugin: Rename quantum_id column to neutron_id
authorAkihiro Motoki <motoki@da.jp.nec.com>
Thu, 6 Mar 2014 20:22:16 +0000 (05:22 +0900)
committerAkihiro Motoki <motoki@da.jp.nec.com>
Fri, 21 Mar 2014 21:30:13 +0000 (06:30 +0900)
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

neutron/db/migration/alembic_migrations/versions/538732fa21e1_nec_rename_quantum_id_to_neutron_id.py [new file with mode: 0644]
neutron/db/migration/alembic_migrations/versions/HEAD
neutron/plugins/nec/db/api.py
neutron/plugins/nec/db/models.py
neutron/plugins/nec/db/packetfilter.py
neutron/tests/unit/nec/test_db.py

diff --git a/neutron/db/migration/alembic_migrations/versions/538732fa21e1_nec_rename_quantum_id_to_neutron_id.py b/neutron/db/migration/alembic_migrations/versions/538732fa21e1_nec_rename_quantum_id_to_neutron_id.py
new file mode 100644 (file)
index 0000000..0dd6ca1
--- /dev/null
@@ -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)
index 41a258e06d8da037a486419e12de7fcc496869e2..59250f3a78c72908efeb9ad1b9687c2b6f308791 100644 (file)
@@ -1 +1 @@
-2447ad0e9585
+538732fa21e1
index 4b59ae3be5a506e5ea3cc713ce98b5b9dd80bd40..7963fdce45e34eef5b01d301b5135876af73f0fa 100644 (file)
@@ -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):
index 64797f6c0cb812ea2a424b555037e6b5c3bae768..302cb610d5eca8ab1a78dca46e64fdd401e7bff6 100644 (file)
@@ -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):
index ddfa50e3d501be89e555e18fe5f94fee0911c009..0ff3cd5b0c9b2b3d14ff6191c2db0f13a543180b 100644 (file)
@@ -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
index 4766a63af30619d0f80aa6f96ee611d9554e7948..e3b8869071a0aadb4b26a1be994e3b89a6c528da 100644 (file)
@@ -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(