Merge lp:~jtv/maas/bug-1313556 into lp:~maas-committers/maas/trunk

Proposed by Jeroen T. Vermeulen
Status: Merged
Approved by: Jeroen T. Vermeulen
Approved revision: no longer in the source branch.
Merged at revision: 2293
Proposed branch: lp:~jtv/maas/bug-1313556
Merge into: lp:~maas-committers/maas/trunk
Diff against target: 39 lines (+12/-3)
2 files modified
src/apiclient/maas_client.py (+4/-2)
src/apiclient/tests/test_maas_client.py (+8/-1)
To merge this branch: bzr merge lp:~jtv/maas/bug-1313556
Reviewer Review Type Date Requested Status
Gavin Panella (community) Approve
Review via email: mp+217508@code.launchpad.net

Commit message

Fix hanging “delete” in apiclient package.

Description of the change

This is a simple change, but it took me quite a while to figure out. Deleting a resource through the API client would hang while trying to read the server's response status. As it turns out, the problem wasn't so much with the response as with the request: it must have a body, even if that body should probably be empty.

Jeroen

To post a comment you must log in.
Revision history for this message
Gavin Panella (allenap) wrote :

Does this boil down to a bug in a library we're using?

review: Approve
Revision history for this message
Jeroen T. Vermeulen (jtv) wrote :

I suspect it falls under “leaky abstraction” — technically our responsibility, but hard to be aware of until you run into trouble and figure it out.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/apiclient/maas_client.py'
2--- src/apiclient/maas_client.py 2013-12-03 07:55:27 +0000
3+++ src/apiclient/maas_client.py 2014-04-28 20:40:40 +0000
4@@ -1,4 +1,4 @@
5-# Copyright 2012 Canonical Ltd. This software is licensed under the
6+# Copyright 2012-2014 Canonical Ltd. This software is licensed under the
7 # GNU Affero General Public License version 3 (see the file LICENSE).
8
9 """MAAS OAuth API connection library."""
10@@ -240,5 +240,7 @@
11 def delete(self, path):
12 """Dispatch a DELETE on the resource at `path`."""
13 url, headers, body = self._formulate_change(path, {})
14+ # The body will be empty, but it must be passed. Otherwise, the
15+ # request will hang while trying to read a response (bug 1313556).
16 return self.dispatcher.dispatch_query(
17- url, method="DELETE", headers=headers)
18+ url, method="DELETE", headers=headers, data=body)
19
20=== modified file 'src/apiclient/tests/test_maas_client.py'
21--- src/apiclient/tests/test_maas_client.py 2013-12-03 07:55:27 +0000
22+++ src/apiclient/tests/test_maas_client.py 2014-04-28 20:40:40 +0000
23@@ -1,4 +1,4 @@
24-# Copyright 2012, 2013 Canonical Ltd. This software is licensed under the
25+# Copyright 2012-2014 Canonical Ltd. This software is licensed under the
26 # GNU Affero General Public License version 3 (see the file LICENSE).
27
28 """Test MAAS HTTP API client."""
29@@ -346,3 +346,10 @@
30 self.assertEqual(client._make_url(path), request['request_url'])
31 self.assertIn('Authorization', request['headers'])
32 self.assertEqual('DELETE', request['method'])
33+
34+ def test_delete_passes_body(self):
35+ # A DELETE request should have an empty body. But we can't just leave
36+ # the body out altogether, or the request will hang (bug 1313556).
37+ client = make_client()
38+ client.delete(make_path())
39+ self.assertIsNotNone(client.dispatcher.last_call['data'])