summaryrefslogtreecommitdiffstats
path: root/nova/tests
diff options
context:
space:
mode:
authorVishvananda Ishaya <vishvananda@gmail.com>2012-09-17 16:09:41 -0700
committerVishvananda Ishaya <vishvananda@gmail.com>2012-09-17 17:47:12 -0700
commit0cba85cb267994018c8a0d5e40b2ed0b5a7837df (patch)
tree69ca7c526bee084a36908bcaf9ff35d2eca8003a /nova/tests
parent91734bad9139555294fe088d2c2d77a9712652ab (diff)
Improve error handling of scheduler
Modifies scheduler errors to report instance faults and to set instance_state back to None on failure. Related to bug 1051066 Change-Id: Id9f36a75370849db7baf3fe24ce96c6f4284255d
Diffstat (limited to 'nova/tests')
-rw-r--r--nova/tests/scheduler/test_scheduler.py41
1 files changed, 22 insertions, 19 deletions
diff --git a/nova/tests/scheduler/test_scheduler.py b/nova/tests/scheduler/test_scheduler.py
index 2e732546c..3c4a789b6 100644
--- a/nova/tests/scheduler/test_scheduler.py
+++ b/nova/tests/scheduler/test_scheduler.py
@@ -19,16 +19,17 @@
Tests For Scheduler
"""
+import mox
+
from nova.compute import api as compute_api
from nova.compute import power_state
from nova.compute import rpcapi as compute_rpcapi
-from nova.compute import task_states
+from nova.compute import utils as compute_utils
from nova.compute import vm_states
from nova import context
from nova import db
from nova import exception
from nova import flags
-from nova import notifications
from nova.openstack.common import jsonutils
from nova.openstack.common import rpc
from nova.openstack.common import timeutils
@@ -48,9 +49,6 @@ class SchedulerManagerTestCase(test.TestCase):
driver_cls = driver.Scheduler
driver_cls_name = 'nova.scheduler.driver.Scheduler'
- class AnException(Exception):
- pass
-
def setUp(self):
super(SchedulerManagerTestCase, self).setUp()
self.flags(scheduler_driver=self.driver_cls_name)
@@ -153,14 +151,11 @@ class SchedulerManagerTestCase(test.TestCase):
method_name)
def test_run_instance_exception_puts_instance_in_error_state(self):
- """Test that a NoValidHost exception for run_instance puts
- the instance in ERROR state and eats the exception.
- """
-
fake_instance_uuid = 'fake-instance-id'
inst = {"vm_state": "", "task_state": ""}
self._mox_schedule_method_helper('schedule_run_instance')
+ self.mox.StubOutWithMock(compute_utils, 'add_instance_fault_from_exc')
self.mox.StubOutWithMock(db, 'instance_update_and_get_original')
request_spec = {'instance_properties':
@@ -170,21 +165,23 @@ class SchedulerManagerTestCase(test.TestCase):
request_spec, None, None, None, None, {}).AndRaise(
exception.NoValidHost(reason=""))
db.instance_update_and_get_original(self.context, fake_instance_uuid,
- {"vm_state": vm_states.ERROR}).AndReturn((inst, inst))
+ {"vm_state": vm_states.ERROR,
+ "task_state": None}).AndReturn((inst, inst))
+ compute_utils.add_instance_fault_from_exc(self.context,
+ fake_instance_uuid, mox.IsA(exception.NoValidHost),
+ mox.IgnoreArg())
self.mox.ReplayAll()
self.manager.run_instance(self.context, request_spec,
None, None, None, None, {})
def test_prep_resize_no_valid_host_back_in_active_state(self):
- """Test that a NoValidHost exception for prep_resize puts
- the instance in ACTIVE state
- """
fake_instance_uuid = 'fake-instance-id'
inst = {"vm_state": "", "task_state": ""}
self._mox_schedule_method_helper('schedule_prep_resize')
+ self.mox.StubOutWithMock(compute_utils, 'add_instance_fault_from_exc')
self.mox.StubOutWithMock(db, 'instance_update_and_get_original')
request_spec = {'instance_type': 'fake_type',
@@ -204,18 +201,19 @@ class SchedulerManagerTestCase(test.TestCase):
db.instance_update_and_get_original(self.context, fake_instance_uuid,
{"vm_state": vm_states.ACTIVE, "task_state": None}).AndReturn(
(inst, inst))
+ compute_utils.add_instance_fault_from_exc(self.context,
+ fake_instance_uuid, mox.IsA(exception.NoValidHost),
+ mox.IgnoreArg())
self.mox.ReplayAll()
self.manager.prep_resize(**kwargs)
def test_prep_resize_exception_host_in_error_state_and_raise(self):
- """Test that a NoValidHost exception for prep_resize puts
- the instance in ACTIVE state
- """
fake_instance_uuid = 'fake-instance-id'
self._mox_schedule_method_helper('schedule_prep_resize')
+ self.mox.StubOutWithMock(compute_utils, 'add_instance_fault_from_exc')
self.mox.StubOutWithMock(db, 'instance_update_and_get_original')
request_spec = {'instance_properties':
@@ -231,18 +229,23 @@ class SchedulerManagerTestCase(test.TestCase):
}
self.manager.driver.schedule_prep_resize(**kwargs).AndRaise(
- self.AnException('something happened'))
+ test.TestingException('something happened'))
inst = {
"vm_state": "",
"task_state": "",
}
db.instance_update_and_get_original(self.context, fake_instance_uuid,
- {"vm_state": vm_states.ERROR}).AndReturn((inst, inst))
+ {"vm_state": vm_states.ERROR,
+ "task_state": None}).AndReturn((inst, inst))
+ compute_utils.add_instance_fault_from_exc(self.context,
+ fake_instance_uuid, mox.IsA(test.TestingException),
+ mox.IgnoreArg())
self.mox.ReplayAll()
- self.assertRaises(self.AnException, self.manager.prep_resize, **kwargs)
+ self.assertRaises(test.TestingException, self.manager.prep_resize,
+ **kwargs)
class SchedulerTestCase(test.TestCase):