Skip to content

Commit

Permalink
set ERROR state when scheduler hits max attempts
Browse files Browse the repository at this point in the history
Presently when scheduler raises NoValidHost due to max attempts
being reached, the instance remains in a build state.
Exception handler for NoValidHost in manager.run_instance() needs
request_spec[instance_uuids] to know which host to put into an
error state in _set_vm_state_and_notify().
schedule_run_instances() was popping instance_uuids from the
request_spec prior to a call to _schedule().
Changed pop of instance_uuids prior to call to _schedule() to be a get.
Added pop of instance_uuids to beneath call to _schedule() as
individual creates do not need them.

Conflicts:
	nova/scheduler/filter_scheduler.py

Change-Id: I9654820e01d5611763e9e673f15f46b947d09e6d
Fixes: bug #1182056
(cherry picked from commit aefc28d)
  • Loading branch information
moorryan authored and Ruby Loo committed May 29, 2013
1 parent 1c074ec commit 7726dae
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
7 changes: 6 additions & 1 deletion nova/scheduler/filter_scheduler.py
Expand Up @@ -70,14 +70,19 @@ def schedule_run_instance(self, context, request_spec,
notifier.notify(context, notifier.publisher_id("scheduler"),
'scheduler.run_instance.start', notifier.INFO, payload)

instance_uuids = request_spec.pop('instance_uuids')
instance_uuids = request_spec.get('instance_uuids')
num_instances = len(instance_uuids)
LOG.debug(_("Attempting to build %(num_instances)d instance(s)") %
locals())

weighed_hosts = self._schedule(context, request_spec,
filter_properties, instance_uuids)

# NOTE: Pop instance_uuids as individual creates do not need the
# set of uuids. Do not pop before here as the upper exception
# handler fo NoValidHost needs the uuid to set error state
instance_uuids = request_spec.pop('instance_uuids')

# NOTE(comstud): Make sure we do not pass this through. It
# contains an instance of RpcContext that cannot be serialized.
filter_properties.pop('context', None)
Expand Down
17 changes: 13 additions & 4 deletions nova/tests/scheduler/test_filter_scheduler.py
Expand Up @@ -279,18 +279,27 @@ def test_retry_attempt_two(self):
self.assertEqual(2, num_attempts)

def test_retry_exceeded_max_attempts(self):
# Test for necessary explosion when max retries is exceeded.
# Test for necessary explosion when max retries is exceeded and that
# the information needed in request_spec is still present for error
# handling
self.flags(scheduler_max_attempts=2)
sched = fakes.FakeFilterScheduler()

instance_properties = {'project_id': '12345', 'os_type': 'Linux'}
request_spec = dict(instance_properties=instance_properties)
instance_uuids = ['fake-id']
request_spec = dict(instance_properties=instance_properties,
instance_uuids=instance_uuids)

retry = dict(num_attempts=2)
filter_properties = dict(retry=retry)

self.assertRaises(exception.NoValidHost, sched._schedule, self.context,
request_spec, filter_properties=filter_properties)
self.assertRaises(exception.NoValidHost, sched.schedule_run_instance,
self.context, request_spec, admin_password=None,
injected_files=None, requested_networks=None,
is_first_time=False,
filter_properties=filter_properties)
uuids = request_spec.get('instance_uuids')
self.assertEqual(uuids, instance_uuids)

def test_add_retry_host(self):
retry = dict(num_attempts=1, hosts=[])
Expand Down

0 comments on commit 7726dae

Please sign in to comment.