Merge lp:~rackspace-titan/nova/lp795772 into lp:~hudson-openstack/nova/trunk

Proposed by Brian Waldon
Status: Merged
Approved by: Brian Lamar
Approved revision: 1173
Merged at revision: 1174
Proposed branch: lp:~rackspace-titan/nova/lp795772
Merge into: lp:~hudson-openstack/nova/trunk
Diff against target: 106 lines (+21/-9)
2 files modified
nova/api/openstack/wsgi.py (+5/-5)
nova/tests/api/openstack/test_wsgi.py (+16/-4)
To merge this branch: bzr merge lp:~rackspace-titan/nova/lp795772
Reviewer Review Type Date Requested Status
Brian Lamar (community) Approve
Devin Carlen (community) Approve
Review via email: mp+64267@code.launchpad.net

Description of the change

- fixes bug that prevented custom wsgi serialization

To post a comment you must log in.
Revision history for this message
Devin Carlen (devcamcar) wrote :

lgtm

review: Approve
Revision history for this message
Brian Lamar (blamar) wrote :

Seems like this could be simplified:

9 + if action is None:
10 + action_method = self.default
11 + else:
12 + action_method = getattr(self, action, self.default)

Wouldn't str(action) do just as well? The case you're checking for is someone explicitly passing in None as the action parameter, but wouldn't any object also break getattr?

9 + return getattr(self, str(action), self.default)(data)

Tests?

review: Needs Fixing
Revision history for this message
Brian Waldon (bcwaldon) wrote :

> Wouldn't str(action) do just as well? The case you're checking for is someone
> explicitly passing in None as the action parameter, but wouldn't any object
> also break getattr?
>
> 9 + return getattr(self, str(action), self.default)(data)

Yeah, you're right. Solving this generically is better than explicitly checking for None. Fixed.

> Tests?

Yeah, I added some more to send an action with None.

Revision history for this message
Brian Lamar (blamar) wrote :

Looks good, going to run tests and smokestack before approval.

review: Approve
Revision history for this message
Trey Morris (tr3buchet) wrote :

blamar: did you review-approve, then plan to run the tests and such, and then afterwards change the status to approved?
I worry someone may see two core dev approves and mark it approved out from under you

Revision history for this message
Brian Lamar (blamar) wrote :

Smokestacked and tests pass, approving.

Revision history for this message
OpenStack Infra (hudson-openstack) wrote :
Download full text (60.2 KiB)

The attempt to merge lp:~rackspace-titan/nova/lp795772 into lp:nova failed. Below is the output from the failed tests.

AccountsTest
    test_account_create OK
    test_account_delete OK
    test_account_update OK
    test_get_account OK
AdminAPITest
    test_admin_disabled OK
    test_admin_enabled OK
APITest
    test_exceptions_are_converted_to_faults OK
Test
    test_authorize_project OK
    test_authorize_token OK
    test_authorize_user OK
    test_bad_project OK
    test_bad_token OK
    test_bad_user_bad_key OK
    test_bad_user_good_key OK
    test_no_user OK
    test_not_existing_project OK
    test_token_expiry OK
TestFunctional
    test_token_doesnotexist OK
    test_token_expiry OK
TestLimiter
    test_authorize_token OK
LimiterTest
    test_limiter_custom_max_limit OK
    test_limiter_limit_and_offset OK
    test_limiter_limit_medium OK
    test_limiter_limit_over_max OK
    test_limiter_limit_zero OK
    test_limiter_negative_limit OK
    test_limiter_negative_offset OK
    test_limiter_nothing OK
    test_limiter_offset_bad OK
    test_limiter_offset_blank OK
    test_limiter_offset_medium OK
    test_limiter_offset_over_max OK
    test_limiter_offset_zero OK
PaginationParamsTest
    test_invalid_limit OK
    test_invalid_marker OK
    test_no_params OK
    test_valid_limit OK
    test_valid_marker OK
ActionExtensionTest
    test_extended_action OK
    test_invalid_action OK
    test_invalid_action_body OK
ExtensionControllerTest
    test_get_by_alias OK
    test_index OK
ExtensionManagerTest
    test_get_resources ...

lp:~rackspace-titan/nova/lp795772 updated
1173. By Brian Waldon

merging trunk, fixing pep8

Revision history for this message
Brian Waldon (bcwaldon) wrote :

I swear I ran pep8!

Fixed now.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'nova/api/openstack/wsgi.py'
2--- nova/api/openstack/wsgi.py 2011-06-13 12:54:21 +0000
3+++ nova/api/openstack/wsgi.py 2011-06-13 20:01:23 +0000
4@@ -60,7 +60,7 @@
5
6 def deserialize(self, datastring, action='default'):
7 """Find local deserialization method and parse request body."""
8- action_method = getattr(self, action, self.default)
9+ action_method = getattr(self, str(action), self.default)
10 return action_method(datastring)
11
12 def default(self, datastring):
13@@ -189,7 +189,7 @@
14
15 def serialize(self, data, action='default'):
16 """Find local serialization method and encode response body."""
17- action_method = getattr(self, action, self.default)
18+ action_method = getattr(self, str(action), self.default)
19 return action_method(data)
20
21 def default(self, data):
22@@ -296,7 +296,7 @@
23 }
24 self.serializers.update(serializers or {})
25
26- def serialize(self, response_data, content_type):
27+ def serialize(self, response_data, content_type, action='default'):
28 """Serialize a dict into a string and wrap in a wsgi.Request object.
29
30 :param response_data: dict produced by the Controller
31@@ -307,7 +307,7 @@
32 response.headers['Content-Type'] = content_type
33
34 serializer = self.get_serializer(content_type)
35- response.body = serializer.serialize(response_data)
36+ response.body = serializer.serialize(response_data, action)
37
38 return response
39
40@@ -358,7 +358,7 @@
41
42 #TODO(bcwaldon): find a more elegant way to pass through non-dict types
43 if type(action_result) is dict:
44- response = self.serializer.serialize(action_result, accept)
45+ response = self.serializer.serialize(action_result, accept, action)
46 else:
47 response = action_result
48
49
50=== modified file 'nova/tests/api/openstack/test_wsgi.py'
51--- nova/tests/api/openstack/test_wsgi.py 2011-05-26 18:09:59 +0000
52+++ nova/tests/api/openstack/test_wsgi.py 2011-06-13 20:01:23 +0000
53@@ -89,6 +89,12 @@
54 serializer.default = lambda x: 'trousers'
55 self.assertEqual(serializer.serialize({}, 'update'), 'trousers')
56
57+ def test_dispatch_action_None(self):
58+ serializer = wsgi.DictSerializer()
59+ serializer.create = lambda x: 'pants'
60+ serializer.default = lambda x: 'trousers'
61+ self.assertEqual(serializer.serialize({}, None), 'trousers')
62+
63
64 class XMLDictSerializerTest(test.TestCase):
65 def test_xml(self):
66@@ -123,6 +129,12 @@
67 deserializer.default = lambda x: 'trousers'
68 self.assertEqual(deserializer.deserialize({}, 'update'), 'trousers')
69
70+ def test_dispatch_action_None(self):
71+ deserializer = wsgi.TextDeserializer()
72+ deserializer.create = lambda x: 'pants'
73+ deserializer.default = lambda x: 'trousers'
74+ self.assertEqual(deserializer.deserialize({}, None), 'trousers')
75+
76
77 class JSONDeserializerTest(test.TestCase):
78 def test_json(self):
79@@ -171,11 +183,11 @@
80 class ResponseSerializerTest(test.TestCase):
81 def setUp(self):
82 class JSONSerializer(object):
83- def serialize(self, data):
84+ def serialize(self, data, action='default'):
85 return 'pew_json'
86
87 class XMLSerializer(object):
88- def serialize(self, data):
89+ def serialize(self, data, action='default'):
90 return 'pew_xml'
91
92 self.serializers = {
93@@ -211,11 +223,11 @@
94 class RequestDeserializerTest(test.TestCase):
95 def setUp(self):
96 class JSONDeserializer(object):
97- def deserialize(self, data):
98+ def deserialize(self, data, action='default'):
99 return 'pew_json'
100
101 class XMLDeserializer(object):
102- def deserialize(self, data):
103+ def deserialize(self, data, action='default'):
104 return 'pew_xml'
105
106 self.deserializers = {