Don't retry forever when a provider is stopped

When we stop a provider, it does not accept any new tasks.  In that
case, we should raise a specific exception so that loops that retry
for a very long time can exit early since the "error" will never
recover.

Change-Id: I7387849ffdb96c487bae4c31ca7cbdd07b8afd8a
This commit is contained in:
James E. Blair 2014-09-03 11:13:27 -07:00 committed by Jeremy Stanley
parent ed29412ed2
commit df5049f2e2
2 changed files with 11 additions and 2 deletions

View File

@ -29,7 +29,7 @@ import keystoneclient.v2_0.client as ksclient
import time
import fakeprovider
from task_manager import Task, TaskManager
from task_manager import Task, TaskManager, ManagerStoppedException
SERVER_LIST_AGE = 5 # How long to keep a cached copy of the server list
@ -423,6 +423,8 @@ class ProviderManager(TaskManager):
resource = self.getImage(resource_id)
except NotFound:
continue
except ManagerStoppedException:
raise
except Exception:
self.log.exception('Unable to list %ss while waiting for '
'%s will retry' % (resource_type,
@ -474,6 +476,8 @@ class ProviderManager(TaskManager):
(server_id, self.provider.name)):
try:
newip = self.getFloatingIP(ip['id'])
except ManagerStoppedException:
raise
except Exception:
self.log.exception('Unable to get IP details for server %s, '
'will retry' % (server_id))

View File

@ -23,6 +23,10 @@ import logging
import time
class ManagerStoppedException(Exception):
pass
class Task(object):
def __init__(self, **kw):
self._wait_event = threading.Event()
@ -93,6 +97,7 @@ class TaskManager(threading.Thread):
def submitTask(self, task):
if not self._running:
raise Exception("Manager %s is no longer running" % self.name)
raise ManagerStoppedException(
"Manager %s is no longer running" % self.name)
self.queue.put(task)
return task.wait()