Commit af2ab60e by Coco

Fix New DB Schema problems.

According to the comments in link:
https://review.openstack.org/#/c/625630/8/cyborg/db/sqlalchemy/models.py
Fix the problems showed in the link. like: Add "deployable_id" field in
extended_accelerator_requests table, add "in_use"field in attach_handles table
etc.

Change-Id: I618ed466132e2ab0c8a02481367a117d793b2c8a
parent 13a3d5a4
......@@ -17,7 +17,7 @@ import sqlalchemy as sa
state = sa.Enum('Initial', 'Bound', 'BindFailed', name='state')
substate = sa.Enum('Initial', name='substate')
attach_type = sa.Enum('PCI', 'MDEV', name='attach_type')
control_type = sa.Enum('PCI', name='control_type')
cpid_type = sa.Enum('PCI', name='cpid_type')
def upgrade():
......@@ -31,7 +31,7 @@ def upgrade():
sa.Column('created_at', sa.DateTime(), nullable=True),
sa.Column('updated_at', sa.DateTime(), nullable=True),
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('uuid', sa.String(length=36), nullable=False),
sa.Column('uuid', sa.String(length=36), nullable=False, unique=True),
sa.Column('type', sa.String(length=255), nullable=False),
sa.Column('vendor', sa.String(length=255), nullable=False),
sa.Column('model', sa.String(length=255), nullable=False),
......@@ -39,7 +39,6 @@ def upgrade():
sa.Column('vendor_board_info', sa.Text(), nullable=True),
sa.Column('hostname', sa.String(length=255), nullable=False),
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('uuid', name='uniq_devices0uuid'),
mysql_ENGINE='InnoDB',
mysql_DEFAULT_CHARSET='UTF8'
)
......@@ -56,13 +55,14 @@ def upgrade():
sa.Column('root_id', sa.Integer(),
sa.ForeignKey('deployables.id', ondelete='CASCADE'),
nullable=True),
sa.Column('name', sa.String(length=32), nullable=False),
sa.Column('name', sa.String(length=255), nullable=False),
sa.Column('num_accelerators', sa.Integer(), nullable=False),
sa.Column('device_id', sa.Integer(),
sa.ForeignKey('devices.id', ondelete="RESTRICT"),
nullable=False),
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('uuid', name='uniq_deployables0uuid'),
sa.UniqueConstraint('uuid', 'name',
name='uniq_deployables0uuid0name'),
sa.Index('deployables_parent_id_idx', 'parent_id'),
sa.Index('deployables_root_id_idx', 'root_id'),
sa.Index('deployables_device_id_idx', 'device_id'),
......@@ -75,15 +75,13 @@ def upgrade():
sa.Column('created_at', sa.DateTime(), nullable=True),
sa.Column('updated_at', sa.DateTime(), nullable=True),
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('uuid', sa.String(length=36), nullable=False),
sa.Column('uuid', sa.String(length=36), nullable=False, unique=True),
sa.Column('deployable_id', sa.Integer(),
sa.ForeignKey('deployables.id', ondelete="RESTRICT"),
nullable=False),
nullable=False, index=True),
sa.Column('key', sa.Text(), nullable=False),
sa.Column('value', sa.Text(), nullable=False),
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('uuid', name='uniq_attributes0uuid'),
sa.Index('attributes_deployable_id_idx', 'deployable_id'),
mysql_ENGINE='InnoDB',
mysql_DEFAULT_CHARSET='UTF8'
)
......@@ -93,15 +91,12 @@ def upgrade():
sa.Column('created_at', sa.DateTime(), nullable=True),
sa.Column('updated_at', sa.DateTime(), nullable=True),
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('uuid', sa.String(length=36), nullable=False),
sa.Column('device_id', sa.Integer(),
sa.ForeignKey('devices.id', ondelete="RESTRICT"),
nullable=False),
sa.Column('cpid_type', control_type, nullable=False),
sa.Column('cpid_info', sa.Text(), nullable=False),
nullable=False, index=True),
sa.Column('cpid_type', cpid_type, nullable=False),
sa.Column('cpid_info', sa.String(length=255), nullable=False),
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('uuid', name='uniq_controlpath_ids0uuid'),
sa.Index('controlpath_ids_device_id_idx', 'device_id'),
mysql_ENGINE='InnoDB',
mysql_DEFAULT_CHARSET='UTF8'
)
......@@ -111,18 +106,18 @@ def upgrade():
sa.Column('created_at', sa.DateTime(), nullable=True),
sa.Column('updated_at', sa.DateTime(), nullable=True),
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('uuid', sa.String(length=36), nullable=False),
sa.Column('deployable_id', sa.Integer(),
sa.ForeignKey('deployables.id', ondelete="RESTRICT"),
nullable=False),
sa.Column('cpid_id', sa.Integer(),
sa.ForeignKey('controlpath_ids.id', ondelete="RESTRICT"),
nullable=False),
sa.Column('in_use', sa.Boolean(), default=False),
sa.Column('attach_type', attach_type, nullable=False),
sa.Column('attach_info', sa.Text(), nullable=False),
sa.Column('attach_info', sa.String(length=255), nullable=False),
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('uuid', name='uniq_attach_handles0uuid'),
sa.Index('attach_handles_deployable_id_idx', 'deployable_id'),
sa.Index('attach_handles_cpid_id_idx', 'cpid_id'),
mysql_ENGINE='InnoDB',
mysql_DEFAULT_CHARSET='UTF8'
)
......@@ -136,20 +131,20 @@ def upgrade():
sa.Column('name', sa.String(length=255), nullable=False),
sa.Column('profile_json', sa.Text(), nullable=False),
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('uuid', name='uniq_device_profiles0uuid'),
sa.UniqueConstraint('uuid', 'name',
name='uniq_device_profiles0uuid0name'),
mysql_ENGINE='InnoDB',
mysql_DEFAULT_CHARSET='UTF8'
)
op.create_table(
'external_accelerator_requests',
'extended_accelerator_requests',
sa.Column('created_at', sa.DateTime(), nullable=True),
sa.Column('updated_at', sa.DateTime(), nullable=True),
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('uuid', sa.String(length=36), nullable=False),
sa.Column('uuid', sa.String(length=36), nullable=False, unique=True),
sa.Column('project_id', sa.String(length=255), nullable=False),
sa.Column('state', state, nullable=False, default='Initial'),
sa.Column('substate', substate, nullable=False, default='Initial'),
sa.Column('device_profile_id', sa.Integer(),
sa.ForeignKey('device_profiles.id', ondelete="RESTRICT"),
nullable=False),
......@@ -160,18 +155,18 @@ def upgrade():
sa.Column('attach_handle_id', sa.Integer(),
sa.ForeignKey('attach_handles.id', ondelete="RESTRICT"),
nullable=True),
# Cyborg Private Fields begin here.
sa.Column('substate', substate, nullable=False, default='Initial'),
sa.Column('deployable_id', sa.Integer(),
sa.ForeignKey('deployables.id', ondelete="RESTRICT"),
nullable=True),
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('uuid',
name='uniq_external_accelerator_requests0uuid'),
sa.Index('external_accelerator_requests_project_id_idx', 'project_id'),
sa.Index('external_accelerator_requests_device_profile_id_idx',
'device_profile_id'),
sa.Index('external_accelerator_requests_device_rp_uuid_idx',
'device_rp_uuid'),
sa.Index('external_accelerator_requests_device_instance_uuid_idx',
'device_instance_uuid'),
sa.Index('external_accelerator_requests_attach_handle_id_idx',
'attach_handle_id'),
sa.Index('extArqs_project_id_idx', 'project_id'),
sa.Index('extArqs_device_profile_id_idx', 'device_profile_id'),
sa.Index('extArqs_device_rp_uuid_idx', 'device_rp_uuid'),
sa.Index('extArqs_device_instance_uuid_idx', 'device_instance_uuid'),
sa.Index('extArqs_attach_handle_id_idx', 'attach_handle_id'),
sa.Index('extArqs_deployable_id_idx', 'deployable_id'),
mysql_ENGINE='InnoDB',
mysql_DEFAULT_CHARSET='UTF8'
)
......@@ -20,7 +20,8 @@ from oslo_db.sqlalchemy import models
from oslo_utils import timeutils
import six.moves.urllib.parse as urlparse
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import Column, String, Integer, Enum, ForeignKey, Index
from sqlalchemy import Column, String, Integer, Boolean, Enum, ForeignKey, \
Index
from sqlalchemy import Text
from sqlalchemy import schema
from sqlalchemy import DateTime
......@@ -71,13 +72,9 @@ class Device(Base):
"""Represents the devices."""
__tablename__ = 'devices'
__table_args__ = (
schema.UniqueConstraint('uuid', name='uniq_devices0uuid'),
table_args()
)
id = Column(Integer, primary_key=True)
uuid = Column(String(36), nullable=False)
uuid = Column(String(36), nullable=False, unique=True)
type = Column(String(255), nullable=False)
vendor = Column(String(255), nullable=False)
model = Column(String(255), nullable=False)
......@@ -91,7 +88,8 @@ class Deployable(Base):
__tablename__ = 'deployables'
__table_args__ = (
schema.UniqueConstraint('uuid', name='uniq_deployables0uuid'),
schema.UniqueConstraint('uuid', 'name',
name='uniq_deployables0uuid0name'),
Index('deployables_parent_id_idx', 'parent_id'),
Index('deployables_root_id_idx', 'root_id'),
Index('deployables_device_id_idx', 'device_id'),
......@@ -102,7 +100,7 @@ class Deployable(Base):
uuid = Column(String(36), nullable=False)
parent_id = Column(Integer, ForeignKey('deployables.id'), nullable=True)
root_id = Column(Integer, ForeignKey('deployables.id'), nullable=True)
name = Column(String(32), nullable=False)
name = Column(String(255), nullable=False)
num_accelerators = Column(Integer, nullable=False)
device_id = Column(Integer, ForeignKey('devices.id', ondelete="RESTRICT"),
nullable=False)
......@@ -110,17 +108,12 @@ class Deployable(Base):
class Attribute(Base):
__tablename__ = 'attributes'
__table_args__ = (
schema.UniqueConstraint('uuid', name='uniq_attributes0uuid'),
Index('attributes_deployable_id_idx', 'deployable_id'),
table_args()
)
id = Column(Integer, primary_key=True)
uuid = Column(String(36), nullable=False)
uuid = Column(String(36), nullable=False, unique=True)
deployable_id = Column(Integer,
ForeignKey('deployables.id', ondelete="RESTRICT"),
nullable=False)
nullable=False, index=True)
key = Column(Text, nullable=False)
value = Column(Text, nullable=False)
......@@ -130,42 +123,36 @@ class ControlpathID(Base):
needed especially when multiple PFs exist in one Devices."""
__tablename__ = 'controlpath_ids'
__table_args__ = (
schema.UniqueConstraint('uuid', name='uniq_controlpath_ids0uuid'),
Index('controlpath_ids_device_id_idx', 'device_id'),
table_args()
)
id = Column(Integer, primary_key=True)
uuid = Column(String(36), nullable=False)
device_id = Column(Integer,
ForeignKey('devices.id', ondelete="RESTRICT"),
nullable=False)
cpid_type = Column(Enum('PCI', name='control_type'), nullable=False)
cpid_info = Column(Text, nullable=False)
nullable=False, index=True)
cpid_type = Column(Enum('PCI', name='cpid_type'), nullable=False)
cpid_info = Column(String(255), nullable=False)
class AttachHandle(Base):
"""Reprensents device's VFs and PFs which can be attached to a VM."""
"""Represents device's VFs and PFs which can be attached to a VM."""
__tablename__ = 'attach_handles'
__table_args__ = (
schema.UniqueConstraint('uuid', name='uniq_attach_handles0uuid'),
Index('attach_handles_cpid_id_idx', 'cpid_id'),
Index('attach_handles_deployable_id_idx', 'deployable_id'),
table_args()
)
id = Column(Integer, primary_key=True)
uuid = Column(String(36), nullable=False)
deployable_id = Column(Integer,
ForeignKey('deployables.id', ondelete="RESTRICT"),
nullable=False)
cpid_id = Column(Integer,
ForeignKey('controlpath_ids.id', ondelete="RESTRICT"),
nullable=False)
in_use = Column(Boolean, default=False)
attach_type = Column(Enum('PCI', 'MDEV', name='attach_type'),
nullable=False)
attach_info = Column(Text, nullable=False)
attach_info = Column(String(255), nullable=False)
class DeviceProfile(Base):
......@@ -173,7 +160,8 @@ class DeviceProfile(Base):
__tablename__ = 'device_profiles'
__table_args__ = (
schema.UniqueConstraint('uuid', name='uniq_device_profiles0uuid'),
schema.UniqueConstraint('uuid', 'name',
name='uniq_device_profiles0uuid0name'),
table_args()
)
......@@ -183,39 +171,40 @@ class DeviceProfile(Base):
profile_json = Column(Text, nullable=False)
class ExternalAcceleratorRequest(Base):
"""Represents external nova requests for attach related operations."""
class ExtendedAcceleratorRequest(Base):
"""Represents extended nova requests for attach related operations."""
__tablename__ = 'external_accelerator_requests'
__tablename__ = 'extended_accelerator_requests'
__table_args__ = (
schema.UniqueConstraint('uuid', name='uniq_ext_arqs0uuid'),
Index('external_accelerator_requests_project_id_idx', 'project_id'),
Index('external_accelerator_requests_device_profile_id_idx',
'device_profile_id'),
Index('external_accelerator_requests_device_rp_uuid_idx',
'device_rp_uuid'),
Index('external_accelerator_requests_device_instance_uuid_idx',
'device_instance_uuid'),
Index('external_accelerator_requests_attach_handle_id_idx',
'attach_handle_id'),
Index('extArqs_project_id_idx', 'project_id'),
Index('extArqs_device_profile_id_idx', 'device_profile_id'),
Index('extArqs_device_rp_uuid_idx', 'device_rp_uuid'),
Index('extArqs_device_instance_uuid_idx', 'device_instance_uuid'),
Index('extArqs_attach_handle_id_idx', 'attach_handle_id'),
Index('extArqs_deployable_id_idx', 'deployable_id'),
table_args()
)
id = Column(Integer, primary_key=True)
uuid = Column(String(36), nullable=False)
uuid = Column(String(36), nullable=False, unique=True)
project_id = Column(String(255), nullable=False)
state = Column(Enum('Initial', 'Bound', 'BindFailed', name='state'),
nullable=False)
substate = Column(Enum('Initial', name='substate'), nullable=False),
device_profile_id = Column(Integer, ForeignKey('device_profiles.id',
ondelete="RESTRICT"),
nullable=False)
hostname = Column(String(255), nullable=True)
device_rp_uuid = Column(String(36), nullable=True)
device_instance_uuid = Column(String(36), nullable=True)
attach_handle_id = Column(Integer(), ForeignKey('attach_handles.id',
ondelete="RESTRICT"),
attach_handle_id = Column(Integer, ForeignKey('attach_handles.id',
ondelete="RESTRICT"),
nullable=True)
# Cyborg Private Fields
substate = Column(Enum('Initial', name='substate'), nullable=False,
default='Initial')
deployable_id = Column(Integer,
ForeignKey('deployables.id', ondelete="RESTRICT"),
nullable=True)
class QuotaUsage(Base):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment