diff --git a/nova/db/sqlalchemy/api_migrations/migrate_repo/versions/029_placement_aggregates.py b/nova/db/sqlalchemy/api_migrations/migrate_repo/versions/029_placement_aggregates.py new file mode 100644 index 000000000000..9dcdcdeb813f --- /dev/null +++ b/nova/db/sqlalchemy/api_migrations/migrate_repo/versions/029_placement_aggregates.py @@ -0,0 +1,37 @@ +# 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. +"""API Database migrations for placement_aggregates""" + +from migrate import UniqueConstraint +from sqlalchemy import Column +from sqlalchemy import DateTime +from sqlalchemy import Integer +from sqlalchemy import MetaData +from sqlalchemy import String +from sqlalchemy import Table + + +def upgrade(migrate_engine): + meta = MetaData() + meta.bind = migrate_engine + + placement_aggregates = Table('placement_aggregates', meta, + Column('created_at', DateTime), + Column('updated_at', DateTime), + Column('id', Integer, primary_key=True, nullable=False), + Column('uuid', String(length=36), index=True), + UniqueConstraint('uuid', name='uniq_placement_aggregates0uuid'), + mysql_engine='InnoDB', + mysql_charset='latin1' + ) + + placement_aggregates.create(checkfirst=True) diff --git a/nova/db/sqlalchemy/api_models.py b/nova/db/sqlalchemy/api_models.py index e82c71dea488..e5c5720dc3b0 100644 --- a/nova/db/sqlalchemy/api_models.py +++ b/nova/db/sqlalchemy/api_models.py @@ -371,6 +371,17 @@ class ResourceProviderAggregate(API_BASE): aggregate_id = Column(Integer, primary_key=True, nullable=False) +class PlacementAggregate(API_BASE): + """A grouping of resource providers.""" + __tablename__ = 'placement_aggregates' + __table_args__ = ( + schema.UniqueConstraint("uuid", name="uniq_placement_aggregates0uuid"), + ) + + id = Column(Integer, primary_key=True, autoincrement=True) + uuid = Column(String(36), index=True) + + class InstanceGroupMember(API_BASE): """Represents the members for an instance group.""" __tablename__ = 'instance_group_member' diff --git a/nova/tests/functional/db/api/test_migrations.py b/nova/tests/functional/db/api/test_migrations.py index 4a5d4562fcef..13f2717be527 100644 --- a/nova/tests/functional/db/api/test_migrations.py +++ b/nova/tests/functional/db/api/test_migrations.py @@ -571,6 +571,10 @@ class NovaAPIMigrationsWalk(test_migrations.WalkVersionsMixin): self.assertEqual('{"uuid": "foo", "name": "bar"}', fake_build_req.instance) + def _check_029(self, engine, data): + for column in ['created_at', 'updated_at', 'id', 'uuid']: + self.assertColumnExists(engine, 'placement_aggregates', column) + class TestNovaAPIMigrationsWalkSQLite(NovaAPIMigrationsWalk, test_base.DbTestCase,