Merge lp:~andreserl/pyjuju/maas_provider_distro_series into lp:pyjuju

Proposed by Andres Rodriguez
Status: Merged
Merged at revision: 579
Proposed branch: lp:~andreserl/pyjuju/maas_provider_distro_series
Merge into: lp:pyjuju
Diff against target: 196 lines (+23/-38)
8 files modified
juju/environment/config.py (+1/-1)
juju/environment/tests/test_config.py (+5/-7)
juju/providers/maas/launch.py (+2/-1)
juju/providers/maas/maas.py (+2/-2)
juju/providers/maas/provider.py (+1/-7)
juju/providers/maas/tests/test_launch.py (+9/-6)
juju/providers/maas/tests/test_maas.py (+3/-2)
juju/providers/maas/tests/test_provider.py (+0/-12)
To merge this branch: bzr merge lp:~andreserl/pyjuju/maas_provider_distro_series
Reviewer Review Type Date Requested Status
Kapil Thangavelu (community) Approve
Review via email: mp+125505@code.launchpad.net

Commit message

Add support for distro/ubuntu series to MAAS provider

Description of the change

Add maas support for release series

Removes hardcoded precise series, as maas now supports multiple distro
series.

To post a comment you must log in.
Revision history for this message
Andres Rodriguez (andreserl) wrote :

All,

I can't seem to figure out the test above and I'd appreciate if someone else could have a look and help me out since we would like to get this merged ASAP.

Cheers.

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

this appears to be a request for help rather than a merge proposal. a diff/patch that fixes this test failure is here.
http://paste.ubuntu.com/1219433/

please repropose if this intended for a review and merge.

Revision history for this message
Andres Rodriguez (andreserl) wrote :

Hi Kapil,

Thanks for the path. I have set this back to 'Needs Review'.

Thank you.

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

tests were broken... should be using lib.serializer.dump

+ self.write_config(yaml.dump(config), other_path=True)

would have been nice to see a test for a non supported series.

the branch looks fine though, nice to see the maas provider improvements.

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

*** Submitted:

Add maas support for release series

Removes hardcoded precise series, as maas now supports multiple distro
series.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'juju/environment/config.py'
2--- juju/environment/config.py 2012-09-15 19:24:00 +0000
3+++ juju/environment/config.py 2012-09-24 17:16:21 +0000
4@@ -118,7 +118,7 @@
5 "placement": _EITHER_PLACEMENT,
6 # MAAS currently only provisions precise; any other default-series
7 # would just lead to errors down the line.
8- "default-series": Constant("precise")},
9+ "default-series": String()},
10 optional=["placement"]),
11 "local": KeyDict({
12 "admin-secret": String(),
13
14=== modified file 'juju/environment/tests/test_config.py'
15--- juju/environment/tests/test_config.py 2012-09-15 18:00:48 +0000
16+++ juju/environment/tests/test_config.py 2012-09-24 17:16:21 +0000
17@@ -722,13 +722,11 @@
18 def test_maas_default_series(self):
19 config = serializer.yaml_load(SAMPLE_MAAS)
20 config["environments"]["sample"]["default-series"] = "magnificent"
21- self.write_config(serializer.yaml_dump(config), other_path=True)
22- e = self.assertRaises(
23- EnvironmentsConfigError, self.config.load, self.other_path)
24- self.assertIn(
25- "environments.sample.default-series: expected 'precise', got "
26- "'magnificent'",
27- str(e))
28+ self.write_config(yaml.dump(config), other_path=True)
29+ self.config.load(self.other_path)
30+
31+ provider = self.config.get_default().get_machine_provider()
32+ self.assertEqual(provider.config["default-series"], "magnificent")
33
34 def test_maas_verifies_placement(self):
35 config = serializer.yaml_load(SAMPLE_MAAS)
36
37=== modified file 'juju/providers/maas/launch.py'
38--- juju/providers/maas/launch.py 2012-03-28 14:40:14 +0000
39+++ juju/providers/maas/launch.py 2012-09-24 17:16:21 +0000
40@@ -36,6 +36,7 @@
41 :rtype: :class:`twisted.internet.defer.Deferred`
42 """
43 maas_client = self._provider.maas_client
44+ series = self._constraints["ubuntu-series"]
45 instance_data = yield maas_client.acquire_node(self._constraints)
46 instance_uri = instance_data["resource_uri"]
47 # If anything goes wrong after the acquire and before the launch
48@@ -45,7 +46,7 @@
49 cloud_init.set_provider_type("maas")
50 cloud_init.set_instance_id_accessor(instance_uri)
51 node_data = yield maas_client.start_node(
52- instance_uri, cloud_init.render())
53+ instance_uri, series, cloud_init.render())
54 machine = MAASMachine.from_dict(node_data)
55 except Exception:
56 log.exception(
57
58=== modified file 'juju/providers/maas/maas.py'
59--- juju/providers/maas/maas.py 2012-05-25 06:49:32 +0000
60+++ juju/providers/maas/maas.py 2012-09-24 17:16:21 +0000
61@@ -124,7 +124,7 @@
62 params["name"] = name
63 return self.post("api/1.0/nodes/", params)
64
65- def start_node(self, resource_uri, user_data):
66+ def start_node(self, resource_uri, ubuntu_series, user_data):
67 """Ask MAAS to start a node.
68
69 :param resource_uri: The MAAS URI for the node you want to start.
70@@ -135,7 +135,7 @@
71 """
72 assert isinstance(user_data, str), (
73 "User data must be a byte string.")
74- params = {"op": "start", "user_data": b64encode(user_data)}
75+ params = {"op": "start", "distro_series": ubuntu_series, "user_data": b64encode(user_data)}
76 return self.post(resource_uri, params)
77
78 def stop_node(self, resource_uri):
79
80=== modified file 'juju/providers/maas/provider.py'
81--- juju/providers/maas/provider.py 2012-03-28 14:40:14 +0000
82+++ juju/providers/maas/provider.py 2012-09-24 17:16:21 +0000
83@@ -38,13 +38,7 @@
84 """Return the set of constraints that are valid for this provider."""
85 cs = yield super(MachineProvider, self).get_constraint_set()
86
87- def require_precise(s):
88- if s != "precise":
89- raise ValueError(
90- "MAAS currently only provisions machines running precise")
91- return s
92-
93- cs.register("ubuntu-series", converter=require_precise, visible=False)
94+ cs.register("ubuntu-series", visible=False)
95 cs.register("maas-name")
96 returnValue(cs)
97
98
99=== modified file 'juju/providers/maas/tests/test_launch.py'
100--- juju/providers/maas/tests/test_launch.py 2012-05-25 06:32:24 +0000
101+++ juju/providers/maas/tests/test_launch.py 2012-09-24 17:16:21 +0000
102@@ -72,7 +72,8 @@
103 provider = self._get_provider(
104 FakeMAASHTTPConnectionWithNoAvailableNodes)
105 machine_data = {
106- "machine-id": "foo", "constraints": {"maas-name": None}}
107+ "machine-id": "foo", "constraints": {"maas-name": None,
108+ "ubuntu-series": "splendid"}}
109 d = provider.start_machine(machine_data)
110
111 # These arbitrary fake failure values come from
112@@ -94,7 +95,8 @@
113 # Try to start up that node using the fake MAAS.
114 provider = self._get_provider(FakeMAASHTTPConnection)
115 machine_data = {
116- "machine-id": machine_id, "constraints": {"maas-name": None}}
117+ "machine-id": machine_id, "constraints": {"maas-name": None,
118+ "ubuntu-series": "splendid"}}
119 machine_list = yield provider.start_machine(machine_data)
120
121 # Test that it returns a list containing a single MAASMachine
122@@ -118,7 +120,7 @@
123 self.assertEqual("moon", target_node["hostname"])
124 machine_id = "foo"
125 provider = self._get_provider(FakeMAASHTTPConnection)
126- constraints = {"maas-name": "moon"}
127+ constraints = {"maas-name": "moon", "ubuntu-series": "splendid"}
128 machine_data = {"machine-id": machine_id, "constraints": constraints}
129 machine_list = yield provider.start_machine(machine_data)
130
131@@ -147,10 +149,10 @@
132 # The following operations happen in sequence.
133 mocker.order()
134 # First, the node is acquired.
135- mock_client.acquire_node({"maas-name": None})
136+ mock_client.acquire_node({"maas-name": None, "ubuntu-series": "precise"})
137 mocker.result({"resource_uri": "/node/123"})
138 # Second, the node is started. We simulate a failure at this stage.
139- mock_client.start_node("/node/123", ANY)
140+ mock_client.start_node("/node/123", "precise", ANY)
141 mocker.throw(ZeroDivisionError)
142 # Last, the node is released.
143 mock_client.release_node("/node/123")
144@@ -158,5 +160,6 @@
145
146 mocker.replay()
147 return self.assertFailure(
148- MAASLaunchMachine(mock_provider, {"maas-name": None}).run("fred"),
149+ MAASLaunchMachine(mock_provider,
150+ {"maas-name": None, "ubuntu-series": "precise"}).run("fred"),
151 ZeroDivisionError)
152
153=== modified file 'juju/providers/maas/tests/test_maas.py'
154--- juju/providers/maas/tests/test_maas.py 2012-06-06 19:08:04 +0000
155+++ juju/providers/maas/tests/test_maas.py 2012-09-24 17:16:21 +0000
156@@ -222,9 +222,10 @@
157 @inlineCallbacks
158 def test_start_node(self):
159 resource_uri = NODE_JSON[0]["resource_uri"]
160+ series = "splendid"
161 data = "This is test data."
162 client, log = self.get_client()
163- returned_data = yield client.start_node(resource_uri, data)
164+ returned_data = yield client.start_node(resource_uri, series, data)
165 self.assertEqual(returned_data, NODE_JSON[0])
166 # Also make sure that the connection was passed the user_data in
167 # the POST data.
168@@ -242,7 +243,7 @@
169 @inlineCallbacks
170 def test_start_node_connects_with_oauth_credentials(self):
171 client, log = self.get_client()
172- yield client.start_node("foo", "bar")
173+ yield client.start_node("foo", "splendid", "bar")
174 [factory_call] = [
175 record for record in log if record.called == "factory"]
176 self.assertIn("Authorization", factory_call.result.headers)
177
178=== modified file 'juju/providers/maas/tests/test_provider.py'
179--- juju/providers/maas/tests/test_provider.py 2012-03-28 14:40:14 +0000
180+++ juju/providers/maas/tests/test_provider.py 2012-09-24 17:16:21 +0000
181@@ -164,15 +164,3 @@
182 self.assertFalse(nil.can_satisfy(ben))
183 self.assertFalse(ben.can_satisfy(bill))
184 self.assertFalse(bill.can_satisfy(ben))
185-
186- @inlineCallbacks
187- def test_precise_only_constraints(self):
188- provider = MachineProvider("blah", CONFIG)
189- cs = yield provider.get_constraint_set()
190- e = self.assertRaises(
191- ConstraintError, cs.parse([]).with_series, "not-precise")
192- self.assertEquals(
193- str(e),
194- "Bad 'ubuntu-series' constraint 'not-precise': MAAS currently "
195- "only provisions machines running precise")
196-

Subscribers

People subscribed via source and target branches

to status/vote changes: