db: adding columns to PciDevice table
Adding a column to hold the PCI device parent address in order to facilitate the relationship between physical and virtual functions Partially implements blueprint sriov-physical-function-passthrough Change-Id: I9bd4959172902b07e681057b41fb668d28d0220d
This commit is contained in:
parent
79d6af9508
commit
9f9711578f
|
@ -0,0 +1,40 @@
|
|||
# Copyright 2015 Red Hat Inc
|
||||
# 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.
|
||||
|
||||
#
|
||||
# See blueprint backportable-db-migrations-icehouse
|
||||
# http://lists.openstack.org/pipermail/openstack-dev/2013-March/006827.html
|
||||
|
||||
from sqlalchemy import MetaData, Table, Column, String, Index
|
||||
|
||||
|
||||
def upgrade(migrate_engine):
|
||||
meta = MetaData(bind=migrate_engine)
|
||||
|
||||
# Add a new column to store PCI device parent address
|
||||
pci_devices = Table('pci_devices', meta, autoload=True)
|
||||
shadow_pci_devices = Table('shadow_pci_devices', meta, autoload=True)
|
||||
|
||||
parent_addr = Column('parent_addr', String(12), nullable=True)
|
||||
|
||||
if not hasattr(pci_devices.c, 'parent_addr'):
|
||||
pci_devices.create_column(parent_addr)
|
||||
if not hasattr(shadow_pci_devices.c, 'parent_addr'):
|
||||
shadow_pci_devices.create_column(parent_addr.copy())
|
||||
|
||||
# Create index
|
||||
parent_index = Index('ix_pci_devices_compute_node_id_parent_addr_deleted',
|
||||
pci_devices.c.compute_node_id,
|
||||
pci_devices.c.parent_addr,
|
||||
pci_devices.c.deleted)
|
||||
parent_index.create(migrate_engine)
|
|
@ -1371,6 +1371,8 @@ class PciDevice(BASE, NovaBase, models.SoftDeleteMixin):
|
|||
'compute_node_id', 'deleted'),
|
||||
Index('ix_pci_devices_instance_uuid_deleted',
|
||||
'instance_uuid', 'deleted'),
|
||||
Index('ix_pci_devices_compute_node_id_parent_addr_deleted',
|
||||
'compute_node_id', 'parent_addr', 'deleted'),
|
||||
schema.UniqueConstraint(
|
||||
"compute_node_id", "address", "deleted",
|
||||
name="uniq_pci_devices0compute_node_id0address0deleted")
|
||||
|
@ -1403,6 +1405,7 @@ class PciDevice(BASE, NovaBase, models.SoftDeleteMixin):
|
|||
|
||||
numa_node = Column(Integer, nullable=True)
|
||||
|
||||
parent_addr = Column(String(12), nullable=True)
|
||||
instance = orm.relationship(Instance, backref="pci_devices",
|
||||
foreign_keys=instance_uuid,
|
||||
primaryjoin='and_('
|
||||
|
|
|
@ -8843,9 +8843,11 @@ class PciDeviceDBApiTestCase(test.TestCase, ModelsObjectComparatorMixin):
|
|||
'status': fields.PciDeviceStatus.AVAILABLE,
|
||||
'instance_uuid': '00000000-0000-0000-0000-000000000010',
|
||||
'request_id': None,
|
||||
'parent_addr': '0000:0f:00.1',
|
||||
}, {'id': 3356,
|
||||
'compute_node_id': 1,
|
||||
'address': '0000:0f:03.7',
|
||||
'parent_addr': '0000:0f:03.0',
|
||||
'vendor_id': '8083',
|
||||
'product_id': '1523',
|
||||
'numa_node': 0,
|
||||
|
|
|
@ -805,6 +805,23 @@ class NovaMigrationsCheckers(test_migrations.ModelsMigrationsSync,
|
|||
self.assertIndexMembers(engine, 'instance_system_metadata',
|
||||
'instance_uuid', ['instance_uuid'])
|
||||
|
||||
def _check_313(self, engine, data):
|
||||
|
||||
self.assertColumnExists(engine, 'pci_devices', 'parent_addr')
|
||||
self.assertColumnExists(engine, 'shadow_pci_devices', 'parent_addr')
|
||||
pci_devices = oslodbutils.get_table(engine, 'pci_devices')
|
||||
shadow_pci_devices = oslodbutils.get_table(
|
||||
engine, 'shadow_pci_devices')
|
||||
self.assertIsInstance(pci_devices.c.parent_addr.type,
|
||||
sqlalchemy.types.String)
|
||||
self.assertTrue(pci_devices.c.parent_addr.nullable)
|
||||
self.assertIsInstance(shadow_pci_devices.c.parent_addr.type,
|
||||
sqlalchemy.types.String)
|
||||
self.assertTrue(shadow_pci_devices.c.parent_addr.nullable)
|
||||
self.assertIndexMembers(engine, 'pci_devices',
|
||||
'ix_pci_devices_compute_node_id_parent_addr_deleted',
|
||||
['compute_node_id', 'parent_addr', 'deleted'])
|
||||
|
||||
|
||||
class TestNovaMigrationsSQLite(NovaMigrationsCheckers,
|
||||
test_base.DbTestCase,
|
||||
|
|
Loading…
Reference in New Issue