Merge lp:~julian-edwards/pyjuju/show-errors-when-acquiring-node into lp:pyjuju

Proposed by Julian Edwards
Status: Merged
Approved by: Kapil Thangavelu
Approved revision: 539
Merged at revision: 539
Proposed branch: lp:~julian-edwards/pyjuju/show-errors-when-acquiring-node
Merge into: lp:pyjuju
Diff against target: 127 lines (+33/-11)
4 files modified
juju/providers/maas/maas.py (+17/-2)
juju/providers/maas/tests/test_launch.py (+4/-6)
juju/providers/maas/tests/test_maas.py (+10/-1)
juju/providers/maas/tests/testing.py (+2/-2)
To merge this branch: bzr merge lp:~julian-edwards/pyjuju/show-errors-when-acquiring-node
Reviewer Review Type Date Requested Status
Kapil Thangavelu (community) Approve
William Reade (community) Approve
Review via email: mp+107332@code.launchpad.net

Commit message

Show error text returned from maas if it has an error bootstrapping.

Description of the change

Fix a problem in the maas provider where it was not showing the text returned when there was an error acquiring a node during bootstrap. Where it was just saying "CONFLICT" it now says "No matching node is available" which is the text returned from maas.

To post a comment you must log in.
Revision history for this message
William Reade (fwereade) wrote :

LGTM

review: Approve
Revision history for this message
Kapil Thangavelu (hazmat) wrote :

lgtm

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'juju/providers/maas/maas.py'
2--- juju/providers/maas/maas.py 2012-03-28 14:40:14 +0000
3+++ juju/providers/maas/maas.py 2012-05-25 06:54:17 +0000
4@@ -6,6 +6,8 @@
5 from base64 import b64encode
6 import json
7 import re
8+from twisted.python.failure import Failure
9+from twisted.web.error import Error
10 from urllib import urlencode
11 from urlparse import urljoin
12
13@@ -55,6 +57,19 @@
14 self.admin_secret = config["admin-secret"]
15 super(MAASClient, self).__init__(self.oauth_info)
16
17+ def _process_error(self, failure):
18+ if isinstance(failure, Failure):
19+ error = failure.value
20+ else:
21+ error = failure
22+
23+ # Catch twisted.web.error.Error here as we need to present the
24+ # error text that it comes with.
25+ if isinstance(error, Error):
26+ raise ProviderError(error.response)
27+
28+ return convert_unknown_error(failure)
29+
30 def get(self, path, params):
31 """Dispatch a C{GET} call to a MAAS server.
32
33@@ -66,7 +81,7 @@
34 url = "%s?%s" % (urljoin(self.url, path), urlencode(params))
35 d = self.dispatch_query(url)
36 d.addCallback(json.loads)
37- d.addErrback(convert_unknown_error)
38+ d.addErrback(self._process_error)
39 return d
40
41 def post(self, path, params):
42@@ -80,7 +95,7 @@
43 body, headers = encode_multipart_data(params, {})
44 d = self.dispatch_query(url, "POST", headers=headers, data=body)
45 d.addCallback(json.loads)
46- d.addErrback(convert_unknown_error)
47+ d.addErrback(self._process_error)
48 return d
49
50 def get_nodes(self, resource_uris=None):
51
52=== modified file 'juju/providers/maas/tests/test_launch.py'
53--- juju/providers/maas/tests/test_launch.py 2012-03-28 14:40:14 +0000
54+++ juju/providers/maas/tests/test_launch.py 2012-05-25 06:54:17 +0000
55@@ -6,7 +6,7 @@
56 from StringIO import StringIO
57 from twisted.internet import defer
58 from twisted.internet.defer import inlineCallbacks
59-from xmlrpclib import Fault
60+from twisted.web.error import Error
61
62 from juju.errors import ProviderError
63 from juju.lib.mocker import ANY
64@@ -78,12 +78,10 @@
65 # These arbitrary fake failure values come from
66 # FakeMAASHTTPConnectionWithNoAvailableNodes.acquire_node()
67 def check_failure_values(failure):
68- code = failure.faultCode
69- text = failure.faultString
70- self.assertEqual(1, code)
71- self.assertEqual("No available nodes", text)
72+ text = failure.message
73+ self.assertEqual("No matching node is available.", text)
74
75- return self.assertFailure(d, Fault).addBoth(check_failure_values)
76+ return self.assertFailure(d, ProviderError).addBoth(check_failure_values)
77
78 @inlineCallbacks
79 def test_actually_launch(self):
80
81=== modified file 'juju/providers/maas/tests/test_maas.py'
82--- juju/providers/maas/tests/test_maas.py 2012-03-28 14:40:14 +0000
83+++ juju/providers/maas/tests/test_maas.py 2012-05-25 06:54:17 +0000
84@@ -11,7 +11,8 @@
85 from juju.errors import ProviderError
86 from juju.providers.maas.maas import extract_system_id, MAASClient
87 from juju.providers.maas.tests.testing import (
88- CONFIG, FakeMAASHTTPConnection, NODE_JSON, TestCase)
89+ CONFIG, FakeMAASHTTPConnection,
90+ FakeMAASHTTPConnectionWithNoAvailableNodes, NODE_JSON, TestCase)
91
92
93 class TestFunctions(TestCase):
94@@ -211,6 +212,14 @@
95 self.assertIn("Authorization", factory_call.result.headers)
96
97 @inlineCallbacks
98+ def test_acquire_node_raises_correct_exception_when_CONFLICT_happens(self):
99+ log = self.setup_connection(
100+ MAASClient, FakeMAASHTTPConnectionWithNoAvailableNodes)
101+ client = MAASClient(CONFIG)
102+ e = yield self.assertFailure(client.acquire_node(), ProviderError)
103+ self.assertEqual("No matching node is available.", str(e))
104+
105+ @inlineCallbacks
106 def test_start_node(self):
107 resource_uri = NODE_JSON[0]["resource_uri"]
108 data = "This is test data."
109
110=== modified file 'juju/providers/maas/tests/testing.py'
111--- juju/providers/maas/tests/testing.py 2012-03-28 14:40:14 +0000
112+++ juju/providers/maas/tests/testing.py 2012-05-25 06:54:17 +0000
113@@ -6,7 +6,7 @@
114 from collections import namedtuple
115 import json
116 from twisted.internet import defer
117-from xmlrpclib import Fault
118+from twisted.web.error import Error
119
120 from juju.lib import testing
121 from juju.providers.maas.auth import DEFAULT_FACTORY, MAASOAuthConnection
122@@ -167,4 +167,4 @@
123 are available."""
124
125 def acquire_node(self):
126- raise Fault(1, "No available nodes")
127+ return defer.fail(Error(409, "CONFLICT", "No matching node is available."))

Subscribers

People subscribed via source and target branches

to status/vote changes: