Add Host Mapping table to API Database

This patch creates the host_mappings table in the API database for cellsv2.
This table will contain mapping of compute hosts to cells.

Change-Id: I1bd35434ce186e1fb49d56c621bff3f09aa90138
Implements: blueprint cells-host-mapping
This commit is contained in:
Dheeraj Gupta 2015-06-12 11:00:37 +00:00
parent 50e77aa9b8
commit df2e42d693
3 changed files with 72 additions and 0 deletions

View File

@ -0,0 +1,43 @@
# 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.
from migrate.changeset.constraint import ForeignKeyConstraint
from migrate import UniqueConstraint
from sqlalchemy import Column
from sqlalchemy import DateTime
from sqlalchemy import Index
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
cell_mappings = Table('cell_mappings', meta, autoload=True)
host_mappings = Table('host_mappings', meta,
Column('created_at', DateTime),
Column('updated_at', DateTime),
Column('id', Integer, primary_key=True, nullable=False),
Column('cell_id', Integer, nullable=False),
Column('host', String(length=255), nullable=False),
UniqueConstraint('host',
name='uniq_host_mappings0host'),
Index('host_idx', 'host'),
ForeignKeyConstraint(columns=['cell_id'],
refcolumns=[cell_mappings.c.id]),
mysql_engine='InnoDB',
mysql_charset='utf8'
)
host_mappings.create(checkfirst=True)

View File

@ -56,3 +56,16 @@ class InstanceMapping(API_BASE):
cell_id = Column(Integer, ForeignKey('cell_mappings.id'),
nullable=False)
project_id = Column(String(255), nullable=False)
class HostMapping(API_BASE):
"""Contains mapping of a compute host to which cell it is in"""
__tablename__ = "host_mappings"
__table_args__ = (Index('host_idx', 'host'),
schema.UniqueConstraint('host',
name='uniq_host_mappings0host'))
id = Column(Integer, primary_key=True)
cell_id = Column(Integer, ForeignKey('cell_mappings.id'),
nullable=False)
host = Column(String(255), nullable=False)

View File

@ -172,6 +172,22 @@ class NovaAPIMigrationsWalk(test_migrations.WalkVersionsMixin):
self.assertEqual(['id'], fk['referred_columns'])
self.assertEqual(['cell_id'], fk['constrained_columns'])
def _check_003(self, engine, data):
for column in ['created_at', 'updated_at', 'id',
'cell_id', 'host']:
self.assertColumnExists(engine, 'host_mappings', column)
self.assertIndexExists(engine, 'host_mappings', 'host_idx')
self.assertUniqueConstraintExists(engine, 'host_mappings',
['host'])
inspector = reflection.Inspector.from_engine(engine)
# There should only be one foreign key here
fk = inspector.get_foreign_keys('host_mappings')[0]
self.assertEqual('cell_mappings', fk['referred_table'])
self.assertEqual(['id'], fk['referred_columns'])
self.assertEqual(['cell_id'], fk['constrained_columns'])
class TestNovaAPIMigrationsWalkSQLite(NovaAPIMigrationsWalk,
test_base.DbTestCase,