[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
This commit is contained in:
Chris Dent 2016-08-30 13:10:37 +00:00
parent a6053dd608
commit b761ea47b9
3 changed files with 52 additions and 0 deletions

View File

@ -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)

View File

@ -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'

View File

@ -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,