db: Add attachment_id to block_device_mapping
This adds an attachment_id column to the block_device_mapping table as required for Nova to begin interacting with cinder v3. Implements: blueprint cinder-new-attach-apis Change-Id: I5d6afbc22ee89b764440f3313229a29311883f52
This commit is contained in:
parent
2380659e35
commit
7653261efc
nova
@ -48,7 +48,7 @@ bdm_new_fields = set(['source_type', 'destination_type',
|
||||
'connection_info', 'tag'])
|
||||
|
||||
|
||||
bdm_db_only_fields = set(['id', 'instance_uuid'])
|
||||
bdm_db_only_fields = set(['id', 'instance_uuid', 'attachment_id'])
|
||||
|
||||
|
||||
bdm_db_inherited_fields = set(['created_at', 'updated_at',
|
||||
|
@ -0,0 +1,28 @@
|
||||
# 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.
|
||||
|
||||
|
||||
from sqlalchemy import Column
|
||||
from sqlalchemy import MetaData
|
||||
from sqlalchemy import String
|
||||
from sqlalchemy import Table
|
||||
|
||||
|
||||
def upgrade(migrate_engine):
|
||||
meta = MetaData()
|
||||
meta.bind = migrate_engine
|
||||
|
||||
for prefix in ('', 'shadow_'):
|
||||
table = Table(prefix + 'block_device_mapping', meta, autoload=True)
|
||||
new_column = Column('attachment_id', String(36), nullable=True)
|
||||
if not hasattr(table.c, 'attachment_id'):
|
||||
table.create_column(new_column)
|
@ -623,6 +623,8 @@ class BlockDeviceMapping(BASE, NovaBase, models.SoftDeleteMixin):
|
||||
|
||||
tag = Column(String(255))
|
||||
|
||||
attachment_id = Column(String(36))
|
||||
|
||||
|
||||
class SecurityGroupInstanceAssociation(BASE, NovaBase, models.SoftDeleteMixin):
|
||||
__tablename__ = 'security_group_instance_association'
|
||||
|
@ -6360,14 +6360,22 @@ class BlockDeviceMappingTestCase(test.TestCase):
|
||||
bdm = self._create_bdm({})
|
||||
self.assertIsNotNone(bdm)
|
||||
|
||||
def test_block_device_mapping_create_with_attachment_id(self):
|
||||
bdm = self._create_bdm({'attachment_id': uuidsentinel.attachment_id})
|
||||
self.assertEqual(uuidsentinel.attachment_id, bdm.attachment_id)
|
||||
|
||||
def test_block_device_mapping_update(self):
|
||||
bdm = self._create_bdm({})
|
||||
self.assertIsNone(bdm.attachment_id)
|
||||
result = db.block_device_mapping_update(
|
||||
self.ctxt, bdm['id'], {'destination_type': 'moon'},
|
||||
legacy=False)
|
||||
self.ctxt, bdm['id'],
|
||||
{'destination_type': 'moon',
|
||||
'attachment_id': uuidsentinel.attachment_id},
|
||||
legacy=False)
|
||||
uuid = bdm['instance_uuid']
|
||||
bdm_real = db.block_device_mapping_get_all_by_instance(self.ctxt, uuid)
|
||||
self.assertEqual(bdm_real[0]['destination_type'], 'moon')
|
||||
self.assertEqual(uuidsentinel.attachment_id, bdm_real[0].attachment_id)
|
||||
# Also make sure the update call returned correct data
|
||||
self.assertEqual(dict(bdm_real[0]),
|
||||
dict(result))
|
||||
|
@ -943,6 +943,10 @@ class NovaMigrationsCheckers(test_migrations.ModelsMigrationsSync,
|
||||
'instances_updated_at_project_id_idx',
|
||||
['updated_at', 'project_id'])
|
||||
|
||||
def _check_358(self, engine, data):
|
||||
self.assertColumnExists(engine, 'block_device_mapping',
|
||||
'attachment_id')
|
||||
|
||||
|
||||
class TestNovaMigrationsSQLite(NovaMigrationsCheckers,
|
||||
test_base.DbTestCase,
|
||||
|
Loading…
x
Reference in New Issue
Block a user