Merge lp:~jameinel/maas/allow-json into lp:maas/trunk
| Status: | Merged |
|---|---|
| Merged at revision: | 1230 |
| Proposed branch: | lp:~jameinel/maas/allow-json |
| Merge into: | lp:maas/trunk |
| Diff against target: |
245 lines (+138/-5) 5 files modified
src/apiclient/encode_json.py (+32/-0) src/apiclient/maas_client.py (+14/-4) src/apiclient/testing/django.py (+26/-0) src/apiclient/tests/test_encode_json.py (+36/-0) src/apiclient/tests/test_maas_client.py (+30/-1) |
| To merge this branch: | bzr merge lp:~jameinel/maas/allow-json |
| Related bugs: |
| Reviewer | Review Type | Date Requested | Status |
|---|---|---|---|
| John A Meinel | Approve on 2012-10-09 | ||
| Gavin Panella (community) | 2012-10-08 | Approve on 2012-10-08 | |
|
Review via email:
|
|||
Commit Message
Add MAASClient.
Testing shows that if the data being uploaded is large, you can see a big improvement in performance.
Description of the Change
This updates MAASClient so that it can take an 'as_json' parameter.
This changes how the data gets POSTed, sending it as JSON encoding, rather than MimeMultipart.
In my testing, this is dramatically faster for the tag processing. (It drops the time to update 10,000 nodes from 45s down to 35s.)
I will be posting a follow up patch that does that code.
The main reason it is still a flag vs the default, is because the API side needs some updates to support this. It seems that most of our API code uses 'request.POST' but this comes in as 'request.data'. Also, multipart comes in as a multidict (mapping each parameter to a list) while if you pass a dict as json you get just a dict on the other side.
| John A Meinel (jameinel) wrote : | # |
| Gavin Panella (allenap) wrote : | # |
Looks good. I think [4] needs fixing, but it's minor, so +1.
[1]
+ :param as_json: Encode params as application/json instead of
+ application/
..
+ :param as_json: Instead of POSTing the content as multipart
+ x-www-
I think this should be multipart/form-data for all non-GET calls.
[2]
+ def assertEncodeJSO
+ self.assertEqual(
+ (expected_body, expected_headers),
+ encode_
Something I used for the first time earlier today might make failures
here prettier:
expected = Equals(
self.assertThat(
params, AfterPreprocessing(
encode_json_data, Equals(expected)))
Up to you though; it's a small win.
[3]
+ self.assertEqu
+ self.assertEqu
+ self.assertEqu
+ data = parse_headers_
+ self.assertEqu
Elsewhere in MAAS it's been useful to use testtools' compound
matchers, so that failures contain more information about their
nature. Consider something like:
observed = (
headers.
headers.
body,
)
expected = (
'application/
"%d" % len(body),
AfterPreproces
)
self.assertTha
[4]
+ self.assertEqu
The header should be a string value, so check that it's being
populated correctly.
| MAAS Lander (maas-lander) wrote : | # |
The Jenkins job https:/
Not merging it.
| John A Meinel (jameinel) wrote : | # |
Submitting again because I think I have a fix for failing tests that should have failed in the first submission.
| MAAS Lander (maas-lander) wrote : | # |
The Jenkins job https:/
Not merging it.


It looks like I accidentally included the API changes necessary to support POSTing as json to the tag-related APIs. I'm updating the branch now to remove them, but that change will be present in the next branch I propose.