From dbb363df6e80b526dc4f41bf2ba35c36c8b7ce27 Mon Sep 17 00:00:00 2001 From: Dan Smith Date: Wed, 1 Feb 2017 07:58:25 -0800 Subject: [PATCH] Remove pre-cellsv2 short circuit in instance get This removes a couple short circuits around instance cell mapping, which were in place for pre-cellsv2 code. Now, they defeat some of our atomic logic around what should be done in and around deletes. These were TODOs to remove once people had to be on cellsv2, which is now the case. Note that the api samples tests were depending on these in order to work at all (which is a good demonstration of why they need to be removed). This patch also extends the SingleCellSimple fixture with a couple more mocks to make them happily take the same path as the rest of the code. Since the default in that fixture is now to make instances look mapped all the time, we also need a flag so the tests that check for yet-to-be-mapped instances can still function. Related-Bug: #1660878 Change-Id: I7eb4b41fd2f33e8a63e329adbafc47d149e31552 --- nova/tests/fixtures.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/nova/tests/fixtures.py b/nova/tests/fixtures.py index 78039b5dd..c332789b9 100644 --- a/nova/tests/fixtures.py +++ b/nova/tests/fixtures.py @@ -264,8 +264,14 @@ class SingleCellSimple(fixtures.Fixture): If you need to distinguish between cell0 and cellN, then you should use the CellDatabases fixture. + + If instances should appear to still be in scheduling state, pass + instances_created=False to init. """ + def __init__(self, instances_created=True): + self.instances_created = instances_created + def setUp(self): super(SingleCellSimple, self).setUp() self.useFixture(fixtures.MonkeyPatch( @@ -277,6 +283,12 @@ class SingleCellSimple(fixtures.Fixture): self.useFixture(fixtures.MonkeyPatch( 'nova.objects.HostMapping._get_by_host_from_db', self._fake_hostmapping_get)) + self.useFixture(fixtures.MonkeyPatch( + 'nova.objects.InstanceMapping._get_by_instance_uuid_from_db', + self._fake_instancemapping_get)) + self.useFixture(fixtures.MonkeyPatch( + 'nova.objects.InstanceMapping._save_in_db', + self._fake_instancemapping_get)) self.useFixture(fixtures.MonkeyPatch( 'nova.context.target_cell', self._fake_target_cell)) @@ -288,6 +300,18 @@ class SingleCellSimple(fixtures.Fixture): 'host': 'host1', 'cell_mapping': self._fake_cell_list()[0]} + def _fake_instancemapping_get(self, *args): + return { + 'id': 1, + 'updated_at': None, + 'created_at': None, + 'instance_uuid': uuidsentinel.instance, + 'cell_id': (self.instances_created and 1 or None), + 'project_id': 'project', + 'cell_mapping': ( + self.instances_created and self._fake_cell_get() or None), + } + def _fake_cell_get(self, *args): return self._fake_cell_list()[0]