Merge lp:~gz/pyjuju/os_token_string_type_1030897 into lp:pyjuju
Proposed by
Martin Packman
Status: | Merged |
---|---|
Approved by: | Martin Packman |
Approved revision: | 583 |
Merged at revision: | 586 |
Proposed branch: | lp:~gz/pyjuju/os_token_string_type_1030897 |
Merge into: | lp:pyjuju |
Diff against target: | 0 lines |
To merge this branch: | bzr merge lp:~gz/pyjuju/os_token_string_type_1030897 |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Clint Byrum (community) | Approve | ||
Review via email: mp+127008@code.launchpad.net |
Description of the change
Fix TypeError with unicode tokens from keystone
One line change to make tokens from v2 keystone auth use the str type
rather than unicode. In mysterious circumstances, that breaks when
twisted tries to construct the request.
Also adds some testing to cover this case and enforce the type.
To post a comment you must log in.
Reviewers: mp+127008_ code.launchpad. net,
Message:
Please take a look.
Description:
Fix TypeError with unicode tokens from keystone
One line change to make tokens from v2 keystone auth use the str type
rather than unicode. In mysterious circumstances, that breaks when
twisted tries to construct the request.
Also adds some testing to cover this case and enforce the type.
https:/ /code.launchpad .net/~gz/ juju/os_ token_string_ type_1030897/ +merge/ 127008
(do not edit description out of merge proposal)
Please review this at https:/ /codereview. appspot. com/6573068/
Affected files: openstack/ client. py openstack/ tests/test_ client. py
A [revision details]
M juju/providers/
M juju/providers/
Index: [revision details]
=== added file '[revision details]'
--- [revision details] 2012-01-01 00:00:00 +0000
+++ [revision details] 2012-01-01 00:00:00 +0000
@@ -0,0 +1,2 @@
+Old revision: <email address hidden>
+New revision: <email address hidden>
Index: juju/providers/ openstack/ client. py /openstack/ client. py' openstack/ client. py 2012-09-26 04:56:39 +0000 openstack/ client. py 2012-09-28 15:53:06 +0000 web._newclient import ResponseFailed web._newclient import ResponseDone, ResponseFailed web.http_ headers import Headers
=== modified file 'juju/providers
--- juju/providers/
+++ juju/providers/
@@ -33,9 +33,9 @@
from twisted.web.client import Agent
# Older twisted versions don't expose _newclient exceptions via client
module
try:
- from twisted.web.client import ResponseFailed
+ from twisted.web.client import ResponseDone, ResponseFailed
except ImportError:
- from twisted.
+ from twisted.
from twisted.
from zope.interface import implements
@@ -249,7 +249,10 @@ v2_auth( self, result):
access_ details = self._json(result, 200, 'access')
token_ details = access_ details[ "token" ] details[ "id"])
def _handle_
- self.token = token_details["id"]
+ # Decoded json uses unicode for all string values, but that can
upset
+ # twisted when serialising headers later. Really should encode at
that
+ # point, but as keystone should only give ascii tokens a cast will
do.
+ self.token = str(token_
# TODO: care about token_details[ "expires" ]
# Don't need to we're not preserving tokens.
Index: juju/providers/ openstack/ tests/test_ client. py /openstack/ tests/test_ client. py' openstack/ tests/test_ client. py 2012-09-26 04:54:55 +0000 openstack/ tests/test_ client. py 2012-09-28 15:53:06 +0000 object) :
=== modified file 'juju/providers
--- juju/providers/
+++ juju/providers/
@@ -62,10 +62,19 @@
class FakeResponse(
"""Bare minimum needed to look like a twisted http response"""
- def __init__(self, code, headers):
self. headers = headers connectionMade( ) dataReceived( self.body) connectionL. ..
+ def __init__(self, code, headers, body=None):
self.code = code
- self.length = 0
+ if body is None:
+ self.length = 0
+ else:
+ self.length = len(body)
+ self.body = body
+
+ def deliverBody(self, reader):
+ reader.
+ reader.
+ reader.