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
=== modified file 'nova/api/openstack/wsgi.py'
--- nova/api/openstack/wsgi.py 2011-06-13 12:54:21 +0000
+++ nova/api/openstack/wsgi.py 2011-06-13 20:01:23 +0000
@@ -60,7 +60,7 @@
6060
61 def deserialize(self, datastring, action='default'):61 def deserialize(self, datastring, action='default'):
62 """Find local deserialization method and parse request body."""62 """Find local deserialization method and parse request body."""
63 action_method = getattr(self, action, self.default)63 action_method = getattr(self, str(action), self.default)
64 return action_method(datastring)64 return action_method(datastring)
6565
66 def default(self, datastring):66 def default(self, datastring):
@@ -189,7 +189,7 @@
189189
190 def serialize(self, data, action='default'):190 def serialize(self, data, action='default'):
191 """Find local serialization method and encode response body."""191 """Find local serialization method and encode response body."""
192 action_method = getattr(self, action, self.default)192 action_method = getattr(self, str(action), self.default)
193 return action_method(data)193 return action_method(data)
194194
195 def default(self, data):195 def default(self, data):
@@ -296,7 +296,7 @@
296 }296 }
297 self.serializers.update(serializers or {})297 self.serializers.update(serializers or {})
298298
299 def serialize(self, response_data, content_type):299 def serialize(self, response_data, content_type, action='default'):
300 """Serialize a dict into a string and wrap in a wsgi.Request object.300 """Serialize a dict into a string and wrap in a wsgi.Request object.
301301
302 :param response_data: dict produced by the Controller302 :param response_data: dict produced by the Controller
@@ -307,7 +307,7 @@
307 response.headers['Content-Type'] = content_type307 response.headers['Content-Type'] = content_type
308308
309 serializer = self.get_serializer(content_type)309 serializer = self.get_serializer(content_type)
310 response.body = serializer.serialize(response_data)310 response.body = serializer.serialize(response_data, action)
311311
312 return response312 return response
313313
@@ -358,7 +358,7 @@
358358
359 #TODO(bcwaldon): find a more elegant way to pass through non-dict types359 #TODO(bcwaldon): find a more elegant way to pass through non-dict types
360 if type(action_result) is dict:360 if type(action_result) is dict:
361 response = self.serializer.serialize(action_result, accept)361 response = self.serializer.serialize(action_result, accept, action)
362 else:362 else:
363 response = action_result363 response = action_result
364364
365365
=== modified file 'nova/tests/api/openstack/test_wsgi.py'
--- nova/tests/api/openstack/test_wsgi.py 2011-05-26 18:09:59 +0000
+++ nova/tests/api/openstack/test_wsgi.py 2011-06-13 20:01:23 +0000
@@ -89,6 +89,12 @@
89 serializer.default = lambda x: 'trousers'89 serializer.default = lambda x: 'trousers'
90 self.assertEqual(serializer.serialize({}, 'update'), 'trousers')90 self.assertEqual(serializer.serialize({}, 'update'), 'trousers')
9191
92 def test_dispatch_action_None(self):
93 serializer = wsgi.DictSerializer()
94 serializer.create = lambda x: 'pants'
95 serializer.default = lambda x: 'trousers'
96 self.assertEqual(serializer.serialize({}, None), 'trousers')
97
9298
93class XMLDictSerializerTest(test.TestCase):99class XMLDictSerializerTest(test.TestCase):
94 def test_xml(self):100 def test_xml(self):
@@ -123,6 +129,12 @@
123 deserializer.default = lambda x: 'trousers'129 deserializer.default = lambda x: 'trousers'
124 self.assertEqual(deserializer.deserialize({}, 'update'), 'trousers')130 self.assertEqual(deserializer.deserialize({}, 'update'), 'trousers')
125131
132 def test_dispatch_action_None(self):
133 deserializer = wsgi.TextDeserializer()
134 deserializer.create = lambda x: 'pants'
135 deserializer.default = lambda x: 'trousers'
136 self.assertEqual(deserializer.deserialize({}, None), 'trousers')
137
126138
127class JSONDeserializerTest(test.TestCase):139class JSONDeserializerTest(test.TestCase):
128 def test_json(self):140 def test_json(self):
@@ -171,11 +183,11 @@
171class ResponseSerializerTest(test.TestCase):183class ResponseSerializerTest(test.TestCase):
172 def setUp(self):184 def setUp(self):
173 class JSONSerializer(object):185 class JSONSerializer(object):
174 def serialize(self, data):186 def serialize(self, data, action='default'):
175 return 'pew_json'187 return 'pew_json'
176188
177 class XMLSerializer(object):189 class XMLSerializer(object):
178 def serialize(self, data):190 def serialize(self, data, action='default'):
179 return 'pew_xml'191 return 'pew_xml'
180192
181 self.serializers = {193 self.serializers = {
@@ -211,11 +223,11 @@
211class RequestDeserializerTest(test.TestCase):223class RequestDeserializerTest(test.TestCase):
212 def setUp(self):224 def setUp(self):
213 class JSONDeserializer(object):225 class JSONDeserializer(object):
214 def deserialize(self, data):226 def deserialize(self, data, action='default'):
215 return 'pew_json'227 return 'pew_json'
216228
217 class XMLDeserializer(object):229 class XMLDeserializer(object):
218 def deserialize(self, data):230 def deserialize(self, data, action='default'):
219 return 'pew_xml'231 return 'pew_xml'
220232
221 self.deserializers = {233 self.deserializers = {