Skip to content

Commit ef08dcb

Browse files
Zuulopenstack-gerrit
authored andcommitted
Merge "Reproducer test of bug #1999674"
2 parents 91f7d23 + e576644 commit ef08dcb

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

nova/tests/unit/compute/test_compute_mgr.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2273,6 +2273,49 @@ def test_init_instance_cleans_image_state_reboot_started_hard(self):
22732273
instance.power_state = power_state.RUNNING
22742274
self._test_init_instance_cleans_reboot_state(instance)
22752275

2276+
def _test_init_instance_cleans_reboot_state_reproducer(self, instance,
2277+
task_state):
2278+
instance.host = self.compute.host
2279+
with test.nested(
2280+
mock.patch.object(self.compute, '_get_power_state',
2281+
return_value=power_state.RUNNING),
2282+
mock.patch.object(instance, 'save', autospec=True),
2283+
mock.patch.object(objects.Instance, 'get_network_info')
2284+
) as (
2285+
_get_power_state,
2286+
instance_save,
2287+
get_network_info
2288+
):
2289+
self.compute._init_instance(self.context, instance)
2290+
# By checking save method is not called we confirm that the init
2291+
# instance does not take into account this use case
2292+
instance_save.assert_not_called()
2293+
# So the instance task_state is still task_state
2294+
self.assertEqual(task_state, instance.task_state)
2295+
self.assertEqual(vm_states.ACTIVE, instance.vm_state)
2296+
2297+
def test_init_instance_cleans_image_state_rebooting(self):
2298+
instance = objects.Instance(self.context)
2299+
instance.uuid = uuids.instance
2300+
instance.vm_state = vm_states.ACTIVE
2301+
instance.task_state = task_states.REBOOTING
2302+
instance.power_state = power_state.RUNNING
2303+
# To uncomment once bug #1999674 is fixed and remove all the code below
2304+
# self._test_init_instance_cleans_reboot_state(instance)
2305+
self._test_init_instance_cleans_reboot_state_reproducer(instance,
2306+
task_states.REBOOTING)
2307+
2308+
def test_init_instance_cleans_image_state_rebooting_hard(self):
2309+
instance = objects.Instance(self.context)
2310+
instance.uuid = uuids.instance
2311+
instance.vm_state = vm_states.ACTIVE
2312+
instance.task_state = task_states.REBOOTING_HARD
2313+
instance.power_state = power_state.RUNNING
2314+
# To uncomment once bug #1999674 is fixed and remove all the code below
2315+
# self._test_init_instance_cleans_reboot_state(instance)
2316+
self._test_init_instance_cleans_reboot_state_reproducer(instance,
2317+
task_states.REBOOTING_HARD)
2318+
22762319
def test_init_instance_retries_power_off(self):
22772320
instance = objects.Instance(self.context)
22782321
instance.uuid = uuids.instance

0 commit comments

Comments
 (0)