Browse Source

Merge "Fix rebuild of baremetal instance when vm_state is ERROR"

changes/72/671072/16
Zuul 1 week ago
parent
commit
ba3147420c
2 changed files with 23 additions and 3 deletions
  1. 19
    1
      nova/tests/unit/virt/ironic/test_driver.py
  2. 4
    2
      nova/virt/ironic/driver.py

+ 19
- 1
nova/tests/unit/virt/ironic/test_driver.py View File

@@ -240,6 +240,23 @@ class IronicDriverTestCase(test.NoDBTestCase):
240 240
         fake_validate.assert_called_once_with(instance)
241 241
         fake_refresh.assert_called_once_with()
242 242
 
243
+    @mock.patch.object(objects.Instance, 'refresh')
244
+    @mock.patch.object(ironic_driver.IronicDriver,
245
+                       '_validate_instance_and_node')
246
+    def test__wait_for_active_from_error(self, fake_validate, fake_refresh):
247
+        instance = fake_instance.fake_instance_obj(self.ctx,
248
+                uuid=uuidutils.generate_uuid(),
249
+                vm_state=vm_states.ERROR,
250
+                task_state=task_states.REBUILD_SPAWNING)
251
+        node = ironic_utils.get_test_node(
252
+                provision_state=ironic_states.ACTIVE)
253
+
254
+        fake_validate.return_value = node
255
+        self.assertRaises(loopingcall.LoopingCallDone,
256
+                self.driver._wait_for_active, instance)
257
+        fake_validate.assert_called_once_with(instance)
258
+        fake_refresh.assert_called_once_with()
259
+
243 260
     @mock.patch.object(objects.Instance, 'refresh')
244 261
     @mock.patch.object(ironic_driver.IronicDriver,
245 262
                        '_validate_instance_and_node')
@@ -275,7 +292,8 @@ class IronicDriverTestCase(test.NoDBTestCase):
275 292
         self._wait_for_active_abort({'vm_state': vm_states.DELETED})
276 293
 
277 294
     def test__wait_for_active_abort_error(self):
278
-        self._wait_for_active_abort({'vm_state': vm_states.ERROR})
295
+        self._wait_for_active_abort({'task_state': task_states.SPAWNING,
296
+                                     'vm_state': vm_states.ERROR})
279 297
 
280 298
     @mock.patch.object(ironic_driver.IronicDriver,
281 299
                        '_validate_instance_and_node')

+ 4
- 2
nova/virt/ironic/driver.py View File

@@ -525,8 +525,10 @@ class IronicDriver(virt_driver.ComputeDriver):
525 525
     def _wait_for_active(self, instance):
526 526
         """Wait for the node to be marked as ACTIVE in Ironic."""
527 527
         instance.refresh()
528
-        if (instance.task_state == task_states.DELETING or
529
-            instance.vm_state in (vm_states.ERROR, vm_states.DELETED)):
528
+        # Ignore REBUILD_SPAWNING when rebuilding from ERROR state.
529
+        if (instance.task_state != task_states.REBUILD_SPAWNING and
530
+                (instance.task_state == task_states.DELETING or
531
+                 instance.vm_state in (vm_states.ERROR, vm_states.DELETED))):
530 532
             raise exception.InstanceDeployFailure(
531 533
                 _("Instance %s provisioning was aborted") % instance.uuid)
532 534
 

Loading…
Cancel
Save