Merge lp:~julian-edwards/pyjuju/maas-get-nodes-fix into lp:pyjuju

Proposed by Julian Edwards
Status: Merged
Approved by: William Reade
Approved revision: 487
Merged at revision: 487
Proposed branch: lp:~julian-edwards/pyjuju/maas-get-nodes-fix
Merge into: lp:pyjuju
Diff against target: 107 lines (+43/-4)
4 files modified
juju/providers/maas/maas.py (+1/-1)
juju/providers/maas/tests/testing.py (+2/-2)
juju/unit/address.py (+14/-0)
juju/unit/tests/test_address.py (+26/-1)
To merge this branch: bzr merge lp:~julian-edwards/pyjuju/maas-get-nodes-fix
Reviewer Review Type Date Requested Status
William Reade (community) Approve
Review via email: mp+98792@code.launchpad.net

Commit message

Fix the MAAS API call that is used for get_nodes so that it only returns allocated nodes. Also add MAASUnitAddress.

Description of the change

Fix the MAAS API call that is used for get_nodes so that it only returns allocated nodes. Also a MAASUnitAddress was missing so I've added one.

To post a comment you must log in.
488. By Julian Edwards

Add MAASUnitAddress

Revision history for this message
William Reade (fwereade) wrote :

LGTM, I will land this shortly.

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-06 11:21:45 +0000
3+++ juju/providers/maas/maas.py 2012-03-22 09:11:18 +0000
4@@ -66,7 +66,7 @@
5
6 :return: A Deferred whose value is the list of nodes.
7 """
8- params = [("op", "list")]
9+ params = [("op", "list_allocated")]
10 if system_ids is not None:
11 params.extend(("id", system_id) for system_id in system_ids)
12 return self._get("/api/1.0/nodes/", params)
13
14=== modified file 'juju/providers/maas/tests/testing.py'
15--- juju/providers/maas/tests/testing.py 2012-03-08 01:19:31 +0000
16+++ juju/providers/maas/tests/testing.py 2012-03-22 09:11:18 +0000
17@@ -111,10 +111,10 @@
18
19 def get(self):
20 # List all nodes.
21- if self.url.endswith("/nodes/?op=list"):
22+ if self.url.endswith("/nodes/?op=list_allocated"):
23 return self.list_nodes()
24 # List some nodes.
25- elif "nodes/?op=list&id=" in self.url:
26+ elif "nodes/?op=list_allocated&id=" in self.url:
27 return self.list_some_nodes()
28 # Not recognized.
29 else:
30
31=== modified file 'juju/unit/address.py'
32--- juju/unit/address.py 2011-10-01 03:55:03 +0000
33+++ juju/unit/address.py 2012-03-22 09:11:18 +0000
34@@ -22,6 +22,8 @@
35 returnValue(OrchestraUnitAddress())
36 elif provider_type == "dummy":
37 returnValue(DummyUnitAddress())
38+ elif provider_type == "maas":
39+ returnValue(MAASUnitAddress())
40
41 raise JujuError(
42 "Unknown provider type: %r, unit addresses unknown." % provider_type)
43@@ -84,3 +86,15 @@
44 def _get_address(self):
45 output = subprocess.check_output(["hostname", "-f"])
46 return output.strip()
47+
48+class MAASUnitAddress(UnitAddress):
49+
50+ def get_private_address(self):
51+ return deferToThread(self._get_address)
52+
53+ def get_public_address(self):
54+ return deferToThread(self._get_address)
55+
56+ def _get_address(self):
57+ output = subprocess.check_output(["hostname", "-f"])
58+ return output.strip()
59
60=== modified file 'juju/unit/tests/test_address.py'
61--- juju/unit/tests/test_address.py 2011-10-01 03:55:03 +0000
62+++ juju/unit/tests/test_address.py 2012-03-22 09:11:18 +0000
63@@ -8,7 +8,7 @@
64 from juju.lib.testing import TestCase
65 from juju.unit.address import (
66 EC2UnitAddress, LocalUnitAddress, OrchestraUnitAddress, DummyUnitAddress,
67- get_unit_address)
68+ MAASUnitAddress, get_unit_address)
69 from juju.state.environment import GlobalSettingsStateManager
70
71
72@@ -46,6 +46,11 @@
73 address = yield self.get_address_for("dummy")
74 self.assertTrue(isinstance(address, DummyUnitAddress))
75
76+ @inlineCallbacks
77+ def test_get_MAAS_address(self):
78+ address = yield self.get_address_for("maas")
79+ self.assertTrue(isinstance(address, MAASUnitAddress))
80+
81 def test_get_unknown_address(self):
82 return self.assertFailure(self.get_address_for("foobar"), JujuError)
83
84@@ -124,3 +129,23 @@
85 self.assertEqual(
86 (yield self.address.get_private_address()),
87 "slice.foobar.domain.net")
88+
89+
90+class MAASAddressTest(TestCase):
91+
92+ def setUp(self):
93+ self.address = OrchestraUnitAddress()
94+
95+ @inlineCallbacks
96+ def test_get_address(self):
97+ self.patch(
98+ subprocess, "check_output",
99+ lambda args: "absent.friends.net\n")
100+
101+ self.assertEqual(
102+ (yield self.address.get_public_address()),
103+ "absent.friends.net")
104+
105+ self.assertEqual(
106+ (yield self.address.get_private_address()),
107+ "absent.friends.net")

Subscribers

People subscribed via source and target branches

to status/vote changes: