From 8da01e74f3f1326bb47aa30e14b0382fb89cc004 Mon Sep 17 00:00:00 2001 From: Matt Riedemann Date: Wed, 14 Mar 2018 17:35:39 -0400 Subject: [PATCH] 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 --- .../unit/db/test_sqlalchemy_migration.py | 83 +++++++++---------- 1 file changed, 37 insertions(+), 46 deletions(-) diff --git a/nova/tests/unit/db/test_sqlalchemy_migration.py b/nova/tests/unit/db/test_sqlalchemy_migration.py index d5f5675c9efa..7c97301d1177 100644 --- a/nova/tests/unit/db/test_sqlalchemy_migration.py +++ b/nova/tests/unit/db/test_sqlalchemy_migration.py @@ -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)