Make InstanceMappings.cell_id nullable
In order to indicate that an instance boot request has been received, but the instance has not yet been scheduled to a cell, it should be mapped to a null cell_id. This will mean that an instance list/show will need to fetch the instance details from the BuildRequest object rather than looking for the instance in a cell database. A migration is added and the InstanceMapping object is modified to make this possible. Partially-implements: bp cells-scheduling-interaction Change-Id: Iee768512314f11a13e2a85a1e7d5442864ddbc4b
This commit is contained in:
parent
62835426f7
commit
c87fc2344c
|
@ -0,0 +1,22 @@
|
|||
# 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 sqlalchemy import MetaData
|
||||
from sqlalchemy import Table
|
||||
|
||||
|
||||
def upgrade(migrate_engine):
|
||||
meta = MetaData()
|
||||
meta.bind = migrate_engine
|
||||
|
||||
instance_mapping = Table('instance_mappings', meta, autoload=True)
|
||||
instance_mapping.c.cell_id.alter(nullable=True)
|
|
@ -60,7 +60,7 @@ class InstanceMapping(API_BASE):
|
|||
id = Column(Integer, primary_key=True)
|
||||
instance_uuid = Column(String(36), nullable=False)
|
||||
cell_id = Column(Integer, ForeignKey('cell_mappings.id'),
|
||||
nullable=False)
|
||||
nullable=True)
|
||||
project_id = Column(String(255), nullable=False)
|
||||
|
||||
|
||||
|
|
|
@ -30,7 +30,7 @@ class InstanceMapping(base.NovaTimestampObject, base.NovaObject,
|
|||
fields = {
|
||||
'id': fields.IntegerField(read_only=True),
|
||||
'instance_uuid': fields.UUIDField(),
|
||||
'cell_id': fields.IntegerField(),
|
||||
'cell_id': fields.IntegerField(nullable=True),
|
||||
'project_id': fields.StringField(),
|
||||
}
|
||||
|
||||
|
|
|
@ -257,6 +257,18 @@ class NovaAPIMigrationsWalk(test_migrations.WalkVersionsMixin):
|
|||
self.assertEqual(['id'], fk['referred_columns'])
|
||||
self.assertEqual(['request_spec_id'], fk['constrained_columns'])
|
||||
|
||||
def _check_007(self, engine, data):
|
||||
map_table = db_utils.get_table(engine, 'instance_mappings')
|
||||
self.assertTrue(map_table.columns['cell_id'].nullable)
|
||||
|
||||
# Ensure the foreign key still exists
|
||||
inspector = reflection.Inspector.from_engine(engine)
|
||||
# There should only be one foreign key here
|
||||
fk = inspector.get_foreign_keys('instance_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,
|
||||
|
|
|
@ -72,6 +72,10 @@ class InstanceMappingTestCase(test.NoDBTestCase):
|
|||
self.mapping_obj._get_by_instance_uuid_from_db, self.context,
|
||||
mapping['instance_uuid'])
|
||||
|
||||
def test_cell_id_nullable(self):
|
||||
# Just ensure this doesn't raise
|
||||
create_mapping(cell_id=None)
|
||||
|
||||
|
||||
class InstanceMappingListTestCase(test.NoDBTestCase):
|
||||
def setUp(self):
|
||||
|
|
|
@ -87,6 +87,11 @@ class _TestInstanceMappingObject(object):
|
|||
mapping_obj.destroy()
|
||||
destroy_in_db.assert_called_once_with(self.context, uuid)
|
||||
|
||||
def test_cell_id_nullable(self):
|
||||
mapping_obj = objects.InstanceMapping(self.context)
|
||||
# Just ensure this doesn't raise an exception
|
||||
mapping_obj.cell_id = None
|
||||
|
||||
|
||||
class TestInstanceMappingObject(test_objects._LocalTest,
|
||||
_TestInstanceMappingObject):
|
||||
|
|
|
@ -1139,7 +1139,7 @@ object_data = {
|
|||
'InstanceGroupList': '1.7-be18078220513316abd0ae1b2d916873',
|
||||
'InstanceInfoCache': '1.5-cd8b96fefe0fc8d4d337243ba0bf0e1e',
|
||||
'InstanceList': '2.0-6c8ba6147cca3082b1e4643f795068bf',
|
||||
'InstanceMapping': '1.0-47ef26034dfcbea78427565d9177fe50',
|
||||
'InstanceMapping': '1.0-94bff38981ef9ce37c9fccf309b94f58',
|
||||
'InstanceMappingList': '1.0-9e982e3de1613b9ada85e35f69b23d47',
|
||||
'InstanceNUMACell': '1.3-6991a20992c5faa57fae71a45b40241b',
|
||||
'InstanceNUMATopology': '1.2-d944a7d6c21e1c773ffdf09c6d025954',
|
||||
|
|
Loading…
Reference in New Issue