openstack_container.py: add shutdown() to avoid unclean reactor errors in tests.
authorDavid-Sarah Hopwood <david-sarah@jacaranda.org>
Mon, 11 Feb 2013 02:43:36 +0000 (02:43 +0000)
committerDaira Hopwood <daira@jacaranda.org>
Fri, 17 Apr 2015 21:31:37 +0000 (22:31 +0100)
Signed-off-by: David-Sarah Hopwood <david-sarah@jacaranda.org>
src/allmydata/storage/backends/cloud/openstack/openstack_container.py

index 7525c279a4806a4c6a257f19d529185b134d17b3..2da588a8b3f9c0bb290b6f404527212b8eb7f510 100644 (file)
@@ -58,6 +58,7 @@ class AuthenticationClient(object):
         self._reauth_period = reauth_period
         self._reactor = override_reactor or reactor
         self._agent = Agent(self._reactor)
+        self._delayed = None
 
         _assert(provider.startswith("rackspace"), provider=provider)
         self._authenticate = self._authenticate_to_rackspace
@@ -121,7 +122,7 @@ class AuthenticationClient(object):
             #log.msg("Auth response is %s %s %s" % (storage_url, cdn_management_url, auth_token))
             self._auth_info = AuthenticationInfo(storage_url, cdn_management_url, auth_token)
 
-            self._reactor.callLater(self._reauth_period, self.get_auth_info_locked, suppress_errors=True)
+            self._delayed = self._reactor.callLater(self._reauth_period, self.get_auth_info_locked, suppress_errors=True)
         d.addCallback(_got_response)
         def _failed(f):
             self._auth_info = None
@@ -131,6 +132,11 @@ class AuthenticationClient(object):
         d.addErrback(_failed)
         return d
 
+    def shutdown(self):
+        """Used by unit tests to avoid unclean reactor errors."""
+        if self._delayed:
+            self._delayed.cancel()
+
 
 class OpenStackContainer(ContainerRetryMixin, ContainerListMixin):
     implements(IContainer)