Merge lp:~hazmat/pyjuju/maas-tags-redux into lp:pyjuju

Proposed by Kapil Thangavelu
Status: Merged
Merged at revision: 616
Proposed branch: lp:~hazmat/pyjuju/maas-tags-redux
Merge into: lp:pyjuju
Diff against target: 133 lines (+34/-9)
5 files modified
juju/lib/serializer.py (+3/-1)
juju/machine/tests/test_constraints.py (+1/-0)
juju/providers/maas/provider.py (+2/-2)
juju/providers/maas/tests/test_provider.py (+28/-4)
juju/unit/lifecycle.py (+0/-2)
To merge this branch: bzr merge lp:~hazmat/pyjuju/maas-tags-redux
Reviewer Review Type Date Requested Status
Juju Engineering Pending
Review via email: mp+148876@code.launchpad.net

Description of the change

Fix broken maas-tags constraint.

The maas tags wasn't properly converting values for comparision
and was not previously testing tag constraint comparisons.

To post a comment you must log in.
Revision history for this message
Kapil Thangavelu (hazmat) wrote :

Please take a look.

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

*** Submitted:

Fix broken maas-tags constraint.

The maas tags wasn't properly converting values for comparision
and was not previously testing tag constraint comparisons.

Revision history for this message
Martin Packman (gz) wrote :

This looks like a straight revert of r597 which confuses me somewhat. Does this mean bug 1064734 is unfixed by this change, or have we changed something since?

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'juju/lib/serializer.py'
--- juju/lib/serializer.py 2012-09-14 15:33:33 +0000
+++ juju/lib/serializer.py 2013-02-16 15:14:26 +0000
@@ -2,20 +2,22 @@
2from yaml import dump as _dump2from yaml import dump as _dump
3from yaml import load as _load3from yaml import load as _load
44
5
5def dump(value):6def dump(value):
6 return _dump(value, Dumper=CSafeDumper)7 return _dump(value, Dumper=CSafeDumper)
78
8yaml_dump = dump9yaml_dump = dump
910
11
10def load(value):12def load(value):
11 return _load(value, Loader=CSafeLoader)13 return _load(value, Loader=CSafeLoader)
1214
13yaml_load = load15yaml_load = load
1416
17
15def yaml_mark_with_path(path, mark):18def yaml_mark_with_path(path, mark):
16 # yaml c ext, cant be modded, convert to capture path19 # yaml c ext, cant be modded, convert to capture path
17 return Mark(20 return Mark(
18 path, mark.index,21 path, mark.index,
19 mark.line, mark.column,22 mark.line, mark.column,
20 mark.buffer, mark.pointer)23 mark.buffer, mark.pointer)
21
2224
=== modified file 'juju/machine/tests/test_constraints.py'
--- juju/machine/tests/test_constraints.py 2012-07-24 15:05:16 +0000
+++ juju/machine/tests/test_constraints.py 2013-02-16 15:14:26 +0000
@@ -165,6 +165,7 @@
165 other_cs = ConstraintSet("other")165 other_cs = ConstraintSet("other")
166 other_cs.register_generics([])166 other_cs.register_generics([])
167 other_constraints = other_cs.parse([])167 other_constraints = other_cs.parse([])
168
168 instances = (169 instances = (
169 dummy_constraints.with_series("x"),170 dummy_constraints.with_series("x"),
170 dummy_constraints.with_series("y"),171 dummy_constraints.with_series("y"),
171172
=== modified file 'juju/providers/maas/provider.py'
--- juju/providers/maas/provider.py 2012-10-10 15:24:48 +0000
+++ juju/providers/maas/provider.py 2013-02-16 15:14:26 +0000
@@ -45,7 +45,7 @@
45 if tag not in self.tag_names:45 if tag not in self.tag_names:
46 raise ValueError("tag %r does not exist" % (tag,))46 raise ValueError("tag %r does not exist" % (tag,))
47 tags.add(tag)47 tags.add(tag)
48 return tag_expression48 return tags
4949
5050
51class MachineProvider(MachineProviderBase):51class MachineProvider(MachineProviderBase):
@@ -79,7 +79,7 @@
79 tags_info = yield self.maas_client.list_tags()79 tags_info = yield self.maas_client.list_tags()
80 handler = _TagHandler(tags_info)80 handler = _TagHandler(tags_info)
81 cs.register("maas-tags", converter=handler.convert,81 cs.register("maas-tags", converter=handler.convert,
82 comparer=handler.compare)82 comparer=handler.compare)
83 returnValue(cs)83 returnValue(cs)
8484
85 def get_serialization_data(self):85 def get_serialization_data(self):
8686
=== modified file 'juju/providers/maas/tests/test_provider.py'
--- juju/providers/maas/tests/test_provider.py 2012-10-10 13:16:45 +0000
+++ juju/providers/maas/tests/test_provider.py 2013-02-16 15:14:26 +0000
@@ -7,6 +7,9 @@
77
8from juju.errors import ConstraintError, MachinesNotFound, ProviderError8from juju.errors import ConstraintError, MachinesNotFound, ProviderError
9from juju.lib.mocker import ANY9from juju.lib.mocker import ANY
10from juju.lib import serializer
11from juju.machine.constraints import Constraints
12
10from juju.providers.maas import MachineProvider13from juju.providers.maas import MachineProvider
11from juju.providers.maas.maas import MAASClient14from juju.providers.maas.maas import MAASClient
12from juju.providers.maas.tests.testing import (15from juju.providers.maas.tests.testing import (
@@ -183,14 +186,35 @@
183 {'name': "clawed", 'definition': "HAS claws", 'comment': ""},186 {'name': "clawed", 'definition': "HAS claws", 'comment': ""},
184 ]))187 ]))
185 self.mocker.replay()188 self.mocker.replay()
189
186 provider = MachineProvider("maasiv", CONFIG)190 provider = MachineProvider("maasiv", CONFIG)
187 provider.maas_client = mock_client191 provider.maas_client = mock_client
188 cs = yield provider.get_constraint_set()192 cs = yield provider.get_constraint_set()
189 bear = cs.parse(["maas-tags=clawed, furry"])193 bear = cs.parse(["maas-tags=clawed, furry"])
190 bear.can_satisfy(bear)194
191 self.assertEqual("clawed, furry", bear["maas-tags"])195 # Incomplete constraints (no series) can't satisify
192 err = self.assertRaises(ConstraintError,196 self.assertFalse(bear.can_satisfy(bear))
197
198 self.assertEqual(set(["clawed", "furry"]), bear["maas-tags"])
199
200 err = self.assertRaises(
201 ConstraintError,
193 cs.parse, ["maas-tags=furry, bouncy"])202 cs.parse, ["maas-tags=furry, bouncy"])
194 self.assertEqual("Bad 'maas-tags' constraint 'furry, bouncy': "203
204 self.assertEqual(
205 "Bad 'maas-tags' constraint 'furry, bouncy': "
195 "tag 'bouncy' does not exist",206 "tag 'bouncy' does not exist",
196 str(err))207 str(err))
208
209 bear = bear.with_series("precise")
210
211 # Ensure we can roundtrip through serialization.
212 raw = serializer.dump(bear.data)
213 grizzly = cs.load(serializer.load(raw))
214
215 self.assertTrue(grizzly.can_satisfy(bear))
216 rodent = cs.parse(
217 ["maas-tags=clawed"]).with_series("raring")
218 self.assertFalse(rodent.can_satisfy(grizzly))
219 self.assertTrue(grizzly.can_satisfy(
220 rodent.with_series("precise")))
197221
=== modified file 'juju/unit/lifecycle.py'
--- juju/unit/lifecycle.py 2013-02-14 22:59:57 +0000
+++ juju/unit/lifecycle.py 2013-02-16 15:14:26 +0000
@@ -401,13 +401,11 @@
401 added = self._sort_relations(401 added = self._sort_relations(
402 set(new_relations.keys()) - set(self._relations.keys()),402 set(new_relations.keys()) - set(self._relations.keys()),
403 new_relations)403 new_relations)
404 print 'add', added, [new_relations[a] for a in added]
405404
406 removed = self._sort_relations(405 removed = self._sort_relations(
407 set(self._relations.keys()) - set(new_relations.keys()),406 set(self._relations.keys()) - set(new_relations.keys()),
408 self._relations,407 self._relations,
409 invert=True)408 invert=True)
410 print 'removed', removed
411409
412 # Could this service be a principal container?410 # Could this service be a principal container?
413 is_principal = not (yield self._service.is_subordinate())411 is_principal = not (yield self._service.is_subordinate())

Subscribers

People subscribed via source and target branches

to status/vote changes: