Change TestNewtonCellsCheck to not rely on objects

The usage of objects in TestNewtonCellsCheck to create
records in the database was just a convenience when it
was written but as the models change we have to fallback
to using direct SQL execution, so this makes that change
for cell and host mappings as has been done before for
flavors.

Change-Id: If565bb11bf0fea07d7c9e5f0f6ba708e2ab8f378
This commit is contained in:
Matt Riedemann 2018-03-14 17:35:39 -04:00
parent 9a49767134
commit 8da01e74f3
1 changed files with 37 additions and 46 deletions

View File

@ -375,6 +375,14 @@ class TestNewtonCellsCheck(test.NoDBTestCase):
flavorid='m1.foo', swap=0)
flavors.insert().execute(values)
def _create_cell_mapping(self, **values):
mappings = db_utils.get_table(self.engine, 'cell_mappings')
return mappings.insert().execute(**values).inserted_primary_key[0]
def _create_host_mapping(self, **values):
mappings = db_utils.get_table(self.engine, 'host_mappings')
return mappings.insert().execute(**values).inserted_primary_key[0]
def test_upgrade_with_no_cell_mappings(self):
self._flavor_me()
self.assertRaisesRegex(exception.ValidationError,
@ -383,48 +391,38 @@ class TestNewtonCellsCheck(test.NoDBTestCase):
def test_upgrade_with_only_cell0(self):
self._flavor_me()
cell0 = objects.CellMapping(context=self.context,
uuid=objects.CellMapping.CELL0_UUID,
name='cell0',
transport_url='fake',
database_connection='fake')
cell0.create()
self._create_cell_mapping(uuid=objects.CellMapping.CELL0_UUID,
name='cell0',
transport_url='fake',
database_connection='fake')
self.assertRaisesRegex(exception.ValidationError,
'Cell mappings',
self.migration.upgrade, self.engine)
def test_upgrade_without_cell0(self):
self._flavor_me()
cell1 = objects.CellMapping(context=self.context,
uuid=uuidsentinel.cell1,
name='cell1',
transport_url='fake',
database_connection='fake')
cell1.create()
cell2 = objects.CellMapping(context=self.context,
uuid=uuidsentinel.cell2,
name='cell2',
transport_url='fake',
database_connection='fake')
cell2.create()
self._create_cell_mapping(uuid=uuidsentinel.cell1,
name='cell1',
transport_url='fake',
database_connection='fake')
self._create_cell_mapping(uuid=uuidsentinel.cell2,
name='cell2',
transport_url='fake',
database_connection='fake')
self.assertRaisesRegex(exception.ValidationError,
'Cell0',
self.migration.upgrade, self.engine)
def test_upgrade_with_no_host_mappings(self):
self._flavor_me()
cell0 = objects.CellMapping(context=self.context,
uuid=objects.CellMapping.CELL0_UUID,
name='cell0',
transport_url='fake',
database_connection='fake')
cell0.create()
cell1 = objects.CellMapping(context=self.context,
uuid=uuidsentinel.cell1,
name='cell1',
transport_url='fake',
database_connection='fake')
cell1.create()
self._create_cell_mapping(uuid=objects.CellMapping.CELL0_UUID,
name='cell0',
transport_url='fake',
database_connection='fake')
self._create_cell_mapping(uuid=uuidsentinel.cell1,
name='cell1',
transport_url='fake',
database_connection='fake')
with mock.patch.object(self.migration, 'LOG') as log:
self.migration.upgrade(self.engine)
@ -432,22 +430,15 @@ class TestNewtonCellsCheck(test.NoDBTestCase):
def test_upgrade_with_required_mappings(self):
self._flavor_me()
cell0 = objects.CellMapping(context=self.context,
uuid=objects.CellMapping.CELL0_UUID,
name='cell0',
transport_url='fake',
database_connection='fake')
cell0.create()
cell1 = objects.CellMapping(context=self.context,
uuid=uuidsentinel.cell1,
name='cell1',
transport_url='fake',
database_connection='fake')
cell1.create()
hostmapping = objects.HostMapping(context=self.context,
cell_mapping=cell1,
host='foo')
hostmapping.create()
self._create_cell_mapping(uuid=objects.CellMapping.CELL0_UUID,
name='cell0',
transport_url='fake',
database_connection='fake')
cell1_id = self._create_cell_mapping(uuid=uuidsentinel.cell1,
name='cell1',
transport_url='fake',
database_connection='fake')
self._create_host_mapping(cell_id=cell1_id, host='foo')
self.migration.upgrade(self.engine)