launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #06636
[Merge] lp:~jtv/maas/reauth into lp:maas
Jeroen T. Vermeulen has proposed merging lp:~jtv/maas/reauth into lp:maas.
Requested reviews:
Launchpad code reviewers (launchpad-reviewers)
For more details, see:
https://code.launchpad.net/~jtv/maas/reauth/+merge/96711
When the provisioning server's authentication token for Cobbler expired, the CobblerSession is supposed to renew it transparently and retry the call. This wasn't working against a real cobbler.
Turns out the faultString on this exception from the Cobbler API included the prefix naming the exception. I made the check for this looser rather than tighter, so as to remain robust against subtle changes. Cobbler raises this exception in more than one place.
--
https://code.launchpad.net/~jtv/maas/reauth/+merge/96711
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~jtv/maas/reauth into lp:maas.
=== modified file 'src/provisioningserver/cobblerclient.py'
--- src/provisioningserver/cobblerclient.py 2012-02-29 10:40:06 +0000
+++ src/provisioningserver/cobblerclient.py 2012-03-09 06:03:19 +0000
@@ -92,7 +92,8 @@
if not hasattr(exception, 'faultString'):
# An auth failure would come as an xmlrpclib.Fault.
return False
- return exception.faultString.startswith("invalid token: ")
+ else:
+ return "invalid token: " in exception.faultString
class CobblerSession:
=== modified file 'src/provisioningserver/testing/fakecobbler.py'
--- src/provisioningserver/testing/fakecobbler.py 2012-02-29 17:48:34 +0000
+++ src/provisioningserver/testing/fakecobbler.py 2012-03-09 06:03:19 +0000
@@ -10,6 +10,7 @@
__metaclass__ = type
__all__ = [
+ 'fake_auth_failure_string',
'FakeCobbler',
'FakeTwistedProxy',
'fake_token',
@@ -35,6 +36,11 @@
unique_ints = count(randint(0, 99999))
+def fake_auth_failure_string(token):
+ """Fake a Cobbler authentication failure fault string for `token`."""
+ return "<class 'cobbler.exceptions.CX'>:'invalid token: %s'" % token
+
+
def fake_token(user=None, custom_id=None):
"""Make up a fake auth token.
@@ -127,7 +133,7 @@
def _check_token(self, token):
if token not in self.tokens:
- raise Fault(1, "invalid token: %s" % token)
+ raise Fault(1, fake_auth_failure_string(token))
def _raise_bad_handle(self, object_type, handle):
raise Fault(1, "Invalid %s handle: %s" % (object_type, handle))
=== modified file 'src/provisioningserver/tests/test_cobblersession.py'
--- src/provisioningserver/tests/test_cobblersession.py 2012-02-29 11:40:46 +0000
+++ src/provisioningserver/tests/test_cobblersession.py 2012-03-09 06:03:19 +0000
@@ -16,7 +16,10 @@
import fixtures
from provisioningserver import cobblerclient
-from provisioningserver.testing.fakecobbler import fake_token
+from provisioningserver.testing.fakecobbler import (
+ fake_auth_failure_string,
+ fake_token,
+ )
from testtools.content import text_content
from testtools.deferredruntest import (
assert_fails_with,
@@ -49,7 +52,8 @@
"""Imitated Cobbler authentication failure."""
def __init__(self, token):
- super(FakeAuthFailure, self).__init__(1, "invalid token: %s" % token)
+ super(FakeAuthFailure, self).__init__(
+ 1, fake_auth_failure_string(token))
def make_auth_failure(broken_token=None):