@@ -2273,6 +2273,49 @@ def test_init_instance_cleans_image_state_reboot_started_hard(self):
2273
2273
instance.power_state = power_state.RUNNING
2274
2274
self._test_init_instance_cleans_reboot_state(instance)
2275
2275
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
+
2276
2319
def test_init_instance_retries_power_off(self):
2277
2320
instance = objects.Instance(self.context)
2278
2321
instance.uuid = uuids.instance
0 commit comments