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
1=== modified file 'juju/lib/serializer.py'
2--- juju/lib/serializer.py 2012-09-14 15:33:33 +0000
3+++ juju/lib/serializer.py 2013-02-16 15:14:26 +0000
4@@ -2,20 +2,22 @@
5 from yaml import dump as _dump
6 from yaml import load as _load
7
8+
9 def dump(value):
10 return _dump(value, Dumper=CSafeDumper)
11
12 yaml_dump = dump
13
14+
15 def load(value):
16 return _load(value, Loader=CSafeLoader)
17
18 yaml_load = load
19
20+
21 def yaml_mark_with_path(path, mark):
22 # yaml c ext, cant be modded, convert to capture path
23 return Mark(
24 path, mark.index,
25 mark.line, mark.column,
26 mark.buffer, mark.pointer)
27-
28
29=== modified file 'juju/machine/tests/test_constraints.py'
30--- juju/machine/tests/test_constraints.py 2012-07-24 15:05:16 +0000
31+++ juju/machine/tests/test_constraints.py 2013-02-16 15:14:26 +0000
32@@ -165,6 +165,7 @@
33 other_cs = ConstraintSet("other")
34 other_cs.register_generics([])
35 other_constraints = other_cs.parse([])
36+
37 instances = (
38 dummy_constraints.with_series("x"),
39 dummy_constraints.with_series("y"),
40
41=== modified file 'juju/providers/maas/provider.py'
42--- juju/providers/maas/provider.py 2012-10-10 15:24:48 +0000
43+++ juju/providers/maas/provider.py 2013-02-16 15:14:26 +0000
44@@ -45,7 +45,7 @@
45 if tag not in self.tag_names:
46 raise ValueError("tag %r does not exist" % (tag,))
47 tags.add(tag)
48- return tag_expression
49+ return tags
50
51
52 class MachineProvider(MachineProviderBase):
53@@ -79,7 +79,7 @@
54 tags_info = yield self.maas_client.list_tags()
55 handler = _TagHandler(tags_info)
56 cs.register("maas-tags", converter=handler.convert,
57- comparer=handler.compare)
58+ comparer=handler.compare)
59 returnValue(cs)
60
61 def get_serialization_data(self):
62
63=== modified file 'juju/providers/maas/tests/test_provider.py'
64--- juju/providers/maas/tests/test_provider.py 2012-10-10 13:16:45 +0000
65+++ juju/providers/maas/tests/test_provider.py 2013-02-16 15:14:26 +0000
66@@ -7,6 +7,9 @@
67
68 from juju.errors import ConstraintError, MachinesNotFound, ProviderError
69 from juju.lib.mocker import ANY
70+from juju.lib import serializer
71+from juju.machine.constraints import Constraints
72+
73 from juju.providers.maas import MachineProvider
74 from juju.providers.maas.maas import MAASClient
75 from juju.providers.maas.tests.testing import (
76@@ -183,14 +186,35 @@
77 {'name': "clawed", 'definition': "HAS claws", 'comment': ""},
78 ]))
79 self.mocker.replay()
80+
81 provider = MachineProvider("maasiv", CONFIG)
82 provider.maas_client = mock_client
83 cs = yield provider.get_constraint_set()
84 bear = cs.parse(["maas-tags=clawed, furry"])
85- bear.can_satisfy(bear)
86- self.assertEqual("clawed, furry", bear["maas-tags"])
87- err = self.assertRaises(ConstraintError,
88+
89+ # Incomplete constraints (no series) can't satisify
90+ self.assertFalse(bear.can_satisfy(bear))
91+
92+ self.assertEqual(set(["clawed", "furry"]), bear["maas-tags"])
93+
94+ err = self.assertRaises(
95+ ConstraintError,
96 cs.parse, ["maas-tags=furry, bouncy"])
97- self.assertEqual("Bad 'maas-tags' constraint 'furry, bouncy': "
98+
99+ self.assertEqual(
100+ "Bad 'maas-tags' constraint 'furry, bouncy': "
101 "tag 'bouncy' does not exist",
102 str(err))
103+
104+ bear = bear.with_series("precise")
105+
106+ # Ensure we can roundtrip through serialization.
107+ raw = serializer.dump(bear.data)
108+ grizzly = cs.load(serializer.load(raw))
109+
110+ self.assertTrue(grizzly.can_satisfy(bear))
111+ rodent = cs.parse(
112+ ["maas-tags=clawed"]).with_series("raring")
113+ self.assertFalse(rodent.can_satisfy(grizzly))
114+ self.assertTrue(grizzly.can_satisfy(
115+ rodent.with_series("precise")))
116
117=== modified file 'juju/unit/lifecycle.py'
118--- juju/unit/lifecycle.py 2013-02-14 22:59:57 +0000
119+++ juju/unit/lifecycle.py 2013-02-16 15:14:26 +0000
120@@ -401,13 +401,11 @@
121 added = self._sort_relations(
122 set(new_relations.keys()) - set(self._relations.keys()),
123 new_relations)
124- print 'add', added, [new_relations[a] for a in added]
125
126 removed = self._sort_relations(
127 set(self._relations.keys()) - set(new_relations.keys()),
128 self._relations,
129 invert=True)
130- print 'removed', removed
131
132 # Could this service be a principal container?
133 is_principal = not (yield self._service.is_subordinate())

Subscribers

People subscribed via source and target branches

to status/vote changes: