Merge lp:~gz/pyjuju/0.6_maas_tagless_compat into lp:pyjuju/0.6

Proposed by Martin Packman on 2012-11-06
Status: Merged
Approved by: Martin Packman on 2012-11-14
Approved revision: 595
Merged at revision: 596
Proposed branch: lp:~gz/pyjuju/0.6_maas_tagless_compat
Merge into: lp:pyjuju/0.6
Diff against target: 100 lines (+35/-3)
2 files modified
juju/providers/maas/maas.py (+13/-2)
juju/providers/maas/tests/test_maas.py (+22/-1)
To merge this branch: bzr merge lp:~gz/pyjuju/0.6_maas_tagless_compat
Reviewer Review Type Date Requested Status
Juju Engineering 2012-11-06 Pending
Review via email: mp+133098@code.launchpad.net

Description of the change

Bring fix for precise MaaS compatibility to quantal Juju version.

Noticed a merge/cleanup issue with the change that left a stub method defintion behind, which will remove from trunk.

To post a comment you must log in.

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-10-04 11:16:58 +0000
3+++ juju/providers/maas/maas.py 2012-11-06 16:43:20 +0000
4@@ -5,7 +5,9 @@
5
6 from base64 import b64encode
7 import json
8+import logging
9 import re
10+from twisted.internet.defer import inlineCallbacks, returnValue
11 from twisted.python.failure import Failure
12 from twisted.web.error import Error
13 from urllib import urlencode
14@@ -17,6 +19,9 @@
15 from juju.providers.maas.files import encode_multipart_data
16
17
18+log = logging.getLogger("juju.maas")
19+
20+
21 CONSUMER_SECRET = ""
22
23
24@@ -80,7 +85,7 @@
25 # error text that it comes with.
26 if isinstance(error, Error):
27 raise ProviderError(error.response)
28-
29+
30 return convert_unknown_error(failure)
31
32 def get(self, path, params):
33@@ -172,10 +177,16 @@
34 params = {"op": "release"}
35 return self.post(resource_uri, params)
36
37+ @inlineCallbacks
38 def list_tags(self):
39 """Ask MAAS to return a list of all the tags defined.
40
41 :return: A Deferred whose value is the list of tags.
42 """
43 params = {"op": "list"}
44- return self.get("api/1.0/tags/", params)
45+ try:
46+ value = yield self.get("api/1.0/tags/", params)
47+ except ProviderError as e:
48+ log.error("Listing valid maas-tags failed: %s", e)
49+ value = []
50+ returnValue(value)
51
52=== modified file 'juju/providers/maas/tests/test_maas.py'
53--- juju/providers/maas/tests/test_maas.py 2012-10-04 11:16:58 +0000
54+++ juju/providers/maas/tests/test_maas.py 2012-11-06 16:43:20 +0000
55@@ -5,9 +5,11 @@
56
57 import json
58 from textwrap import dedent
59-from twisted.internet.defer import inlineCallbacks, succeed
60 from urlparse import urlparse
61
62+from twisted.internet.defer import inlineCallbacks, fail, succeed
63+from twisted.web.error import Error
64+
65 from juju.errors import ProviderError
66 from juju.providers.maas.maas import extract_system_id, MAASClient
67 from juju.providers.maas.tests.testing import (
68@@ -15,6 +17,13 @@
69 FakeMAASHTTPConnectionWithNoAvailableNodes, NODE_JSON, TestCase)
70
71
72+class FakeMAASHTTPConnectionWithNoTags(FakeMAASHTTPConnection):
73+ """Fake client that raises Not Found on tag listing"""
74+
75+ def list_tags(self):
76+ return fail(Error(404, "Not Found", "Tags? What tags?"))
77+
78+
79 class TestFunctions(TestCase):
80
81 def assertExtractSystemID(self, system_id, resource_uri):
82@@ -220,6 +229,18 @@
83 self.assertEqual("No matching node is available.", str(e))
84
85 @inlineCallbacks
86+ def test_list_tags_unsupported(self):
87+ """When tags are unspupported just report no valid tags"""
88+ log = self.setup_connection(
89+ MAASClient, FakeMAASHTTPConnectionWithNoTags)
90+ client = MAASClient(CONFIG)
91+ log = self.capture_logging()
92+ result = yield client.list_tags()
93+ self.assertEqual([], result)
94+ self.assertRegexpMatches(log.getvalue(),
95+ "(?m)^Listing valid maas-tags failed: ")
96+
97+ @inlineCallbacks
98 def test_start_node(self):
99 resource_uri = NODE_JSON[0]["resource_uri"]
100 series = "splendid"

Subscribers

People subscribed via source and target branches