Merge "Change TestNewtonCellsCheck to not rely on objects"

This commit is contained in:
Zuul 2018-03-17 00:07:10 +00:00 committed by Gerrit Code Review
commit fce1902ea4
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)