diff options
| author | Chris Behrens <cbehrens@codestud.com> | 2011-12-15 14:16:42 -0800 |
|---|---|---|
| committer | Chris Behrens <cbehrens@codestud.com> | 2011-12-15 20:54:48 -0800 |
| commit | baf7e02f29600e79eacb6c0f747075afeb74fdd5 (patch) | |
| tree | fd2afa54998112883d9b5240cb99a30e3179e98a /nova/tests | |
| parent | 3f7353d14183a93099c99dc2fc72614265f1c72c (diff) | |
Fix scheduler error handler
Fixes bug 904971
Scheduler error handler was looking for instance_id when it may or may
not exist. Added the proper code for it to determine whether the
instance was actually created in the DB or not and how to find its ID.
Note: there's some pretty nasty stuff in here, but unavoidable without
larger changes. I'd like to hold off on these larger changes, because
the problem should be solved with some of the scalability work coming.
Tests included.
Change-Id: Ief5fde8128437c9dc257af9c4d0c2950d0962ce5
Diffstat (limited to 'nova/tests')
| -rw-r--r-- | nova/tests/scheduler/test_scheduler.py | 31 |
1 files changed, 29 insertions, 2 deletions
diff --git a/nova/tests/scheduler/test_scheduler.py b/nova/tests/scheduler/test_scheduler.py index c0fce0fe3..57218fca3 100644 --- a/nova/tests/scheduler/test_scheduler.py +++ b/nova/tests/scheduler/test_scheduler.py @@ -113,6 +113,7 @@ def _fake_create_instance_db_entry(simple_self, context, request_spec): instance = _create_instance_from_spec(request_spec) global instance_uuids instance_uuids.append(instance['uuid']) + request_spec['instance_properties']['uuid'] = instance['uuid'] return instance @@ -236,15 +237,41 @@ class SchedulerTestCase(test.TestCase): scheduler = manager.SchedulerManager() ins_ref = _create_instance(task_state=task_states.STARTING, vm_state=vm_states.STOPPED) - self.stubs = stubout.StubOutForTesting() self.stubs.Set(TestDriver, 'schedule', NoValidHost_raiser) - self.mox.StubOutWithMock(rpc, 'cast', use_mock_anything=True) ctxt = context.get_admin_context() scheduler.start_instance(ctxt, 'topic', instance_id=ins_ref['id']) # assert that the instance goes to ERROR state self._assert_state({'vm_state': vm_states.ERROR, 'task_state': task_states.STARTING}) + def test_no_valid_host_exception_on_run_with_id(self): + """check the vm goes to ERROR state if run_instance fails""" + + def NoValidHost_raiser(context, topic, *args, **kwargs): + raise exception.NoValidHost(_("Test NoValidHost exception")) + scheduler = manager.SchedulerManager() + ins_ref = _create_instance(task_state=task_states.STARTING, + vm_state=vm_states.STOPPED) + self.stubs.Set(TestDriver, 'schedule', NoValidHost_raiser) + ctxt = context.get_admin_context() + request_spec = {'instance_properties': {'uuid': ins_ref['uuid']}} + scheduler.run_instance(ctxt, 'topic', request_spec=request_spec) + # assert that the instance goes to ERROR state + self._assert_state({'vm_state': vm_states.ERROR, + 'task_state': task_states.STARTING}) + + def test_no_valid_host_exception_on_run_without_id(self): + """check error handler doesn't raise if instance wasn't created""" + + def NoValidHost_raiser(context, topic, *args, **kwargs): + raise exception.NoValidHost(_("Test NoValidHost exception")) + scheduler = manager.SchedulerManager() + self.stubs.Set(TestDriver, 'schedule', NoValidHost_raiser) + ctxt = context.get_admin_context() + request_spec = {'instance_properties': {}} + scheduler.run_instance(ctxt, 'topic', request_spec=request_spec) + # No error + def test_show_host_resources_no_project(self): """No instance are running on the given host.""" |
