From b761ea47b97c6df09e21755f7fbaaa2061290fbb Mon Sep 17 00:00:00 2001 From: Chris Dent Date: Tue, 30 Aug 2016 13:10:37 +0000 Subject: [PATCH] [placement] add a placement_aggregates table to api_db In order to facilitate a future extraction of the placement service we want to record the association between a resource provider and an arbitrary aggregate uuid in its own table. A PlacementAggregate model is joined from ResourceProvider via ResourceProviderAggregate. Note that this structure is used so we can join on ids instead of strings (the uuids). A direct mapping between ResourceProvider uuid and Aggregate uuid was mooted earlier in the year but was determined to be suboptimal. The name 'placement_aggregates' is used as the least problematic of several choices after discussion amongst several parties. The data will be used by the forthcoming get_ and set_aggregates methods on the ResourceProvider object. Change-Id: Id0355cb022f68e962af306ff04cf724d22b68d19 Partially-Implements: blueprint generic-resource-pools-ocata --- .../versions/029_placement_aggregates.py | 37 +++++++++++++++++++ nova/db/sqlalchemy/api_models.py | 11 ++++++ .../functional/db/api/test_migrations.py | 4 ++ 3 files changed, 52 insertions(+) create mode 100644 nova/db/sqlalchemy/api_migrations/migrate_repo/versions/029_placement_aggregates.py 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,