From fb1f3502da1839d7bb700af16cc3a107da5d8624 Mon Sep 17 00:00:00 2001 From: Russell Bryant Date: Fri, 21 Sep 2012 13:51:15 -0400 Subject: [PATCH] Set volume status to error if scheduling fails. Fix bug 1053931. When scheduling volume creation fails, the volume was left with a status of 'creating'. This patch changes the scheduler manager to set the status to 'error' if scheduling fails. This matches the behavior of the cinder scheduler manager in this case. This particular issue was addressed in Cinder as a part of commit f758bde47439be52a743b2b4181d4900f2c1bc8a. Change-Id: Ieb453ab05b3b84de53f72323c536a9567555df1e (cherry picked from commit 75fa03557fd6f1e7c62079e9e89556f1af139202) --- nova/scheduler/manager.py | 6 +++--- nova/tests/scheduler/test_scheduler.py | 12 ++++++++++++ 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/nova/scheduler/manager.py b/nova/scheduler/manager.py index 450111828dfb..09eb7c235866 100644 --- a/nova/scheduler/manager.py +++ b/nova/scheduler/manager.py @@ -78,9 +78,9 @@ class SchedulerManager(manager.Manager): context, volume_id, snapshot_id, image_id) except Exception as ex: with excutils.save_and_reraise_exception(): - self._set_vm_state_and_notify('create_volume', - {'vm_state': vm_states.ERROR}, - context, ex, {}) + LOG.warning(_("Failed to schedule create_volume: %(ex)s") % + locals()) + db.volume_update(context, volume_id, {'status': 'error'}) def live_migration(self, context, instance, dest, block_migration, disk_over_commit): diff --git a/nova/tests/scheduler/test_scheduler.py b/nova/tests/scheduler/test_scheduler.py index 3c4a789b6361..83e9cffc8c58 100644 --- a/nova/tests/scheduler/test_scheduler.py +++ b/nova/tests/scheduler/test_scheduler.py @@ -175,6 +175,18 @@ class SchedulerManagerTestCase(test.TestCase): self.manager.run_instance(self.context, request_spec, None, None, None, None, {}) + def test_create_volume_no_valid_host_puts_volume_in_error(self): + self._mox_schedule_method_helper('schedule_create_volume') + self.mox.StubOutWithMock(db, 'volume_update') + + self.manager.driver.schedule_create_volume(self.context, '1', '2', + None).AndRaise(exception.NoValidHost(reason='')) + db.volume_update(self.context, '1', {'status': 'error'}) + + self.mox.ReplayAll() + self.assertRaises(exception.NoValidHost, self.manager.create_volume, + self.context, '1', '2') + def test_prep_resize_no_valid_host_back_in_active_state(self): fake_instance_uuid = 'fake-instance-id' inst = {"vm_state": "", "task_state": ""}