Merge lp:~hazmat/pyjuju/fast-yaml into lp:pyjuju
- fast-yaml
- Merge into trunk
Status: | Merged | ||||
---|---|---|---|---|---|
Approved by: | Jim Baker | ||||
Approved revision: | 576 | ||||
Merged at revision: | 578 | ||||
Proposed branch: | lp:~hazmat/pyjuju/fast-yaml | ||||
Merge into: | lp:pyjuju | ||||
Diff against target: |
3890 lines (+454/-553) 84 files modified
juju/agents/tests/test_unit.py (+2/-2) juju/charm/config.py (+4/-3) juju/charm/metadata.py (+5/-2) juju/charm/tests/test_base.py (+6/-4) juju/charm/tests/test_bundle.py (+5/-5) juju/charm/tests/test_config.py (+10/-8) juju/charm/tests/test_directory.py (+3/-3) juju/charm/tests/test_metadata.py (+4/-3) juju/charm/tests/test_publisher.py (+3/-3) juju/control/config_set.py (+2/-2) juju/control/constraints_get.py (+3/-2) juju/control/deploy.py (+4/-3) juju/control/initialize.py (+2/-2) juju/control/status.py (+4/-2) juju/control/tests/test_add_unit.py (+2/-3) juju/control/tests/test_bootstrap.py (+2/-2) juju/control/tests/test_config_get.py (+3/-5) juju/control/tests/test_config_set.py (+9/-10) juju/control/tests/test_constraints_get.py (+7/-8) juju/control/tests/test_deploy.py (+10/-11) juju/control/tests/test_destroy_environment.py (+1/-1) juju/control/tests/test_expose.py (+2/-2) juju/control/tests/test_initialize.py (+3/-3) juju/control/tests/test_open_tunnel.py (+3/-2) juju/control/tests/test_remove_relation.py (+2/-2) juju/control/tests/test_scp.py (+0/-1) juju/control/tests/test_status.py (+6/-6) juju/control/tests/test_unexpose.py (+2/-2) juju/control/tests/test_upgrade_charm.py (+3/-2) juju/control/tests/test_utils.py (+1/-1) juju/environment/config.py (+3/-2) juju/environment/tests/test_config.py (+63/-62) juju/hooks/protocol.py (+4/-3) juju/hooks/scheduler.py (+4/-3) juju/hooks/tests/test_invoker.py (+5/-5) juju/hooks/tests/test_scheduler.py (+19/-20) juju/lib/format.py (+3/-3) juju/lib/serializer.py (+21/-0) juju/providers/common/cloudinit.py (+3/-2) juju/providers/common/state.py (+4/-3) juju/providers/common/tests/test_cloudinit.py (+3/-3) juju/providers/common/tests/test_findzookeepers.py (+2/-2) juju/providers/common/tests/test_state.py (+4/-3) juju/providers/common/tests/test_utils.py (+2/-2) juju/providers/common/utils.py (+3/-2) juju/providers/ec2/tests/common.py (+2/-2) juju/providers/ec2/tests/test_bootstrap.py (+4/-5) juju/providers/ec2/tests/test_findzookeeper.py (+1/-2) juju/providers/ec2/tests/test_launch.py (+3/-4) juju/providers/ec2/tests/test_provider.py (+1/-0) juju/providers/ec2/tests/test_state.py (+6/-6) juju/providers/local/files.py (+3/-4) juju/providers/local/tests/test_agent.py (+1/-2) juju/providers/local/tests/test_container.py (+1/-0) juju/providers/local/tests/test_files.py (+3/-2) juju/providers/openstack/tests/test_bootstrap.py (+4/-8) juju/providers/openstack/tests/test_launch.py (+2/-2) juju/providers/openstack/tests/test_state.py (+4/-5) juju/providers/orchestra/tests/common.py (+2/-1) juju/providers/orchestra/tests/test_bootstrap.py (+1/-1) juju/providers/orchestra/tests/test_findzookeepers.py (+1/-2) juju/providers/orchestra/tests/test_state.py (+1/-1) juju/state/charm.py (+4/-4) juju/state/environment.py (+7/-6) juju/state/hook.py (+1/-2) juju/state/machine.py (+2/-2) juju/state/relation.py (+8/-8) juju/state/security.py (+6/-5) juju/state/service.py (+24/-21) juju/state/tests/test_charm.py (+3/-2) juju/state/tests/test_environment.py (+9/-7) juju/state/tests/test_hook.py (+19/-20) juju/state/tests/test_machine.py (+5/-6) juju/state/tests/test_relation.py (+12/-12) juju/state/tests/test_security.py (+4/-4) juju/state/tests/test_service.py (+12/-12) juju/state/tests/test_topology.py (+3/-63) juju/state/tests/test_utils.py (+10/-8) juju/state/topology.py (+5/-82) juju/state/utils.py (+5/-4) juju/unit/lifecycle.py (+3/-3) juju/unit/tests/test_lifecycle.py (+3/-2) juju/unit/tests/test_workflow.py (+5/-5) juju/unit/workflow.py (+8/-8) |
||||
To merge this branch: | bzr merge lp:~hazmat/pyjuju/fast-yaml | ||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Juju Engineering | Pending | ||
Review via email: mp+123470@code.launchpad.net |
Commit message
Description of the change
ensure use of py yaml c extension for speed.
Backwards compatible. Drops test time in half. Should improve speed
across the board, things like status will see marked improvements.
Kapil Thangavelu (hazmat) wrote : | # |
Martin Packman (gz) wrote : | # |
Looks like a good improvement, I like that this also sorts out the
confusion over whether to use dump/load or safe_dump/safe_load at the
same time.
I would have been tempted to name the wrapper module juju.lib.yaml to
avoid touching most lines, but this way means you did look at all the
callers at least.
There are several callsites that still use the yaml module functions and
pass in a Loader or Dumper, apart from the one noted below, shouldn't
they all be changed to using juju.lib for consistency?
https:/
File juju/charm/
https:/
juju/charm/
Loader=
Why not use dump from juju.lib here rather than specifying the loader?
Will need the yaml import for the Mark below anyway, but seems best to
consistently use the same loader.
https:/
File juju/control/
https:/
juju/control/
Dumper=
I'd dump using the juju.lib function and write to stout separately
afterwards here.
https:/
File juju/control/
https:/
juju/control/
Dumper=
This looks like the only place that really wants extra args to dump,
leaving this as a special case seems fine.
https:/
File juju/lib/
https:/
juju/lib/
I'd be tempted to make this just take a dict rather than passing through
args and kwargs.
https:/
juju/lib/
Likewise, would make this just take a string.
- 576. By Kapil Thangavelu
-
explicit yaml dump/load in serializer, and yaml_mark_with_path utility method, switch out juju/charm & juju/control to use
Kapil Thangavelu (hazmat) wrote : | # |
Please take a look.
Jim Baker (jimbaker) wrote : | # |
+1, LGTM, nice speedup and a clean transition to the C extensions. Just
need to take care of the two trivials where CSafeLoader/
used instead of the equivalent juju.lib.serializer wrappers.
https:/
File juju/environmen
https:/
juju/environmen
Loader=
Use juju.lib.
https:/
juju/environmen
Dumper=
Use juju.lib.
- 577. By Kapil Thangavelu
-
switch out juju/env pkg to use serializer for yaml dump/load
- 578. By Kapil Thangavelu
-
merge trunk and resolve conflicts
- 579. By Kapil Thangavelu
-
address some comments from martin's review (sys.stdout.write, use contextmanager for files)
- 580. By Kapil Thangavelu
-
kill useless topo migration, fix some laggards wrt to dump/load future format change isomorphism
Preview Diff
1 | === modified file 'juju/agents/tests/test_unit.py' | |||
2 | --- juju/agents/tests/test_unit.py 2012-03-28 18:57:58 +0000 | |||
3 | +++ juju/agents/tests/test_unit.py 2012-09-15 19:26:18 +0000 | |||
4 | @@ -1,7 +1,6 @@ | |||
5 | 1 | import argparse | 1 | import argparse |
6 | 2 | import logging | 2 | import logging |
7 | 3 | import os | 3 | import os |
8 | 4 | import yaml | ||
9 | 5 | 4 | ||
10 | 6 | from twisted.internet.defer import inlineCallbacks, returnValue | 5 | from twisted.internet.defer import inlineCallbacks, returnValue |
11 | 7 | 6 | ||
12 | @@ -10,6 +9,7 @@ | |||
13 | 10 | from juju.charm import get_charm_from_path | 9 | from juju.charm import get_charm_from_path |
14 | 11 | from juju.charm.url import CharmURL | 10 | from juju.charm.url import CharmURL |
15 | 12 | from juju.errors import JujuError | 11 | from juju.errors import JujuError |
16 | 12 | from juju.lib import serializer | ||
17 | 13 | from juju.state.environment import GlobalSettingsStateManager | 13 | from juju.state.environment import GlobalSettingsStateManager |
18 | 14 | from juju.state.errors import ServiceStateNotFound | 14 | from juju.state.errors import ServiceStateNotFound |
19 | 15 | from juju.state.service import NO_HOOKS, RETRY_HOOKS | 15 | from juju.state.service import NO_HOOKS, RETRY_HOOKS |
20 | @@ -375,7 +375,7 @@ | |||
21 | 375 | self.assertEqual( | 375 | self.assertEqual( |
22 | 376 | {"greeting": "hello", "planet": "earth", | 376 | {"greeting": "hello", "planet": "earth", |
23 | 377 | "private-address": "mysql-0.example.com"}, | 377 | "private-address": "mysql-0.example.com"}, |
25 | 378 | yaml.load(contents)) | 378 | serializer.load(contents)) |
26 | 379 | 379 | ||
27 | 380 | self.failUnlessIn("wordpress/0", output) | 380 | self.failUnlessIn("wordpress/0", output) |
28 | 381 | 381 | ||
29 | 382 | 382 | ||
30 | === modified file 'juju/charm/config.py' | |||
31 | --- juju/charm/config.py 2012-08-30 03:06:56 +0000 | |||
32 | +++ juju/charm/config.py 2012-09-15 19:26:18 +0000 | |||
33 | @@ -1,9 +1,9 @@ | |||
34 | 1 | import copy | 1 | import copy |
35 | 2 | import os | 2 | import os |
36 | 3 | import sys | 3 | import sys |
37 | 4 | |||
38 | 5 | import yaml | 4 | import yaml |
39 | 6 | 5 | ||
40 | 6 | from juju.lib import serializer | ||
41 | 7 | from juju.lib.format import YAMLFormat | 7 | from juju.lib.format import YAMLFormat |
42 | 8 | from juju.lib.schema import (SchemaError, KeyDict, Dict, String, | 8 | from juju.lib.schema import (SchemaError, KeyDict, Dict, String, |
43 | 9 | Constant, OneOf, Int, Float) | 9 | Constant, OneOf, Int, Float) |
44 | @@ -78,11 +78,12 @@ | |||
45 | 78 | """ | 78 | """ |
46 | 79 | if isinstance(data, basestring): | 79 | if isinstance(data, basestring): |
47 | 80 | try: | 80 | try: |
49 | 81 | raw_data = yaml.load(data) | 81 | raw_data = serializer.yaml_load(data) |
50 | 82 | except yaml.MarkedYAMLError, e: | 82 | except yaml.MarkedYAMLError, e: |
51 | 83 | # Capture the path name on the error if present. | 83 | # Capture the path name on the error if present. |
52 | 84 | if pathname is not None: | 84 | if pathname is not None: |
54 | 85 | e.problem_mark.name = pathname | 85 | e.problem_mark = serializer.yaml_mark_with_path( |
55 | 86 | pathname, e.problem_mark) | ||
56 | 86 | raise | 87 | raise |
57 | 87 | elif isinstance(data, dict): | 88 | elif isinstance(data, dict): |
58 | 88 | raw_data = data | 89 | raw_data = data |
59 | 89 | 90 | ||
60 | === modified file 'juju/charm/metadata.py' | |||
61 | --- juju/charm/metadata.py 2012-06-14 17:51:48 +0000 | |||
62 | +++ juju/charm/metadata.py 2012-09-15 19:26:18 +0000 | |||
63 | @@ -5,6 +5,7 @@ | |||
64 | 5 | 5 | ||
65 | 6 | from juju.charm.errors import MetaDataError | 6 | from juju.charm.errors import MetaDataError |
66 | 7 | from juju.errors import FileNotFound | 7 | from juju.errors import FileNotFound |
67 | 8 | from juju.lib import serializer | ||
68 | 8 | from juju.lib.format import is_valid_charm_format | 9 | from juju.lib.format import is_valid_charm_format |
69 | 9 | from juju.lib.schema import ( | 10 | from juju.lib.schema import ( |
70 | 10 | SchemaError, Bool, Constant, Dict, Int, | 11 | SchemaError, Bool, Constant, Dict, Int, |
71 | @@ -200,11 +201,13 @@ | |||
72 | 200 | @raise MetaDataError: When errors are found in the info data. | 201 | @raise MetaDataError: When errors are found in the info data. |
73 | 201 | """ | 202 | """ |
74 | 202 | try: | 203 | try: |
76 | 203 | self.parse_serialization_data(yaml.load(content), path) | 204 | self.parse_serialization_data( |
77 | 205 | serializer.yaml_load(content), path) | ||
78 | 204 | except yaml.MarkedYAMLError, e: | 206 | except yaml.MarkedYAMLError, e: |
79 | 205 | # Capture the path name on the error if present. | 207 | # Capture the path name on the error if present. |
80 | 206 | if path is not None: | 208 | if path is not None: |
82 | 207 | e.problem_mark.name = path | 209 | e.problem_mark = serializer.yaml_mark_with_path( |
83 | 210 | path, e.problem_mark) | ||
84 | 208 | raise | 211 | raise |
85 | 209 | 212 | ||
86 | 210 | if "revision" in self._data and path: | 213 | if "revision" in self._data and path: |
87 | 211 | 214 | ||
88 | === modified file 'juju/charm/tests/test_base.py' | |||
89 | --- juju/charm/tests/test_base.py 2011-10-05 19:12:34 +0000 | |||
90 | +++ juju/charm/tests/test_base.py 2012-09-15 19:26:18 +0000 | |||
91 | @@ -1,8 +1,7 @@ | |||
92 | 1 | import yaml | ||
93 | 2 | |||
94 | 3 | from juju.charm.base import CharmBase, get_revision | 1 | from juju.charm.base import CharmBase, get_revision |
95 | 4 | from juju.charm.metadata import MetaData | 2 | from juju.charm.metadata import MetaData |
96 | 5 | from juju.errors import CharmError | 3 | from juju.errors import CharmError |
97 | 4 | from juju.lib import serializer | ||
98 | 6 | from juju.lib.testing import TestCase | 5 | from juju.lib.testing import TestCase |
99 | 7 | 6 | ||
100 | 8 | 7 | ||
101 | @@ -73,6 +72,9 @@ | |||
102 | 73 | def test_metadata_fallback(self): | 72 | def test_metadata_fallback(self): |
103 | 74 | metadata = MetaData() | 73 | metadata = MetaData() |
104 | 75 | self.assertEquals(get_revision(None, metadata, None), None) | 74 | self.assertEquals(get_revision(None, metadata, None), None) |
107 | 76 | metadata.parse(yaml.dump({ | 75 | metadata.parse( |
108 | 77 | "name": "x", "summary": "y", "description": "z","revision": 33})) | 76 | serializer.yaml_dump( |
109 | 77 | {"name": "x", "summary": "y", "description": "z","revision": 33}, | ||
110 | 78 | )) | ||
111 | 79 | |||
112 | 78 | self.assertEquals(get_revision(None, metadata, None), 33) | 80 | self.assertEquals(get_revision(None, metadata, None), 33) |
113 | 79 | 81 | ||
114 | === modified file 'juju/charm/tests/test_bundle.py' | |||
115 | --- juju/charm/tests/test_bundle.py 2012-04-04 11:26:08 +0000 | |||
116 | +++ juju/charm/tests/test_bundle.py 2012-09-15 19:26:18 +0000 | |||
117 | @@ -3,9 +3,9 @@ | |||
118 | 3 | import inspect | 3 | import inspect |
119 | 4 | import shutil | 4 | import shutil |
120 | 5 | import stat | 5 | import stat |
121 | 6 | import yaml | ||
122 | 7 | import zipfile | 6 | import zipfile |
123 | 8 | 7 | ||
124 | 8 | from juju.lib import serializer | ||
125 | 9 | from juju.lib.testing import TestCase | 9 | from juju.lib.testing import TestCase |
126 | 10 | from juju.lib.filehash import compute_file_hash | 10 | from juju.lib.filehash import compute_file_hash |
127 | 11 | from juju.charm.metadata import MetaData | 11 | from juju.charm.metadata import MetaData |
128 | @@ -84,9 +84,9 @@ | |||
129 | 84 | continue | 84 | continue |
130 | 85 | content = zf_src.read(name) | 85 | content = zf_src.read(name) |
131 | 86 | if name == "metadata.yaml": | 86 | if name == "metadata.yaml": |
133 | 87 | data = yaml.load(content) | 87 | data = serializer.yaml_load(content) |
134 | 88 | data["revision"] = 303 | 88 | data["revision"] = 303 |
136 | 89 | content = yaml.dump(data) | 89 | content = serializer.yaml_dump(data) |
137 | 90 | zf_dst.writestr(name, content) | 90 | zf_dst.writestr(name, content) |
138 | 91 | zf_src.close() | 91 | zf_src.close() |
139 | 92 | zf_dst.close() | 92 | zf_dst.close() |
140 | @@ -97,9 +97,9 @@ | |||
141 | 97 | def test_competing_revisions(self): | 97 | def test_competing_revisions(self): |
142 | 98 | zf = zipfile.ZipFile(self.filename, "a") | 98 | zf = zipfile.ZipFile(self.filename, "a") |
143 | 99 | zf.writestr("revision", "999") | 99 | zf.writestr("revision", "999") |
145 | 100 | data = yaml.load(zf.read("metadata.yaml")) | 100 | data = serializer.yaml_load(zf.read("metadata.yaml")) |
146 | 101 | data["revision"] = 303 | 101 | data["revision"] = 303 |
148 | 102 | zf.writestr("metadata.yaml", yaml.dump(data)) | 102 | zf.writestr("metadata.yaml", serializer.yaml_dump(data)) |
149 | 103 | zf.close() | 103 | zf.close() |
150 | 104 | 104 | ||
151 | 105 | charm = CharmBundle(self.filename) | 105 | charm = CharmBundle(self.filename) |
152 | 106 | 106 | ||
153 | === modified file 'juju/charm/tests/test_config.py' | |||
154 | --- juju/charm/tests/test_config.py 2012-07-02 08:48:19 +0000 | |||
155 | +++ juju/charm/tests/test_config.py 2012-09-15 19:26:18 +0000 | |||
156 | @@ -3,6 +3,7 @@ | |||
157 | 3 | 3 | ||
158 | 4 | import yaml | 4 | import yaml |
159 | 5 | 5 | ||
160 | 6 | from juju.lib import serializer | ||
161 | 6 | from juju.lib.testing import TestCase | 7 | from juju.lib.testing import TestCase |
162 | 7 | from juju.charm.config import ConfigOptions | 8 | from juju.charm.config import ConfigOptions |
163 | 8 | from juju.charm.errors import ServiceConfigError, ServiceConfigValueError | 9 | from juju.charm.errors import ServiceConfigError, ServiceConfigValueError |
164 | @@ -25,7 +26,7 @@ | |||
165 | 25 | type: int | 26 | type: int |
166 | 26 | """ | 27 | """ |
167 | 27 | 28 | ||
169 | 28 | sample_yaml_data = yaml.load(sample_configuration) | 29 | sample_yaml_data = serializer.yaml_load(sample_configuration) |
170 | 29 | 30 | ||
171 | 30 | sample_config_defaults = {"title": "My Title", | 31 | sample_config_defaults = {"title": "My Title", |
172 | 31 | "username": "admin001"} | 32 | "username": "admin001"} |
173 | @@ -82,7 +83,7 @@ | |||
174 | 82 | e = self.assertRaises( | 83 | e = self.assertRaises( |
175 | 83 | ServiceConfigValueError, | 84 | ServiceConfigValueError, |
176 | 84 | self.config.parse, | 85 | self.config.parse, |
178 | 85 | yaml.dump( | 86 | serializer.yaml_dump( |
179 | 86 | {"options": { | 87 | {"options": { |
180 | 87 | "foobar": { | 88 | "foobar": { |
181 | 88 | "description": "beyond what?", | 89 | "description": "beyond what?", |
182 | @@ -98,8 +99,9 @@ | |||
183 | 98 | 99 | ||
184 | 99 | # Verify dictionary serialization | 100 | # Verify dictionary serialization |
185 | 100 | schema_dict = self.config.as_dict() | 101 | schema_dict = self.config.as_dict() |
188 | 101 | self.assertEqual(schema_dict, | 102 | self.assertEqual( |
189 | 102 | yaml.load(sample_configuration)["options"]) | 103 | schema_dict, |
190 | 104 | serializer.yaml_load(sample_configuration)["options"]) | ||
191 | 103 | 105 | ||
192 | 104 | # Verify the dictionary is a copy | 106 | # Verify the dictionary is a copy |
193 | 105 | # Poke at embedded objects | 107 | # Poke at embedded objects |
194 | @@ -143,7 +145,7 @@ | |||
195 | 143 | ServiceConfigValueError, config.validate, sample_input) | 145 | ServiceConfigValueError, config.validate, sample_input) |
196 | 144 | 146 | ||
197 | 145 | def test_validate_float(self): | 147 | def test_validate_float(self): |
199 | 146 | self.config.parse(yaml.dump( | 148 | self.config.parse(serializer.yaml_dump( |
200 | 147 | {"options": { | 149 | {"options": { |
201 | 148 | "score": { | 150 | "score": { |
202 | 149 | "description": "A number indicating score.", | 151 | "description": "A number indicating score.", |
203 | @@ -166,7 +168,7 @@ | |||
204 | 166 | self.assertEqual(data, {"title": u"Good"}) | 168 | self.assertEqual(data, {"title": u"Good"}) |
205 | 167 | 169 | ||
206 | 168 | def test_validate_boolean(self): | 170 | def test_validate_boolean(self): |
208 | 169 | self.config.parse(yaml.dump( | 171 | self.config.parse(serializer.yaml_dump( |
209 | 170 | {"options": { | 172 | {"options": { |
210 | 171 | "active": { | 173 | "active": { |
211 | 172 | "description": "A boolean indicating activity.", | 174 | "description": "A boolean indicating activity.", |
212 | @@ -200,9 +202,9 @@ | |||
213 | 200 | 'string' now). Remove support for it after a while, and take | 202 | 'string' now). Remove support for it after a while, and take |
214 | 201 | this test with it. | 203 | this test with it. |
215 | 202 | """ | 204 | """ |
217 | 203 | config = yaml.load(sample_configuration) | 205 | config = serializer.yaml_load(sample_configuration) |
218 | 204 | config["options"]["title"]["type"] = "str" | 206 | config["options"]["title"]["type"] = "str" |
220 | 205 | obsolete_config = yaml.dump(config) | 207 | obsolete_config = serializer.yaml_dump(config) |
221 | 206 | 208 | ||
222 | 207 | sio = StringIO() | 209 | sio = StringIO() |
223 | 208 | self.patch(sys, "stderr", sio) | 210 | self.patch(sys, "stderr", sio) |
224 | 209 | 211 | ||
225 | === modified file 'juju/charm/tests/test_directory.py' | |||
226 | --- juju/charm/tests/test_directory.py 2012-03-08 02:50:43 +0000 | |||
227 | +++ juju/charm/tests/test_directory.py 2012-09-15 19:26:18 +0000 | |||
228 | @@ -4,7 +4,6 @@ | |||
229 | 4 | import inspect | 4 | import inspect |
230 | 5 | import shutil | 5 | import shutil |
231 | 6 | import tempfile | 6 | import tempfile |
232 | 7 | import yaml | ||
233 | 8 | import zipfile | 7 | import zipfile |
234 | 9 | 8 | ||
235 | 10 | from juju.errors import CharmError, FileNotFound | 9 | from juju.errors import CharmError, FileNotFound |
236 | @@ -12,6 +11,7 @@ | |||
237 | 12 | from juju.charm.metadata import MetaData | 11 | from juju.charm.metadata import MetaData |
238 | 13 | from juju.charm.directory import CharmDirectory | 12 | from juju.charm.directory import CharmDirectory |
239 | 14 | from juju.charm.bundle import CharmBundle | 13 | from juju.charm.bundle import CharmBundle |
240 | 14 | from juju.lib import serializer | ||
241 | 15 | from juju.lib.filehash import compute_file_hash | 15 | from juju.lib.filehash import compute_file_hash |
242 | 16 | from juju.charm import tests | 16 | from juju.charm import tests |
243 | 17 | 17 | ||
244 | @@ -46,10 +46,10 @@ | |||
245 | 46 | def set_metadata_revision(self, dir_, revision): | 46 | def set_metadata_revision(self, dir_, revision): |
246 | 47 | metadata_path = os.path.join(dir_, "metadata.yaml") | 47 | metadata_path = os.path.join(dir_, "metadata.yaml") |
247 | 48 | with open(metadata_path) as f: | 48 | with open(metadata_path) as f: |
249 | 49 | data = yaml.load(f.read()) | 49 | data = serializer.yaml_load(f.read()) |
250 | 50 | data["revision"] = 999 | 50 | data["revision"] = 999 |
251 | 51 | with open(metadata_path, "w") as f: | 51 | with open(metadata_path, "w") as f: |
253 | 52 | f.write(yaml.dump(data)) | 52 | f.write(serializer.yaml_dump(data)) |
254 | 53 | 53 | ||
255 | 54 | def test_metadata_is_required(self): | 54 | def test_metadata_is_required(self): |
256 | 55 | directory = self.makeDir() | 55 | directory = self.makeDir() |
257 | 56 | 56 | ||
258 | === modified file 'juju/charm/tests/test_metadata.py' | |||
259 | --- juju/charm/tests/test_metadata.py 2012-05-25 22:43:52 +0000 | |||
260 | +++ juju/charm/tests/test_metadata.py 2012-09-15 19:26:18 +0000 | |||
261 | @@ -9,6 +9,7 @@ | |||
262 | 9 | MetaData, MetaDataError, InterfaceExpander, SchemaError) | 9 | MetaData, MetaDataError, InterfaceExpander, SchemaError) |
263 | 10 | from juju.errors import FileNotFound | 10 | from juju.errors import FileNotFound |
264 | 11 | from juju.lib.testing import TestCase | 11 | from juju.lib.testing import TestCase |
265 | 12 | from juju.lib import serializer | ||
266 | 12 | 13 | ||
267 | 13 | test_repository_path = os.path.join( | 14 | test_repository_path = os.path.join( |
268 | 14 | os.path.dirname(inspect.getabsfile(tests)), | 15 | os.path.dirname(inspect.getabsfile(tests)), |
269 | @@ -39,11 +40,11 @@ | |||
270 | 39 | class HackManager(object): | 40 | class HackManager(object): |
271 | 40 | 41 | ||
272 | 41 | def __enter__(mgr): | 42 | def __enter__(mgr): |
274 | 42 | mgr.data = yaml.load(self.sample) | 43 | mgr.data = serializer.yaml_load(self.sample) |
275 | 43 | return mgr.data | 44 | return mgr.data |
276 | 44 | 45 | ||
277 | 45 | def __exit__(mgr, exc_type, exc_val, exc_tb): | 46 | def __exit__(mgr, exc_type, exc_val, exc_tb): |
279 | 46 | self.sample = yaml.dump(mgr.data) | 47 | self.sample = serializer.yaml_dump(mgr.data) |
280 | 47 | return False | 48 | return False |
281 | 48 | return HackManager() | 49 | return HackManager() |
282 | 49 | 50 | ||
283 | @@ -145,7 +146,7 @@ | |||
284 | 145 | others. | 146 | others. |
285 | 146 | """ | 147 | """ |
286 | 147 | serialization_data = {"Hi": "there!"} | 148 | serialization_data = {"Hi": "there!"} |
288 | 148 | yaml_data = yaml.dump(serialization_data) | 149 | yaml_data = serializer.yaml_dump(serialization_data) |
289 | 149 | path = self.makeFile(yaml_data) | 150 | path = self.makeFile(yaml_data) |
290 | 150 | mock = self.mocker.patch(self.metadata) | 151 | mock = self.mocker.patch(self.metadata) |
291 | 151 | mock.parse(yaml_data, path) | 152 | mock.parse(yaml_data, path) |
292 | 152 | 153 | ||
293 | === modified file 'juju/charm/tests/test_publisher.py' | |||
294 | --- juju/charm/tests/test_publisher.py 2012-04-06 16:35:31 +0000 | |||
295 | +++ juju/charm/tests/test_publisher.py 2012-09-15 19:26:18 +0000 | |||
296 | @@ -1,6 +1,5 @@ | |||
297 | 1 | import fcntl | 1 | import fcntl |
298 | 2 | import os | 2 | import os |
299 | 3 | import yaml | ||
300 | 4 | import zookeeper | 3 | import zookeeper |
301 | 5 | 4 | ||
302 | 6 | from twisted.internet.defer import inlineCallbacks, fail | 5 | from twisted.internet.defer import inlineCallbacks, fail |
303 | @@ -12,7 +11,7 @@ | |||
304 | 12 | from juju.charm.directory import CharmDirectory | 11 | from juju.charm.directory import CharmDirectory |
305 | 13 | from juju.charm.publisher import CharmPublisher | 12 | from juju.charm.publisher import CharmPublisher |
306 | 14 | from juju.charm.tests import local_charm_id | 13 | from juju.charm.tests import local_charm_id |
308 | 15 | from juju.lib import under | 14 | from juju.lib import under, serializer |
309 | 16 | from juju.providers.dummy import FileStorage | 15 | from juju.providers.dummy import FileStorage |
310 | 17 | from juju.state.charm import CharmStateManager | 16 | from juju.state.charm import CharmStateManager |
311 | 18 | from juju.state.errors import StateChanged | 17 | from juju.state.errors import StateChanged |
312 | @@ -140,7 +139,8 @@ | |||
313 | 140 | 139 | ||
314 | 141 | # assert the checksum matches the initially published checksum | 140 | # assert the checksum matches the initially published checksum |
315 | 142 | self.assertEqual( | 141 | self.assertEqual( |
317 | 143 | yaml.load(content)["sha256"], self.charm.get_sha256()) | 142 | serializer.yaml_load(content)["sha256"], |
318 | 143 | self.charm.get_sha256()) | ||
319 | 144 | 144 | ||
320 | 145 | store_path = os.path.join(self.storage_dir, self.charm_storage_key) | 145 | store_path = os.path.join(self.storage_dir, self.charm_storage_key) |
321 | 146 | self.assertTrue(os.path.exists(store_path)) | 146 | self.assertTrue(os.path.exists(store_path)) |
322 | 147 | 147 | ||
323 | === modified file 'juju/control/config_set.py' | |||
324 | --- juju/control/config_set.py 2012-07-02 23:55:27 +0000 | |||
325 | +++ juju/control/config_set.py 2012-09-15 19:26:18 +0000 | |||
326 | @@ -1,11 +1,11 @@ | |||
327 | 1 | import argparse | 1 | import argparse |
328 | 2 | |||
329 | 3 | import yaml | 2 | import yaml |
330 | 4 | 3 | ||
331 | 5 | from twisted.internet.defer import inlineCallbacks | 4 | from twisted.internet.defer import inlineCallbacks |
332 | 6 | 5 | ||
333 | 7 | from juju.charm.errors import ServiceConfigValueError | 6 | from juju.charm.errors import ServiceConfigValueError |
334 | 8 | from juju.control.utils import get_environment | 7 | from juju.control.utils import get_environment |
335 | 8 | from juju.lib import serializer | ||
336 | 9 | from juju.lib.format import get_charm_formatter | 9 | from juju.lib.format import get_charm_formatter |
337 | 10 | from juju.state.service import ServiceStateManager | 10 | from juju.state.service import ServiceStateManager |
338 | 11 | 11 | ||
339 | @@ -62,7 +62,7 @@ | |||
340 | 62 | 62 | ||
341 | 63 | yaml_data = options.config.read() | 63 | yaml_data = options.config.read() |
342 | 64 | try: | 64 | try: |
344 | 65 | data = yaml.safe_load(yaml_data) | 65 | data = serializer.yaml_load(yaml_data) |
345 | 66 | except yaml.YAMLError: | 66 | except yaml.YAMLError: |
346 | 67 | raise ServiceConfigValueError( | 67 | raise ServiceConfigValueError( |
347 | 68 | "Config file %r not valid YAML" % options.config.name) | 68 | "Config file %r not valid YAML" % options.config.name) |
348 | 69 | 69 | ||
349 | === modified file 'juju/control/constraints_get.py' | |||
350 | --- juju/control/constraints_get.py 2012-03-30 09:41:54 +0000 | |||
351 | +++ juju/control/constraints_get.py 2012-09-15 19:26:18 +0000 | |||
352 | @@ -1,10 +1,10 @@ | |||
353 | 1 | import argparse | 1 | import argparse |
354 | 2 | import sys | 2 | import sys |
355 | 3 | import yaml | ||
356 | 4 | 3 | ||
357 | 5 | from twisted.internet.defer import inlineCallbacks | 4 | from twisted.internet.defer import inlineCallbacks |
358 | 6 | 5 | ||
359 | 7 | from juju.control.utils import get_environment, sync_environment_state | 6 | from juju.control.utils import get_environment, sync_environment_state |
360 | 7 | from juju.lib import serializer | ||
361 | 8 | from juju.state.environment import EnvironmentStateManager | 8 | from juju.state.environment import EnvironmentStateManager |
362 | 9 | from juju.state.machine import MachineStateManager | 9 | from juju.state.machine import MachineStateManager |
363 | 10 | from juju.state.service import ServiceStateManager | 10 | from juju.state.service import ServiceStateManager |
364 | @@ -70,6 +70,7 @@ | |||
365 | 70 | log.info("Fetching constraints for environment") | 70 | log.info("Fetching constraints for environment") |
366 | 71 | constraints = yield esm.get_constraints() | 71 | constraints = yield esm.get_constraints() |
367 | 72 | result = dict(constraints) | 72 | result = dict(constraints) |
369 | 73 | yaml.safe_dump(result, sys.stdout) | 73 | contents = serializer.yaml_dump(result) |
370 | 74 | sys.stdout.write(contents) | ||
371 | 74 | finally: | 75 | finally: |
372 | 75 | yield client.close() | 76 | yield client.close() |
373 | 76 | 77 | ||
374 | === modified file 'juju/control/deploy.py' | |||
375 | --- juju/control/deploy.py 2012-04-01 00:48:01 +0000 | |||
376 | +++ juju/control/deploy.py 2012-09-15 19:26:18 +0000 | |||
377 | @@ -1,7 +1,5 @@ | |||
378 | 1 | import os | 1 | import os |
379 | 2 | 2 | ||
380 | 3 | import yaml | ||
381 | 4 | |||
382 | 5 | from twisted.internet.defer import inlineCallbacks | 3 | from twisted.internet.defer import inlineCallbacks |
383 | 6 | 4 | ||
384 | 7 | from juju.control import legacy | 5 | from juju.control import legacy |
385 | @@ -12,6 +10,7 @@ | |||
386 | 12 | from juju.charm.publisher import CharmPublisher | 10 | from juju.charm.publisher import CharmPublisher |
387 | 13 | from juju.charm.repository import resolve | 11 | from juju.charm.repository import resolve |
388 | 14 | from juju.errors import CharmError | 12 | from juju.errors import CharmError |
389 | 13 | from juju.lib import serializer | ||
390 | 15 | from juju.state.endpoint import RelationEndpoint | 14 | from juju.state.endpoint import RelationEndpoint |
391 | 16 | from juju.state.placement import place_unit | 15 | from juju.state.placement import place_unit |
392 | 17 | from juju.state.relation import RelationStateManager | 16 | from juju.state.relation import RelationStateManager |
393 | @@ -85,7 +84,9 @@ | |||
394 | 85 | raise ServiceConfigValueError( | 84 | raise ServiceConfigValueError( |
395 | 86 | "Config file %r not accessible." % config_file) | 85 | "Config file %r not accessible." % config_file) |
396 | 87 | 86 | ||
398 | 88 | options = yaml.load(open(config_file, "r").read()) | 87 | with open(config_file) as fh: |
399 | 88 | options = serializer.yaml_load(fh.read()) | ||
400 | 89 | |||
401 | 89 | if not options or not isinstance(options, dict) or \ | 90 | if not options or not isinstance(options, dict) or \ |
402 | 90 | service_name not in options: | 91 | service_name not in options: |
403 | 91 | raise ServiceConfigValueError( | 92 | raise ServiceConfigValueError( |
404 | 92 | 93 | ||
405 | === modified file 'juju/control/initialize.py' | |||
406 | --- juju/control/initialize.py 2012-03-29 01:37:57 +0000 | |||
407 | +++ juju/control/initialize.py 2012-09-15 19:26:18 +0000 | |||
408 | @@ -1,11 +1,11 @@ | |||
409 | 1 | from base64 import b64decode | 1 | from base64 import b64decode |
410 | 2 | import os | 2 | import os |
411 | 3 | import yaml | ||
412 | 4 | 3 | ||
413 | 5 | from twisted.internet.defer import inlineCallbacks | 4 | from twisted.internet.defer import inlineCallbacks |
414 | 6 | 5 | ||
415 | 7 | from txzookeeper import ZookeeperClient | 6 | from txzookeeper import ZookeeperClient |
416 | 8 | 7 | ||
417 | 8 | from juju.lib import serializer | ||
418 | 9 | from juju.state.initialize import StateHierarchy | 9 | from juju.state.initialize import StateHierarchy |
419 | 10 | 10 | ||
420 | 11 | 11 | ||
421 | @@ -34,7 +34,7 @@ | |||
422 | 34 | zk_address = os.environ.get("ZOOKEEPER_ADDRESS", "127.0.0.1:2181") | 34 | zk_address = os.environ.get("ZOOKEEPER_ADDRESS", "127.0.0.1:2181") |
423 | 35 | client = yield ZookeeperClient(zk_address).connect() | 35 | client = yield ZookeeperClient(zk_address).connect() |
424 | 36 | try: | 36 | try: |
426 | 37 | constraints_data = yaml.load(b64decode(options.constraints_data)) | 37 | constraints_data = serializer.load(b64decode(options.constraints_data)) |
427 | 38 | hierarchy = StateHierarchy( | 38 | hierarchy = StateHierarchy( |
428 | 39 | client, | 39 | client, |
429 | 40 | options.admin_identity, | 40 | options.admin_identity, |
430 | 41 | 41 | ||
431 | === modified file 'juju/control/status.py' | |||
432 | --- juju/control/status.py 2012-08-05 00:18:28 +0000 | |||
433 | +++ juju/control/status.py 2012-09-15 19:26:18 +0000 | |||
434 | @@ -3,12 +3,13 @@ | |||
435 | 3 | import functools | 3 | import functools |
436 | 4 | import json | 4 | import json |
437 | 5 | import sys | 5 | import sys |
438 | 6 | import yaml | ||
439 | 6 | 7 | ||
440 | 7 | from twisted.internet.defer import inlineCallbacks, returnValue | 8 | from twisted.internet.defer import inlineCallbacks, returnValue |
441 | 8 | import yaml | ||
442 | 9 | 9 | ||
443 | 10 | from juju.control.utils import get_environment | 10 | from juju.control.utils import get_environment |
444 | 11 | from juju.errors import ProviderError | 11 | from juju.errors import ProviderError |
445 | 12 | |||
446 | 12 | from juju.state.errors import UnitRelationStateNotFound | 13 | from juju.state.errors import UnitRelationStateNotFound |
447 | 13 | from juju.state.charm import CharmStateManager | 14 | from juju.state.charm import CharmStateManager |
448 | 14 | from juju.state.machine import MachineStateManager | 15 | from juju.state.machine import MachineStateManager |
449 | @@ -576,7 +577,8 @@ | |||
450 | 576 | 577 | ||
451 | 577 | def render_yaml(data, filelike, environment): | 578 | def render_yaml(data, filelike, environment): |
452 | 578 | # remove the root nodes empty name | 579 | # remove the root nodes empty name |
454 | 579 | yaml.safe_dump(data, filelike, default_flow_style=False) | 580 | yaml.dump( |
455 | 581 | data, filelike, default_flow_style=False, Dumper=yaml.CSafeDumper) | ||
456 | 580 | 582 | ||
457 | 581 | renderers["yaml"] = render_yaml | 583 | renderers["yaml"] = render_yaml |
458 | 582 | 584 | ||
459 | 583 | 585 | ||
460 | === modified file 'juju/control/tests/test_add_unit.py' | |||
461 | --- juju/control/tests/test_add_unit.py 2012-05-04 22:43:40 +0000 | |||
462 | +++ juju/control/tests/test_add_unit.py 2012-09-15 19:26:18 +0000 | |||
463 | @@ -1,8 +1,7 @@ | |||
464 | 1 | from yaml import dump | ||
465 | 2 | |||
466 | 3 | from twisted.internet.defer import inlineCallbacks | 1 | from twisted.internet.defer import inlineCallbacks |
467 | 4 | 2 | ||
468 | 5 | from juju.control import main | 3 | from juju.control import main |
469 | 4 | from juju.lib.serializer import yaml_dump | ||
470 | 6 | from juju.state.environment import EnvironmentStateManager | 5 | from juju.state.environment import EnvironmentStateManager |
471 | 7 | 6 | ||
472 | 8 | from .common import MachineControlToolTest | 7 | from .common import MachineControlToolTest |
473 | @@ -184,7 +183,7 @@ | |||
474 | 184 | "environments": {"firstenv": { | 183 | "environments": {"firstenv": { |
475 | 185 | "some-legacy-key": "blah", | 184 | "some-legacy-key": "blah", |
476 | 186 | "type": "dummy"}}} | 185 | "type": "dummy"}}} |
478 | 187 | self.write_config(dump(local_config)) | 186 | self.write_config(yaml_dump(local_config)) |
479 | 188 | self.config.load() | 187 | self.config.load() |
480 | 189 | 188 | ||
481 | 190 | finished = self.setup_cli_reactor() | 189 | finished = self.setup_cli_reactor() |
482 | 191 | 190 | ||
483 | === modified file 'juju/control/tests/test_bootstrap.py' | |||
484 | --- juju/control/tests/test_bootstrap.py 2012-05-04 22:43:40 +0000 | |||
485 | +++ juju/control/tests/test_bootstrap.py 2012-09-15 19:26:18 +0000 | |||
486 | @@ -1,9 +1,9 @@ | |||
487 | 1 | 1 | ||
488 | 2 | from twisted.internet.defer import inlineCallbacks, succeed | 2 | from twisted.internet.defer import inlineCallbacks, succeed |
489 | 3 | from yaml import dump | ||
490 | 4 | 3 | ||
491 | 4 | from juju.control import main | ||
492 | 5 | from juju.lib.serializer import yaml_dump as dump | ||
493 | 5 | from juju.providers.dummy import MachineProvider | 6 | from juju.providers.dummy import MachineProvider |
494 | 6 | from juju.control import main | ||
495 | 7 | 7 | ||
496 | 8 | from .common import ControlToolTest | 8 | from .common import ControlToolTest |
497 | 9 | 9 | ||
498 | 10 | 10 | ||
499 | === modified file 'juju/control/tests/test_config_get.py' | |||
500 | --- juju/control/tests/test_config_get.py 2012-09-13 18:31:19 +0000 | |||
501 | +++ juju/control/tests/test_config_get.py 2012-09-15 19:26:18 +0000 | |||
502 | @@ -1,10 +1,8 @@ | |||
503 | 1 | import yaml | ||
504 | 2 | |||
505 | 3 | from twisted.internet.defer import inlineCallbacks | 1 | from twisted.internet.defer import inlineCallbacks |
506 | 4 | 2 | ||
507 | 5 | from juju.control import main | 3 | from juju.control import main |
508 | 6 | |||
509 | 7 | from juju.charm.tests import local_charm_id | 4 | from juju.charm.tests import local_charm_id |
510 | 5 | from juju.lib import serializer | ||
511 | 8 | from .common import MachineControlToolTest | 6 | from .common import MachineControlToolTest |
512 | 9 | 7 | ||
513 | 10 | 8 | ||
514 | @@ -32,7 +30,7 @@ | |||
515 | 32 | main(["get", "wordpress"]) | 30 | main(["get", "wordpress"]) |
516 | 33 | 31 | ||
517 | 34 | yield finished | 32 | yield finished |
519 | 35 | data = yaml.load(output.getvalue()) | 33 | data = serializer.yaml_load(output.getvalue()) |
520 | 36 | self.assertEqual( | 34 | self.assertEqual( |
521 | 37 | {"service": "wordpress", | 35 | {"service": "wordpress", |
522 | 38 | "charm": "local:series/wordpress-3", | 36 | "charm": "local:series/wordpress-3", |
523 | @@ -59,7 +57,7 @@ | |||
524 | 59 | main(["get", "dummy"]) | 57 | main(["get", "dummy"]) |
525 | 60 | 58 | ||
526 | 61 | yield finished | 59 | yield finished |
528 | 62 | data = yaml.load(output.getvalue()) | 60 | data = serializer.yaml_load(output.getvalue()) |
529 | 63 | 61 | ||
530 | 64 | self.assertEqual( | 62 | self.assertEqual( |
531 | 65 | {"service": "dummy", | 63 | {"service": "dummy", |
532 | 66 | 64 | ||
533 | === modified file 'juju/control/tests/test_config_set.py' | |||
534 | --- juju/control/tests/test_config_set.py 2012-08-30 03:06:56 +0000 | |||
535 | +++ juju/control/tests/test_config_set.py 2012-09-15 19:26:18 +0000 | |||
536 | @@ -1,9 +1,8 @@ | |||
537 | 1 | from yaml import dump | ||
538 | 2 | |||
539 | 3 | from twisted.internet.defer import inlineCallbacks | 1 | from twisted.internet.defer import inlineCallbacks |
540 | 4 | 2 | ||
541 | 5 | from juju.control import main | 3 | from juju.control import main |
542 | 6 | from juju.control.config_set import config_set | 4 | from juju.control.config_set import config_set |
543 | 5 | from juju.lib import serializer | ||
544 | 7 | from .common import MachineControlToolTest | 6 | from .common import MachineControlToolTest |
545 | 8 | 7 | ||
546 | 9 | 8 | ||
547 | @@ -38,8 +37,8 @@ | |||
548 | 38 | finished = self.setup_cli_reactor() | 37 | finished = self.setup_cli_reactor() |
549 | 39 | self.setup_exit(0) | 38 | self.setup_exit(0) |
550 | 40 | self.mocker.replay() | 39 | self.mocker.replay() |
553 | 41 | config_file = self.makeFile(dump(dict( | 40 | config_file = self.makeFile(serializer.yaml_dump( |
554 | 42 | wordpress={"blog-title": "Hello World"}))) | 41 | dict(wordpress={"blog-title": "Hello World"}))) |
555 | 43 | 42 | ||
556 | 44 | main(["set", "wordpress", | 43 | main(["set", "wordpress", |
557 | 45 | "--config=%s" % config_file]) | 44 | "--config=%s" % config_file]) |
558 | @@ -54,13 +53,13 @@ | |||
559 | 54 | finished = self.setup_cli_reactor() | 53 | finished = self.setup_cli_reactor() |
560 | 55 | self.setup_exit(0) | 54 | self.setup_exit(0) |
561 | 56 | self.mocker.replay() | 55 | self.mocker.replay() |
562 | 56 | |||
563 | 57 | # missing the service_name dict (will do nothing to values) | 57 | # missing the service_name dict (will do nothing to values) |
569 | 58 | config_file = self.makeFile(dump({"blog-title": "Hello World"})) | 58 | config_file = self.makeFile( |
570 | 59 | 59 | serializer.yaml_dump({"blog-title": "Hello World"})) | |
571 | 60 | main(["set", "wordpress", | 60 | main(["set", "wordpress", "--config=%s" % config_file]) |
567 | 61 | "--config=%s" % config_file]) | ||
568 | 62 | |||
572 | 63 | yield finished | 61 | yield finished |
573 | 62 | |||
574 | 64 | state = yield self.service_state.get_config() | 63 | state = yield self.service_state.get_config() |
575 | 65 | self.assertEqual(state, {'blog-title': 'My Title'}) | 64 | self.assertEqual(state, {'blog-title': 'My Title'}) |
576 | 66 | 65 | ||
577 | @@ -90,7 +89,7 @@ | |||
578 | 90 | self.mocker.replay() | 89 | self.mocker.replay() |
579 | 91 | 90 | ||
580 | 92 | # valid file, but incorrect cli usage | 91 | # valid file, but incorrect cli usage |
582 | 93 | config_file = self.makeFile(dump(dict( | 92 | config_file = self.makeFile(serializer.yaml_dump(dict( |
583 | 94 | wordpress={"blog-title": "Hello World"}))) | 93 | wordpress={"blog-title": "Hello World"}))) |
584 | 95 | 94 | ||
585 | 96 | main(["-v", "set", "wordpress", | 95 | main(["-v", "set", "wordpress", |
586 | 97 | 96 | ||
587 | === modified file 'juju/control/tests/test_constraints_get.py' | |||
588 | --- juju/control/tests/test_constraints_get.py 2012-03-30 09:41:54 +0000 | |||
589 | +++ juju/control/tests/test_constraints_get.py 2012-09-15 19:26:18 +0000 | |||
590 | @@ -1,8 +1,7 @@ | |||
591 | 1 | import yaml | ||
592 | 2 | |||
593 | 3 | from twisted.internet.defer import inlineCallbacks | 1 | from twisted.internet.defer import inlineCallbacks |
594 | 4 | 2 | ||
595 | 5 | from juju.control import main | 3 | from juju.control import main |
596 | 4 | from juju.lib import serializer | ||
597 | 6 | from juju.machine.tests.test_constraints import dummy_cs | 5 | from juju.machine.tests.test_constraints import dummy_cs |
598 | 7 | from juju.state.environment import EnvironmentStateManager | 6 | from juju.state.environment import EnvironmentStateManager |
599 | 8 | 7 | ||
600 | @@ -65,7 +64,7 @@ | |||
601 | 65 | def test_env(self): | 64 | def test_env(self): |
602 | 66 | main(["get-constraints"]) | 65 | main(["get-constraints"]) |
603 | 67 | yield self.finished | 66 | yield self.finished |
605 | 68 | result = yaml.load(self.stdout.getvalue()) | 67 | result = serializer.load(self.stdout.getvalue()) |
606 | 69 | self.assertEquals(result, self.expect_env) | 68 | self.assertEquals(result, self.expect_env) |
607 | 70 | self.assert_messages(env_log) | 69 | self.assert_messages(env_log) |
608 | 71 | 70 | ||
609 | @@ -73,7 +72,7 @@ | |||
610 | 73 | def test_service(self): | 72 | def test_service(self): |
611 | 74 | main(["get-constraints", "mysql"]) | 73 | main(["get-constraints", "mysql"]) |
612 | 75 | yield self.finished | 74 | yield self.finished |
614 | 76 | result = yaml.load(self.stdout.getvalue()) | 75 | result = serializer.load(self.stdout.getvalue()) |
615 | 77 | self.assertEquals(result, {"mysql": self.expect_service}) | 76 | self.assertEquals(result, {"mysql": self.expect_service}) |
616 | 78 | self.assert_messages(service_log) | 77 | self.assert_messages(service_log) |
617 | 79 | 78 | ||
618 | @@ -81,7 +80,7 @@ | |||
619 | 81 | def test_unit(self): | 80 | def test_unit(self): |
620 | 82 | main(["get-constraints", "mysql/0"]) | 81 | main(["get-constraints", "mysql/0"]) |
621 | 83 | yield self.finished | 82 | yield self.finished |
623 | 84 | result = yaml.load(self.stdout.getvalue()) | 83 | result = serializer.load(self.stdout.getvalue()) |
624 | 85 | self.assertEquals(result, {"mysql/0": self.expect_unit}) | 84 | self.assertEquals(result, {"mysql/0": self.expect_unit}) |
625 | 86 | self.assert_messages(unit_log) | 85 | self.assert_messages(unit_log) |
626 | 87 | 86 | ||
627 | @@ -89,7 +88,7 @@ | |||
628 | 89 | def test_machine(self): | 88 | def test_machine(self): |
629 | 90 | main(["get-constraints", "1"]) | 89 | main(["get-constraints", "1"]) |
630 | 91 | yield self.finished | 90 | yield self.finished |
632 | 92 | result = yaml.load(self.stdout.getvalue()) | 91 | result = serializer.load(self.stdout.getvalue()) |
633 | 93 | self.assertEquals(result, {"1": self.expect_machine}) | 92 | self.assertEquals(result, {"1": self.expect_machine}) |
634 | 94 | self.assert_messages(machine_log) | 93 | self.assert_messages(machine_log) |
635 | 95 | 94 | ||
636 | @@ -97,7 +96,7 @@ | |||
637 | 97 | def test_all(self): | 96 | def test_all(self): |
638 | 98 | main(["get-constraints", "mysql", "mysql/0", "1"]) | 97 | main(["get-constraints", "mysql", "mysql/0", "1"]) |
639 | 99 | yield self.finished | 98 | yield self.finished |
641 | 100 | result = yaml.load(self.stdout.getvalue()) | 99 | result = serializer.load(self.stdout.getvalue()) |
642 | 101 | expect = {"mysql": self.expect_service, | 100 | expect = {"mysql": self.expect_service, |
643 | 102 | "mysql/0": self.expect_unit, | 101 | "mysql/0": self.expect_unit, |
644 | 103 | "1": self.expect_machine} | 102 | "1": self.expect_machine} |
645 | @@ -111,6 +110,6 @@ | |||
646 | 111 | yield self.client.delete("/environment") | 110 | yield self.client.delete("/environment") |
647 | 112 | main(["get-constraints", "mysql/0"]) | 111 | main(["get-constraints", "mysql/0"]) |
648 | 113 | yield self.finished | 112 | yield self.finished |
650 | 114 | result = yaml.load(self.stdout.getvalue()) | 113 | result = serializer.load(self.stdout.getvalue()) |
651 | 115 | self.assertEquals(result, {"mysql/0": self.expect_unit}) | 114 | self.assertEquals(result, {"mysql/0": self.expect_unit}) |
652 | 116 | self.assert_messages(unit_log) | 115 | self.assert_messages(unit_log) |
653 | 117 | 116 | ||
654 | === modified file 'juju/control/tests/test_deploy.py' | |||
655 | --- juju/control/tests/test_deploy.py 2012-05-04 22:43:40 +0000 | |||
656 | +++ juju/control/tests/test_deploy.py 2012-09-15 19:26:18 +0000 | |||
657 | @@ -1,7 +1,5 @@ | |||
658 | 1 | import logging | 1 | import logging |
659 | 2 | import os | 2 | import os |
660 | 3 | import yaml | ||
661 | 4 | |||
662 | 5 | 3 | ||
663 | 6 | from twisted.internet.defer import inlineCallbacks, succeed | 4 | from twisted.internet.defer import inlineCallbacks, succeed |
664 | 7 | 5 | ||
665 | @@ -15,6 +13,7 @@ | |||
666 | 15 | from juju.charm.repository import RemoteCharmRepository | 13 | from juju.charm.repository import RemoteCharmRepository |
667 | 16 | from juju.charm.url import CharmURL | 14 | from juju.charm.url import CharmURL |
668 | 17 | from juju.charm.errors import ServiceConfigValueError | 15 | from juju.charm.errors import ServiceConfigValueError |
669 | 16 | from juju.lib import serializer | ||
670 | 18 | 17 | ||
671 | 19 | from juju.state.charm import CharmStateManager | 18 | from juju.state.charm import CharmStateManager |
672 | 20 | from juju.state.environment import EnvironmentStateManager | 19 | from juju.state.environment import EnvironmentStateManager |
673 | @@ -58,7 +57,7 @@ | |||
674 | 58 | "secondenv": { | 57 | "secondenv": { |
675 | 59 | "type": "dummy", "admin-secret": "marge"}}} | 58 | "type": "dummy", "admin-secret": "marge"}}} |
676 | 60 | 59 | ||
678 | 61 | self.write_config(yaml.dump(config)) | 60 | self.write_config(serializer.dump(config)) |
679 | 62 | stderr = self.capture_logging() | 61 | stderr = self.capture_logging() |
680 | 63 | main(["deploy", "--repository", self.unbundled_repo_path, "mysql"]) | 62 | main(["deploy", "--repository", self.unbundled_repo_path, "mysql"]) |
681 | 64 | self.assertIn("There are multiple environments", stderr.getvalue()) | 63 | self.assertIn("There are multiple environments", stderr.getvalue()) |
682 | @@ -167,7 +166,7 @@ | |||
683 | 167 | "secondenv": { | 166 | "secondenv": { |
684 | 168 | "type": "dummy", "admin-secret": "marge"}}} | 167 | "type": "dummy", "admin-secret": "marge"}}} |
685 | 169 | 168 | ||
687 | 170 | self.write_config(yaml.dump(config)) | 169 | self.write_config(serializer.dump(config)) |
688 | 171 | 170 | ||
689 | 172 | stderr = self.capture_logging() | 171 | stderr = self.capture_logging() |
690 | 173 | main(["deploy", "--environment", "roman-candle", | 172 | main(["deploy", "--environment", "roman-candle", |
691 | @@ -186,7 +185,7 @@ | |||
692 | 186 | "secondenv": { | 185 | "secondenv": { |
693 | 187 | "type": "dummy", "admin-secret": "marge"}}} | 186 | "type": "dummy", "admin-secret": "marge"}}} |
694 | 188 | 187 | ||
696 | 189 | self.write_config(yaml.dump(config)) | 188 | self.write_config(serializer.dump(config)) |
697 | 190 | 189 | ||
698 | 191 | def match_config(config): | 190 | def match_config(config): |
699 | 192 | return isinstance(config, EnvironmentsConfig) | 191 | return isinstance(config, EnvironmentsConfig) |
700 | @@ -353,8 +352,8 @@ | |||
701 | 353 | env_state_manager = EnvironmentStateManager(self.client) | 352 | env_state_manager = EnvironmentStateManager(self.client) |
702 | 354 | env_config = yield env_state_manager.get_config() | 353 | env_config = yield env_state_manager.get_config() |
703 | 355 | 354 | ||
706 | 356 | self.assertEquals(yaml.load(env_config.serialize("firstenv")), | 355 | self.assertEquals(serializer.load(env_config.serialize("firstenv")), |
707 | 357 | yaml.load(self.config.serialize("firstenv"))) | 356 | serializer.load(self.config.serialize("firstenv"))) |
708 | 358 | 357 | ||
709 | 359 | @inlineCallbacks | 358 | @inlineCallbacks |
710 | 360 | def test_deploy_reuses_machines(self): | 359 | def test_deploy_reuses_machines(self): |
711 | @@ -394,7 +393,7 @@ | |||
712 | 394 | """Valid config options should be available to the deployed | 393 | """Valid config options should be available to the deployed |
713 | 395 | service.""" | 394 | service.""" |
714 | 396 | config_file = self.makeFile( | 395 | config_file = self.makeFile( |
716 | 397 | yaml.dump(dict(otherservice=dict(application_file="foo")))) | 396 | serializer.dump(dict(otherservice=dict(application_file="foo")))) |
717 | 398 | environment = self.config.get("firstenv") | 397 | environment = self.config.get("firstenv") |
718 | 399 | 398 | ||
719 | 400 | failure = deploy.deploy( | 399 | failure = deploy.deploy( |
720 | @@ -408,7 +407,7 @@ | |||
721 | 408 | def test_deploy_with_invalid_config(self): | 407 | def test_deploy_with_invalid_config(self): |
722 | 409 | """Can't deploy with config that doesn't pass charm validation.""" | 408 | """Can't deploy with config that doesn't pass charm validation.""" |
723 | 410 | config_file = self.makeFile( | 409 | config_file = self.makeFile( |
725 | 411 | yaml.dump(dict(myblog=dict(application_file="foo")))) | 410 | serializer.dump(dict(myblog=dict(application_file="foo")))) |
726 | 412 | environment = self.config.get("firstenv") | 411 | environment = self.config.get("firstenv") |
727 | 413 | 412 | ||
728 | 414 | failure = deploy.deploy( | 413 | failure = deploy.deploy( |
729 | @@ -426,7 +425,7 @@ | |||
730 | 426 | def test_deploy_with_config(self): | 425 | def test_deploy_with_config(self): |
731 | 427 | """Valid config options should be available to the deployed | 426 | """Valid config options should be available to the deployed |
732 | 428 | service.""" | 427 | service.""" |
734 | 429 | config_file = self.makeFile(yaml.dump(dict( | 428 | config_file = self.makeFile(serializer.dump(dict( |
735 | 430 | myblog=dict(outlook="sunny", | 429 | myblog=dict(outlook="sunny", |
736 | 431 | username="tester01")))) | 430 | username="tester01")))) |
737 | 432 | environment = self.config.get("firstenv") | 431 | environment = self.config.get("firstenv") |
738 | @@ -555,7 +554,7 @@ | |||
739 | 555 | "type": "dummy", | 554 | "type": "dummy", |
740 | 556 | "some-legacy-key": "blah", | 555 | "some-legacy-key": "blah", |
741 | 557 | "default-series": "series"}}} | 556 | "default-series": "series"}}} |
743 | 558 | self.write_config(yaml.dump(local_config)) | 557 | self.write_config(serializer.dump(local_config)) |
744 | 559 | self.config.load() | 558 | self.config.load() |
745 | 560 | finished = self.setup_cli_reactor() | 559 | finished = self.setup_cli_reactor() |
746 | 561 | self.setup_exit(0) | 560 | self.setup_exit(0) |
747 | 562 | 561 | ||
748 | === modified file 'juju/control/tests/test_destroy_environment.py' | |||
749 | --- juju/control/tests/test_destroy_environment.py 2012-05-04 22:43:40 +0000 | |||
750 | +++ juju/control/tests/test_destroy_environment.py 2012-09-15 19:26:18 +0000 | |||
751 | @@ -1,6 +1,6 @@ | |||
752 | 1 | from twisted.internet.defer import succeed, inlineCallbacks | 1 | from twisted.internet.defer import succeed, inlineCallbacks |
753 | 2 | from yaml import dump | ||
754 | 3 | 2 | ||
755 | 3 | from juju.lib.serializer import dump | ||
756 | 4 | from juju.lib.mocker import MATCH | 4 | from juju.lib.mocker import MATCH |
757 | 5 | from juju.providers.dummy import MachineProvider | 5 | from juju.providers.dummy import MachineProvider |
758 | 6 | from juju.control import main | 6 | from juju.control import main |
759 | 7 | 7 | ||
760 | === modified file 'juju/control/tests/test_expose.py' | |||
761 | --- juju/control/tests/test_expose.py 2012-05-04 22:43:40 +0000 | |||
762 | +++ juju/control/tests/test_expose.py 2012-09-15 19:26:18 +0000 | |||
763 | @@ -1,8 +1,8 @@ | |||
764 | 1 | import yaml | ||
765 | 2 | from twisted.internet.defer import inlineCallbacks | 1 | from twisted.internet.defer import inlineCallbacks |
766 | 3 | 2 | ||
767 | 4 | from juju.control import main | 3 | from juju.control import main |
768 | 5 | from juju.control.tests.common import ControlToolTest | 4 | from juju.control.tests.common import ControlToolTest |
769 | 5 | from juju.lib import serializer | ||
770 | 6 | from juju.state.tests.test_service import ServiceStateManagerTestBase | 6 | from juju.state.tests.test_service import ServiceStateManagerTestBase |
771 | 7 | 7 | ||
772 | 8 | 8 | ||
773 | @@ -15,7 +15,7 @@ | |||
774 | 15 | config = { | 15 | config = { |
775 | 16 | "environments": {"firstenv": {"type": "dummy"}}} | 16 | "environments": {"firstenv": {"type": "dummy"}}} |
776 | 17 | 17 | ||
778 | 18 | self.write_config(yaml.dump(config)) | 18 | self.write_config(serializer.dump(config)) |
779 | 19 | self.config.load() | 19 | self.config.load() |
780 | 20 | self.service_state = yield self.add_service_from_charm("wordpress") | 20 | self.service_state = yield self.add_service_from_charm("wordpress") |
781 | 21 | self.output = self.capture_logging() | 21 | self.output = self.capture_logging() |
782 | 22 | 22 | ||
783 | === modified file 'juju/control/tests/test_initialize.py' | |||
784 | --- juju/control/tests/test_initialize.py 2012-03-30 09:12:11 +0000 | |||
785 | +++ juju/control/tests/test_initialize.py 2012-09-15 19:26:18 +0000 | |||
786 | @@ -1,11 +1,11 @@ | |||
787 | 1 | from base64 import b64encode | 1 | from base64 import b64encode |
789 | 2 | from yaml import safe_dump | 2 | |
790 | 3 | 3 | ||
791 | 4 | from twisted.internet.defer import succeed | 4 | from twisted.internet.defer import succeed |
792 | 5 | 5 | ||
793 | 6 | from txzookeeper import ZookeeperClient | 6 | from txzookeeper import ZookeeperClient |
794 | 7 | from juju.state.initialize import StateHierarchy | 7 | from juju.state.initialize import StateHierarchy |
796 | 8 | 8 | from juju.lib.serializer import dump | |
797 | 9 | from juju.control import admin | 9 | from juju.control import admin |
798 | 10 | from .common import ControlToolTest | 10 | from .common import ControlToolTest |
799 | 11 | 11 | ||
800 | @@ -29,7 +29,7 @@ | |||
801 | 29 | self.setup_exit(0) | 29 | self.setup_exit(0) |
802 | 30 | self.mocker.replay() | 30 | self.mocker.replay() |
803 | 31 | 31 | ||
805 | 32 | constraints_data = b64encode(safe_dump({ | 32 | constraints_data = b64encode(dump({ |
806 | 33 | "ubuntu-series": "foo", "provider-type": "bar"})) | 33 | "ubuntu-series": "foo", "provider-type": "bar"})) |
807 | 34 | 34 | ||
808 | 35 | admin(["initialize", | 35 | admin(["initialize", |
809 | 36 | 36 | ||
810 | === modified file 'juju/control/tests/test_open_tunnel.py' | |||
811 | --- juju/control/tests/test_open_tunnel.py 2011-09-15 19:24:47 +0000 | |||
812 | +++ juju/control/tests/test_open_tunnel.py 2012-09-15 19:26:18 +0000 | |||
813 | @@ -1,7 +1,8 @@ | |||
814 | 1 | from yaml import dump | ||
815 | 2 | 1 | ||
816 | 2 | from juju.control import main, open_tunnel | ||
817 | 3 | from juju.lib.serializer import dump | ||
818 | 3 | from juju.providers.dummy import MachineProvider | 4 | from juju.providers.dummy import MachineProvider |
820 | 4 | from juju.control import main, open_tunnel | 5 | |
821 | 5 | 6 | ||
822 | 6 | from .common import ControlToolTest | 7 | from .common import ControlToolTest |
823 | 7 | 8 | ||
824 | 8 | 9 | ||
825 | === modified file 'juju/control/tests/test_remove_relation.py' | |||
826 | --- juju/control/tests/test_remove_relation.py 2012-05-04 22:43:40 +0000 | |||
827 | +++ juju/control/tests/test_remove_relation.py 2012-09-15 19:26:18 +0000 | |||
828 | @@ -1,12 +1,12 @@ | |||
829 | 1 | import logging | 1 | import logging |
830 | 2 | 2 | ||
831 | 3 | import yaml | ||
832 | 4 | 3 | ||
833 | 5 | from twisted.internet.defer import inlineCallbacks, returnValue | 4 | from twisted.internet.defer import inlineCallbacks, returnValue |
834 | 6 | 5 | ||
835 | 7 | from juju.charm.tests.test_repository import RepositoryTestBase | 6 | from juju.charm.tests.test_repository import RepositoryTestBase |
836 | 8 | from juju.control import main, remove_relation | 7 | from juju.control import main, remove_relation |
837 | 9 | from juju.control.tests.common import ControlToolTest | 8 | from juju.control.tests.common import ControlToolTest |
838 | 9 | from juju.lib import serializer | ||
839 | 10 | from juju.machine.tests.test_constraints import dummy_constraints | 10 | from juju.machine.tests.test_constraints import dummy_constraints |
840 | 11 | from juju.state.errors import ServiceStateNotFound | 11 | from juju.state.errors import ServiceStateNotFound |
841 | 12 | from juju.state.tests.test_service import ServiceStateManagerTestBase | 12 | from juju.state.tests.test_service import ServiceStateManagerTestBase |
842 | @@ -22,7 +22,7 @@ | |||
843 | 22 | "environments": { | 22 | "environments": { |
844 | 23 | "firstenv": { | 23 | "firstenv": { |
845 | 24 | "type": "dummy", "admin-secret": "homer"}}} | 24 | "type": "dummy", "admin-secret": "homer"}}} |
847 | 25 | self.write_config(yaml.dump(config)) | 25 | self.write_config(serializer.dump(config)) |
848 | 26 | self.config.load() | 26 | self.config.load() |
849 | 27 | self.output = self.capture_logging() | 27 | self.output = self.capture_logging() |
850 | 28 | self.stderr = self.capture_stream("stderr") | 28 | self.stderr = self.capture_stream("stderr") |
851 | 29 | 29 | ||
852 | === modified file 'juju/control/tests/test_scp.py' | |||
853 | --- juju/control/tests/test_scp.py 2012-03-27 23:56:09 +0000 | |||
854 | +++ juju/control/tests/test_scp.py 2012-09-15 19:26:18 +0000 | |||
855 | @@ -1,7 +1,6 @@ | |||
856 | 1 | import logging | 1 | import logging |
857 | 2 | import os | 2 | import os |
858 | 3 | 3 | ||
859 | 4 | from yaml import dump | ||
860 | 5 | 4 | ||
861 | 6 | from twisted.internet.defer import inlineCallbacks | 5 | from twisted.internet.defer import inlineCallbacks |
862 | 7 | 6 | ||
863 | 8 | 7 | ||
864 | === modified file 'juju/control/tests/test_status.py' | |||
865 | --- juju/control/tests/test_status.py 2012-08-09 09:53:55 +0000 | |||
866 | +++ juju/control/tests/test_status.py 2012-09-15 19:26:18 +0000 | |||
867 | @@ -4,7 +4,7 @@ | |||
868 | 4 | import logging | 4 | import logging |
869 | 5 | import os | 5 | import os |
870 | 6 | from StringIO import StringIO | 6 | from StringIO import StringIO |
872 | 7 | import yaml | 7 | |
873 | 8 | 8 | ||
874 | 9 | from twisted.internet.defer import inlineCallbacks, returnValue | 9 | from twisted.internet.defer import inlineCallbacks, returnValue |
875 | 10 | 10 | ||
876 | @@ -13,7 +13,7 @@ | |||
877 | 13 | from juju.environment.environment import Environment | 13 | from juju.environment.environment import Environment |
878 | 14 | from juju.control import status | 14 | from juju.control import status |
879 | 15 | from juju.control import tests | 15 | from juju.control import tests |
881 | 16 | from juju.lib.mocker import ANY | 16 | from juju.lib import serializer |
882 | 17 | from juju.state.endpoint import RelationEndpoint | 17 | from juju.state.endpoint import RelationEndpoint |
883 | 18 | from juju.state.environment import GlobalSettingsStateManager | 18 | from juju.state.environment import GlobalSettingsStateManager |
884 | 19 | from juju.state.tests.test_service import ServiceStateManagerTestBase | 19 | from juju.state.tests.test_service import ServiceStateManagerTestBase |
885 | @@ -24,7 +24,7 @@ | |||
886 | 24 | 24 | ||
887 | 25 | tests_path = os.path.dirname(inspect.getabsfile(tests)) | 25 | tests_path = os.path.dirname(inspect.getabsfile(tests)) |
888 | 26 | sample_path = os.path.join(tests_path, "sample_cluster.yaml") | 26 | sample_path = os.path.join(tests_path, "sample_cluster.yaml") |
890 | 27 | sample_cluster = yaml.load(open(sample_path, "r")) | 27 | sample_cluster = serializer.load(open(sample_path, "r")) |
891 | 28 | 28 | ||
892 | 29 | 29 | ||
893 | 30 | def dump_stringio(stringio, filename): | 30 | def dump_stringio(stringio, filename): |
894 | @@ -643,7 +643,7 @@ | |||
895 | 643 | 643 | ||
896 | 644 | yield status.status(self.environment, [], | 644 | yield status.status(self.environment, [], |
897 | 645 | status.render_yaml, self.output, None) | 645 | status.render_yaml, self.output, None) |
899 | 646 | state = yaml.load(self.output.getvalue()) | 646 | state = serializer.yaml_load(self.output.getvalue()) |
900 | 647 | 647 | ||
901 | 648 | self.assertEqual(set(state["machines"].keys()), | 648 | self.assertEqual(set(state["machines"].keys()), |
902 | 649 | set([0, 1, 2, 3, 4, 5, 6])) | 649 | set([0, 1, 2, 3, 4, 5, 6])) |
903 | @@ -863,7 +863,7 @@ | |||
904 | 863 | yield status.status(self.environment, [], | 863 | yield status.status(self.environment, [], |
905 | 864 | status.render_yaml, self.output, None) | 864 | status.render_yaml, self.output, None) |
906 | 865 | 865 | ||
908 | 866 | state = yaml.load(self.output.getvalue()) | 866 | state = serializer.load(self.output.getvalue()) |
909 | 867 | 867 | ||
910 | 868 | # verify our changes | 868 | # verify our changes |
911 | 869 | log_state = state["services"]["logging"] | 869 | log_state = state["services"]["logging"] |
912 | @@ -920,6 +920,6 @@ | |||
913 | 920 | yield status.status(self.environment, [], | 920 | yield status.status(self.environment, [], |
914 | 921 | status.render_yaml, self.output, None) | 921 | status.render_yaml, self.output, None) |
915 | 922 | 922 | ||
917 | 923 | output = yaml.load(self.output.getvalue()) | 923 | output = serializer.load(self.output.getvalue()) |
918 | 924 | self.assertNotIn(mu1.unit_name, output["services"]["mysql"]["units"]) | 924 | self.assertNotIn(mu1.unit_name, output["services"]["mysql"]["units"]) |
919 | 925 | self.assertIn(mu2.unit_name, output["services"]["mysql"]["units"]) | 925 | self.assertIn(mu2.unit_name, output["services"]["mysql"]["units"]) |
920 | 926 | 926 | ||
921 | === modified file 'juju/control/tests/test_unexpose.py' | |||
922 | --- juju/control/tests/test_unexpose.py 2012-05-04 22:43:40 +0000 | |||
923 | +++ juju/control/tests/test_unexpose.py 2012-09-15 19:26:18 +0000 | |||
924 | @@ -1,8 +1,8 @@ | |||
925 | 1 | import yaml | ||
926 | 2 | from twisted.internet.defer import inlineCallbacks | 1 | from twisted.internet.defer import inlineCallbacks |
927 | 3 | 2 | ||
928 | 4 | from juju.control import main | 3 | from juju.control import main |
929 | 5 | from juju.control.tests.common import ControlToolTest | 4 | from juju.control.tests.common import ControlToolTest |
930 | 5 | from juju.lib import serializer | ||
931 | 6 | from juju.state.tests.test_service import ServiceStateManagerTestBase | 6 | from juju.state.tests.test_service import ServiceStateManagerTestBase |
932 | 7 | 7 | ||
933 | 8 | 8 | ||
934 | @@ -15,7 +15,7 @@ | |||
935 | 15 | config = { | 15 | config = { |
936 | 16 | "environments": {"firstenv": {"type": "dummy"}}} | 16 | "environments": {"firstenv": {"type": "dummy"}}} |
937 | 17 | 17 | ||
939 | 18 | self.write_config(yaml.dump(config)) | 18 | self.write_config(serializer.dump(config)) |
940 | 19 | self.config.load() | 19 | self.config.load() |
941 | 20 | self.service_state = yield self.add_service_from_charm("wordpress") | 20 | self.service_state = yield self.add_service_from_charm("wordpress") |
942 | 21 | self.output = self.capture_logging() | 21 | self.output = self.capture_logging() |
943 | 22 | 22 | ||
944 | === modified file 'juju/control/tests/test_upgrade_charm.py' | |||
945 | --- juju/control/tests/test_upgrade_charm.py 2012-08-06 19:29:30 +0000 | |||
946 | +++ juju/control/tests/test_upgrade_charm.py 2012-09-15 19:26:18 +0000 | |||
947 | @@ -1,6 +1,5 @@ | |||
948 | 1 | import json | 1 | import json |
949 | 2 | import os | 2 | import os |
950 | 3 | from yaml import dump | ||
951 | 4 | 3 | ||
952 | 5 | from twisted.internet.defer import inlineCallbacks, succeed | 4 | from twisted.internet.defer import inlineCallbacks, succeed |
953 | 6 | 5 | ||
954 | @@ -11,8 +10,10 @@ | |||
955 | 11 | from juju.control import main | 10 | from juju.control import main |
956 | 12 | from juju.errors import FileNotFound | 11 | from juju.errors import FileNotFound |
957 | 13 | from juju.environment.environment import Environment | 12 | from juju.environment.environment import Environment |
958 | 13 | from juju.lib.mocker import ANY | ||
959 | 14 | from juju.lib.serializer import dump | ||
960 | 14 | from juju.unit.workflow import UnitWorkflowState | 15 | from juju.unit.workflow import UnitWorkflowState |
962 | 15 | from juju.lib.mocker import ANY | 16 | |
963 | 16 | 17 | ||
964 | 17 | from .common import MachineControlToolTest | 18 | from .common import MachineControlToolTest |
965 | 18 | 19 | ||
966 | 19 | 20 | ||
967 | === modified file 'juju/control/tests/test_utils.py' | |||
968 | --- juju/control/tests/test_utils.py 2012-03-27 23:56:09 +0000 | |||
969 | +++ juju/control/tests/test_utils.py 2012-09-15 19:26:18 +0000 | |||
970 | @@ -1,7 +1,6 @@ | |||
971 | 1 | import os | 1 | import os |
972 | 2 | 2 | ||
973 | 3 | from twisted.internet.defer import inlineCallbacks, returnValue | 3 | from twisted.internet.defer import inlineCallbacks, returnValue |
974 | 4 | from yaml import dump | ||
975 | 5 | 4 | ||
976 | 6 | from juju.environment.tests.test_config import EnvironmentsConfigTestBase | 5 | from juju.environment.tests.test_config import EnvironmentsConfigTestBase |
977 | 7 | from juju.control.tests.common import ControlToolTest | 6 | from juju.control.tests.common import ControlToolTest |
978 | @@ -10,6 +9,7 @@ | |||
979 | 10 | expand_path, parse_passthrough_args, ParseError) | 9 | expand_path, parse_passthrough_args, ParseError) |
980 | 11 | from juju.environment.config import EnvironmentsConfig | 10 | from juju.environment.config import EnvironmentsConfig |
981 | 12 | from juju.environment.errors import EnvironmentsConfigError | 11 | from juju.environment.errors import EnvironmentsConfigError |
982 | 12 | from juju.lib.serializer import yaml_dump as dump | ||
983 | 13 | from juju.lib.testing import TestCase | 13 | from juju.lib.testing import TestCase |
984 | 14 | from juju.state.errors import ServiceUnitStateMachineNotAssigned | 14 | from juju.state.errors import ServiceUnitStateMachineNotAssigned |
985 | 15 | from juju.state.tests.test_service import ServiceStateManagerTestBase | 15 | from juju.state.tests.test_service import ServiceStateManagerTestBase |
986 | 16 | 16 | ||
987 | === modified file 'juju/environment/config.py' | |||
988 | --- juju/environment/config.py 2012-08-31 15:03:31 +0000 | |||
989 | +++ juju/environment/config.py 2012-09-15 19:26:18 +0000 | |||
990 | @@ -5,6 +5,7 @@ | |||
991 | 5 | from juju.environment.environment import Environment | 5 | from juju.environment.environment import Environment |
992 | 6 | from juju.environment.errors import EnvironmentsConfigError | 6 | from juju.environment.errors import EnvironmentsConfigError |
993 | 7 | from juju.errors import FileAlreadyExists, FileNotFound | 7 | from juju.errors import FileAlreadyExists, FileNotFound |
994 | 8 | from juju.lib import serializer | ||
995 | 8 | from juju.lib.schema import ( | 9 | from juju.lib.schema import ( |
996 | 9 | Constant, Dict, Int, KeyDict, OAuthString, OneOf, SchemaError, SelectDict, | 10 | Constant, Dict, Int, KeyDict, OAuthString, OneOf, SchemaError, SelectDict, |
997 | 10 | String, Bool) | 11 | String, Bool) |
998 | @@ -174,7 +175,7 @@ | |||
999 | 174 | self._fail("Configuration must be a string", path, repr(content)) | 175 | self._fail("Configuration must be a string", path, repr(content)) |
1000 | 175 | 176 | ||
1001 | 176 | try: | 177 | try: |
1003 | 177 | config = yaml.load(content) | 178 | config = serializer.yaml_load(content) |
1004 | 178 | except yaml.YAMLError, error: | 179 | except yaml.YAMLError, error: |
1005 | 179 | self._fail(error, path=path, content=content) | 180 | self._fail(error, path=path, content=content) |
1006 | 180 | 181 | ||
1007 | @@ -309,4 +310,4 @@ | |||
1008 | 309 | assert data.keys() == [name] | 310 | assert data.keys() == [name] |
1009 | 310 | config["environments"].update(data) | 311 | config["environments"].update(data) |
1010 | 311 | 312 | ||
1012 | 312 | return yaml.safe_dump(config) | 313 | return serializer.dump(config) |
1013 | 313 | 314 | ||
1014 | === modified file 'juju/environment/tests/test_config.py' | |||
1015 | --- juju/environment/tests/test_config.py 2012-08-31 15:17:53 +0000 | |||
1016 | +++ juju/environment/tests/test_config.py 2012-09-15 19:26:18 +0000 | |||
1017 | @@ -1,5 +1,4 @@ | |||
1018 | 1 | import os | 1 | import os |
1019 | 2 | import yaml | ||
1020 | 3 | 2 | ||
1021 | 4 | from twisted.internet.defer import inlineCallbacks | 3 | from twisted.internet.defer import inlineCallbacks |
1022 | 5 | 4 | ||
1023 | @@ -8,8 +7,10 @@ | |||
1024 | 8 | from juju.environment.environment import Environment | 7 | from juju.environment.environment import Environment |
1025 | 9 | from juju.environment.errors import EnvironmentsConfigError | 8 | from juju.environment.errors import EnvironmentsConfigError |
1026 | 10 | from juju.errors import FileNotFound, FileAlreadyExists | 9 | from juju.errors import FileNotFound, FileAlreadyExists |
1027 | 10 | from juju.lib import serializer | ||
1028 | 11 | from juju.state.environment import EnvironmentStateManager | 11 | from juju.state.environment import EnvironmentStateManager |
1029 | 12 | 12 | ||
1030 | 13 | |||
1031 | 13 | from juju.lib.testing import TestCase | 14 | from juju.lib.testing import TestCase |
1032 | 14 | 15 | ||
1033 | 15 | 16 | ||
1034 | @@ -102,7 +103,7 @@ | |||
1035 | 102 | # self.client. | 103 | # self.client. |
1036 | 103 | 104 | ||
1037 | 104 | def push_config(self, name, config): | 105 | def push_config(self, name, config): |
1039 | 105 | self.write_config(yaml.dump(config)) | 106 | self.write_config(serializer.yaml_dump(config)) |
1040 | 106 | self.config.load() | 107 | self.config.load() |
1041 | 107 | esm = EnvironmentStateManager(self.client) | 108 | esm = EnvironmentStateManager(self.client) |
1042 | 108 | return esm.set_config_state(self.config, name) | 109 | return esm.set_config_state(self.config, name) |
1043 | @@ -129,8 +130,8 @@ | |||
1044 | 129 | self.assertEquals(self.config.get_default_path(), self.default_path) | 130 | self.assertEquals(self.config.get_default_path(), self.default_path) |
1045 | 130 | 131 | ||
1046 | 131 | def compare_config(self, config1, sample_config2): | 132 | def compare_config(self, config1, sample_config2): |
1049 | 132 | config1 = yaml.load(config1) | 133 | config1 = serializer.yaml_load(config1) |
1050 | 133 | config2 = yaml.load( | 134 | config2 = serializer.yaml_load( |
1051 | 134 | sample_config2 % config1["environments"]["sample"]) | 135 | sample_config2 % config1["environments"]["sample"]) |
1052 | 135 | self.assertEqual(config1, config2) | 136 | self.assertEqual(config1, config2) |
1053 | 136 | 137 | ||
1054 | @@ -193,7 +194,7 @@ | |||
1055 | 193 | self.assertTrue(os.path.isfile(self.default_path)) | 194 | self.assertTrue(os.path.isfile(self.default_path)) |
1056 | 194 | 195 | ||
1057 | 195 | with open(self.default_path) as file: | 196 | with open(self.default_path) as file: |
1059 | 196 | config = yaml.load(file.read()) | 197 | config = serializer.yaml_load(file.read()) |
1060 | 197 | self.assertEqual( | 198 | self.assertEqual( |
1061 | 198 | config["environments"]["sample"]["type"], "ec2") | 199 | config["environments"]["sample"]["type"], "ec2") |
1062 | 199 | self.assertEqual( | 200 | self.assertEqual( |
1063 | @@ -373,9 +374,9 @@ | |||
1064 | 373 | get_default() must return the one defined environment, when it's | 374 | get_default() must return the one defined environment, when it's |
1065 | 374 | indeed a single one. | 375 | indeed a single one. |
1066 | 375 | """ | 376 | """ |
1068 | 376 | config = yaml.load(SAMPLE_ENV) | 377 | config = serializer.yaml_load(SAMPLE_ENV) |
1069 | 377 | del config["environments"]["mysecondenv"] | 378 | del config["environments"]["mysecondenv"] |
1071 | 378 | self.write_config(yaml.dump(config)) | 379 | self.write_config(serializer.yaml_dump(config)) |
1072 | 379 | self.config.load() | 380 | self.config.load() |
1073 | 380 | env = self.config.get_default() | 381 | env = self.config.get_default() |
1074 | 381 | self.assertEquals(env.name, "myfirstenv") | 382 | self.assertEquals(env.name, "myfirstenv") |
1075 | @@ -385,9 +386,9 @@ | |||
1076 | 385 | get_default() must otherwise return the environment named | 386 | get_default() must otherwise return the environment named |
1077 | 386 | through the "default:" option. | 387 | through the "default:" option. |
1078 | 387 | """ | 388 | """ |
1080 | 388 | config = yaml.load(SAMPLE_ENV) | 389 | config = serializer.yaml_load(SAMPLE_ENV) |
1081 | 389 | config["default"] = "mysecondenv" | 390 | config["default"] = "mysecondenv" |
1083 | 390 | self.write_config(yaml.dump(config)) | 391 | self.write_config(serializer.yaml_dump(config)) |
1084 | 391 | self.config.load() | 392 | self.config.load() |
1085 | 392 | env = self.config.get_default() | 393 | env = self.config.get_default() |
1086 | 393 | self.assertEquals(env.name, "mysecondenv") | 394 | self.assertEquals(env.name, "mysecondenv") |
1087 | @@ -396,9 +397,9 @@ | |||
1088 | 396 | """ | 397 | """ |
1089 | 397 | The schema should mention the "default:" option as a string. | 398 | The schema should mention the "default:" option as a string. |
1090 | 398 | """ | 399 | """ |
1092 | 399 | config = yaml.load(SAMPLE_ENV) | 400 | config = serializer.yaml_load(SAMPLE_ENV) |
1093 | 400 | config["default"] = 1 | 401 | config["default"] = 1 |
1095 | 401 | self.write_config(yaml.dump(config)) | 402 | self.write_config(serializer.yaml_dump(config)) |
1096 | 402 | error = self.assertRaises(EnvironmentsConfigError, self.config.load) | 403 | error = self.assertRaises(EnvironmentsConfigError, self.config.load) |
1097 | 403 | self.assertEquals( | 404 | self.assertEquals( |
1098 | 404 | str(error), | 405 | str(error), |
1099 | @@ -410,10 +411,10 @@ | |||
1100 | 410 | get_default() must raise an error if the environment named through | 411 | get_default() must raise an error if the environment named through |
1101 | 411 | the "default:" option isn't found. | 412 | the "default:" option isn't found. |
1102 | 412 | """ | 413 | """ |
1104 | 413 | config = yaml.load(SAMPLE_ENV) | 414 | config = serializer.yaml_load(SAMPLE_ENV) |
1105 | 414 | config["default"] = "non-existent" | 415 | config["default"] = "non-existent" |
1106 | 415 | # Use a different path to ensure the error message is right. | 416 | # Use a different path to ensure the error message is right. |
1108 | 416 | self.write_config(yaml.dump(config), other_path=True) | 417 | self.write_config(serializer.yaml_dump(config), other_path=True) |
1109 | 417 | self.config.load(self.other_path) | 418 | self.config.load(self.other_path) |
1110 | 418 | try: | 419 | try: |
1111 | 419 | self.config.get_default() | 420 | self.config.get_default() |
1112 | @@ -447,10 +448,10 @@ | |||
1113 | 447 | contains a machine provider configuration without any type | 448 | contains a machine provider configuration without any type |
1114 | 448 | information. | 449 | information. |
1115 | 449 | """ | 450 | """ |
1117 | 450 | config = yaml.load(SAMPLE_ENV) | 451 | config = serializer.yaml_load(SAMPLE_ENV) |
1118 | 451 | # Delete the type. | 452 | # Delete the type. |
1119 | 452 | del config["environments"]["myfirstenv"]["type"] | 453 | del config["environments"]["myfirstenv"]["type"] |
1121 | 453 | self.write_config(yaml.dump(config), other_path=True) | 454 | self.write_config(serializer.yaml_dump(config), other_path=True) |
1122 | 454 | 455 | ||
1123 | 455 | try: | 456 | try: |
1124 | 456 | self.config.load(self.other_path) | 457 | self.config.load(self.other_path) |
1125 | @@ -468,12 +469,12 @@ | |||
1126 | 468 | self.write_config(SAMPLE_ENV) | 469 | self.write_config(SAMPLE_ENV) |
1127 | 469 | self.config.load() | 470 | self.config.load() |
1128 | 470 | config = self.config.serialize() | 471 | config = self.config.serialize() |
1130 | 471 | serialized = yaml.load(SAMPLE_ENV) | 472 | serialized = serializer.yaml_load(SAMPLE_ENV) |
1131 | 472 | 473 | ||
1132 | 473 | for d in serialized["environments"].values(): | 474 | for d in serialized["environments"].values(): |
1133 | 474 | d["dynamicduck"] = "magic" | 475 | d["dynamicduck"] = "magic" |
1134 | 475 | 476 | ||
1136 | 476 | self.assertEqual(yaml.load(config), serialized) | 477 | self.assertEqual(serializer.yaml_load(config), serialized) |
1137 | 477 | 478 | ||
1138 | 478 | def test_serialize_environment(self): | 479 | def test_serialize_environment(self): |
1139 | 479 | """ | 480 | """ |
1140 | @@ -484,12 +485,12 @@ | |||
1141 | 484 | self.write_config(SAMPLE_ENV) | 485 | self.write_config(SAMPLE_ENV) |
1142 | 485 | self.config.load() | 486 | self.config.load() |
1143 | 486 | 487 | ||
1145 | 487 | data = yaml.load(SAMPLE_ENV) | 488 | data = serializer.yaml_load(SAMPLE_ENV) |
1146 | 488 | del data["environments"]["mysecondenv"] | 489 | del data["environments"]["mysecondenv"] |
1147 | 489 | data["environments"]["myfirstenv"]["dynamicduck"] = "magic" | 490 | data["environments"]["myfirstenv"]["dynamicduck"] = "magic" |
1148 | 490 | 491 | ||
1149 | 491 | self.assertEqual( | 492 | self.assertEqual( |
1151 | 492 | yaml.load(self.config.serialize("myfirstenv")), | 493 | serializer.yaml_load(self.config.serialize("myfirstenv")), |
1152 | 493 | data) | 494 | data) |
1153 | 494 | 495 | ||
1154 | 495 | def test_load_serialized_environment(self): | 496 | def test_load_serialized_environment(self): |
1155 | @@ -518,9 +519,9 @@ | |||
1156 | 518 | 519 | ||
1157 | 519 | def test_serialize_custom_variables_outside_environment(self): | 520 | def test_serialize_custom_variables_outside_environment(self): |
1158 | 520 | """Serializing captures custom variables out of the environment.""" | 521 | """Serializing captures custom variables out of the environment.""" |
1160 | 521 | data = yaml.load(SAMPLE_ENV) | 522 | data = serializer.yaml_load(SAMPLE_ENV) |
1161 | 522 | data["default"] = "myfirstenv" | 523 | data["default"] = "myfirstenv" |
1163 | 523 | self.write_config(yaml.dump(data)) | 524 | self.write_config(serializer.yaml_dump(data)) |
1164 | 524 | self.config.load() | 525 | self.config.load() |
1165 | 525 | serialized = self.config.serialize() | 526 | serialized = self.config.serialize() |
1166 | 526 | 527 | ||
1167 | @@ -543,17 +544,17 @@ | |||
1168 | 543 | self.write_config("\0") | 544 | self.write_config("\0") |
1169 | 544 | error = self.assertRaises(EnvironmentsConfigError, self.config.load) | 545 | error = self.assertRaises(EnvironmentsConfigError, self.config.load) |
1170 | 545 | self.assertIn( | 546 | self.assertIn( |
1172 | 546 | "special characters are not allowed", str(error)) | 547 | "control characters are not allowed", str(error)) |
1173 | 547 | 548 | ||
1174 | 548 | def test_ec2_verifies_region(self): | 549 | def test_ec2_verifies_region(self): |
1175 | 549 | # sample doesn't include credentials | 550 | # sample doesn't include credentials |
1176 | 550 | self.setup_ec2_credentials() | 551 | self.setup_ec2_credentials() |
1177 | 551 | self.config.write_sample() | 552 | self.config.write_sample() |
1178 | 552 | with open(self.default_path) as file: | 553 | with open(self.default_path) as file: |
1180 | 553 | config = yaml.load(file.read()) | 554 | config = serializer.yaml_load(file.read()) |
1181 | 554 | config["environments"]["sample"]["region"] = "ap-southeast-2" | 555 | config["environments"]["sample"]["region"] = "ap-southeast-2" |
1182 | 555 | 556 | ||
1184 | 556 | self.write_config(yaml.dump(config), other_path=True) | 557 | self.write_config(serializer.yaml_dump(config), other_path=True) |
1185 | 557 | 558 | ||
1186 | 558 | e = self.assertRaises(EnvironmentsConfigError, | 559 | e = self.assertRaises(EnvironmentsConfigError, |
1187 | 559 | self.config.load, | 560 | self.config.load, |
1188 | @@ -562,11 +563,11 @@ | |||
1189 | 562 | str(e)) | 563 | str(e)) |
1190 | 563 | 564 | ||
1191 | 564 | with open(self.default_path) as file: | 565 | with open(self.default_path) as file: |
1193 | 565 | config = yaml.load(file.read()) | 566 | config = serializer.yaml_load(file.read()) |
1194 | 566 | # Authorized keys are required for environment serialization. | 567 | # Authorized keys are required for environment serialization. |
1195 | 567 | config["environments"]["sample"]["authorized-keys"] = "mickey" | 568 | config["environments"]["sample"]["authorized-keys"] = "mickey" |
1196 | 568 | config["environments"]["sample"]["region"] = "ap-southeast-1" | 569 | config["environments"]["sample"]["region"] = "ap-southeast-1" |
1198 | 569 | self.write_config(yaml.dump(config), other_path=True) | 570 | self.write_config(serializer.yaml_dump(config), other_path=True) |
1199 | 570 | 571 | ||
1200 | 571 | self.config.load(self.other_path) | 572 | self.config.load(self.other_path) |
1201 | 572 | data = self.config.get_default().get_serialization_data() | 573 | data = self.config.get_default().get_serialization_data() |
1202 | @@ -575,9 +576,9 @@ | |||
1203 | 575 | def assert_ec2_sample_config(self, delete_key): | 576 | def assert_ec2_sample_config(self, delete_key): |
1204 | 576 | self.config.write_sample() | 577 | self.config.write_sample() |
1205 | 577 | with open(self.default_path) as file: | 578 | with open(self.default_path) as file: |
1207 | 578 | config = yaml.load(file.read()) | 579 | config = serializer.yaml_load(file.read()) |
1208 | 579 | del config["environments"]["sample"][delete_key] | 580 | del config["environments"]["sample"][delete_key] |
1210 | 580 | self.write_config(yaml.dump(config), other_path=True) | 581 | self.write_config(serializer.yaml_dump(config), other_path=True) |
1211 | 581 | 582 | ||
1212 | 582 | try: | 583 | try: |
1213 | 583 | self.config.load(self.other_path) | 584 | self.config.load(self.other_path) |
1214 | @@ -604,9 +605,9 @@ | |||
1215 | 604 | self.setup_ec2_credentials() | 605 | self.setup_ec2_credentials() |
1216 | 605 | self.config.write_sample() | 606 | self.config.write_sample() |
1217 | 606 | with open(self.default_path) as file: | 607 | with open(self.default_path) as file: |
1219 | 607 | config = yaml.load(file.read()) | 608 | config = serializer.yaml_load(file.read()) |
1220 | 608 | config["environments"]["sample"]["placement"] = "random" | 609 | config["environments"]["sample"]["placement"] = "random" |
1222 | 609 | self.write_config(yaml.dump(config), other_path=True) | 610 | self.write_config(serializer.yaml_dump(config), other_path=True) |
1223 | 610 | 611 | ||
1224 | 611 | e = self.assertRaises(EnvironmentsConfigError, | 612 | e = self.assertRaises(EnvironmentsConfigError, |
1225 | 612 | self.config.load, | 613 | self.config.load, |
1226 | @@ -615,11 +616,11 @@ | |||
1227 | 615 | str(e)) | 616 | str(e)) |
1228 | 616 | 617 | ||
1229 | 617 | with open(self.default_path) as file: | 618 | with open(self.default_path) as file: |
1231 | 618 | config = yaml.load(file.read()) | 619 | config = serializer.yaml_load(file.read()) |
1232 | 619 | # Authorized keys are required for environment serialization. | 620 | # Authorized keys are required for environment serialization. |
1233 | 620 | config["environments"]["sample"]["authorized-keys"] = "mickey" | 621 | config["environments"]["sample"]["authorized-keys"] = "mickey" |
1234 | 621 | config["environments"]["sample"]["placement"] = "local" | 622 | config["environments"]["sample"]["placement"] = "local" |
1236 | 622 | self.write_config(yaml.dump(config), other_path=True) | 623 | self.write_config(serializer.yaml_dump(config), other_path=True) |
1237 | 623 | 624 | ||
1238 | 624 | self.config.load(self.other_path) | 625 | self.config.load(self.other_path) |
1239 | 625 | data = self.config.get_default().get_serialization_data() | 626 | data = self.config.get_default().get_serialization_data() |
1240 | @@ -630,9 +631,9 @@ | |||
1241 | 630 | self.setup_ec2_credentials() | 631 | self.setup_ec2_credentials() |
1242 | 631 | self.config.write_sample() | 632 | self.config.write_sample() |
1243 | 632 | with open(self.default_path) as f: | 633 | with open(self.default_path) as f: |
1245 | 633 | config = yaml.load(f.read()) | 634 | config = serializer.yaml_load(f.read()) |
1246 | 634 | config["environments"]["sample"]["default-series"] = "astounding" | 635 | config["environments"]["sample"]["default-series"] = "astounding" |
1248 | 635 | self.write_config(yaml.dump(config), other_path=True) | 636 | self.write_config(serializer.yaml_dump(config), other_path=True) |
1249 | 636 | 637 | ||
1250 | 637 | self.config.load(self.other_path) | 638 | self.config.load(self.other_path) |
1251 | 638 | 639 | ||
1252 | @@ -643,9 +644,9 @@ | |||
1253 | 643 | self.setup_ec2_credentials() | 644 | self.setup_ec2_credentials() |
1254 | 644 | self.config.write_sample() | 645 | self.config.write_sample() |
1255 | 645 | with open(self.default_path) as f: | 646 | with open(self.default_path) as f: |
1257 | 646 | config = yaml.load(f.read()) | 647 | config = serializer.yaml_load(f.read()) |
1258 | 647 | config["environments"]["sample"]["ssl-hostname-verification"] = True | 648 | config["environments"]["sample"]["ssl-hostname-verification"] = True |
1260 | 648 | self.write_config(yaml.dump(config), other_path=True) | 649 | self.write_config(serializer.yaml_dump(config), other_path=True) |
1261 | 649 | 650 | ||
1262 | 650 | self.config.load(self.other_path) | 651 | self.config.load(self.other_path) |
1263 | 651 | 652 | ||
1264 | @@ -658,9 +659,9 @@ | |||
1265 | 658 | "admin-secret acquired-mgmt-class available-mgmt-class " | 659 | "admin-secret acquired-mgmt-class available-mgmt-class " |
1266 | 659 | "default-series").split() | 660 | "default-series").split() |
1267 | 660 | for require in requires: | 661 | for require in requires: |
1269 | 661 | config = yaml.load(SAMPLE_ORCHESTRA) | 662 | config = serializer.yaml_load(SAMPLE_ORCHESTRA) |
1270 | 662 | del config["environments"]["sample"][require] | 663 | del config["environments"]["sample"][require] |
1272 | 663 | self.write_config(yaml.dump(config), other_path=True) | 664 | self.write_config(serializer.yaml_dump(config), other_path=True) |
1273 | 664 | 665 | ||
1274 | 665 | try: | 666 | try: |
1275 | 666 | self.config.load(self.other_path) | 667 | self.config.load(self.other_path) |
1276 | @@ -675,25 +676,25 @@ | |||
1277 | 675 | % require) | 676 | % require) |
1278 | 676 | 677 | ||
1279 | 677 | def test_orchestra_respects_default_series(self): | 678 | def test_orchestra_respects_default_series(self): |
1281 | 678 | config = yaml.load(SAMPLE_ORCHESTRA) | 679 | config = serializer.yaml_load(SAMPLE_ORCHESTRA) |
1282 | 679 | config["environments"]["sample"]["default-series"] = "magnificent" | 680 | config["environments"]["sample"]["default-series"] = "magnificent" |
1284 | 680 | self.write_config(yaml.dump(config), other_path=True) | 681 | self.write_config(serializer.yaml_dump(config), other_path=True) |
1285 | 681 | self.config.load(self.other_path) | 682 | self.config.load(self.other_path) |
1286 | 682 | 683 | ||
1287 | 683 | provider = self.config.get_default().get_machine_provider() | 684 | provider = self.config.get_default().get_machine_provider() |
1288 | 684 | self.assertEqual(provider.config["default-series"], "magnificent") | 685 | self.assertEqual(provider.config["default-series"], "magnificent") |
1289 | 685 | 686 | ||
1290 | 686 | def test_orchestra_verifies_placement(self): | 687 | def test_orchestra_verifies_placement(self): |
1292 | 687 | config = yaml.load(SAMPLE_ORCHESTRA) | 688 | config = serializer.yaml_load(SAMPLE_ORCHESTRA) |
1293 | 688 | config["environments"]["sample"]["placement"] = "random" | 689 | config["environments"]["sample"]["placement"] = "random" |
1295 | 689 | self.write_config(yaml.dump(config), other_path=True) | 690 | self.write_config(serializer.yaml_dump(config), other_path=True) |
1296 | 690 | e = self.assertRaises( | 691 | e = self.assertRaises( |
1297 | 691 | EnvironmentsConfigError, self.config.load, self.other_path) | 692 | EnvironmentsConfigError, self.config.load, self.other_path) |
1298 | 692 | self.assertIn("expected 'unassigned', got 'random'", | 693 | self.assertIn("expected 'unassigned', got 'random'", |
1299 | 693 | str(e)) | 694 | str(e)) |
1300 | 694 | 695 | ||
1301 | 695 | config["environments"]["sample"]["placement"] = "local" | 696 | config["environments"]["sample"]["placement"] = "local" |
1303 | 696 | self.write_config(yaml.dump(config), other_path=True) | 697 | self.write_config(serializer.yaml_dump(config), other_path=True) |
1304 | 697 | self.config.load(self.other_path) | 698 | self.config.load(self.other_path) |
1305 | 698 | 699 | ||
1306 | 699 | data = self.config.get_default().placement | 700 | data = self.config.get_default().placement |
1307 | @@ -702,9 +703,9 @@ | |||
1308 | 702 | def test_maas_schema_requires(self): | 703 | def test_maas_schema_requires(self): |
1309 | 703 | requires = "maas-server maas-oauth admin-secret default-series".split() | 704 | requires = "maas-server maas-oauth admin-secret default-series".split() |
1310 | 704 | for require in requires: | 705 | for require in requires: |
1312 | 705 | config = yaml.load(SAMPLE_MAAS) | 706 | config = serializer.yaml_load(SAMPLE_MAAS) |
1313 | 706 | del config["environments"]["sample"][require] | 707 | del config["environments"]["sample"][require] |
1315 | 707 | self.write_config(yaml.dump(config), other_path=True) | 708 | self.write_config(serializer.yaml_dump(config), other_path=True) |
1316 | 708 | 709 | ||
1317 | 709 | try: | 710 | try: |
1318 | 710 | self.config.load(self.other_path) | 711 | self.config.load(self.other_path) |
1319 | @@ -719,9 +720,9 @@ | |||
1320 | 719 | % require) | 720 | % require) |
1321 | 720 | 721 | ||
1322 | 721 | def test_maas_default_series(self): | 722 | def test_maas_default_series(self): |
1324 | 722 | config = yaml.load(SAMPLE_MAAS) | 723 | config = serializer.yaml_load(SAMPLE_MAAS) |
1325 | 723 | config["environments"]["sample"]["default-series"] = "magnificent" | 724 | config["environments"]["sample"]["default-series"] = "magnificent" |
1327 | 724 | self.write_config(yaml.dump(config), other_path=True) | 725 | self.write_config(serializer.yaml_dump(config), other_path=True) |
1328 | 725 | e = self.assertRaises( | 726 | e = self.assertRaises( |
1329 | 726 | EnvironmentsConfigError, self.config.load, self.other_path) | 727 | EnvironmentsConfigError, self.config.load, self.other_path) |
1330 | 727 | self.assertIn( | 728 | self.assertIn( |
1331 | @@ -730,16 +731,16 @@ | |||
1332 | 730 | str(e)) | 731 | str(e)) |
1333 | 731 | 732 | ||
1334 | 732 | def test_maas_verifies_placement(self): | 733 | def test_maas_verifies_placement(self): |
1336 | 733 | config = yaml.load(SAMPLE_MAAS) | 734 | config = serializer.yaml_load(SAMPLE_MAAS) |
1337 | 734 | config["environments"]["sample"]["placement"] = "random" | 735 | config["environments"]["sample"]["placement"] = "random" |
1339 | 735 | self.write_config(yaml.dump(config), other_path=True) | 736 | self.write_config(serializer.yaml_dump(config), other_path=True) |
1340 | 736 | e = self.assertRaises( | 737 | e = self.assertRaises( |
1341 | 737 | EnvironmentsConfigError, self.config.load, self.other_path) | 738 | EnvironmentsConfigError, self.config.load, self.other_path) |
1342 | 738 | self.assertIn("expected 'unassigned', got 'random'", | 739 | self.assertIn("expected 'unassigned', got 'random'", |
1343 | 739 | str(e)) | 740 | str(e)) |
1344 | 740 | 741 | ||
1345 | 741 | config["environments"]["sample"]["placement"] = "local" | 742 | config["environments"]["sample"]["placement"] = "local" |
1347 | 742 | self.write_config(yaml.dump(config), other_path=True) | 743 | self.write_config(serializer.yaml_dump(config), other_path=True) |
1348 | 743 | self.config.load(self.other_path) | 744 | self.config.load(self.other_path) |
1349 | 744 | 745 | ||
1350 | 745 | data = self.config.get_default().placement | 746 | data = self.config.get_default().placement |
1351 | @@ -747,51 +748,51 @@ | |||
1352 | 747 | 748 | ||
1353 | 748 | def test_lxc_requires_data_dir(self): | 749 | def test_lxc_requires_data_dir(self): |
1354 | 749 | """lxc dev only supports local placement.""" | 750 | """lxc dev only supports local placement.""" |
1357 | 750 | config = yaml.load(SAMPLE_LOCAL) | 751 | config = serializer.yaml_load(SAMPLE_LOCAL) |
1358 | 751 | self.write_config(yaml.dump(config), other_path=True) | 752 | self.write_config(serializer.yaml_dump(config), other_path=True) |
1359 | 752 | error = self.assertRaises( | 753 | error = self.assertRaises( |
1360 | 753 | EnvironmentsConfigError, self.config.load, self.other_path) | 754 | EnvironmentsConfigError, self.config.load, self.other_path) |
1361 | 754 | self.assertIn("data-dir: required value not found", str(error)) | 755 | self.assertIn("data-dir: required value not found", str(error)) |
1362 | 755 | 756 | ||
1363 | 756 | def test_lxc_verifies_placement(self): | 757 | def test_lxc_verifies_placement(self): |
1364 | 757 | """lxc dev only supports local placement.""" | 758 | """lxc dev only supports local placement.""" |
1366 | 758 | config = yaml.load(SAMPLE_LOCAL) | 759 | config = serializer.yaml_load(SAMPLE_LOCAL) |
1367 | 759 | config["environments"]["sample"]["placement"] = "unassigned" | 760 | config["environments"]["sample"]["placement"] = "unassigned" |
1369 | 760 | self.write_config(yaml.dump(config), other_path=True) | 761 | self.write_config(serializer.yaml_dump(config), other_path=True) |
1370 | 761 | error = self.assertRaises( | 762 | error = self.assertRaises( |
1371 | 762 | EnvironmentsConfigError, self.config.load, self.other_path) | 763 | EnvironmentsConfigError, self.config.load, self.other_path) |
1372 | 763 | self.assertIn("expected 'local', got 'unassigned'", str(error)) | 764 | self.assertIn("expected 'local', got 'unassigned'", str(error)) |
1373 | 764 | 765 | ||
1374 | 765 | def test_openstack_requires_default_image_id(self): | 766 | def test_openstack_requires_default_image_id(self): |
1375 | 766 | """A VM image must be supplied for openstack provider.""" | 767 | """A VM image must be supplied for openstack provider.""" |
1377 | 767 | config = yaml.load(SAMPLE_OPENSTACK) | 768 | config = serializer.yaml_load(SAMPLE_OPENSTACK) |
1378 | 768 | del config["environments"]["sample"]["default-image-id"] | 769 | del config["environments"]["sample"]["default-image-id"] |
1380 | 769 | self.write_config(yaml.dump(config), other_path=True) | 770 | self.write_config(serializer.yaml_dump(config), other_path=True) |
1381 | 770 | error = self.assertRaises( | 771 | error = self.assertRaises( |
1382 | 771 | EnvironmentsConfigError, self.config.load, self.other_path) | 772 | EnvironmentsConfigError, self.config.load, self.other_path) |
1383 | 772 | self.assertIn("default-image-id: required value not found", str(error)) | 773 | self.assertIn("default-image-id: required value not found", str(error)) |
1384 | 773 | 774 | ||
1385 | 774 | def test_openstack_ignores_placement(self): | 775 | def test_openstack_ignores_placement(self): |
1386 | 775 | """The placement config is not verified for openstack provider.""" | 776 | """The placement config is not verified for openstack provider.""" |
1388 | 776 | config = yaml.load(SAMPLE_OPENSTACK) | 777 | config = serializer.yaml_load(SAMPLE_OPENSTACK) |
1389 | 777 | config["environments"]["sample"]["placement"] = "whatever" | 778 | config["environments"]["sample"]["placement"] = "whatever" |
1391 | 778 | self.write_config(yaml.dump(config), other_path=True) | 779 | self.write_config(serializer.yaml_dump(config), other_path=True) |
1392 | 779 | self.config.load(self.other_path) | 780 | self.config.load(self.other_path) |
1393 | 780 | 781 | ||
1394 | 781 | def test_openstack_s3_requires_default_image_id(self): | 782 | def test_openstack_s3_requires_default_image_id(self): |
1395 | 782 | """A VM image must be supplied for openstack_s3 provider.""" | 783 | """A VM image must be supplied for openstack_s3 provider.""" |
1397 | 783 | config = yaml.load(SAMPLE_OPENSTACK) | 784 | config = serializer.yaml_load(SAMPLE_OPENSTACK) |
1398 | 784 | config["environments"]["sample"]["type"] = "openstack_s3" | 785 | config["environments"]["sample"]["type"] = "openstack_s3" |
1399 | 785 | del config["environments"]["sample"]["default-image-id"] | 786 | del config["environments"]["sample"]["default-image-id"] |
1401 | 786 | self.write_config(yaml.dump(config), other_path=True) | 787 | self.write_config(serializer.yaml_dump(config), other_path=True) |
1402 | 787 | error = self.assertRaises( | 788 | error = self.assertRaises( |
1403 | 788 | EnvironmentsConfigError, self.config.load, self.other_path) | 789 | EnvironmentsConfigError, self.config.load, self.other_path) |
1404 | 789 | self.assertIn("default-image-id: required value not found", str(error)) | 790 | self.assertIn("default-image-id: required value not found", str(error)) |
1405 | 790 | 791 | ||
1406 | 791 | def test_openstack_s3_ignores_placement(self): | 792 | def test_openstack_s3_ignores_placement(self): |
1407 | 792 | """The placement config is not verified for openstack_s3 provider.""" | 793 | """The placement config is not verified for openstack_s3 provider.""" |
1409 | 793 | config = yaml.load(SAMPLE_OPENSTACK) | 794 | config = serializer.yaml_load(SAMPLE_OPENSTACK) |
1410 | 794 | config["environments"]["sample"]["type"] = "openstack_s3" | 795 | config["environments"]["sample"]["type"] = "openstack_s3" |
1411 | 795 | config["environments"]["sample"]["placement"] = "whatever" | 796 | config["environments"]["sample"]["placement"] = "whatever" |
1413 | 796 | self.write_config(yaml.dump(config), other_path=True) | 797 | self.write_config(serializer.yaml_dump(config), other_path=True) |
1414 | 797 | self.config.load(self.other_path) | 798 | self.config.load(self.other_path) |
1415 | 798 | 799 | ||
1416 | === modified file 'juju/hooks/protocol.py' | |||
1417 | --- juju/hooks/protocol.py 2012-08-30 03:25:04 +0000 | |||
1418 | +++ juju/hooks/protocol.py 2012-09-15 19:26:18 +0000 | |||
1419 | @@ -48,9 +48,10 @@ | |||
1420 | 48 | from twisted.internet import defer | 48 | from twisted.internet import defer |
1421 | 49 | from twisted.internet import protocol | 49 | from twisted.internet import protocol |
1422 | 50 | from twisted.protocols import amp | 50 | from twisted.protocols import amp |
1424 | 51 | import yaml | 51 | |
1425 | 52 | 52 | ||
1426 | 53 | from juju.errors import JujuError | 53 | from juju.errors import JujuError |
1427 | 54 | from juju.lib import serializer | ||
1428 | 54 | from juju.lib.format import get_charm_formatter, get_charm_formatter_from_env | 55 | from juju.lib.format import get_charm_formatter, get_charm_formatter_from_env |
1429 | 55 | from juju.state.errors import UnitRelationStateNotFound | 56 | from juju.state.errors import UnitRelationStateNotFound |
1430 | 56 | from juju.state.hook import RelationHookContext | 57 | from juju.state.hook import RelationHookContext |
1431 | @@ -310,7 +311,7 @@ | |||
1432 | 310 | 311 | ||
1433 | 311 | # NOTE: no need to consider charm format for blob here, this | 312 | # NOTE: no need to consider charm format for blob here, this |
1434 | 312 | # blob has always been in YAML format | 313 | # blob has always been in YAML format |
1436 | 313 | defer.returnValue(dict(data=yaml.safe_dump(options))) | 314 | defer.returnValue(dict(data=serializer.dump(options))) |
1437 | 314 | 315 | ||
1438 | 315 | @OpenPortCommand.responder | 316 | @OpenPortCommand.responder |
1439 | 316 | @defer.inlineCallbacks | 317 | @defer.inlineCallbacks |
1440 | @@ -457,7 +458,7 @@ | |||
1441 | 457 | client_id=client_id, | 458 | client_id=client_id, |
1442 | 458 | option_name=option_name) | 459 | option_name=option_name) |
1443 | 459 | # Unbundle and deserialize | 460 | # Unbundle and deserialize |
1445 | 460 | result = yaml.safe_load(result["data"]) | 461 | result = serializer.load(result["data"]) |
1446 | 461 | defer.returnValue(result) | 462 | defer.returnValue(result) |
1447 | 462 | 463 | ||
1448 | 463 | @defer.inlineCallbacks | 464 | @defer.inlineCallbacks |
1449 | 464 | 465 | ||
1450 | === modified file 'juju/hooks/scheduler.py' | |||
1451 | --- juju/hooks/scheduler.py 2012-03-30 05:17:34 +0000 | |||
1452 | +++ juju/hooks/scheduler.py 2012-09-15 19:26:18 +0000 | |||
1453 | @@ -1,10 +1,11 @@ | |||
1454 | 1 | import logging | 1 | import logging |
1455 | 2 | import os | 2 | import os |
1457 | 3 | import yaml | 3 | |
1458 | 4 | 4 | ||
1459 | 5 | from twisted.internet.defer import ( | 5 | from twisted.internet.defer import ( |
1460 | 6 | DeferredQueue, inlineCallbacks, succeed, Deferred, | 6 | DeferredQueue, inlineCallbacks, succeed, Deferred, |
1461 | 7 | QueueUnderflow, QueueOverflow) | 7 | QueueUnderflow, QueueOverflow) |
1462 | 8 | from juju.lib import serializer | ||
1463 | 8 | from juju.state.hook import RelationHookContext, RelationChange | 9 | from juju.state.hook import RelationHookContext, RelationChange |
1464 | 9 | 10 | ||
1465 | 10 | 11 | ||
1466 | @@ -202,7 +203,7 @@ | |||
1467 | 202 | 203 | ||
1468 | 203 | def _load_state(self): | 204 | def _load_state(self): |
1469 | 204 | with open(self._state_path) as f: | 205 | with open(self._state_path) as f: |
1471 | 205 | state = yaml.load(f.read()) | 206 | state = serializer.load(f.read()) |
1472 | 206 | if not state: | 207 | if not state: |
1473 | 207 | return self._create_state() | 208 | return self._create_state() |
1474 | 208 | self._context_members = set(state["context_members"]) | 209 | self._context_members = set(state["context_members"]) |
1475 | @@ -211,7 +212,7 @@ | |||
1476 | 211 | self._run_queue.pending = state["change_queue"] | 212 | self._run_queue.pending = state["change_queue"] |
1477 | 212 | 213 | ||
1478 | 213 | def _save_state(self): | 214 | def _save_state(self): |
1480 | 214 | state = yaml.dump({ | 215 | state = serializer.dump({ |
1481 | 215 | "context_members": sorted(self._context_members), | 216 | "context_members": sorted(self._context_members), |
1482 | 216 | "member_versions": self._member_versions, | 217 | "member_versions": self._member_versions, |
1483 | 217 | "change_queue": self._run_queue.pending}) | 218 | "change_queue": self._run_queue.pending}) |
1484 | 218 | 219 | ||
1485 | === modified file 'juju/hooks/tests/test_invoker.py' | |||
1486 | --- juju/hooks/tests/test_invoker.py 2012-09-01 05:22:05 +0000 | |||
1487 | +++ juju/hooks/tests/test_invoker.py 2012-09-15 19:26:18 +0000 | |||
1488 | @@ -7,7 +7,6 @@ | |||
1489 | 7 | import os | 7 | import os |
1490 | 8 | import stat | 8 | import stat |
1491 | 9 | import sys | 9 | import sys |
1492 | 10 | import yaml | ||
1493 | 11 | 10 | ||
1494 | 12 | from twisted.internet import defer | 11 | from twisted.internet import defer |
1495 | 13 | from twisted.internet.process import Process | 12 | from twisted.internet.process import Process |
1496 | @@ -20,6 +19,7 @@ | |||
1497 | 20 | from juju.hooks import invoker | 19 | from juju.hooks import invoker |
1498 | 21 | from juju.hooks import commands | 20 | from juju.hooks import commands |
1499 | 22 | from juju.hooks.protocol import UnitSettingsFactory | 21 | from juju.hooks.protocol import UnitSettingsFactory |
1500 | 22 | from juju.lib import serializer | ||
1501 | 23 | from juju.lib.mocker import MATCH | 23 | from juju.lib.mocker import MATCH |
1502 | 24 | from juju.lib.twistutils import get_module_directory | 24 | from juju.lib.twistutils import get_module_directory |
1503 | 25 | from juju.state import hook | 25 | from juju.state import hook |
1504 | @@ -728,7 +728,7 @@ | |||
1505 | 728 | zk_data = yield self.relation.get_data() | 728 | zk_data = yield self.relation.get_data() |
1506 | 729 | self.assertEqual( | 729 | self.assertEqual( |
1507 | 730 | {"a": "b", "c": "d", "private-address": "mysql-0.example.com"}, | 730 | {"a": "b", "c": "d", "private-address": "mysql-0.example.com"}, |
1509 | 731 | yaml.load(zk_data)) | 731 | serializer.load(zk_data)) |
1510 | 732 | yield exe.ended | 732 | yield exe.ended |
1511 | 733 | self.assertIn( | 733 | self.assertIn( |
1512 | 734 | "Flushed values for hook %r on 'database:42'\n" | 734 | "Flushed values for hook %r on 'database:42'\n" |
1513 | @@ -771,7 +771,7 @@ | |||
1514 | 771 | self.assertEqual( | 771 | self.assertEqual( |
1515 | 772 | {"new-value": "2", "changed": "abc", "changed2": "xyz", | 772 | {"new-value": "2", "changed": "abc", "changed2": "xyz", |
1516 | 773 | "private-address": "mysql-0.example.com"}, | 773 | "private-address": "mysql-0.example.com"}, |
1518 | 774 | yaml.load(zk_data)) | 774 | serializer.load(zk_data)) |
1519 | 775 | 775 | ||
1520 | 776 | # Verify that unicode/strings longer than 100 characters in | 776 | # Verify that unicode/strings longer than 100 characters in |
1521 | 777 | # representation (including quotes and the u marker) are cut | 777 | # representation (including quotes and the u marker) are cut |
1522 | @@ -816,7 +816,7 @@ | |||
1523 | 816 | zk_data = yield self.relation.get_data() | 816 | zk_data = yield self.relation.get_data() |
1524 | 817 | self.assertEqual({"no-change": "42", "untouched": "xyz", | 817 | self.assertEqual({"no-change": "42", "untouched": "xyz", |
1525 | 818 | "private-address": "mysql-0.example.com"}, | 818 | "private-address": "mysql-0.example.com"}, |
1527 | 819 | yaml.load(zk_data)) | 819 | serializer.load(zk_data)) |
1528 | 820 | self.assertNotIn( | 820 | self.assertNotIn( |
1529 | 821 | "Flushed values for hook 'set-does-nothing'", | 821 | "Flushed values for hook 'set-does-nothing'", |
1530 | 822 | output.getvalue()) | 822 | output.getvalue()) |
1531 | @@ -960,7 +960,7 @@ | |||
1532 | 960 | internal_unit_id = (yield context.get_local_unit_state()).internal_id | 960 | internal_unit_id = (yield context.get_local_unit_state()).internal_id |
1533 | 961 | path = yield context.get_settings_path(internal_unit_id) | 961 | path = yield context.get_settings_path(internal_unit_id) |
1534 | 962 | data, stat = yield self.client.get(path) | 962 | data, stat = yield self.client.get(path) |
1536 | 963 | self.assertEqual(yaml.load(data), expected) | 963 | self.assertEqual(serializer.load(data), expected) |
1537 | 964 | 964 | ||
1538 | 965 | @defer.inlineCallbacks | 965 | @defer.inlineCallbacks |
1539 | 966 | def test_implied_relation_hook_context(self): | 966 | def test_implied_relation_hook_context(self): |
1540 | 967 | 967 | ||
1541 | === modified file 'juju/hooks/tests/test_scheduler.py' | |||
1542 | --- juju/hooks/tests/test_scheduler.py 2012-03-28 02:55:12 +0000 | |||
1543 | +++ juju/hooks/tests/test_scheduler.py 2012-09-15 19:26:18 +0000 | |||
1544 | @@ -1,10 +1,9 @@ | |||
1545 | 1 | import logging | 1 | import logging |
1546 | 2 | import os | 2 | import os |
1547 | 3 | import yaml | ||
1548 | 4 | 3 | ||
1549 | 5 | from twisted.internet.defer import ( | 4 | from twisted.internet.defer import ( |
1550 | 6 | inlineCallbacks, fail, succeed, Deferred, returnValue) | 5 | inlineCallbacks, fail, succeed, Deferred, returnValue) |
1552 | 7 | 6 | from juju.lib import serializer | |
1553 | 8 | from juju.hooks.scheduler import HookScheduler | 7 | from juju.hooks.scheduler import HookScheduler |
1554 | 9 | from juju.state.tests.test_service import ServiceStateManagerTestBase | 8 | from juju.state.tests.test_service import ServiceStateManagerTestBase |
1555 | 10 | 9 | ||
1556 | @@ -44,7 +43,7 @@ | |||
1557 | 44 | 43 | ||
1558 | 45 | def write_single_unit_state(self): | 44 | def write_single_unit_state(self): |
1559 | 46 | with open(self.state_file, "w") as f: | 45 | with open(self.state_file, "w") as f: |
1561 | 47 | f.write(yaml.dump({ | 46 | f.write(serializer.dump({ |
1562 | 48 | "context_members": ["u-1"], | 47 | "context_members": ["u-1"], |
1563 | 49 | "member_versions": {"u-1": 0}, | 48 | "member_versions": {"u-1": 0}, |
1564 | 50 | "unit_ops": {}, | 49 | "unit_ops": {}, |
1565 | @@ -82,7 +81,7 @@ | |||
1566 | 82 | yield sched_done | 81 | yield sched_done |
1567 | 83 | self.assertFalse(self.scheduler.running) | 82 | self.assertFalse(self.scheduler.running) |
1568 | 84 | with open(self.state_file) as f: | 83 | with open(self.state_file) as f: |
1570 | 85 | self.assertEquals(yaml.load(f.read()), { | 84 | self.assertEquals(serializer.load(f.read()), { |
1571 | 86 | "context_members": ['u-1'], | 85 | "context_members": ['u-1'], |
1572 | 87 | "member_versions": {"u-1": 0}, | 86 | "member_versions": {"u-1": 0}, |
1573 | 88 | "change_queue": [ | 87 | "change_queue": [ |
1574 | @@ -118,7 +117,7 @@ | |||
1575 | 118 | self.assertFalse(collected) | 117 | self.assertFalse(collected) |
1576 | 119 | 118 | ||
1577 | 120 | with open(self.state_file) as f: | 119 | with open(self.state_file) as f: |
1579 | 121 | self.assertEquals(yaml.load(f.read()), { | 120 | self.assertEquals(serializer.load(f.read()), { |
1580 | 122 | "context_members": [], | 121 | "context_members": [], |
1581 | 123 | "member_versions": {}, | 122 | "member_versions": {}, |
1582 | 124 | "change_queue": [ | 123 | "change_queue": [ |
1583 | @@ -163,7 +162,7 @@ | |||
1584 | 163 | self.scheduler.cb_change_members(["u-1"], ["u-2"]) | 162 | self.scheduler.cb_change_members(["u-1"], ["u-2"]) |
1585 | 164 | 163 | ||
1586 | 165 | with open(self.state_file) as f: | 164 | with open(self.state_file) as f: |
1588 | 166 | self.assertEquals(yaml.load(f.read()), { | 165 | self.assertEquals(serializer.load(f.read()), { |
1589 | 167 | "context_members": ['u-2'], | 166 | "context_members": ['u-2'], |
1590 | 168 | "member_versions": {"u-2": 0}, | 167 | "member_versions": {"u-2": 0}, |
1591 | 169 | "change_queue": [ | 168 | "change_queue": [ |
1592 | @@ -200,7 +199,7 @@ | |||
1593 | 200 | self.assertFalse(self.scheduler.running) | 199 | self.assertFalse(self.scheduler.running) |
1594 | 201 | 200 | ||
1595 | 202 | with open(self.state_file) as f: | 201 | with open(self.state_file) as f: |
1597 | 203 | self.assertEquals(yaml.load(f.read()), { | 202 | self.assertEquals(serializer.load(f.read()), { |
1598 | 204 | "context_members": ['u-2'], | 203 | "context_members": ['u-2'], |
1599 | 205 | "member_versions": {"u-2": 0}, | 204 | "member_versions": {"u-2": 0}, |
1600 | 206 | "change_queue": [ | 205 | "change_queue": [ |
1601 | @@ -318,7 +317,7 @@ | |||
1602 | 318 | ("u-1", "modified", ["u-1"])]) | 317 | ("u-1", "modified", ["u-1"])]) |
1603 | 319 | 318 | ||
1604 | 320 | with open(self.state_file) as f: | 319 | with open(self.state_file) as f: |
1606 | 321 | self.assertEquals(yaml.load(f.read()), { | 320 | self.assertEquals(serializer.load(f.read()), { |
1607 | 322 | "context_members": ['u-1'], | 321 | "context_members": ['u-1'], |
1608 | 323 | "member_versions": {"u-1": 0}, | 322 | "member_versions": {"u-1": 0}, |
1609 | 324 | "change_queue": []}) | 323 | "change_queue": []}) |
1610 | @@ -468,7 +467,7 @@ | |||
1611 | 468 | 467 | ||
1612 | 469 | def test_empty_state(self): | 468 | def test_empty_state(self): |
1613 | 470 | with open(self.state_file, "w") as f: | 469 | with open(self.state_file, "w") as f: |
1615 | 471 | f.write(yaml.dump({})) | 470 | f.write(serializer.dump({})) |
1616 | 472 | 471 | ||
1617 | 473 | # Induce lazy creation to verify it can still survive | 472 | # Induce lazy creation to verify it can still survive |
1618 | 474 | self.scheduler | 473 | self.scheduler |
1619 | @@ -527,7 +526,7 @@ | |||
1620 | 527 | it hasn't previously been given a notify of before. | 526 | it hasn't previously been given a notify of before. |
1621 | 528 | """ | 527 | """ |
1622 | 529 | with open(self.state_file, "w") as f: | 528 | with open(self.state_file, "w") as f: |
1624 | 530 | f.write(yaml.dump({ | 529 | f.write(serializer.dump({ |
1625 | 531 | "context_members": ["u-1", "u-2"], | 530 | "context_members": ["u-1", "u-2"], |
1626 | 532 | "member_versions": {"u-1": 0, "u-2": 0}, | 531 | "member_versions": {"u-1": 0, "u-2": 0}, |
1627 | 533 | "change_queue": []})) | 532 | "change_queue": []})) |
1628 | @@ -559,7 +558,7 @@ | |||
1629 | 559 | self.assertEqual(members, ["u-2", "u-3", "u-4"]) | 558 | self.assertEqual(members, ["u-2", "u-3", "u-4"]) |
1630 | 560 | 559 | ||
1631 | 561 | with open(self.state_file) as f: | 560 | with open(self.state_file) as f: |
1633 | 562 | state = yaml.load(f.read()) | 561 | state = serializer.load(f.read()) |
1634 | 563 | self.assertEquals(state, { | 562 | self.assertEquals(state, { |
1635 | 564 | "change_queue": [], | 563 | "change_queue": [], |
1636 | 565 | "context_members": ["u-2", "u-3", "u-4"], | 564 | "context_members": ["u-2", "u-3", "u-4"], |
1637 | @@ -568,7 +567,7 @@ | |||
1638 | 568 | @inlineCallbacks | 567 | @inlineCallbacks |
1639 | 569 | def test_state_is_loaded(self): | 568 | def test_state_is_loaded(self): |
1640 | 570 | with open(self.state_file, "w") as f: | 569 | with open(self.state_file, "w") as f: |
1642 | 571 | f.write(yaml.dump({ | 570 | f.write(serializer.dump({ |
1643 | 572 | "context_members": ["u-1", "u-2", "u-3"], | 571 | "context_members": ["u-1", "u-2", "u-3"], |
1644 | 573 | "member_versions": {"u-1": 5, "u-2": 2, "u-3": 0}, | 572 | "member_versions": {"u-1": 5, "u-2": 2, "u-3": 0}, |
1645 | 574 | "change_queue": [ | 573 | "change_queue": [ |
1646 | @@ -594,7 +593,7 @@ | |||
1647 | 594 | self.assertEqual(members, ["u-1", "u-2", "u-3"]) | 593 | self.assertEqual(members, ["u-1", "u-2", "u-3"]) |
1648 | 595 | 594 | ||
1649 | 596 | with open(self.state_file) as f: | 595 | with open(self.state_file) as f: |
1651 | 597 | state = yaml.load(f.read()) | 596 | state = serializer.load(f.read()) |
1652 | 598 | self.assertEquals(state, { | 597 | self.assertEquals(state, { |
1653 | 599 | "context_members": ["u-1", "u-2", "u-3"], | 598 | "context_members": ["u-1", "u-2", "u-3"], |
1654 | 600 | "member_versions": {"u-1": 5, "u-2": 2, "u-3": 0}, | 599 | "member_versions": {"u-1": 5, "u-2": 2, "u-3": 0}, |
1655 | @@ -602,7 +601,7 @@ | |||
1656 | 602 | 601 | ||
1657 | 603 | def test_state_is_stored(self): | 602 | def test_state_is_stored(self): |
1658 | 604 | with open(self.state_file, "w") as f: | 603 | with open(self.state_file, "w") as f: |
1660 | 605 | f.write(yaml.dump({ | 604 | f.write(serializer.dump({ |
1661 | 606 | "context_members": ["u-1", "u-2"], | 605 | "context_members": ["u-1", "u-2"], |
1662 | 607 | "member_versions": {"u-1": 0, "u-2": 2}, | 606 | "member_versions": {"u-1": 0, "u-2": 2}, |
1663 | 608 | "change_queue": []})) | 607 | "change_queue": []})) |
1664 | @@ -614,7 +613,7 @@ | |||
1665 | 614 | self.scheduler.stop() | 613 | self.scheduler.stop() |
1666 | 615 | 614 | ||
1667 | 616 | with open(self.state_file) as f: | 615 | with open(self.state_file) as f: |
1669 | 617 | state = yaml.load(f.read()) | 616 | state = serializer.load(f.read()) |
1670 | 618 | self.assertEquals(state, { | 617 | self.assertEquals(state, { |
1671 | 619 | "context_members": ["u-2", "u-3"], | 618 | "context_members": ["u-2", "u-3"], |
1672 | 620 | "member_versions": {"u-2": 3, "u-3": 0}, | 619 | "member_versions": {"u-2": 3, "u-3": 0}, |
1673 | @@ -641,7 +640,7 @@ | |||
1674 | 641 | self.executor = execute | 640 | self.executor = execute |
1675 | 642 | 641 | ||
1676 | 643 | with open(self.state_file, "w") as f: | 642 | with open(self.state_file, "w") as f: |
1678 | 644 | f.write(yaml.dump({ | 643 | f.write(serializer.dump({ |
1679 | 645 | "context_members": ["u-1", "u-2"], | 644 | "context_members": ["u-1", "u-2"], |
1680 | 646 | "member_versions": {"u-1": 1, "u-2": 0, "u-3": 0}, | 645 | "member_versions": {"u-1": 1, "u-2": 0, "u-3": 0}, |
1681 | 647 | "change_queue": [ | 646 | "change_queue": [ |
1682 | @@ -655,7 +654,7 @@ | |||
1683 | 655 | yield self.poke_zk() | 654 | yield self.poke_zk() |
1684 | 656 | yield self.assertFailure(d, SomeError) | 655 | yield self.assertFailure(d, SomeError) |
1685 | 657 | with open(self.state_file) as f: | 656 | with open(self.state_file) as f: |
1687 | 658 | self.assertEquals(yaml.load(f.read()), { | 657 | self.assertEquals(serializer.load(f.read()), { |
1688 | 659 | "context_members": ["u-1", "u-2"], | 658 | "context_members": ["u-1", "u-2"], |
1689 | 660 | "member_versions": {"u-1": 1, "u-2": 0, "u-3": 0}, | 659 | "member_versions": {"u-1": 1, "u-2": 0, "u-3": 0}, |
1690 | 661 | "change_queue": [ | 660 | "change_queue": [ |
1691 | @@ -681,14 +680,14 @@ | |||
1692 | 681 | "members":["u-1", "u-2", "u-3"]}, | 680 | "members":["u-1", "u-2", "u-3"]}, |
1693 | 682 | ]} | 681 | ]} |
1694 | 683 | with open(self.state_file, "w") as f: | 682 | with open(self.state_file, "w") as f: |
1696 | 684 | f.write(yaml.dump(initial_state)) | 683 | f.write(serializer.dump(initial_state)) |
1697 | 685 | 684 | ||
1698 | 686 | d = self.scheduler.run() | 685 | d = self.scheduler.run() |
1699 | 687 | while not self.execute_called: | 686 | while not self.execute_called: |
1700 | 688 | yield self.poke_zk() | 687 | yield self.poke_zk() |
1701 | 689 | yield self.assertFailure(d, SomeError) | 688 | yield self.assertFailure(d, SomeError) |
1702 | 690 | with open(self.state_file) as f: | 689 | with open(self.state_file) as f: |
1704 | 691 | self.assertEquals(yaml.load(f.read()), initial_state) | 690 | self.assertEquals(serializer.load(f.read()), initial_state) |
1705 | 692 | 691 | ||
1706 | 693 | def test_ignore_equal_settings_version(self): | 692 | def test_ignore_equal_settings_version(self): |
1707 | 694 | """ | 693 | """ |
1708 | @@ -718,7 +717,7 @@ | |||
1709 | 718 | on old_units. | 717 | on old_units. |
1710 | 719 | """ | 718 | """ |
1711 | 720 | with open(self.state_file, "w") as f: | 719 | with open(self.state_file, "w") as f: |
1713 | 721 | f.write(yaml.dump({ | 720 | f.write(serializer.dump({ |
1714 | 722 | "context_members": ["u-1", "u-2"], | 721 | "context_members": ["u-1", "u-2"], |
1715 | 723 | "member_versions": {"u-1": 0, "u-2": 0}, | 722 | "member_versions": {"u-1": 0, "u-2": 0}, |
1716 | 724 | "change_queue": []})) | 723 | "change_queue": []})) |
1717 | 725 | 724 | ||
1718 | === modified file 'juju/lib/format.py' | |||
1719 | --- juju/lib/format.py 2012-09-01 05:22:05 +0000 | |||
1720 | +++ juju/lib/format.py 2012-09-15 19:26:18 +0000 | |||
1721 | @@ -90,9 +90,9 @@ | |||
1722 | 90 | # output format, False | 90 | # output format, False |
1723 | 91 | if data is None: | 91 | if data is None: |
1724 | 92 | return "" | 92 | return "" |
1726 | 93 | serialized = yaml.safe_dump( | 93 | serialized = yaml.dump( |
1727 | 94 | data, indent=4, default_flow_style=False, width=80, | 94 | data, indent=4, default_flow_style=False, width=80, |
1729 | 95 | allow_unicode=True) | 95 | allow_unicode=True, Dumper=yaml.CSafeDumper) |
1730 | 96 | if serialized.endswith("\n...\n"): | 96 | if serialized.endswith("\n...\n"): |
1731 | 97 | # Remove explicit doc end sentinel, still valid yaml | 97 | # Remove explicit doc end sentinel, still valid yaml |
1732 | 98 | serialized = serialized[0:-5] | 98 | serialized = serialized[0:-5] |
1733 | @@ -111,7 +111,7 @@ | |||
1734 | 111 | 111 | ||
1735 | 112 | def load(self, data): | 112 | def load(self, data): |
1736 | 113 | """Loads data safely, ensuring no Python specific type info leaks""" | 113 | """Loads data safely, ensuring no Python specific type info leaks""" |
1738 | 114 | return yaml.safe_load(data) | 114 | return yaml.load(data, Loader=yaml.CSafeLoader) |
1739 | 115 | 115 | ||
1740 | 116 | 116 | ||
1741 | 117 | def is_valid_charm_format(charm_format): | 117 | def is_valid_charm_format(charm_format): |
1742 | 118 | 118 | ||
1743 | === added file 'juju/lib/serializer.py' | |||
1744 | --- juju/lib/serializer.py 1970-01-01 00:00:00 +0000 | |||
1745 | +++ juju/lib/serializer.py 2012-09-15 19:26:18 +0000 | |||
1746 | @@ -0,0 +1,21 @@ | |||
1747 | 1 | from yaml import CSafeLoader, CSafeDumper, Mark | ||
1748 | 2 | from yaml import dump as _dump | ||
1749 | 3 | from yaml import load as _load | ||
1750 | 4 | |||
1751 | 5 | def dump(value): | ||
1752 | 6 | return _dump(value, Dumper=CSafeDumper) | ||
1753 | 7 | |||
1754 | 8 | yaml_dump = dump | ||
1755 | 9 | |||
1756 | 10 | def load(value): | ||
1757 | 11 | return _load(value, Loader=CSafeLoader) | ||
1758 | 12 | |||
1759 | 13 | yaml_load = load | ||
1760 | 14 | |||
1761 | 15 | def yaml_mark_with_path(path, mark): | ||
1762 | 16 | # yaml c ext, cant be modded, convert to capture path | ||
1763 | 17 | return Mark( | ||
1764 | 18 | path, mark.index, | ||
1765 | 19 | mark.line, mark.column, | ||
1766 | 20 | mark.buffer, mark.pointer) | ||
1767 | 21 | |||
1768 | 0 | 22 | ||
1769 | === modified file 'juju/providers/common/cloudinit.py' | |||
1770 | --- juju/providers/common/cloudinit.py 2012-05-29 15:23:08 +0000 | |||
1771 | +++ juju/providers/common/cloudinit.py 2012-09-15 19:26:18 +0000 | |||
1772 | @@ -1,9 +1,10 @@ | |||
1773 | 1 | from base64 import b64encode | 1 | from base64 import b64encode |
1774 | 2 | from subprocess import Popen, PIPE | 2 | from subprocess import Popen, PIPE |
1776 | 3 | from yaml import safe_dump | 3 | |
1777 | 4 | 4 | ||
1778 | 5 | from juju.errors import CloudInitError | 5 | from juju.errors import CloudInitError |
1779 | 6 | from juju.lib.upstart import UpstartService | 6 | from juju.lib.upstart import UpstartService |
1780 | 7 | from juju.lib import serializer | ||
1781 | 7 | from juju.providers.common.utils import format_cloud_init | 8 | from juju.providers.common.utils import format_cloud_init |
1782 | 8 | from juju.state.auth import make_identity | 9 | from juju.state.auth import make_identity |
1783 | 9 | import juju | 10 | import juju |
1784 | @@ -41,7 +42,7 @@ | |||
1785 | 41 | " --constraints-data=%s" | 42 | " --constraints-data=%s" |
1786 | 42 | " --provider-type=%s" | 43 | " --provider-type=%s" |
1787 | 43 | % (instance_id, make_identity("admin:%s" % secret), | 44 | % (instance_id, make_identity("admin:%s" % secret), |
1789 | 44 | b64encode(safe_dump(constraints.data)), provider_type)] | 45 | b64encode(serializer.dump(constraints.data)), provider_type)] |
1790 | 45 | 46 | ||
1791 | 46 | 47 | ||
1792 | 47 | def _machine_scripts(machine_id, zookeeper_hosts): | 48 | def _machine_scripts(machine_id, zookeeper_hosts): |
1793 | 48 | 49 | ||
1794 | === modified file 'juju/providers/common/state.py' | |||
1795 | --- juju/providers/common/state.py 2011-09-15 18:50:23 +0000 | |||
1796 | +++ juju/providers/common/state.py 2012-09-15 19:26:18 +0000 | |||
1797 | @@ -1,5 +1,6 @@ | |||
1798 | 1 | from cStringIO import StringIO | 1 | from cStringIO import StringIO |
1800 | 2 | from yaml import safe_dump, load | 2 | from juju.lib import serializer |
1801 | 3 | |||
1802 | 3 | 4 | ||
1803 | 4 | from juju.errors import FileNotFound | 5 | from juju.errors import FileNotFound |
1804 | 5 | 6 | ||
1805 | @@ -28,7 +29,7 @@ | |||
1806 | 28 | return d | 29 | return d |
1807 | 29 | 30 | ||
1808 | 30 | def _deserialize(self, data): | 31 | def _deserialize(self, data): |
1810 | 31 | return load(data.read()) or False | 32 | return serializer.load(data.read()) or False |
1811 | 32 | 33 | ||
1812 | 33 | def _no_data(self, failure): | 34 | def _no_data(self, failure): |
1813 | 34 | failure.trap(FileNotFound) | 35 | failure.trap(FileNotFound) |
1814 | @@ -51,5 +52,5 @@ | |||
1815 | 51 | :param dict state: state to save. | 52 | :param dict state: state to save. |
1816 | 52 | """ | 53 | """ |
1817 | 53 | storage = self._provider.get_file_storage() | 54 | storage = self._provider.get_file_storage() |
1819 | 54 | data = safe_dump(state) | 55 | data = serializer.dump(state) |
1820 | 55 | return storage.put(_STATE_FILE, StringIO(data)) | 56 | return storage.put(_STATE_FILE, StringIO(data)) |
1821 | 56 | 57 | ||
1822 | === modified file 'juju/providers/common/tests/test_cloudinit.py' | |||
1823 | --- juju/providers/common/tests/test_cloudinit.py 2012-05-22 22:08:15 +0000 | |||
1824 | +++ juju/providers/common/tests/test_cloudinit.py 2012-09-15 19:26:18 +0000 | |||
1825 | @@ -1,9 +1,9 @@ | |||
1826 | 1 | import os | 1 | import os |
1827 | 2 | import stat | 2 | import stat |
1828 | 3 | 3 | ||
1829 | 4 | import yaml | ||
1830 | 5 | 4 | ||
1831 | 6 | from juju.errors import CloudInitError | 5 | from juju.errors import CloudInitError |
1832 | 6 | from juju.lib import serializer | ||
1833 | 7 | from juju.lib.testing import TestCase | 7 | from juju.lib.testing import TestCase |
1834 | 8 | from juju.machine.tests.test_constraints import dummy_cs | 8 | from juju.machine.tests.test_constraints import dummy_cs |
1835 | 9 | from juju.providers.common.cloudinit import ( | 9 | from juju.providers.common.cloudinit import ( |
1836 | @@ -46,10 +46,10 @@ | |||
1837 | 46 | 46 | ||
1838 | 47 | def assert_render(self, cloud_init, name): | 47 | def assert_render(self, cloud_init, name): |
1839 | 48 | with open(os.path.join(DATA_DIR, name)) as f: | 48 | with open(os.path.join(DATA_DIR, name)) as f: |
1841 | 49 | expected = yaml.load(f.read()) | 49 | expected = serializer.load(f.read()) |
1842 | 50 | rendered = cloud_init.render() | 50 | rendered = cloud_init.render() |
1843 | 51 | self.assertTrue(rendered.startswith("#cloud-config")) | 51 | self.assertTrue(rendered.startswith("#cloud-config")) |
1845 | 52 | self.assertEquals(yaml.load(rendered), expected) | 52 | self.assertEquals(serializer.load(rendered), expected) |
1846 | 53 | 53 | ||
1847 | 54 | def test_render_validate_normal(self): | 54 | def test_render_validate_normal(self): |
1848 | 55 | cloud_init = CloudInit() | 55 | cloud_init = CloudInit() |
1849 | 56 | 56 | ||
1850 | === modified file 'juju/providers/common/tests/test_findzookeepers.py' | |||
1851 | --- juju/providers/common/tests/test_findzookeepers.py 2012-07-18 19:46:53 +0000 | |||
1852 | +++ juju/providers/common/tests/test_findzookeepers.py 2012-09-15 19:26:18 +0000 | |||
1853 | @@ -1,9 +1,9 @@ | |||
1854 | 1 | from cStringIO import StringIO | 1 | from cStringIO import StringIO |
1855 | 2 | from yaml import dump | ||
1856 | 3 | 2 | ||
1857 | 4 | from twisted.internet.defer import fail, succeed | 3 | from twisted.internet.defer import fail, succeed |
1858 | 5 | 4 | ||
1859 | 6 | from juju.errors import EnvironmentNotFound, MachinesNotFound | 5 | from juju.errors import EnvironmentNotFound, MachinesNotFound |
1860 | 6 | from juju.lib import serializer | ||
1861 | 7 | from juju.lib.testing import TestCase | 7 | from juju.lib.testing import TestCase |
1862 | 8 | from juju.providers.common.base import MachineProviderBase | 8 | from juju.providers.common.base import MachineProviderBase |
1863 | 9 | 9 | ||
1864 | @@ -21,7 +21,7 @@ | |||
1865 | 21 | 21 | ||
1866 | 22 | def get(self, path): | 22 | def get(self, path): |
1867 | 23 | test.assertEquals(path, "provider-state") | 23 | test.assertEquals(path, "provider-state") |
1869 | 24 | return succeed(StringIO(dump(state))) | 24 | return succeed(StringIO(serializer.dump(state))) |
1870 | 25 | 25 | ||
1871 | 26 | class DummyProvider(MachineProviderBase): | 26 | class DummyProvider(MachineProviderBase): |
1872 | 27 | 27 | ||
1873 | 28 | 28 | ||
1874 | === modified file 'juju/providers/common/tests/test_state.py' | |||
1875 | --- juju/providers/common/tests/test_state.py 2011-09-15 18:50:23 +0000 | |||
1876 | +++ juju/providers/common/tests/test_state.py 2012-09-15 19:26:18 +0000 | |||
1877 | @@ -1,10 +1,10 @@ | |||
1878 | 1 | from cStringIO import StringIO | 1 | from cStringIO import StringIO |
1879 | 2 | from yaml import dump | ||
1880 | 3 | 2 | ||
1881 | 4 | from twisted.internet.defer import fail, succeed | 3 | from twisted.internet.defer import fail, succeed |
1882 | 5 | 4 | ||
1883 | 6 | from juju.errors import FileNotFound | 5 | from juju.errors import FileNotFound |
1884 | 7 | from juju.lib.mocker import MATCH | 6 | from juju.lib.mocker import MATCH |
1885 | 7 | from juju.lib import serializer | ||
1886 | 8 | from juju.lib.testing import TestCase | 8 | from juju.lib.testing import TestCase |
1887 | 9 | from juju.providers.common.base import MachineProviderBase | 9 | from juju.providers.common.base import MachineProviderBase |
1888 | 10 | from juju.providers.common.state import LoadState, SaveState | 10 | from juju.providers.common.state import LoadState, SaveState |
1889 | @@ -39,7 +39,8 @@ | |||
1890 | 39 | return load_state.run() | 39 | return load_state.run() |
1891 | 40 | 40 | ||
1892 | 41 | def test_load_state(self): | 41 | def test_load_state(self): |
1894 | 42 | d = self.mock_get(succeed(StringIO(dump({"some": "thing"})))) | 42 | d = self.mock_get(succeed(StringIO( |
1895 | 43 | serializer.dump({"some": "thing"})))) | ||
1896 | 43 | 44 | ||
1897 | 44 | def verify(result): | 45 | def verify(result): |
1898 | 45 | self.assertEquals(result, {"some": "thing"}) | 46 | self.assertEquals(result, {"some": "thing"}) |
1899 | @@ -74,7 +75,7 @@ | |||
1900 | 74 | class SaveStateTest(TestCase): | 75 | class SaveStateTest(TestCase): |
1901 | 75 | 76 | ||
1902 | 76 | def is_expected_yaml(self, result): | 77 | def is_expected_yaml(self, result): |
1904 | 77 | return result.read() == dump({"some": "thing"}) | 78 | return result.read() == serializer.dump({"some": "thing"}) |
1905 | 78 | 79 | ||
1906 | 79 | def test_save(self): | 80 | def test_save(self): |
1907 | 80 | put = self.mocker.mock() | 81 | put = self.mocker.mock() |
1908 | 81 | 82 | ||
1909 | === modified file 'juju/providers/common/tests/test_utils.py' | |||
1910 | --- juju/providers/common/tests/test_utils.py 2012-08-23 16:14:42 +0000 | |||
1911 | +++ juju/providers/common/tests/test_utils.py 2012-09-15 19:26:18 +0000 | |||
1912 | @@ -1,10 +1,10 @@ | |||
1913 | 1 | import os | 1 | import os |
1914 | 2 | from yaml import load | ||
1915 | 3 | 2 | ||
1916 | 4 | from twisted.python.failure import Failure | 3 | from twisted.python.failure import Failure |
1917 | 5 | 4 | ||
1918 | 6 | from juju.environment.tests.test_config import EnvironmentsConfigTestBase | 5 | from juju.environment.tests.test_config import EnvironmentsConfigTestBase |
1919 | 7 | from juju.errors import ProviderInteractionError, JujuError | 6 | from juju.errors import ProviderInteractionError, JujuError |
1920 | 7 | from juju.lib import serializer | ||
1921 | 8 | from juju.lib.testing import TestCase | 8 | from juju.lib.testing import TestCase |
1922 | 9 | from juju.providers.common.utils import ( | 9 | from juju.providers.common.utils import ( |
1923 | 10 | convert_unknown_error, format_cloud_init, get_user_authorized_keys) | 10 | convert_unknown_error, format_cloud_init, get_user_authorized_keys) |
1924 | @@ -107,7 +107,7 @@ | |||
1925 | 107 | 107 | ||
1926 | 108 | lines = output.split("\n") | 108 | lines = output.split("\n") |
1927 | 109 | self.assertEqual(lines.pop(0), "#cloud-config") | 109 | self.assertEqual(lines.pop(0), "#cloud-config") |
1929 | 110 | config = load("\n".join(lines)) | 110 | config = serializer.load("\n".join(lines)) |
1930 | 111 | self.assertEqual(config["ssh_authorized_keys"], ["zebra"]) | 111 | self.assertEqual(config["ssh_authorized_keys"], ["zebra"]) |
1931 | 112 | self.assertTrue(config["apt_update"]) | 112 | self.assertTrue(config["apt_update"]) |
1932 | 113 | self.assertTrue(config["apt_upgrade"]) | 113 | self.assertTrue(config["apt_upgrade"]) |
1933 | 114 | 114 | ||
1934 | === modified file 'juju/providers/common/utils.py' | |||
1935 | --- juju/providers/common/utils.py 2012-08-23 16:14:42 +0000 | |||
1936 | +++ juju/providers/common/utils.py 2012-09-15 19:26:18 +0000 | |||
1937 | @@ -1,9 +1,10 @@ | |||
1938 | 1 | import logging | 1 | import logging |
1939 | 2 | import os | 2 | import os |
1941 | 3 | from yaml import safe_dump | 3 | |
1942 | 4 | 4 | ||
1943 | 5 | from twisted.python.failure import Failure | 5 | from twisted.python.failure import Failure |
1944 | 6 | 6 | ||
1945 | 7 | from juju.lib import serializer | ||
1946 | 7 | from juju.errors import JujuError, ProviderInteractionError | 8 | from juju.errors import JujuError, ProviderInteractionError |
1947 | 8 | 9 | ||
1948 | 9 | log = logging.getLogger("juju.common") | 10 | log = logging.getLogger("juju.common") |
1949 | @@ -136,6 +137,6 @@ | |||
1950 | 136 | if scripts: | 137 | if scripts: |
1951 | 137 | cloud_config["runcmd"] = scripts | 138 | cloud_config["runcmd"] = scripts |
1952 | 138 | 139 | ||
1954 | 139 | output = safe_dump(cloud_config) | 140 | output = serializer.dump(cloud_config) |
1955 | 140 | output = "#cloud-config\n%s" % (output) | 141 | output = "#cloud-config\n%s" % (output) |
1956 | 141 | return output | 142 | return output |
1957 | 142 | 143 | ||
1958 | === modified file 'juju/providers/ec2/tests/common.py' | |||
1959 | --- juju/providers/ec2/tests/common.py 2012-07-05 21:49:12 +0000 | |||
1960 | +++ juju/providers/ec2/tests/common.py 2012-09-15 19:26:18 +0000 | |||
1961 | @@ -1,4 +1,3 @@ | |||
1962 | 1 | from yaml import dump | ||
1963 | 2 | 1 | ||
1964 | 3 | from twisted.internet.defer import fail, succeed, inlineCallbacks, returnValue | 2 | from twisted.internet.defer import fail, succeed, inlineCallbacks, returnValue |
1965 | 4 | 3 | ||
1966 | @@ -8,6 +7,7 @@ | |||
1967 | 8 | from txaws.ec2.exception import EC2Error | 7 | from txaws.ec2.exception import EC2Error |
1968 | 9 | from txaws.ec2.model import Instance, Reservation, SecurityGroup | 8 | from txaws.ec2.model import Instance, Reservation, SecurityGroup |
1969 | 10 | 9 | ||
1970 | 10 | from juju.lib import serializer | ||
1971 | 11 | from juju.lib.mocker import KWARGS, MATCH | 11 | from juju.lib.mocker import KWARGS, MATCH |
1972 | 12 | from juju.providers.ec2 import MachineProvider | 12 | from juju.providers.ec2 import MachineProvider |
1973 | 13 | from juju.providers.ec2.machine import EC2ProviderMachine | 13 | from juju.providers.ec2.machine import EC2ProviderMachine |
1974 | @@ -156,7 +156,7 @@ | |||
1975 | 156 | self.mocker.result(fail(error)) | 156 | self.mocker.result(fail(error)) |
1976 | 157 | return | 157 | return |
1977 | 158 | 158 | ||
1979 | 159 | state = dump({ | 159 | state = serializer.dump({ |
1980 | 160 | "zookeeper-instances": | 160 | "zookeeper-instances": |
1981 | 161 | [i.instance_id for i in hosts]}) | 161 | [i.instance_id for i in hosts]}) |
1982 | 162 | 162 | ||
1983 | 163 | 163 | ||
1984 | === modified file 'juju/providers/ec2/tests/test_bootstrap.py' | |||
1985 | --- juju/providers/ec2/tests/test_bootstrap.py 2012-03-29 01:37:57 +0000 | |||
1986 | +++ juju/providers/ec2/tests/test_bootstrap.py 2012-09-15 19:26:18 +0000 | |||
1987 | @@ -1,12 +1,11 @@ | |||
1988 | 1 | import logging | 1 | import logging |
1989 | 2 | import os | 2 | import os |
1990 | 3 | 3 | ||
1991 | 4 | import yaml | ||
1992 | 5 | |||
1993 | 6 | from twisted.internet.defer import succeed, inlineCallbacks | 4 | from twisted.internet.defer import succeed, inlineCallbacks |
1994 | 7 | 5 | ||
1995 | 8 | from txaws.ec2.model import SecurityGroup | 6 | from txaws.ec2.model import SecurityGroup |
1996 | 9 | 7 | ||
1997 | 8 | from juju.lib import serializer | ||
1998 | 10 | from juju.lib.mocker import MATCH | 9 | from juju.lib.mocker import MATCH |
1999 | 11 | from juju.lib.testing import TestCase | 10 | from juju.lib.testing import TestCase |
2000 | 12 | from juju.providers.ec2.machine import EC2ProviderMachine | 11 | from juju.providers.ec2.machine import EC2ProviderMachine |
2001 | @@ -40,8 +39,8 @@ | |||
2002 | 40 | def verify_user_data(data): | 39 | def verify_user_data(data): |
2003 | 41 | expect_path = os.path.join(DATA_DIR, "bootstrap_cloud_init") | 40 | expect_path = os.path.join(DATA_DIR, "bootstrap_cloud_init") |
2004 | 42 | with open(expect_path) as f: | 41 | with open(expect_path) as f: |
2007 | 43 | expect_cloud_init = yaml.load(f.read()) | 42 | expect_cloud_init = serializer.load(f.read()) |
2008 | 44 | self.assertEquals(yaml.load(data), expect_cloud_init) | 43 | self.assertEquals(serializer.load(data), expect_cloud_init) |
2009 | 45 | return True | 44 | return True |
2010 | 46 | 45 | ||
2011 | 47 | self.ec2.run_instances( | 46 | self.ec2.run_instances( |
2012 | @@ -109,7 +108,7 @@ | |||
2013 | 109 | If the provider bootstrap is run when there is already a running | 108 | If the provider bootstrap is run when there is already a running |
2014 | 110 | bootstrap instance, it will just return the existing machine. | 109 | bootstrap instance, it will just return the existing machine. |
2015 | 111 | """ | 110 | """ |
2017 | 112 | state = yaml.dump({"zookeeper-instances": ["i-foobar"]}) | 111 | state = serializer.dump({"zookeeper-instances": ["i-foobar"]}) |
2018 | 113 | self.s3.get_object(self.env_name, "provider-state") | 112 | self.s3.get_object(self.env_name, "provider-state") |
2019 | 114 | self.mocker.result(succeed(state)) | 113 | self.mocker.result(succeed(state)) |
2020 | 115 | self.ec2.describe_instances("i-foobar") | 114 | self.ec2.describe_instances("i-foobar") |
2021 | 116 | 115 | ||
2022 | === modified file 'juju/providers/ec2/tests/test_findzookeeper.py' | |||
2023 | --- juju/providers/ec2/tests/test_findzookeeper.py 2011-09-15 18:50:23 +0000 | |||
2024 | +++ juju/providers/ec2/tests/test_findzookeeper.py 2012-09-15 19:26:18 +0000 | |||
2025 | @@ -3,9 +3,8 @@ | |||
2026 | 3 | from txaws.ec2.exception import EC2Error | 3 | from txaws.ec2.exception import EC2Error |
2027 | 4 | from txaws.s3.exception import S3Error | 4 | from txaws.s3.exception import S3Error |
2028 | 5 | 5 | ||
2029 | 6 | from yaml import dump | ||
2030 | 7 | |||
2031 | 8 | from juju.errors import EnvironmentNotFound | 6 | from juju.errors import EnvironmentNotFound |
2032 | 7 | from juju.lib.serializer import dump | ||
2033 | 9 | from juju.lib.testing import TestCase | 8 | from juju.lib.testing import TestCase |
2034 | 10 | from juju.providers.ec2.machine import EC2ProviderMachine | 9 | from juju.providers.ec2.machine import EC2ProviderMachine |
2035 | 11 | from juju.providers.ec2.tests.common import EC2TestMixin | 10 | from juju.providers.ec2.tests.common import EC2TestMixin |
2036 | 12 | 11 | ||
2037 | === modified file 'juju/providers/ec2/tests/test_launch.py' | |||
2038 | --- juju/providers/ec2/tests/test_launch.py 2012-07-18 20:04:16 +0000 | |||
2039 | +++ juju/providers/ec2/tests/test_launch.py 2012-09-15 19:26:18 +0000 | |||
2040 | @@ -1,7 +1,5 @@ | |||
2041 | 1 | import os | 1 | import os |
2042 | 2 | 2 | ||
2043 | 3 | import yaml | ||
2044 | 4 | |||
2045 | 5 | from twisted.internet.defer import inlineCallbacks, succeed | 3 | from twisted.internet.defer import inlineCallbacks, succeed |
2046 | 6 | 4 | ||
2047 | 7 | from txaws.ec2.model import Instance, SecurityGroup | 5 | from txaws.ec2.model import Instance, SecurityGroup |
2048 | @@ -9,6 +7,7 @@ | |||
2049 | 9 | from juju.errors import EnvironmentNotFound, ProviderError | 7 | from juju.errors import EnvironmentNotFound, ProviderError |
2050 | 10 | from juju.providers.ec2.machine import EC2ProviderMachine | 8 | from juju.providers.ec2.machine import EC2ProviderMachine |
2051 | 11 | 9 | ||
2052 | 10 | from juju.lib import serializer | ||
2053 | 12 | from juju.lib.testing import TestCase | 11 | from juju.lib.testing import TestCase |
2054 | 13 | from juju.lib.mocker import MATCH | 12 | from juju.lib.mocker import MATCH |
2055 | 14 | 13 | ||
2056 | @@ -37,8 +36,8 @@ | |||
2057 | 37 | def verify_user_data(data): | 36 | def verify_user_data(data): |
2058 | 38 | expect_path = os.path.join(DATA_DIR, cloud_init) | 37 | expect_path = os.path.join(DATA_DIR, cloud_init) |
2059 | 39 | with open(expect_path) as f: | 38 | with open(expect_path) as f: |
2062 | 40 | expect_cloud_init = yaml.load(f.read()) | 39 | expect_cloud_init = serializer.load(f.read()) |
2063 | 41 | self.assertEquals(yaml.load(data), expect_cloud_init) | 40 | self.assertEquals(serializer.load(data), expect_cloud_init) |
2064 | 42 | return True | 41 | return True |
2065 | 43 | 42 | ||
2066 | 44 | self.ec2.run_instances( | 43 | self.ec2.run_instances( |
2067 | 45 | 44 | ||
2068 | === modified file 'juju/providers/ec2/tests/test_provider.py' | |||
2069 | --- juju/providers/ec2/tests/test_provider.py 2012-08-29 16:36:54 +0000 | |||
2070 | +++ juju/providers/ec2/tests/test_provider.py 2012-09-15 19:26:18 +0000 | |||
2071 | @@ -7,6 +7,7 @@ | |||
2072 | 7 | from juju.providers import ec2 as _mod_provider | 7 | from juju.providers import ec2 as _mod_provider |
2073 | 8 | from juju.providers.ec2 import MachineProvider | 8 | from juju.providers.ec2 import MachineProvider |
2074 | 9 | from juju.providers.ec2.files import FileStorage | 9 | from juju.providers.ec2.files import FileStorage |
2075 | 10 | |||
2076 | 10 | import logging | 11 | import logging |
2077 | 11 | 12 | ||
2078 | 12 | from .common import EC2TestMixin | 13 | from .common import EC2TestMixin |
2079 | 13 | 14 | ||
2080 | === modified file 'juju/providers/ec2/tests/test_state.py' | |||
2081 | --- juju/providers/ec2/tests/test_state.py 2011-09-15 18:50:23 +0000 | |||
2082 | +++ juju/providers/ec2/tests/test_state.py 2012-09-15 19:26:18 +0000 | |||
2083 | @@ -1,9 +1,8 @@ | |||
2084 | 1 | from yaml import dump | ||
2085 | 2 | |||
2086 | 3 | from twisted.internet.defer import succeed, fail | 1 | from twisted.internet.defer import succeed, fail |
2087 | 4 | 2 | ||
2088 | 5 | from txaws.s3.exception import S3Error | 3 | from txaws.s3.exception import S3Error |
2089 | 6 | 4 | ||
2090 | 5 | from juju.lib import serializer | ||
2091 | 7 | from juju.lib.testing import TestCase | 6 | from juju.lib.testing import TestCase |
2092 | 8 | from juju.providers.ec2.tests.common import EC2TestMixin | 7 | from juju.providers.ec2.tests.common import EC2TestMixin |
2093 | 9 | 8 | ||
2094 | @@ -20,7 +19,7 @@ | |||
2095 | 20 | the machine, it will serialize the data to an s3 bucket. | 19 | the machine, it will serialize the data to an s3 bucket. |
2096 | 21 | """ | 20 | """ |
2097 | 22 | instances = [self.get_instance("i-foobar", dns_name="x1.example.com")] | 21 | instances = [self.get_instance("i-foobar", dns_name="x1.example.com")] |
2099 | 23 | state = dump( | 22 | state = serializer.dump( |
2100 | 24 | {"zookeeper-instances": | 23 | {"zookeeper-instances": |
2101 | 25 | [[i.instance_id, i.dns_name] for i in instances]}) | 24 | [[i.instance_id, i.dns_name] for i in instances]}) |
2102 | 26 | self.s3.put_object( | 25 | self.s3.put_object( |
2103 | @@ -46,7 +45,7 @@ | |||
2104 | 46 | already exist. | 45 | already exist. |
2105 | 47 | """ | 46 | """ |
2106 | 48 | instances = [self.get_instance("i-foobar", dns_name="x1.example.com")] | 47 | instances = [self.get_instance("i-foobar", dns_name="x1.example.com")] |
2108 | 49 | state = dump( | 48 | state = serializer.dump( |
2109 | 50 | {"zookeeper-instances": | 49 | {"zookeeper-instances": |
2110 | 51 | [[i.instance_id, i.dns_name] for i in instances]}) | 50 | [[i.instance_id, i.dns_name] for i in instances]}) |
2111 | 52 | self.s3.put_object( | 51 | self.s3.put_object( |
2112 | @@ -78,7 +77,8 @@ | |||
2113 | 78 | s3. | 77 | s3. |
2114 | 79 | """ | 78 | """ |
2115 | 80 | self.s3.get_object(self.env_name, "provider-state") | 79 | self.s3.get_object(self.env_name, "provider-state") |
2117 | 81 | self.mocker.result(succeed(dump({"zookeeper-instances": []}))) | 80 | self.mocker.result( |
2118 | 81 | succeed(serializer.dump({"zookeeper-instances": []}))) | ||
2119 | 82 | self.mocker.replay() | 82 | self.mocker.replay() |
2120 | 83 | 83 | ||
2121 | 84 | provider = self.get_provider() | 84 | provider = self.get_provider() |
2122 | @@ -116,7 +116,7 @@ | |||
2123 | 116 | handles the scenario where there is no saved state. | 116 | handles the scenario where there is no saved state. |
2124 | 117 | """ | 117 | """ |
2125 | 118 | self.s3.get_object(self.env_name, "provider-state") | 118 | self.s3.get_object(self.env_name, "provider-state") |
2127 | 119 | self.mocker.result(succeed(dump([]))) | 119 | self.mocker.result(succeed(serializer.dump([]))) |
2128 | 120 | self.mocker.replay() | 120 | self.mocker.replay() |
2129 | 121 | 121 | ||
2130 | 122 | provider = self.get_provider() | 122 | provider = self.get_provider() |
2131 | 123 | 123 | ||
2132 | === modified file 'juju/providers/local/files.py' | |||
2133 | --- juju/providers/local/files.py 2012-01-13 00:15:07 +0000 | |||
2134 | +++ juju/providers/local/files.py 2012-09-15 19:26:18 +0000 | |||
2135 | @@ -1,13 +1,12 @@ | |||
2136 | 1 | from getpass import getuser | ||
2137 | 2 | import os | 1 | import os |
2138 | 3 | from StringIO import StringIO | 2 | from StringIO import StringIO |
2139 | 4 | import yaml | ||
2140 | 5 | 3 | ||
2141 | 6 | from twisted.internet.defer import inlineCallbacks, returnValue | 4 | from twisted.internet.defer import inlineCallbacks, returnValue |
2142 | 7 | from twisted.internet.error import ConnectionRefusedError | 5 | from twisted.internet.error import ConnectionRefusedError |
2143 | 8 | from twisted.web.client import getPage | 6 | from twisted.web.client import getPage |
2144 | 9 | 7 | ||
2145 | 10 | from juju.errors import ProviderError, FileNotFound | 8 | from juju.errors import ProviderError, FileNotFound |
2146 | 9 | from juju.lib import serializer | ||
2147 | 11 | from juju.lib.upstart import UpstartService | 10 | from juju.lib.upstart import UpstartService |
2148 | 12 | from juju.providers.common.files import FileStorage | 11 | from juju.providers.common.files import FileStorage |
2149 | 13 | 12 | ||
2150 | @@ -79,7 +78,7 @@ | |||
2151 | 79 | storage = LocalStorage(self._storage_dir) | 78 | storage = LocalStorage(self._storage_dir) |
2152 | 80 | yield storage.put( | 79 | yield storage.put( |
2153 | 81 | SERVER_URL_KEY, | 80 | SERVER_URL_KEY, |
2155 | 82 | StringIO(yaml.safe_dump( | 81 | StringIO(serializer.dump( |
2156 | 83 | {"storage-url": "http://%s:%s/" % (self._host, self._port)}))) | 82 | {"storage-url": "http://%s:%s/" % (self._host, self._port)}))) |
2157 | 84 | 83 | ||
2158 | 85 | self._service.set_command(" ".join(self._service_args)) | 84 | self._service.set_command(" ".join(self._service_args)) |
2159 | @@ -112,5 +111,5 @@ | |||
2160 | 112 | 111 | ||
2161 | 113 | if not storage_data or not "storage-url" in storage_data: | 112 | if not storage_data or not "storage-url" in storage_data: |
2162 | 114 | raise ProviderError("Storage not initialized") | 113 | raise ProviderError("Storage not initialized") |
2164 | 115 | url = yaml.load(storage_data)["storage-url"] | 114 | url = serializer.load(storage_data)["storage-url"] |
2165 | 116 | returnValue(url + key) | 115 | returnValue(url + key) |
2166 | 117 | 116 | ||
2167 | === modified file 'juju/providers/local/tests/test_agent.py' | |||
2168 | --- juju/providers/local/tests/test_agent.py 2012-08-03 12:28:29 +0000 | |||
2169 | +++ juju/providers/local/tests/test_agent.py 2012-09-15 19:26:18 +0000 | |||
2170 | @@ -1,9 +1,8 @@ | |||
2171 | 1 | import os | 1 | import os |
2172 | 2 | import tempfile | 2 | import tempfile |
2173 | 3 | import subprocess | 3 | import subprocess |
2174 | 4 | import sys | ||
2175 | 5 | 4 | ||
2177 | 6 | from twisted.internet.defer import inlineCallbacks, succeed | 5 | from twisted.internet.defer import inlineCallbacks |
2178 | 7 | 6 | ||
2179 | 8 | from juju.lib.lxc.tests.test_lxc import uses_sudo | 7 | from juju.lib.lxc.tests.test_lxc import uses_sudo |
2180 | 9 | from juju.lib.testing import TestCase | 8 | from juju.lib.testing import TestCase |
2181 | 10 | 9 | ||
2182 | === modified file 'juju/providers/local/tests/test_container.py' | |||
2183 | --- juju/providers/local/tests/test_container.py 2011-09-30 03:20:11 +0000 | |||
2184 | +++ juju/providers/local/tests/test_container.py 2012-09-15 19:26:18 +0000 | |||
2185 | @@ -3,6 +3,7 @@ | |||
2186 | 3 | from juju.lib.testing import TestCase | 3 | from juju.lib.testing import TestCase |
2187 | 4 | from juju.lib.lxc import get_containers | 4 | from juju.lib.lxc import get_containers |
2188 | 5 | from juju.lib import lxc | 5 | from juju.lib import lxc |
2189 | 6 | |||
2190 | 6 | lxc_output_sample = "\ | 7 | lxc_output_sample = "\ |
2191 | 7 | calendarserver\ncaprica\ngemini\nreconnoiter\nvirgo\ncalendarserver\n" | 8 | calendarserver\ncaprica\ngemini\nreconnoiter\nvirgo\ncalendarserver\n" |
2192 | 8 | 9 | ||
2193 | 9 | 10 | ||
2194 | === modified file 'juju/providers/local/tests/test_files.py' | |||
2195 | --- juju/providers/local/tests/test_files.py 2012-01-27 17:02:48 +0000 | |||
2196 | +++ juju/providers/local/tests/test_files.py 2012-09-15 19:26:18 +0000 | |||
2197 | @@ -2,12 +2,12 @@ | |||
2198 | 2 | import signal | 2 | import signal |
2199 | 3 | from StringIO import StringIO | 3 | from StringIO import StringIO |
2200 | 4 | import subprocess | 4 | import subprocess |
2201 | 5 | import yaml | ||
2202 | 6 | 5 | ||
2203 | 7 | from twisted.internet.defer import inlineCallbacks, succeed | 6 | from twisted.internet.defer import inlineCallbacks, succeed |
2204 | 8 | from twisted.web.client import getPage | 7 | from twisted.web.client import getPage |
2205 | 9 | 8 | ||
2206 | 10 | from juju.errors import ProviderError, ServiceError | 9 | from juju.errors import ProviderError, ServiceError |
2207 | 10 | from juju.lib import serializer | ||
2208 | 11 | from juju.lib.lxc.tests.test_lxc import uses_sudo | 11 | from juju.lib.lxc.tests.test_lxc import uses_sudo |
2209 | 12 | from juju.lib.testing import TestCase | 12 | from juju.lib.testing import TestCase |
2210 | 13 | from juju.lib.upstart import UpstartService | 13 | from juju.lib.upstart import UpstartService |
2211 | @@ -177,7 +177,8 @@ | |||
2212 | 177 | yield self.assertFailure(self._storage.get_url("abc"), ProviderError) | 177 | yield self.assertFailure(self._storage.get_url("abc"), ProviderError) |
2213 | 178 | self._storage.put( | 178 | self._storage.put( |
2214 | 179 | SERVER_URL_KEY, | 179 | SERVER_URL_KEY, |
2216 | 180 | StringIO(yaml.dump({"storage-url": "http://localhost/"}))) | 180 | StringIO( |
2217 | 181 | serializer.dump({"storage-url": "http://localhost/"}))) | ||
2218 | 181 | 182 | ||
2219 | 182 | self.assertEqual((yield self._storage.get_url("abc")), | 183 | self.assertEqual((yield self._storage.get_url("abc")), |
2220 | 183 | "http://localhost/abc") | 184 | "http://localhost/abc") |
2221 | 184 | 185 | ||
2222 | === modified file 'juju/providers/openstack/tests/test_bootstrap.py' | |||
2223 | --- juju/providers/openstack/tests/test_bootstrap.py 2012-07-20 15:45:56 +0000 | |||
2224 | +++ juju/providers/openstack/tests/test_bootstrap.py 2012-09-15 19:26:18 +0000 | |||
2225 | @@ -6,12 +6,8 @@ | |||
2226 | 6 | """ | 6 | """ |
2227 | 7 | 7 | ||
2228 | 8 | import logging | 8 | import logging |
2229 | 9 | import yaml | ||
2230 | 10 | 9 | ||
2235 | 11 | from juju.lib import ( | 10 | from juju.lib import mocker, testing, serializer |
2232 | 12 | mocker, | ||
2233 | 13 | testing, | ||
2234 | 14 | ) | ||
2236 | 15 | 11 | ||
2237 | 16 | from juju.providers.openstack.machine import NovaProviderMachine | 12 | from juju.providers.openstack.machine import NovaProviderMachine |
2238 | 17 | from juju.providers.openstack.tests import OpenStackTestMixin | 13 | from juju.providers.openstack.tests import OpenStackTestMixin |
2239 | @@ -104,7 +100,7 @@ | |||
2240 | 104 | self.expect_nova_post("servers/1000/action", | 100 | self.expect_nova_post("servers/1000/action", |
2241 | 105 | {"addFloatingIp": {"address": "8.8.8.8"}}, code=202) | 101 | {"addFloatingIp": {"address": "8.8.8.8"}}, code=202) |
2242 | 106 | self.expect_swift_put("testing/provider-state", | 102 | self.expect_swift_put("testing/provider-state", |
2244 | 107 | yaml.dump({'zookeeper-instances': ['1000']})) | 103 | serializer.dump({'zookeeper-instances': ['1000']})) |
2245 | 108 | 104 | ||
2246 | 109 | def _check_machine(self, machine_list): | 105 | def _check_machine(self, machine_list): |
2247 | 110 | [machine] = machine_list | 106 | [machine] = machine_list |
2248 | @@ -165,7 +161,7 @@ | |||
2249 | 165 | def test_existing_machine(self): | 161 | def test_existing_machine(self): |
2250 | 166 | """A preexisting zookeeper instance is returned if present""" | 162 | """A preexisting zookeeper instance is returned if present""" |
2251 | 167 | self.expect_swift_get("testing/provider-state", | 163 | self.expect_swift_get("testing/provider-state", |
2253 | 168 | response=yaml.dump({'zookeeper-instances': ['1000']})) | 164 | response=serializer.dump({'zookeeper-instances': ['1000']})) |
2254 | 169 | self.expect_nova_get("servers/1000", | 165 | self.expect_nova_get("servers/1000", |
2255 | 170 | response={'server': { | 166 | response={'server': { |
2256 | 171 | 'id': '1000', | 167 | 'id': '1000', |
2257 | @@ -187,7 +183,7 @@ | |||
2258 | 187 | def test_existing_machine_missing(self): | 183 | def test_existing_machine_missing(self): |
2259 | 188 | """Bootstrap overwrites existing zookeeper if instance is present""" | 184 | """Bootstrap overwrites existing zookeeper if instance is present""" |
2260 | 189 | self.expect_swift_get("testing/provider-state", | 185 | self.expect_swift_get("testing/provider-state", |
2262 | 190 | response=yaml.dump({'zookeeper-instances': [3000]})) | 186 | response=serializer.dump({'zookeeper-instances': [3000]})) |
2263 | 191 | self.expect_nova_get("servers/3000", code=404, | 187 | self.expect_nova_get("servers/3000", code=404, |
2264 | 192 | response={'itemNotFound': | 188 | response={'itemNotFound': |
2265 | 193 | {'message': "The resource could not be found.", 'code': 404} | 189 | {'message': "The resource could not be found.", 'code': 404} |
2266 | 194 | 190 | ||
2267 | === modified file 'juju/providers/openstack/tests/test_launch.py' | |||
2268 | --- juju/providers/openstack/tests/test_launch.py 2012-08-24 14:21:57 +0000 | |||
2269 | +++ juju/providers/openstack/tests/test_launch.py 2012-09-15 19:26:18 +0000 | |||
2270 | @@ -1,10 +1,10 @@ | |||
2271 | 1 | """Tests for launching a new server customised for juju using Nova""" | 1 | """Tests for launching a new server customised for juju using Nova""" |
2272 | 2 | 2 | ||
2273 | 3 | import yaml | ||
2274 | 4 | 3 | ||
2275 | 5 | from twisted.internet.defer import succeed | 4 | from twisted.internet.defer import succeed |
2276 | 6 | 5 | ||
2277 | 7 | from juju import errors | 6 | from juju import errors |
2278 | 7 | from juju.lib import serializer | ||
2279 | 8 | from juju.lib.mocker import MATCH | 8 | from juju.lib.mocker import MATCH |
2280 | 9 | from juju.lib.testing import TestCase | 9 | from juju.lib.testing import TestCase |
2281 | 10 | 10 | ||
2282 | @@ -68,7 +68,7 @@ | |||
2283 | 68 | def match(self, user_data): | 68 | def match(self, user_data): |
2284 | 69 | """Check contents of user_data but always match if assertions pass""" | 69 | """Check contents of user_data but always match if assertions pass""" |
2285 | 70 | self._case.assertEqual("#cloud-config", user_data.split("\n", 1)[0]) | 70 | self._case.assertEqual("#cloud-config", user_data.split("\n", 1)[0]) |
2287 | 71 | cc = yaml.safe_load(user_data) | 71 | cc = serializer.load(user_data) |
2288 | 72 | if self.is_master: | 72 | if self.is_master: |
2289 | 73 | zookeeper_hosts = "localhost:2181" | 73 | zookeeper_hosts = "localhost:2181" |
2290 | 74 | else: | 74 | else: |
2291 | 75 | 75 | ||
2292 | === modified file 'juju/providers/openstack/tests/test_state.py' | |||
2293 | --- juju/providers/openstack/tests/test_state.py 2012-06-18 15:03:50 +0000 | |||
2294 | +++ juju/providers/openstack/tests/test_state.py 2012-09-15 19:26:18 +0000 | |||
2295 | @@ -4,8 +4,7 @@ | |||
2296 | 4 | state handling is a pretty thin layer over the file storage. | 4 | state handling is a pretty thin layer over the file storage. |
2297 | 5 | """ | 5 | """ |
2298 | 6 | 6 | ||
2301 | 7 | import yaml | 7 | from juju.lib import serializer |
2300 | 8 | |||
2302 | 9 | from juju.lib.testing import TestCase | 8 | from juju.lib.testing import TestCase |
2303 | 10 | from juju.providers.openstack.tests import OpenStackTestMixin | 9 | from juju.providers.openstack.tests import OpenStackTestMixin |
2304 | 11 | 10 | ||
2305 | @@ -17,7 +16,7 @@ | |||
2306 | 17 | state = {"zookeeper-instances": [ | 16 | state = {"zookeeper-instances": [ |
2307 | 18 | [1000, "x1.example.com"], | 17 | [1000, "x1.example.com"], |
2308 | 19 | ]} | 18 | ]} |
2310 | 20 | self.expect_swift_put("testing/provider-state", yaml.dump(state)) | 19 | self.expect_swift_put("testing/provider-state", serializer.dump(state)) |
2311 | 21 | self.mocker.replay() | 20 | self.mocker.replay() |
2312 | 22 | return self.get_provider().save_state(state) | 21 | return self.get_provider().save_state(state) |
2313 | 23 | 22 | ||
2314 | @@ -26,7 +25,7 @@ | |||
2315 | 26 | state = {"zookeeper-instances": [ | 25 | state = {"zookeeper-instances": [ |
2316 | 27 | [1000, "x1.example.com"], | 26 | [1000, "x1.example.com"], |
2317 | 28 | ]} | 27 | ]} |
2319 | 29 | state_bytes = yaml.dump(state) | 28 | state_bytes = serializer.dump(state) |
2320 | 30 | self.expect_swift_put("testing/provider-state", state_bytes, code=404) | 29 | self.expect_swift_put("testing/provider-state", state_bytes, code=404) |
2321 | 31 | self.expect_swift_put_container("testing") | 30 | self.expect_swift_put_container("testing") |
2322 | 32 | self.expect_swift_put("testing/provider-state", state_bytes) | 31 | self.expect_swift_put("testing/provider-state", state_bytes) |
2323 | @@ -37,7 +36,7 @@ | |||
2324 | 37 | """Loading deserializes yaml from provider-state to a python dict""" | 36 | """Loading deserializes yaml from provider-state to a python dict""" |
2325 | 38 | state = {"zookeeper-instances": []} | 37 | state = {"zookeeper-instances": []} |
2326 | 39 | self.expect_swift_get("testing/provider-state", | 38 | self.expect_swift_get("testing/provider-state", |
2328 | 40 | response=yaml.dump(state)) | 39 | response=serializer.dump(state)) |
2329 | 41 | self.mocker.replay() | 40 | self.mocker.replay() |
2330 | 42 | deferred = self.get_provider().load_state() | 41 | deferred = self.get_provider().load_state() |
2331 | 43 | return deferred.addCallback(self.assertEqual, state) | 42 | return deferred.addCallback(self.assertEqual, state) |
2332 | 44 | 43 | ||
2333 | === modified file 'juju/providers/orchestra/tests/common.py' | |||
2334 | --- juju/providers/orchestra/tests/common.py 2012-04-12 01:01:57 +0000 | |||
2335 | +++ juju/providers/orchestra/tests/common.py 2012-09-15 19:26:18 +0000 | |||
2336 | @@ -1,12 +1,13 @@ | |||
2337 | 1 | from base64 import b64decode | 1 | from base64 import b64decode |
2338 | 2 | import os | 2 | import os |
2339 | 3 | from xmlrpclib import Fault | 3 | from xmlrpclib import Fault |
2341 | 4 | from yaml import dump, load | 4 | |
2342 | 5 | 5 | ||
2343 | 6 | from twisted.internet.defer import fail, succeed | 6 | from twisted.internet.defer import fail, succeed |
2344 | 7 | from twisted.web.error import Error | 7 | from twisted.web.error import Error |
2345 | 8 | from twisted.web.xmlrpc import Proxy | 8 | from twisted.web.xmlrpc import Proxy |
2346 | 9 | 9 | ||
2347 | 10 | from juju.lib.serializer import dump, load | ||
2348 | 10 | from juju.lib.mocker import ANY, MATCH | 11 | from juju.lib.mocker import ANY, MATCH |
2349 | 11 | from juju.providers.orchestra import MachineProvider | 12 | from juju.providers.orchestra import MachineProvider |
2350 | 12 | 13 | ||
2351 | 13 | 14 | ||
2352 | === modified file 'juju/providers/orchestra/tests/test_bootstrap.py' | |||
2353 | --- juju/providers/orchestra/tests/test_bootstrap.py 2012-04-12 01:01:57 +0000 | |||
2354 | +++ juju/providers/orchestra/tests/test_bootstrap.py 2012-09-15 19:26:18 +0000 | |||
2355 | @@ -1,9 +1,9 @@ | |||
2356 | 1 | from xmlrpclib import Fault | 1 | from xmlrpclib import Fault |
2357 | 2 | from yaml import dump | ||
2358 | 3 | 2 | ||
2359 | 4 | from twisted.internet.defer import succeed, inlineCallbacks | 3 | from twisted.internet.defer import succeed, inlineCallbacks |
2360 | 5 | 4 | ||
2361 | 6 | from juju.errors import ProviderError | 5 | from juju.errors import ProviderError |
2362 | 6 | from juju.lib.serializer import dump | ||
2363 | 7 | from juju.lib.testing import TestCase | 7 | from juju.lib.testing import TestCase |
2364 | 8 | from juju.providers.orchestra.machine import OrchestraMachine | 8 | from juju.providers.orchestra.machine import OrchestraMachine |
2365 | 9 | from juju.providers.orchestra.tests.common import OrchestraTestMixin | 9 | from juju.providers.orchestra.tests.common import OrchestraTestMixin |
2366 | 10 | 10 | ||
2367 | === modified file 'juju/providers/orchestra/tests/test_findzookeepers.py' | |||
2368 | --- juju/providers/orchestra/tests/test_findzookeepers.py 2011-10-17 13:49:47 +0000 | |||
2369 | +++ juju/providers/orchestra/tests/test_findzookeepers.py 2012-09-15 19:26:18 +0000 | |||
2370 | @@ -1,8 +1,7 @@ | |||
2371 | 1 | from yaml import dump | ||
2372 | 2 | |||
2373 | 3 | from twisted.internet.defer import succeed | 1 | from twisted.internet.defer import succeed |
2374 | 4 | 2 | ||
2375 | 5 | from juju.errors import EnvironmentNotFound | 3 | from juju.errors import EnvironmentNotFound |
2376 | 4 | from juju.lib.serializer import dump | ||
2377 | 6 | from juju.lib.testing import TestCase | 5 | from juju.lib.testing import TestCase |
2378 | 7 | from juju.providers.orchestra import MachineProvider | 6 | from juju.providers.orchestra import MachineProvider |
2379 | 8 | from juju.providers.orchestra.machine import OrchestraMachine | 7 | from juju.providers.orchestra.machine import OrchestraMachine |
2380 | 9 | 8 | ||
2381 | === modified file 'juju/providers/orchestra/tests/test_state.py' | |||
2382 | --- juju/providers/orchestra/tests/test_state.py 2011-10-10 07:18:11 +0000 | |||
2383 | +++ juju/providers/orchestra/tests/test_state.py 2012-09-15 19:26:18 +0000 | |||
2384 | @@ -1,5 +1,5 @@ | |||
2385 | 1 | from yaml import dump | ||
2386 | 2 | 1 | ||
2387 | 2 | from juju.lib.serializer import dump | ||
2388 | 3 | from juju.lib.testing import TestCase | 3 | from juju.lib.testing import TestCase |
2389 | 4 | from juju.providers.orchestra import MachineProvider | 4 | from juju.providers.orchestra import MachineProvider |
2390 | 5 | 5 | ||
2391 | 6 | 6 | ||
2392 | === modified file 'juju/state/charm.py' | |||
2393 | --- juju/state/charm.py 2012-04-01 03:53:48 +0000 | |||
2394 | +++ juju/state/charm.py 2012-09-15 19:26:18 +0000 | |||
2395 | @@ -1,4 +1,4 @@ | |||
2397 | 1 | import yaml | 1 | |
2398 | 2 | 2 | ||
2399 | 3 | from twisted.internet.defer import ( | 3 | from twisted.internet.defer import ( |
2400 | 4 | inlineCallbacks, returnValue, succeed) | 4 | inlineCallbacks, returnValue, succeed) |
2401 | @@ -8,7 +8,7 @@ | |||
2402 | 8 | from juju.charm.config import ConfigOptions | 8 | from juju.charm.config import ConfigOptions |
2403 | 9 | from juju.charm.metadata import MetaData | 9 | from juju.charm.metadata import MetaData |
2404 | 10 | from juju.charm.url import CharmURL | 10 | from juju.charm.url import CharmURL |
2406 | 11 | from juju.lib import under | 11 | from juju.lib import under, serializer |
2407 | 12 | from juju.state.base import StateBase | 12 | from juju.state.base import StateBase |
2408 | 13 | from juju.state.errors import CharmStateNotFound | 13 | from juju.state.errors import CharmStateNotFound |
2409 | 14 | 14 | ||
2410 | @@ -41,7 +41,7 @@ | |||
2411 | 41 | # replacements here. For now this will do, and will | 41 | # replacements here. For now this will do, and will |
2412 | 42 | # explode reliably in case of conflicts. | 42 | # explode reliably in case of conflicts. |
2413 | 43 | yield self._client.create( | 43 | yield self._client.create( |
2415 | 44 | _charm_path(charm_id), yaml.safe_dump(charm_data)) | 44 | _charm_path(charm_id), serializer.dump(charm_data)) |
2416 | 45 | charm_state = CharmState(self._client, charm_id, charm_data) | 45 | charm_state = CharmState(self._client, charm_id, charm_data) |
2417 | 46 | returnValue(charm_state) | 46 | returnValue(charm_state) |
2418 | 47 | 47 | ||
2419 | @@ -52,7 +52,7 @@ | |||
2420 | 52 | content, stat = yield self._client.get(_charm_path(charm_id)) | 52 | content, stat = yield self._client.get(_charm_path(charm_id)) |
2421 | 53 | except NoNodeException: | 53 | except NoNodeException: |
2422 | 54 | raise CharmStateNotFound(charm_id) | 54 | raise CharmStateNotFound(charm_id) |
2424 | 55 | charm_data = yaml.load(content) | 55 | charm_data = serializer.load(content) |
2425 | 56 | charm_state = CharmState(self._client, charm_id, charm_data) | 56 | charm_state = CharmState(self._client, charm_id, charm_data) |
2426 | 57 | returnValue(charm_state) | 57 | returnValue(charm_state) |
2427 | 58 | 58 | ||
2428 | 59 | 59 | ||
2429 | === modified file 'juju/state/environment.py' | |||
2430 | --- juju/state/environment.py 2012-03-30 08:26:21 +0000 | |||
2431 | +++ juju/state/environment.py 2012-09-15 19:26:18 +0000 | |||
2432 | @@ -1,11 +1,12 @@ | |||
2433 | 1 | import zookeeper | 1 | import zookeeper |
2435 | 2 | import yaml | 2 | |
2436 | 3 | 3 | ||
2437 | 4 | from twisted.internet.defer import inlineCallbacks, returnValue | 4 | from twisted.internet.defer import inlineCallbacks, returnValue |
2438 | 5 | 5 | ||
2439 | 6 | from txzookeeper.utils import retry_change | 6 | from txzookeeper.utils import retry_change |
2440 | 7 | 7 | ||
2441 | 8 | from juju.environment.config import EnvironmentsConfig | 8 | from juju.environment.config import EnvironmentsConfig |
2442 | 9 | from juju.lib import serializer | ||
2443 | 9 | from juju.state.errors import EnvironmentStateNotFound | 10 | from juju.state.errors import EnvironmentStateNotFound |
2444 | 10 | from juju.state.base import StateBase | 11 | from juju.state.base import StateBase |
2445 | 11 | 12 | ||
2446 | @@ -45,7 +46,7 @@ | |||
2447 | 45 | """ | 46 | """ |
2448 | 46 | data = constraints.data | 47 | data = constraints.data |
2449 | 47 | data.pop("ubuntu-series", None) | 48 | data.pop("ubuntu-series", None) |
2451 | 48 | return self._force("/constraints", yaml.safe_dump(data)) | 49 | return self._force("/constraints", serializer.dump(data)) |
2452 | 49 | 50 | ||
2453 | 50 | @inlineCallbacks | 51 | @inlineCallbacks |
2454 | 51 | def get_constraint_set(self): | 52 | def get_constraint_set(self): |
2455 | @@ -66,7 +67,7 @@ | |||
2456 | 66 | constraint_set = yield self.get_constraint_set() | 67 | constraint_set = yield self.get_constraint_set() |
2457 | 67 | try: | 68 | try: |
2458 | 68 | content, stat = yield self._client.get("/constraints") | 69 | content, stat = yield self._client.get("/constraints") |
2460 | 69 | data = yaml.load(content) | 70 | data = serializer.load(content) |
2461 | 70 | except zookeeper.NoNodeException: | 71 | except zookeeper.NoNodeException: |
2462 | 71 | data = {} | 72 | data = {} |
2463 | 72 | returnValue(constraint_set.load(data)) | 73 | returnValue(constraint_set.load(data)) |
2464 | @@ -107,7 +108,7 @@ | |||
2465 | 107 | content, stat = yield self._client.get(SETTINGS_PATH) | 108 | content, stat = yield self._client.get(SETTINGS_PATH) |
2466 | 108 | except zookeeper.NoNodeException: | 109 | except zookeeper.NoNodeException: |
2467 | 109 | returnValue(default) | 110 | returnValue(default) |
2469 | 110 | data = yaml.load(content) | 111 | data = serializer.load(content) |
2470 | 111 | returnValue(data.get(key, default)) | 112 | returnValue(data.get(key, default)) |
2471 | 112 | 113 | ||
2472 | 113 | def _set_value(self, key, value): | 114 | def _set_value(self, key, value): |
2473 | @@ -116,9 +117,9 @@ | |||
2474 | 116 | if not old_content: | 117 | if not old_content: |
2475 | 117 | data = {} | 118 | data = {} |
2476 | 118 | else: | 119 | else: |
2478 | 119 | data = yaml.load(old_content) | 120 | data = serializer.load(old_content) |
2479 | 120 | data[key] = value | 121 | data[key] = value |
2481 | 121 | return yaml.safe_dump(data) | 122 | return serializer.dump(data) |
2482 | 122 | 123 | ||
2483 | 123 | return retry_change(self._client, SETTINGS_PATH, set_value) | 124 | return retry_change(self._client, SETTINGS_PATH, set_value) |
2484 | 124 | 125 | ||
2485 | 125 | 126 | ||
2486 | === modified file 'juju/state/hook.py' | |||
2487 | --- juju/state/hook.py 2012-04-09 19:40:57 +0000 | |||
2488 | +++ juju/state/hook.py 2012-09-15 19:26:18 +0000 | |||
2489 | @@ -6,8 +6,7 @@ | |||
2490 | 6 | from juju.state.errors import ( | 6 | from juju.state.errors import ( |
2491 | 7 | UnitRelationStateNotFound, StateNotFound, RelationBrokenContextError, | 7 | UnitRelationStateNotFound, StateNotFound, RelationBrokenContextError, |
2492 | 8 | RelationStateNotFound, InvalidRelationIdentity, StateChanged) | 8 | RelationStateNotFound, InvalidRelationIdentity, StateChanged) |
2495 | 9 | from juju.state.relation import ( | 9 | from juju.state.relation import ServiceRelationState, UnitRelationState |
2494 | 10 | RelationStateManager, ServiceRelationState, UnitRelationState) | ||
2496 | 11 | from juju.state.service import ServiceStateManager, parse_service_name | 10 | from juju.state.service import ServiceStateManager, parse_service_name |
2497 | 12 | from juju.state.utils import YAMLState | 11 | from juju.state.utils import YAMLState |
2498 | 13 | 12 | ||
2499 | 14 | 13 | ||
2500 | === modified file 'juju/state/machine.py' | |||
2501 | --- juju/state/machine.py 2012-04-02 23:33:39 +0000 | |||
2502 | +++ juju/state/machine.py 2012-09-15 19:26:18 +0000 | |||
2503 | @@ -1,9 +1,9 @@ | |||
2504 | 1 | import yaml | ||
2505 | 2 | import zookeeper | 1 | import zookeeper |
2506 | 3 | 2 | ||
2507 | 4 | from twisted.internet.defer import inlineCallbacks, returnValue | 3 | from twisted.internet.defer import inlineCallbacks, returnValue |
2508 | 5 | 4 | ||
2509 | 6 | from juju.errors import ConstraintError | 5 | from juju.errors import ConstraintError |
2510 | 6 | from juju.lib import serializer | ||
2511 | 7 | from juju.state.agent import AgentStateMixin | 7 | from juju.state.agent import AgentStateMixin |
2512 | 8 | from juju.state.environment import EnvironmentStateManager | 8 | from juju.state.environment import EnvironmentStateManager |
2513 | 9 | from juju.state.errors import MachineStateNotFound, MachineStateInUse | 9 | from juju.state.errors import MachineStateNotFound, MachineStateInUse |
2514 | @@ -25,7 +25,7 @@ | |||
2515 | 25 | "Unprovisionable machine: incomplete constraints") | 25 | "Unprovisionable machine: incomplete constraints") |
2516 | 26 | machine_data = {"constraints": constraints.data} | 26 | machine_data = {"constraints": constraints.data} |
2517 | 27 | path = yield self._client.create( | 27 | path = yield self._client.create( |
2519 | 28 | "/machines/machine-", yaml.dump(machine_data), | 28 | "/machines/machine-", serializer.dump(machine_data), |
2520 | 29 | flags=zookeeper.SEQUENCE) | 29 | flags=zookeeper.SEQUENCE) |
2521 | 30 | _, internal_id = path.rsplit("/", 1) | 30 | _, internal_id = path.rsplit("/", 1) |
2522 | 31 | 31 | ||
2523 | 32 | 32 | ||
2524 | === modified file 'juju/state/relation.py' | |||
2525 | --- juju/state/relation.py 2012-05-15 19:07:47 +0000 | |||
2526 | +++ juju/state/relation.py 2012-09-15 19:26:18 +0000 | |||
2527 | @@ -1,7 +1,6 @@ | |||
2528 | 1 | import logging | 1 | import logging |
2529 | 2 | from os.path import basename, dirname | 2 | from os.path import basename, dirname |
2530 | 3 | 3 | ||
2531 | 4 | import yaml | ||
2532 | 5 | import zookeeper | 4 | import zookeeper |
2533 | 6 | 5 | ||
2534 | 7 | from twisted.internet.defer import ( | 6 | from twisted.internet.defer import ( |
2535 | @@ -9,6 +8,7 @@ | |||
2536 | 9 | 8 | ||
2537 | 10 | from txzookeeper.utils import retry_change | 9 | from txzookeeper.utils import retry_change |
2538 | 11 | 10 | ||
2539 | 11 | from juju.lib import serializer | ||
2540 | 12 | from juju.state.base import StateBase | 12 | from juju.state.base import StateBase |
2541 | 13 | from juju.state.errors import ( | 13 | from juju.state.errors import ( |
2542 | 14 | DuplicateEndpoints, IncompatibleEndpoints, RelationAlreadyExists, | 14 | DuplicateEndpoints, IncompatibleEndpoints, RelationAlreadyExists, |
2543 | @@ -310,7 +310,7 @@ | |||
2544 | 310 | except zookeeper.NodeExistsException: | 310 | except zookeeper.NodeExistsException: |
2545 | 311 | pass | 311 | pass |
2546 | 312 | 312 | ||
2548 | 313 | node_data = yaml.safe_dump(relation_data) | 313 | node_data = serializer.dump(relation_data) |
2549 | 314 | role_path = "%s/%s" % (scope_path, relation_data["role"]) | 314 | role_path = "%s/%s" % (scope_path, relation_data["role"]) |
2550 | 315 | 315 | ||
2551 | 316 | yield retry_change( | 316 | yield retry_change( |
2552 | @@ -346,18 +346,18 @@ | |||
2553 | 346 | def update_address(content, stat): | 346 | def update_address(content, stat): |
2554 | 347 | unit_map = None | 347 | unit_map = None |
2555 | 348 | if content: | 348 | if content: |
2557 | 349 | unit_map = yaml.load(content) | 349 | unit_map = serializer.load(content) |
2558 | 350 | if not unit_map: | 350 | if not unit_map: |
2559 | 351 | unit_map = {} | 351 | unit_map = {} |
2560 | 352 | unit_map["private-address"] = private_address | 352 | unit_map["private-address"] = private_address |
2562 | 353 | return yaml.safe_dump(unit_map) | 353 | return serializer.dump(unit_map) |
2563 | 354 | 354 | ||
2564 | 355 | yield retry_change(self._client, settings_path, update_address) | 355 | yield retry_change(self._client, settings_path, update_address) |
2565 | 356 | 356 | ||
2566 | 357 | # Update the unit name -> id mapping on the relation node | 357 | # Update the unit name -> id mapping on the relation node |
2567 | 358 | def update_unit_mapping(content, stat): | 358 | def update_unit_mapping(content, stat): |
2568 | 359 | if content: | 359 | if content: |
2570 | 360 | unit_map = yaml.load(content) | 360 | unit_map = serializer.load(content) |
2571 | 361 | else: | 361 | else: |
2572 | 362 | unit_map = {} | 362 | unit_map = {} |
2573 | 363 | # If it's already present, we're done, just return the | 363 | # If it's already present, we're done, just return the |
2574 | @@ -366,7 +366,7 @@ | |||
2575 | 366 | if unit_state.internal_id in unit_map: | 366 | if unit_state.internal_id in unit_map: |
2576 | 367 | return content | 367 | return content |
2577 | 368 | unit_map[unit_state.internal_id] = unit_state.unit_name | 368 | unit_map[unit_state.internal_id] = unit_state.unit_name |
2579 | 369 | return yaml.dump(unit_map) | 369 | return serializer.dump(unit_map) |
2580 | 370 | 370 | ||
2581 | 371 | yield retry_change(self._client, | 371 | yield retry_change(self._client, |
2582 | 372 | "/relations/%s" % self._relation_id, | 372 | "/relations/%s" % self._relation_id, |
2583 | @@ -481,7 +481,7 @@ | |||
2584 | 481 | """ | 481 | """ |
2585 | 482 | path = yield self.get_settings_path() | 482 | path = yield self.get_settings_path() |
2586 | 483 | # encode as a YAML string | 483 | # encode as a YAML string |
2588 | 484 | data = yaml.safe_dump(data) | 484 | data = serializer.dump(data) |
2589 | 485 | 485 | ||
2590 | 486 | yield retry_change( | 486 | yield retry_change( |
2591 | 487 | self._client, path, lambda content, stat: data) | 487 | self._client, path, lambda content, stat: data) |
2592 | @@ -724,7 +724,7 @@ | |||
2593 | 724 | if self._relation_scope == "container": | 724 | if self._relation_scope == "container": |
2594 | 725 | relation_path = dirname(relation_path) | 725 | relation_path = dirname(relation_path) |
2595 | 726 | content, stat = yield self._client.get(relation_path) | 726 | content, stat = yield self._client.get(relation_path) |
2597 | 727 | self._unit_name_map = yaml.load(content) | 727 | self._unit_name_map = serializer.load(content) |
2598 | 728 | results = [] | 728 | results = [] |
2599 | 729 | for unit_id_list in unit_ids: | 729 | for unit_id_list in unit_ids: |
2600 | 730 | names = [] | 730 | names = [] |
2601 | 731 | 731 | ||
2602 | === modified file 'juju/state/security.py' | |||
2603 | --- juju/state/security.py 2011-09-15 18:50:23 +0000 | |||
2604 | +++ juju/state/security.py 2012-09-15 19:26:18 +0000 | |||
2605 | @@ -1,7 +1,7 @@ | |||
2606 | 1 | import base64 | 1 | import base64 |
2607 | 2 | import random | 2 | import random |
2608 | 3 | import string | 3 | import string |
2610 | 4 | import yaml | 4 | |
2611 | 5 | 5 | ||
2612 | 6 | from zookeeper import ( | 6 | from zookeeper import ( |
2613 | 7 | BadArgumentsException, BadVersionException, | 7 | BadArgumentsException, BadVersionException, |
2614 | @@ -10,6 +10,7 @@ | |||
2615 | 10 | from twisted.internet.defer import inlineCallbacks, returnValue | 10 | from twisted.internet.defer import inlineCallbacks, returnValue |
2616 | 11 | from txzookeeper.client import ZOO_OPEN_ACL_UNSAFE, ZookeeperClient | 11 | from txzookeeper.client import ZOO_OPEN_ACL_UNSAFE, ZookeeperClient |
2617 | 12 | 12 | ||
2618 | 13 | from juju.lib import serializer | ||
2619 | 13 | from juju.state.auth import make_identity, make_ace | 14 | from juju.state.auth import make_identity, make_ace |
2620 | 14 | from juju.state.errors import ( | 15 | from juju.state.errors import ( |
2621 | 15 | StateNotFound, PrincipalNotFound) | 16 | StateNotFound, PrincipalNotFound) |
2622 | @@ -74,7 +75,7 @@ | |||
2623 | 74 | except NoNodeException: | 75 | except NoNodeException: |
2624 | 75 | raise StateNotFound("Group does not exist at %r" % self._path) | 76 | raise StateNotFound("Group does not exist at %r" % self._path) |
2625 | 76 | 77 | ||
2627 | 77 | credentials = yaml.load(data) | 78 | credentials = serializer.load(data) |
2628 | 78 | self._name = credentials["name"] | 79 | self._name = credentials["name"] |
2629 | 79 | self._password = credentials["password"] | 80 | self._password = credentials["password"] |
2630 | 80 | 81 | ||
2631 | @@ -108,7 +109,7 @@ | |||
2632 | 108 | try: | 109 | try: |
2633 | 109 | yield self._client.create( | 110 | yield self._client.create( |
2634 | 110 | self._path, | 111 | self._path, |
2636 | 111 | yaml.safe_dump(dict(name=name, password=password))) | 112 | serializer.dump(dict(name=name, password=password))) |
2637 | 112 | except NodeExistsException: | 113 | except NodeExistsException: |
2638 | 113 | raise RuntimeError("Group already exists at %r" % self._path) | 114 | raise RuntimeError("Group already exists at %r" % self._path) |
2639 | 114 | self._name = name | 115 | self._name = name |
2640 | @@ -211,7 +212,7 @@ | |||
2641 | 211 | yield client.add_auth("digest", credentials) | 212 | yield client.add_auth("digest", credentials) |
2642 | 212 | # Load the otp principal data | 213 | # Load the otp principal data |
2643 | 213 | data, stat = yield client.get(path) | 214 | data, stat = yield client.get(path) |
2645 | 214 | principal_data = yaml.load(data) | 215 | principal_data = serializer.load(data) |
2646 | 215 | # Consume the otp node | 216 | # Consume the otp node |
2647 | 216 | yield client.delete(path) | 217 | yield client.delete(path) |
2648 | 217 | returnValue((principal_data["name"], principal_data["password"])) | 218 | returnValue((principal_data["name"], principal_data["password"])) |
2649 | @@ -237,7 +238,7 @@ | |||
2650 | 237 | 238 | ||
2651 | 238 | self._path = yield self._client.create( | 239 | self._path = yield self._client.create( |
2652 | 239 | self._path, | 240 | self._path, |
2654 | 240 | yaml.safe_dump(dict(name=name, password=password)), | 241 | serializer.dump(dict(name=name, password=password)), |
2655 | 241 | acls=acl, | 242 | acls=acl, |
2656 | 242 | flags=SEQUENCE) | 243 | flags=SEQUENCE) |
2657 | 243 | 244 | ||
2658 | 244 | 245 | ||
2659 | === modified file 'juju/state/service.py' | |||
2660 | --- juju/state/service.py 2012-04-05 22:27:11 +0000 | |||
2661 | +++ juju/state/service.py 2012-09-15 19:26:18 +0000 | |||
2662 | @@ -1,4 +1,3 @@ | |||
2663 | 1 | import yaml | ||
2664 | 2 | import zookeeper | 1 | import zookeeper |
2665 | 3 | 2 | ||
2666 | 4 | from twisted.internet.defer import ( | 3 | from twisted.internet.defer import ( |
2667 | @@ -7,6 +6,7 @@ | |||
2668 | 7 | from txzookeeper.utils import retry_change | 6 | from txzookeeper.utils import retry_change |
2669 | 8 | 7 | ||
2670 | 9 | from juju.charm.url import CharmURL | 8 | from juju.charm.url import CharmURL |
2671 | 9 | from juju.lib import serializer | ||
2672 | 10 | from juju.state.agent import AgentStateMixin | 10 | from juju.state.agent import AgentStateMixin |
2673 | 11 | from juju.state.base import log, StateBase | 11 | from juju.state.base import log, StateBase |
2674 | 12 | from juju.state.endpoint import RelationEndpoint | 12 | from juju.state.endpoint import RelationEndpoint |
2675 | @@ -55,13 +55,14 @@ | |||
2676 | 55 | "charm": charm_id, "constraints": constraints.data} | 55 | "charm": charm_id, "constraints": constraints.data} |
2677 | 56 | # charm metadata is always decoded into unicode, ensure any | 56 | # charm metadata is always decoded into unicode, ensure any |
2678 | 57 | # serialized state references strings to avoid tying to py runtime. | 57 | # serialized state references strings to avoid tying to py runtime. |
2680 | 58 | node_data = yaml.safe_dump(service_details) | 58 | node_data = serializer.dump(service_details) |
2681 | 59 | path = yield self._client.create("/services/service-", node_data, | 59 | path = yield self._client.create("/services/service-", node_data, |
2682 | 60 | flags=zookeeper.SEQUENCE) | 60 | flags=zookeeper.SEQUENCE) |
2683 | 61 | internal_id = path.rsplit("/", 1)[1] | 61 | internal_id = path.rsplit("/", 1)[1] |
2684 | 62 | 62 | ||
2685 | 63 | # create a child node for configuration options | 63 | # create a child node for configuration options |
2687 | 64 | yield self._client.create("%s/config" % path, yaml.dump({})) | 64 | yield self._client.create( |
2688 | 65 | "%s/config" % path, serializer.dump({})) | ||
2689 | 65 | 66 | ||
2690 | 66 | def add_service(topology): | 67 | def add_service(topology): |
2691 | 67 | if topology.find_service_with_name(service_name): | 68 | if topology.find_service_with_name(service_name): |
2692 | @@ -416,7 +417,9 @@ | |||
2693 | 416 | charm_id = yield self.get_charm_id() | 417 | charm_id = yield self.get_charm_id() |
2694 | 417 | unit_data = {"charm": charm_id, "constraints": constraints.data} | 418 | unit_data = {"charm": charm_id, "constraints": constraints.data} |
2695 | 418 | path = yield self._client.create( | 419 | path = yield self._client.create( |
2697 | 419 | "/units/unit-", yaml.dump(unit_data), flags=zookeeper.SEQUENCE) | 420 | "/units/unit-", |
2698 | 421 | serializer.dump(unit_data), | ||
2699 | 422 | flags=zookeeper.SEQUENCE) | ||
2700 | 420 | 423 | ||
2701 | 421 | internal_unit_id = path.rsplit("/", 1)[1] | 424 | internal_unit_id = path.rsplit("/", 1)[1] |
2702 | 422 | 425 | ||
2703 | @@ -1094,7 +1097,7 @@ | |||
2704 | 1094 | try: | 1097 | try: |
2705 | 1095 | yield self._client.create( | 1098 | yield self._client.create( |
2706 | 1096 | self._hook_debug_path, | 1099 | self._hook_debug_path, |
2708 | 1097 | yaml.safe_dump({"debug_hooks": hook_names}), | 1100 | serializer.dump({"debug_hooks": hook_names}), |
2709 | 1098 | flags=zookeeper.EPHEMERAL) | 1101 | flags=zookeeper.EPHEMERAL) |
2710 | 1099 | except zookeeper.NodeExistsException: | 1102 | except zookeeper.NodeExistsException: |
2711 | 1100 | raise ServiceUnitDebugAlreadyEnabled(self.unit_name) | 1103 | raise ServiceUnitDebugAlreadyEnabled(self.unit_name) |
2712 | @@ -1125,7 +1128,7 @@ | |||
2713 | 1125 | except zookeeper.NoNodeException: | 1128 | except zookeeper.NoNodeException: |
2714 | 1126 | # We get to the same end state. | 1129 | # We get to the same end state. |
2715 | 1127 | returnValue(None) | 1130 | returnValue(None) |
2717 | 1128 | returnValue(yaml.load(content)) | 1131 | returnValue(serializer.load(content)) |
2718 | 1129 | 1132 | ||
2719 | 1130 | @inlineCallbacks | 1133 | @inlineCallbacks |
2720 | 1131 | def watch_hook_debug(self, callback, permanent=True): | 1134 | def watch_hook_debug(self, callback, permanent=True): |
2721 | @@ -1179,12 +1182,12 @@ | |||
2722 | 1179 | def update(content, stat): | 1182 | def update(content, stat): |
2723 | 1180 | if not content: | 1183 | if not content: |
2724 | 1181 | flags = dict(force=force) | 1184 | flags = dict(force=force) |
2726 | 1182 | return yaml.dump(flags) | 1185 | return serializer.dump(flags) |
2727 | 1183 | 1186 | ||
2729 | 1184 | flags = yaml.load(content) | 1187 | flags = serializer.load(content) |
2730 | 1185 | if not isinstance(flags, dict): | 1188 | if not isinstance(flags, dict): |
2731 | 1186 | flags = dict(force=force) | 1189 | flags = dict(force=force) |
2733 | 1187 | return yaml.dump(flags) | 1190 | return serializer.dump(flags) |
2734 | 1188 | 1191 | ||
2735 | 1189 | if flags['force'] != force: | 1192 | if flags['force'] != force: |
2736 | 1190 | raise ServiceUnitUpgradeAlreadyEnabled(self.unit_name) | 1193 | raise ServiceUnitUpgradeAlreadyEnabled(self.unit_name) |
2737 | @@ -1205,7 +1208,7 @@ | |||
2738 | 1205 | returnValue(False) | 1208 | returnValue(False) |
2739 | 1206 | except zookeeper.NoNodeException: | 1209 | except zookeeper.NoNodeException: |
2740 | 1207 | returnValue(False) | 1210 | returnValue(False) |
2742 | 1208 | returnValue(yaml.load(content)) | 1211 | returnValue(serializer.load(content)) |
2743 | 1209 | 1212 | ||
2744 | 1210 | @inlineCallbacks | 1213 | @inlineCallbacks |
2745 | 1211 | def clear_upgrade_flag(self): | 1214 | def clear_upgrade_flag(self): |
2746 | @@ -1282,7 +1285,7 @@ | |||
2747 | 1282 | 1285 | ||
2748 | 1283 | try: | 1286 | try: |
2749 | 1284 | yield self._client.create( | 1287 | yield self._client.create( |
2751 | 1285 | self._unit_resolved_path, yaml.safe_dump({"retry": retry})) | 1288 | self._unit_resolved_path, serializer.dump({"retry": retry})) |
2752 | 1286 | except zookeeper.NodeExistsException: | 1289 | except zookeeper.NodeExistsException: |
2753 | 1287 | raise ServiceUnitResolvedAlreadyEnabled(self.unit_name) | 1290 | raise ServiceUnitResolvedAlreadyEnabled(self.unit_name) |
2754 | 1288 | 1291 | ||
2755 | @@ -1299,7 +1302,7 @@ | |||
2756 | 1299 | except zookeeper.NoNodeException: | 1302 | except zookeeper.NoNodeException: |
2757 | 1300 | # Return a default value. | 1303 | # Return a default value. |
2758 | 1301 | returnValue(None) | 1304 | returnValue(None) |
2760 | 1302 | returnValue(yaml.load(content)) | 1305 | returnValue(serializer.load(content)) |
2761 | 1303 | 1306 | ||
2762 | 1304 | @inlineCallbacks | 1307 | @inlineCallbacks |
2763 | 1305 | def clear_resolved(self): | 1308 | def clear_resolved(self): |
2764 | @@ -1392,10 +1395,10 @@ | |||
2765 | 1392 | 1395 | ||
2766 | 1393 | def update_relation_resolved(content, stat): | 1396 | def update_relation_resolved(content, stat): |
2767 | 1394 | if not content: | 1397 | if not content: |
2769 | 1395 | return yaml.safe_dump(relation_map) | 1398 | return serializer.dump(relation_map) |
2770 | 1396 | 1399 | ||
2773 | 1397 | content = yaml.safe_dump( | 1400 | content = serializer.dump( |
2774 | 1398 | dict_merge(yaml.load(content), relation_map)) | 1401 | dict_merge(serializer.load(content), relation_map)) |
2775 | 1399 | return content | 1402 | return content |
2776 | 1400 | 1403 | ||
2777 | 1401 | try: | 1404 | try: |
2778 | @@ -1416,7 +1419,7 @@ | |||
2779 | 1416 | self._relation_resolved_path) | 1419 | self._relation_resolved_path) |
2780 | 1417 | except zookeeper.NoNodeException: | 1420 | except zookeeper.NoNodeException: |
2781 | 1418 | returnValue(None) | 1421 | returnValue(None) |
2783 | 1419 | returnValue(yaml.load(content)) | 1422 | returnValue(serializer.load(content)) |
2784 | 1420 | 1423 | ||
2785 | 1421 | @inlineCallbacks | 1424 | @inlineCallbacks |
2786 | 1422 | def clear_relation_resolved(self): | 1425 | def clear_relation_resolved(self): |
2787 | @@ -1477,14 +1480,14 @@ | |||
2788 | 1477 | if content is None: | 1480 | if content is None: |
2789 | 1478 | data = {} | 1481 | data = {} |
2790 | 1479 | else: | 1482 | else: |
2792 | 1480 | data = yaml.load(content) | 1483 | data = serializer.load(content) |
2793 | 1481 | if data is None: | 1484 | if data is None: |
2794 | 1482 | data = {} | 1485 | data = {} |
2795 | 1483 | open_ports = data.setdefault("open", []) | 1486 | open_ports = data.setdefault("open", []) |
2796 | 1484 | port_proto = dict(port=port, proto=proto) | 1487 | port_proto = dict(port=port, proto=proto) |
2797 | 1485 | if port_proto not in open_ports: | 1488 | if port_proto not in open_ports: |
2798 | 1486 | open_ports.append(port_proto) | 1489 | open_ports.append(port_proto) |
2800 | 1487 | return yaml.safe_dump(data) | 1490 | return serializer.dump(data) |
2801 | 1488 | 1491 | ||
2802 | 1489 | yield retry_change(self._client, self._ports_path, zk_open_port) | 1492 | yield retry_change(self._client, self._ports_path, zk_open_port) |
2803 | 1490 | 1493 | ||
2804 | @@ -1499,14 +1502,14 @@ | |||
2805 | 1499 | if content is None: | 1502 | if content is None: |
2806 | 1500 | data = {} | 1503 | data = {} |
2807 | 1501 | else: | 1504 | else: |
2809 | 1502 | data = yaml.load(content) | 1505 | data = serializer.load(content) |
2810 | 1503 | if data is None: | 1506 | if data is None: |
2811 | 1504 | data = {} | 1507 | data = {} |
2812 | 1505 | open_ports = data.setdefault("open", []) | 1508 | open_ports = data.setdefault("open", []) |
2813 | 1506 | port_proto = dict(port=port, proto=proto) | 1509 | port_proto = dict(port=port, proto=proto) |
2814 | 1507 | if port_proto in open_ports: | 1510 | if port_proto in open_ports: |
2815 | 1508 | open_ports.remove(port_proto) | 1511 | open_ports.remove(port_proto) |
2817 | 1509 | return yaml.dump(data) | 1512 | return serializer.dump(data) |
2818 | 1510 | 1513 | ||
2819 | 1511 | yield retry_change( | 1514 | yield retry_change( |
2820 | 1512 | self._client, self._ports_path, zk_close_port) | 1515 | self._client, self._ports_path, zk_close_port) |
2821 | @@ -1524,7 +1527,7 @@ | |||
2822 | 1524 | content, stat = yield self._client.get(self._ports_path) | 1527 | content, stat = yield self._client.get(self._ports_path) |
2823 | 1525 | except zookeeper.NoNodeException: | 1528 | except zookeeper.NoNodeException: |
2824 | 1526 | returnValue([]) | 1529 | returnValue([]) |
2826 | 1527 | data = yaml.load(content) | 1530 | data = serializer.load(content) |
2827 | 1528 | if data is None: | 1531 | if data is None: |
2828 | 1529 | returnValue(()) | 1532 | returnValue(()) |
2829 | 1530 | returnValue(data.get("open", ())) | 1533 | returnValue(data.get("open", ())) |
2830 | 1531 | 1534 | ||
2831 | === modified file 'juju/state/tests/test_charm.py' | |||
2832 | --- juju/state/tests/test_charm.py 2012-03-29 08:26:36 +0000 | |||
2833 | +++ juju/state/tests/test_charm.py 2012-09-15 19:26:18 +0000 | |||
2834 | @@ -1,7 +1,6 @@ | |||
2835 | 1 | import os | 1 | import os |
2836 | 2 | import shutil | 2 | import shutil |
2837 | 3 | 3 | ||
2838 | 4 | import yaml | ||
2839 | 5 | 4 | ||
2840 | 6 | from twisted.internet.defer import inlineCallbacks | 5 | from twisted.internet.defer import inlineCallbacks |
2841 | 7 | 6 | ||
2842 | @@ -10,6 +9,8 @@ | |||
2843 | 10 | from juju.charm.tests.test_directory import sample_directory | 9 | from juju.charm.tests.test_directory import sample_directory |
2844 | 11 | from juju.charm.tests.test_repository import unbundled_repository | 10 | from juju.charm.tests.test_repository import unbundled_repository |
2845 | 12 | 11 | ||
2846 | 12 | from juju.lib import serializer | ||
2847 | 13 | |||
2848 | 13 | from juju.state.charm import CharmStateManager | 14 | from juju.state.charm import CharmStateManager |
2849 | 14 | from juju.state.errors import CharmStateNotFound | 15 | from juju.state.errors import CharmStateNotFound |
2850 | 15 | from juju.state.tests.common import StateTestBase | 16 | from juju.state.tests.common import StateTestBase |
2851 | @@ -44,7 +45,7 @@ | |||
2852 | 44 | content, stat = yield self.client.get( | 45 | content, stat = yield self.client.get( |
2853 | 45 | "/charms/local_3a_series_2f_dummy-1") | 46 | "/charms/local_3a_series_2f_dummy-1") |
2854 | 46 | 47 | ||
2856 | 47 | charm_data = yaml.load(content) | 48 | charm_data = serializer.load(content) |
2857 | 48 | self.assertEquals(charm_data, { | 49 | self.assertEquals(charm_data, { |
2858 | 49 | "metadata": self.charm.metadata.get_serialization_data(), | 50 | "metadata": self.charm.metadata.get_serialization_data(), |
2859 | 50 | "config": self.charm.config.get_serialization_data(), | 51 | "config": self.charm.config.get_serialization_data(), |
2860 | 51 | 52 | ||
2861 | === modified file 'juju/state/tests/test_environment.py' | |||
2862 | --- juju/state/tests/test_environment.py 2012-03-29 01:37:57 +0000 | |||
2863 | +++ juju/state/tests/test_environment.py 2012-09-15 19:26:18 +0000 | |||
2864 | @@ -1,10 +1,9 @@ | |||
2865 | 1 | import yaml | ||
2866 | 2 | |||
2867 | 3 | from twisted.internet.defer import inlineCallbacks, Deferred | 1 | from twisted.internet.defer import inlineCallbacks, Deferred |
2868 | 4 | 2 | ||
2869 | 5 | from juju.environment.tests.test_config import ( | 3 | from juju.environment.tests.test_config import ( |
2870 | 6 | EnvironmentsConfigTestBase, SAMPLE_ENV) | 4 | EnvironmentsConfigTestBase, SAMPLE_ENV) |
2871 | 7 | from juju.machine.tests.test_constraints import dummy_cs | 5 | from juju.machine.tests.test_constraints import dummy_cs |
2872 | 6 | from juju.lib import serializer | ||
2873 | 8 | from juju.state.errors import EnvironmentStateNotFound | 7 | from juju.state.errors import EnvironmentStateNotFound |
2874 | 9 | from juju.state.environment import ( | 8 | from juju.state.environment import ( |
2875 | 10 | EnvironmentStateManager, GlobalSettingsStateManager, SETTINGS_PATH) | 9 | EnvironmentStateManager, GlobalSettingsStateManager, SETTINGS_PATH) |
2876 | @@ -38,7 +37,8 @@ | |||
2877 | 38 | 37 | ||
2878 | 39 | serialized = self.config.serialize("myfirstenv") | 38 | serialized = self.config.serialize("myfirstenv") |
2879 | 40 | content, stat = yield self.client.get("/environment") | 39 | content, stat = yield self.client.get("/environment") |
2881 | 41 | self.assertEquals(yaml.load(content), yaml.load(serialized)) | 40 | self.assertEquals(serializer.load(content), |
2882 | 41 | serializer.load(serialized)) | ||
2883 | 42 | 42 | ||
2884 | 43 | @inlineCallbacks | 43 | @inlineCallbacks |
2885 | 44 | def test_set_config_state_replaces_environment(self): | 44 | def test_set_config_state_replaces_environment(self): |
2886 | @@ -53,7 +53,8 @@ | |||
2887 | 53 | 53 | ||
2888 | 54 | serialized = self.config.serialize("myfirstenv") | 54 | serialized = self.config.serialize("myfirstenv") |
2889 | 55 | content, stat = yield self.client.get("/environment") | 55 | content, stat = yield self.client.get("/environment") |
2891 | 56 | self.assertEquals(yaml.load(content), yaml.load(serialized)) | 56 | self.assertEquals(serializer.load(content), |
2892 | 57 | serializer.load(serialized)) | ||
2893 | 57 | 58 | ||
2894 | 58 | @inlineCallbacks | 59 | @inlineCallbacks |
2895 | 59 | def test_get_config(self): | 60 | def test_get_config(self): |
2896 | @@ -65,7 +66,8 @@ | |||
2897 | 65 | config = yield manager.get_config() | 66 | config = yield manager.get_config() |
2898 | 66 | serialized1 = self.config.serialize("myfirstenv") | 67 | serialized1 = self.config.serialize("myfirstenv") |
2899 | 67 | serialized2 = config.serialize("myfirstenv") | 68 | serialized2 = config.serialize("myfirstenv") |
2901 | 68 | self.assertEquals(yaml.load(serialized1), yaml.load(serialized2)) | 69 | self.assertEquals(serializer.load(serialized1), |
2902 | 70 | serializer.load(serialized2)) | ||
2903 | 69 | 71 | ||
2904 | 70 | def test_get_config_when_missing(self): | 72 | def test_get_config_when_missing(self): |
2905 | 71 | """ | 73 | """ |
2906 | @@ -140,7 +142,7 @@ | |||
2907 | 140 | yield self.manager.set_provider_type("ec2") | 142 | yield self.manager.set_provider_type("ec2") |
2908 | 141 | self.assertEqual((yield self.manager.get_provider_type()), "ec2") | 143 | self.assertEqual((yield self.manager.get_provider_type()), "ec2") |
2909 | 142 | content, stat = yield self.client.get("/settings") | 144 | content, stat = yield self.client.get("/settings") |
2911 | 143 | self.assertEqual(yaml.load(content), | 145 | self.assertEqual(serializer.load(content), |
2912 | 144 | {"provider-type": "ec2"}) | 146 | {"provider-type": "ec2"}) |
2913 | 145 | 147 | ||
2914 | 146 | @inlineCallbacks | 148 | @inlineCallbacks |
2915 | @@ -211,7 +213,7 @@ | |||
2916 | 211 | 213 | ||
2917 | 212 | data = dict(x=1, y=2, z=3, moose=u"moon") | 214 | data = dict(x=1, y=2, z=3, moose=u"moon") |
2918 | 213 | yield self.client.set( | 215 | yield self.client.set( |
2920 | 214 | SETTINGS_PATH, yaml.safe_dump(data)) | 216 | SETTINGS_PATH, serializer.dump(data)) |
2921 | 215 | value = yield callbacks[1] | 217 | value = yield callbacks[1] |
2922 | 216 | self.assertEqual(value.type_name, "changed") | 218 | self.assertEqual(value.type_name, "changed") |
2923 | 217 | 219 | ||
2924 | 218 | 220 | ||
2925 | === modified file 'juju/state/tests/test_hook.py' | |||
2926 | --- juju/state/tests/test_hook.py 2012-04-09 19:40:57 +0000 | |||
2927 | +++ juju/state/tests/test_hook.py 2012-09-15 19:26:18 +0000 | |||
2928 | @@ -1,7 +1,6 @@ | |||
2929 | 1 | import yaml | ||
2930 | 2 | |||
2931 | 3 | from twisted.internet.defer import inlineCallbacks, returnValue | 1 | from twisted.internet.defer import inlineCallbacks, returnValue |
2932 | 4 | from juju.lib.pick import pick_attr | 2 | from juju.lib.pick import pick_attr |
2933 | 3 | from juju.lib import serializer | ||
2934 | 5 | from juju.lib.testing import TestCase | 4 | from juju.lib.testing import TestCase |
2935 | 6 | 5 | ||
2936 | 7 | from juju.state.endpoint import RelationEndpoint | 6 | from juju.state.endpoint import RelationEndpoint |
2937 | @@ -218,7 +217,7 @@ | |||
2938 | 218 | self.assertNotEqual(current_data, data) | 217 | self.assertNotEqual(current_data, data) |
2939 | 219 | 218 | ||
2940 | 220 | self.client.set(self.get_unit_settings_path(self.mysql_states), | 219 | self.client.set(self.get_unit_settings_path(self.mysql_states), |
2942 | 221 | yaml.dump({"hello": "world"})) | 220 | serializer.dump({"hello": "world"})) |
2943 | 222 | data = yield self.context.get("mysql/0") | 221 | data = yield self.context.get("mysql/0") |
2944 | 223 | data["abc"] = 1 | 222 | data["abc"] = 1 |
2945 | 224 | 223 | ||
2946 | @@ -286,7 +285,7 @@ | |||
2947 | 286 | content, stat = yield self.client.get( | 285 | content, stat = yield self.client.get( |
2948 | 287 | self.get_unit_settings_path(self.wordpress_states)) | 286 | self.get_unit_settings_path(self.wordpress_states)) |
2949 | 288 | data["private-address"] = "wordpress-0.example.com" | 287 | data["private-address"] = "wordpress-0.example.com" |
2951 | 289 | self.assertEqual(yaml.load(content), data) | 288 | self.assertEqual(serializer.load(content), data) |
2952 | 290 | self.assertEqual(changes, | 289 | self.assertEqual(changes, |
2953 | 291 | [AddedItem("abc", 12), AddedItem("bar", "21")]) | 290 | [AddedItem("abc", 12), AddedItem("bar", "21")]) |
2954 | 292 | 291 | ||
2955 | @@ -297,7 +296,7 @@ | |||
2956 | 297 | yield self.context.set_value("donkey", u"abc") | 296 | yield self.context.set_value("donkey", u"abc") |
2957 | 298 | data, stat = yield self.client.get( | 297 | data, stat = yield self.client.get( |
2958 | 299 | self.get_unit_settings_path(self.wordpress_states)) | 298 | self.get_unit_settings_path(self.wordpress_states)) |
2960 | 300 | self.assertEqual(yaml.load(data), | 299 | self.assertEqual(serializer.load(data), |
2961 | 301 | {"private-address": "wordpress-0.example.com"}) | 300 | {"private-address": "wordpress-0.example.com"}) |
2962 | 302 | 301 | ||
2963 | 303 | changes = yield self.context.flush() | 302 | changes = yield self.context.flush() |
2964 | @@ -305,7 +304,7 @@ | |||
2965 | 305 | self.get_unit_settings_path(self.wordpress_states)) | 304 | self.get_unit_settings_path(self.wordpress_states)) |
2966 | 306 | 305 | ||
2967 | 307 | self.assertEqual( | 306 | self.assertEqual( |
2969 | 308 | yaml.load(data), | 307 | serializer.load(data), |
2970 | 309 | {"zebra": 12, "donkey": "abc", | 308 | {"zebra": 12, "donkey": "abc", |
2971 | 310 | "private-address": "wordpress-0.example.com"}) | 309 | "private-address": "wordpress-0.example.com"}) |
2972 | 311 | 310 | ||
2973 | @@ -320,14 +319,14 @@ | |||
2974 | 320 | yield self.client.set( | 319 | yield self.client.set( |
2975 | 321 | self.get_unit_settings_path( | 320 | self.get_unit_settings_path( |
2976 | 322 | self.wordpress_states), | 321 | self.wordpress_states), |
2978 | 323 | yaml.dump({"key": "secret"})) | 322 | serializer.dump({"key": "secret"})) |
2979 | 324 | 323 | ||
2980 | 325 | yield self.context.delete_value("key") | 324 | yield self.context.delete_value("key") |
2981 | 326 | changes = yield self.context.flush() | 325 | changes = yield self.context.flush() |
2982 | 327 | data, stat = yield self.client.get( | 326 | data, stat = yield self.client.get( |
2983 | 328 | self.get_unit_settings_path(self.wordpress_states)) | 327 | self.get_unit_settings_path(self.wordpress_states)) |
2984 | 329 | 328 | ||
2986 | 330 | self.assertNotIn("key", yaml.load(data)) | 329 | self.assertNotIn("key", serializer.load(data)) |
2987 | 331 | self.assertEqual(changes, [DeletedItem("key", "secret")]) | 330 | self.assertEqual(changes, [DeletedItem("key", "secret")]) |
2988 | 332 | 331 | ||
2989 | 333 | @inlineCallbacks | 332 | @inlineCallbacks |
2990 | @@ -336,14 +335,14 @@ | |||
2991 | 336 | """ | 335 | """ |
2992 | 337 | yield self.client.set( | 336 | yield self.client.set( |
2993 | 338 | self.get_unit_settings_path(self.wordpress_states), | 337 | self.get_unit_settings_path(self.wordpress_states), |
2995 | 339 | yaml.dump({"lantern": "green"})) | 338 | serializer.dump({"lantern": "green"})) |
2996 | 340 | 339 | ||
2997 | 341 | yield self.context.delete_value("key") | 340 | yield self.context.delete_value("key") |
2998 | 342 | changes = yield self.context.flush() | 341 | changes = yield self.context.flush() |
2999 | 343 | data, stat = yield self.client.get( | 342 | data, stat = yield self.client.get( |
3000 | 344 | self.get_unit_settings_path(self.wordpress_states)) | 343 | self.get_unit_settings_path(self.wordpress_states)) |
3001 | 345 | 344 | ||
3003 | 346 | self.assertEqual(yaml.load(data), {"lantern": "green"}) | 345 | self.assertEqual(serializer.load(data), {"lantern": "green"}) |
3004 | 347 | self.assertEqual(changes, []) | 346 | self.assertEqual(changes, []) |
3005 | 348 | 347 | ||
3006 | 349 | @inlineCallbacks | 348 | @inlineCallbacks |
3007 | @@ -351,12 +350,12 @@ | |||
3008 | 351 | """Flushing a context which has no writes is a noop.""" | 350 | """Flushing a context which has no writes is a noop.""" |
3009 | 352 | yield self.client.set( | 351 | yield self.client.set( |
3010 | 353 | self.get_unit_settings_path(self.wordpress_states), | 352 | self.get_unit_settings_path(self.wordpress_states), |
3012 | 354 | yaml.dump({"key": "secret"})) | 353 | serializer.dump({"key": "secret"})) |
3013 | 355 | changes = yield self.context.flush() | 354 | changes = yield self.context.flush() |
3014 | 356 | data, stat = yield self.client.get( | 355 | data, stat = yield self.client.get( |
3015 | 357 | self.get_unit_settings_path(self.wordpress_states)) | 356 | self.get_unit_settings_path(self.wordpress_states)) |
3016 | 358 | 357 | ||
3018 | 359 | self.assertEqual(yaml.load(data), | 358 | self.assertEqual(serializer.load(data), |
3019 | 360 | {"key": "secret"}) | 359 | {"key": "secret"}) |
3020 | 361 | self.assertEqual(changes, []) | 360 | self.assertEqual(changes, []) |
3021 | 362 | 361 | ||
3022 | @@ -378,7 +377,7 @@ | |||
3023 | 378 | 377 | ||
3024 | 379 | yield self.client.set( | 378 | yield self.client.set( |
3025 | 380 | self.get_unit_settings_path(self.wordpress_states), | 379 | self.get_unit_settings_path(self.wordpress_states), |
3027 | 381 | yaml.dump(data)) | 380 | serializer.dump(data)) |
3028 | 382 | 381 | ||
3029 | 383 | # On the context: | 382 | # On the context: |
3030 | 384 | # - add a new key | 383 | # - add a new key |
3031 | @@ -406,7 +405,7 @@ | |||
3032 | 406 | 405 | ||
3033 | 407 | yield self.client.set( | 406 | yield self.client.set( |
3034 | 408 | self.get_unit_settings_path(self.wordpress_states), | 407 | self.get_unit_settings_path(self.wordpress_states), |
3036 | 409 | yaml.dump(data)) | 408 | serializer.dump(data)) |
3037 | 410 | 409 | ||
3038 | 411 | changes = yield self.context.flush() | 410 | changes = yield self.context.flush() |
3039 | 412 | 411 | ||
3040 | @@ -414,7 +413,7 @@ | |||
3041 | 414 | self.get_unit_settings_path(self.wordpress_states)) | 413 | self.get_unit_settings_path(self.wordpress_states)) |
3042 | 415 | 414 | ||
3043 | 416 | self.assertEqual( | 415 | self.assertEqual( |
3045 | 417 | yaml.load(data), | 416 | serializer.load(data), |
3046 | 418 | {"port": 22, "host": "xe2.example.com", "db": 21, "home": "good", | 417 | {"port": 22, "host": "xe2.example.com", "db": 21, "home": "good", |
3047 | 419 | "tower": "rock", "zoo": "keeper"}) | 418 | "tower": "rock", "zoo": "keeper"}) |
3048 | 420 | self.assertEqual( | 419 | self.assertEqual( |
3049 | @@ -430,7 +429,7 @@ | |||
3050 | 430 | """We can set a value even if we have existing saved settings.""" | 429 | """We can set a value even if we have existing saved settings.""" |
3051 | 431 | yield self.client.set( | 430 | yield self.client.set( |
3052 | 432 | self.get_unit_settings_path(self.wordpress_states), | 431 | self.get_unit_settings_path(self.wordpress_states), |
3054 | 433 | yaml.dump({"key": "secret"})) | 432 | serializer.dump({"key": "secret"})) |
3055 | 434 | yield self.context.set_value("magic", "room") | 433 | yield self.context.set_value("magic", "room") |
3056 | 435 | value = yield self.context.get_value("wordpress/0", "key") | 434 | value = yield self.context.get_value("wordpress/0", "key") |
3057 | 436 | self.assertEqual(value, "secret") | 435 | self.assertEqual(value, "secret") |
3058 | @@ -675,7 +674,7 @@ | |||
3059 | 675 | def test_get_self(self): | 674 | def test_get_self(self): |
3060 | 676 | """Own settings can be retrieved.""" | 675 | """Own settings can be retrieved.""" |
3061 | 677 | self.client.set(self.get_unit_settings_path(self.wordpress_states), | 676 | self.client.set(self.get_unit_settings_path(self.wordpress_states), |
3063 | 678 | yaml.dump({"hello": "world"})) | 677 | serializer.dump({"hello": "world"})) |
3064 | 679 | data = yield self.context.get(None) | 678 | data = yield self.context.get(None) |
3065 | 680 | self.assertEquals(data, {"hello": "world"}) | 679 | self.assertEquals(data, {"hello": "world"}) |
3066 | 681 | 680 | ||
3067 | @@ -683,7 +682,7 @@ | |||
3068 | 683 | def test_get_self_by_name(self): | 682 | def test_get_self_by_name(self): |
3069 | 684 | """Own settings can be retrieved by name.""" | 683 | """Own settings can be retrieved by name.""" |
3070 | 685 | self.client.set(self.get_unit_settings_path(self.wordpress_states), | 684 | self.client.set(self.get_unit_settings_path(self.wordpress_states), |
3072 | 686 | yaml.dump({"hello": "world"})) | 685 | serializer.dump({"hello": "world"})) |
3073 | 687 | data = yield self.context.get("wordpress/0") | 686 | data = yield self.context.get("wordpress/0") |
3074 | 688 | self.assertEquals(data, {"hello": "world"}) | 687 | self.assertEquals(data, {"hello": "world"}) |
3075 | 689 | 688 | ||
3076 | @@ -699,7 +698,7 @@ | |||
3077 | 699 | def test_get_value_self(self): | 698 | def test_get_value_self(self): |
3078 | 700 | """Own settings can be retrieved.""" | 699 | """Own settings can be retrieved.""" |
3079 | 701 | self.client.set(self.get_unit_settings_path(self.wordpress_states), | 700 | self.client.set(self.get_unit_settings_path(self.wordpress_states), |
3081 | 702 | yaml.dump({"hello": "world"})) | 701 | serializer.dump({"hello": "world"})) |
3082 | 703 | self.assertEquals( | 702 | self.assertEquals( |
3083 | 704 | (yield self.context.get_value("wordpress/0", "hello")), "world") | 703 | (yield self.context.get_value("wordpress/0", "hello")), "world") |
3084 | 705 | self.assertEquals( | 704 | self.assertEquals( |
3085 | @@ -847,7 +846,7 @@ | |||
3086 | 847 | self.unit, | 846 | self.unit, |
3087 | 848 | self.container_unit) | 847 | self.container_unit) |
3088 | 849 | self.client.set(settings_path, | 848 | self.client.set(settings_path, |
3090 | 850 | yaml.dump({"hello": "world"})) | 849 | serializer.dump({"hello": "world"})) |
3091 | 851 | data = yield self.context.get(None) | 850 | data = yield self.context.get(None) |
3092 | 852 | self.assertEquals(data, {"hello": "world"}) | 851 | self.assertEquals(data, {"hello": "world"}) |
3093 | 853 | 852 | ||
3094 | 854 | 853 | ||
3095 | === modified file 'juju/state/tests/test_machine.py' | |||
3096 | --- juju/state/tests/test_machine.py 2012-03-28 00:38:16 +0000 | |||
3097 | +++ juju/state/tests/test_machine.py 2012-09-15 19:26:18 +0000 | |||
3098 | @@ -1,11 +1,10 @@ | |||
3099 | 1 | import functools | 1 | import functools |
3100 | 2 | 2 | ||
3101 | 3 | import yaml | ||
3102 | 4 | |||
3103 | 5 | from twisted.internet.defer import inlineCallbacks, Deferred, returnValue | 3 | from twisted.internet.defer import inlineCallbacks, Deferred, returnValue |
3104 | 6 | 4 | ||
3105 | 7 | from juju.charm.tests import local_charm_id | 5 | from juju.charm.tests import local_charm_id |
3106 | 8 | from juju.errors import ConstraintError | 6 | from juju.errors import ConstraintError |
3107 | 7 | from juju.lib import serializer | ||
3108 | 9 | from juju.machine.tests.test_constraints import ( | 8 | from juju.machine.tests.test_constraints import ( |
3109 | 10 | dummy_constraints, series_constraints) | 9 | dummy_constraints, series_constraints) |
3110 | 11 | from juju.state.charm import CharmStateManager | 10 | from juju.state.charm import CharmStateManager |
3111 | @@ -237,7 +236,7 @@ | |||
3112 | 237 | 236 | ||
3113 | 238 | content, stat = yield self.client.get("/machines/machine-0000000000") | 237 | content, stat = yield self.client.get("/machines/machine-0000000000") |
3114 | 239 | self.assertEquals( | 238 | self.assertEquals( |
3116 | 240 | yaml.load(content)["provider-machine-id"], "custom-id") | 239 | serializer.load(content)["provider-machine-id"], "custom-id") |
3117 | 241 | 240 | ||
3118 | 242 | @inlineCallbacks | 241 | @inlineCallbacks |
3119 | 243 | def test_set_instance_id_preserves_existing_data(self): | 242 | def test_set_instance_id_preserves_existing_data(self): |
3120 | @@ -246,11 +245,11 @@ | |||
3121 | 246 | """ | 245 | """ |
3122 | 247 | machine_state = yield self.add_machine_state() | 246 | machine_state = yield self.add_machine_state() |
3123 | 248 | yield self.client.set("/machines/machine-0000000000", | 247 | yield self.client.set("/machines/machine-0000000000", |
3125 | 249 | yaml.dump({"foo": "bar"})) | 248 | serializer.dump({"foo": "bar"})) |
3126 | 250 | yield machine_state.set_instance_id("custom-id") | 249 | yield machine_state.set_instance_id("custom-id") |
3127 | 251 | 250 | ||
3128 | 252 | content, stat = yield self.client.get("/machines/machine-0000000000") | 251 | content, stat = yield self.client.get("/machines/machine-0000000000") |
3130 | 253 | self.assertEquals(yaml.load(content), | 252 | self.assertEquals(serializer.load(content), |
3131 | 254 | {"provider-machine-id": "custom-id", | 253 | {"provider-machine-id": "custom-id", |
3132 | 255 | "foo": "bar"}) | 254 | "foo": "bar"}) |
3133 | 256 | 255 | ||
3134 | @@ -299,7 +298,7 @@ | |||
3135 | 299 | """ | 298 | """ |
3136 | 300 | machine_state = yield self.add_machine_state() | 299 | machine_state = yield self.add_machine_state() |
3137 | 301 | yield self.client.set("/machines/machine-0000000000", | 300 | yield self.client.set("/machines/machine-0000000000", |
3139 | 302 | yaml.dump({"foo": "bar"})) | 301 | serializer.dump({"foo": "bar"})) |
3140 | 303 | 302 | ||
3141 | 304 | instance_id = yield machine_state.get_instance_id() | 303 | instance_id = yield machine_state.get_instance_id() |
3142 | 305 | self.assertEquals(instance_id, None) | 304 | self.assertEquals(instance_id, None) |
3143 | 306 | 305 | ||
3144 | === modified file 'juju/state/tests/test_relation.py' | |||
3145 | --- juju/state/tests/test_relation.py 2012-06-01 22:50:44 +0000 | |||
3146 | +++ juju/state/tests/test_relation.py 2012-09-15 19:26:18 +0000 | |||
3147 | @@ -2,15 +2,14 @@ | |||
3148 | 2 | import os | 2 | import os |
3149 | 3 | import time | 3 | import time |
3150 | 4 | 4 | ||
3151 | 5 | import yaml | ||
3152 | 6 | import zookeeper | 5 | import zookeeper |
3153 | 7 | 6 | ||
3154 | 8 | |||
3155 | 9 | from twisted.internet.defer import ( | 7 | from twisted.internet.defer import ( |
3156 | 10 | inlineCallbacks, returnValue, Deferred, fail, succeed) | 8 | inlineCallbacks, returnValue, Deferred, fail, succeed) |
3157 | 11 | 9 | ||
3158 | 12 | from juju.charm.directory import CharmDirectory | 10 | from juju.charm.directory import CharmDirectory |
3159 | 13 | from juju.charm.tests import local_charm_id | 11 | from juju.charm.tests import local_charm_id |
3160 | 12 | from juju.lib import serializer | ||
3161 | 14 | from juju.machine.tests.test_constraints import dummy_constraints | 13 | from juju.machine.tests.test_constraints import dummy_constraints |
3162 | 15 | from juju.charm.tests.test_metadata import test_repository_path | 14 | from juju.charm.tests.test_metadata import test_repository_path |
3163 | 16 | from juju.charm.tests.test_repository import unbundled_repository | 15 | from juju.charm.tests.test_repository import unbundled_repository |
3164 | @@ -803,14 +802,14 @@ | |||
3165 | 803 | # Verify the unit mapping | 802 | # Verify the unit mapping |
3166 | 804 | unit_map_data, stat = yield self.client.get("/relations/%s" % ( | 803 | unit_map_data, stat = yield self.client.get("/relations/%s" % ( |
3167 | 805 | self.relation_state.internal_id)) | 804 | self.relation_state.internal_id)) |
3169 | 806 | unit_map = yaml.load(unit_map_data) | 805 | unit_map = serializer.load(unit_map_data) |
3170 | 807 | self.assertEqual( | 806 | self.assertEqual( |
3171 | 808 | unit_map, | 807 | unit_map, |
3172 | 809 | {unit_state.internal_id: unit_state.unit_name}) | 808 | {unit_state.internal_id: unit_state.unit_name}) |
3173 | 810 | 809 | ||
3174 | 811 | content, stat = yield self.client.get(settings_path) | 810 | content, stat = yield self.client.get(settings_path) |
3175 | 812 | self.assertEqual( | 811 | self.assertEqual( |
3177 | 813 | yaml.load(content), {"private-address": "foobar.local"}) | 812 | serializer.load(content), {"private-address": "foobar.local"}) |
3178 | 814 | 813 | ||
3179 | 815 | @inlineCallbacks | 814 | @inlineCallbacks |
3180 | 816 | def test_add_unit_state_scope_container_relation(self): | 815 | def test_add_unit_state_scope_container_relation(self): |
3181 | @@ -930,7 +929,7 @@ | |||
3182 | 930 | unit_state.internal_id) | 929 | unit_state.internal_id) |
3183 | 931 | 930 | ||
3184 | 932 | data = {"hello": "world", "private-address": "foobar.local"} | 931 | data = {"hello": "world", "private-address": "foobar.local"} |
3186 | 933 | yield self.client.create(settings_path, yaml.dump(data)) | 932 | yield self.client.create(settings_path, serializer.dump(data)) |
3187 | 934 | 933 | ||
3188 | 935 | yield unit_state.set_private_address("northwest.local") | 934 | yield unit_state.set_private_address("northwest.local") |
3189 | 936 | yield self.service1_relation.add_unit_state(unit_state) | 935 | yield self.service1_relation.add_unit_state(unit_state) |
3190 | @@ -939,11 +938,11 @@ | |||
3191 | 939 | 938 | ||
3192 | 940 | # The unit address has been updated to current | 939 | # The unit address has been updated to current |
3193 | 941 | data["private-address"] = "northwest.local" | 940 | data["private-address"] = "northwest.local" |
3195 | 942 | self.assertEqual(node_data, yaml.dump(data)) | 941 | self.assertEqual(node_data, serializer.dump(data)) |
3196 | 943 | 942 | ||
3197 | 944 | data, stat = yield self.client.get( | 943 | data, stat = yield self.client.get( |
3198 | 945 | "/relations/%s" % self.relation_state.internal_id) | 944 | "/relations/%s" % self.relation_state.internal_id) |
3200 | 946 | unit_map = yaml.load(data) | 945 | unit_map = serializer.load(data) |
3201 | 947 | self.assertEqual(unit_map, | 946 | self.assertEqual(unit_map, |
3202 | 948 | {unit_state.internal_id: unit_state.unit_name}) | 947 | {unit_state.internal_id: unit_state.unit_name}) |
3203 | 949 | 948 | ||
3204 | @@ -1094,13 +1093,14 @@ | |||
3205 | 1094 | unit_relation = states["unit_relation"] | 1093 | unit_relation = states["unit_relation"] |
3206 | 1095 | 1094 | ||
3207 | 1096 | data = yield unit_relation.get_data() | 1095 | data = yield unit_relation.get_data() |
3209 | 1097 | self.assertEqual(yaml.load(data), {"private-address": None}) | 1096 | self.assertEqual(serializer.load(data), {"private-address": None}) |
3210 | 1098 | 1097 | ||
3211 | 1099 | unit_relation_path = self.get_unit_settings_path(states) | 1098 | unit_relation_path = self.get_unit_settings_path(states) |
3213 | 1100 | self.client.set(unit_relation_path, yaml.dump(dict(hello="world"))) | 1099 | self.client.set( |
3214 | 1100 | unit_relation_path, serializer.dump(dict(hello="world"))) | ||
3215 | 1101 | 1101 | ||
3216 | 1102 | data = yield unit_relation.get_data() | 1102 | data = yield unit_relation.get_data() |
3218 | 1103 | self.assertEqual(data, yaml.dump(dict(hello="world"))) | 1103 | self.assertEqual(data, serializer.dump(dict(hello="world"))) |
3219 | 1104 | 1104 | ||
3220 | 1105 | @inlineCallbacks | 1105 | @inlineCallbacks |
3221 | 1106 | def test_set_data(self): | 1106 | def test_set_data(self): |
3222 | @@ -1109,7 +1109,7 @@ | |||
3223 | 1109 | unit_relation_path = self.get_unit_settings_path(states) | 1109 | unit_relation_path = self.get_unit_settings_path(states) |
3224 | 1110 | yield unit_relation.set_data(dict(hello="world")) | 1110 | yield unit_relation.set_data(dict(hello="world")) |
3225 | 1111 | data, stat = yield self.client.get(unit_relation_path) | 1111 | data, stat = yield self.client.get(unit_relation_path) |
3227 | 1112 | self.assertEqual(data, yaml.dump(dict(hello="world"))) | 1112 | self.assertEqual(data, serializer.dump(dict(hello="world"))) |
3228 | 1113 | 1113 | ||
3229 | 1114 | @inlineCallbacks | 1114 | @inlineCallbacks |
3230 | 1115 | def test_get_relation_role(self): | 1115 | def test_get_relation_role(self): |
3231 | @@ -1137,7 +1137,7 @@ | |||
3232 | 1137 | yield self.service_manager.remove_service_state(states["service"]) | 1137 | yield self.service_manager.remove_service_state(states["service"]) |
3233 | 1138 | yield self.assertFailure( | 1138 | yield self.assertFailure( |
3234 | 1139 | states["unit_relation"].get_relation_role(), StateChanged) | 1139 | states["unit_relation"].get_relation_role(), StateChanged) |
3236 | 1140 | 1140 | ||
3237 | 1141 | @inlineCallbacks | 1141 | @inlineCallbacks |
3238 | 1142 | def test_get_related_unit_container(self): | 1142 | def test_get_related_unit_container(self): |
3239 | 1143 | """Retrieve the container path of the related units.""" | 1143 | """Retrieve the container path of the related units.""" |
3240 | 1144 | 1144 | ||
3241 | === modified file 'juju/state/tests/test_security.py' | |||
3242 | --- juju/state/tests/test_security.py 2012-02-22 09:23:16 +0000 | |||
3243 | +++ juju/state/tests/test_security.py 2012-09-15 19:26:18 +0000 | |||
3244 | @@ -1,5 +1,4 @@ | |||
3245 | 1 | import base64 | 1 | import base64 |
3246 | 2 | import yaml | ||
3247 | 3 | import zookeeper | 2 | import zookeeper |
3248 | 4 | 3 | ||
3249 | 5 | from twisted.internet.defer import inlineCallbacks, succeed | 4 | from twisted.internet.defer import inlineCallbacks, succeed |
3250 | @@ -11,6 +10,7 @@ | |||
3251 | 11 | ACL, Principal, GroupPrincipal, OTPPrincipal, TokenDatabase, | 10 | ACL, Principal, GroupPrincipal, OTPPrincipal, TokenDatabase, |
3252 | 12 | SecurityPolicy, SecurityPolicyConnection) | 11 | SecurityPolicy, SecurityPolicyConnection) |
3253 | 13 | 12 | ||
3254 | 13 | from juju.lib import serializer | ||
3255 | 14 | from juju.lib.testing import TestCase | 14 | from juju.lib.testing import TestCase |
3256 | 15 | from juju.tests.common import get_test_zookeeper_address | 15 | from juju.tests.common import get_test_zookeeper_address |
3257 | 16 | 16 | ||
3258 | @@ -230,7 +230,7 @@ | |||
3259 | 230 | 230 | ||
3260 | 231 | data, stat = yield self.client.get(otp_path) | 231 | data, stat = yield self.client.get(otp_path) |
3261 | 232 | 232 | ||
3263 | 233 | credentials = yaml.load(data) | 233 | credentials = serializer.load(data) |
3264 | 234 | self.assertEqual(credentials["name"], "foobar") | 234 | self.assertEqual(credentials["name"], "foobar") |
3265 | 235 | self.assertEqual(credentials["password"], "secret") | 235 | self.assertEqual(credentials["password"], "secret") |
3266 | 236 | 236 | ||
3267 | @@ -291,7 +291,7 @@ | |||
3268 | 291 | principal = Principal("zebra", "zoo") | 291 | principal = Principal("zebra", "zoo") |
3269 | 292 | yield self.db.add(principal) | 292 | yield self.db.add(principal) |
3270 | 293 | content, stat = yield self.client.get("/token-test") | 293 | content, stat = yield self.client.get("/token-test") |
3272 | 294 | data = yaml.load(content) | 294 | data = serializer.load(content) |
3273 | 295 | self.assertEqual(data, {"zebra": principal.get_token()}) | 295 | self.assertEqual(data, {"zebra": principal.get_token()}) |
3274 | 296 | 296 | ||
3275 | 297 | @inlineCallbacks | 297 | @inlineCallbacks |
3276 | @@ -300,7 +300,7 @@ | |||
3277 | 300 | yield self.db.add(principal) | 300 | yield self.db.add(principal) |
3278 | 301 | yield self.db.remove(principal) | 301 | yield self.db.remove(principal) |
3279 | 302 | content, stat = yield self.client.get("/token-test") | 302 | content, stat = yield self.client.get("/token-test") |
3281 | 303 | data = yaml.load(content) | 303 | data = serializer.load(content) |
3282 | 304 | self.assertEqual(data, {"zebra": principal.get_token()}) | 304 | self.assertEqual(data, {"zebra": principal.get_token()}) |
3283 | 305 | 305 | ||
3284 | 306 | @inlineCallbacks | 306 | @inlineCallbacks |
3285 | 307 | 307 | ||
3286 | === modified file 'juju/state/tests/test_service.py' | |||
3287 | --- juju/state/tests/test_service.py 2012-07-03 07:30:53 +0000 | |||
3288 | +++ juju/state/tests/test_service.py 2012-09-15 19:26:18 +0000 | |||
3289 | @@ -1,7 +1,6 @@ | |||
3290 | 1 | import os | 1 | import os |
3291 | 2 | import shutil | 2 | import shutil |
3292 | 3 | 3 | ||
3293 | 4 | import yaml | ||
3294 | 5 | import zookeeper | 4 | import zookeeper |
3295 | 6 | 5 | ||
3296 | 7 | from twisted.internet.defer import inlineCallbacks, Deferred, returnValue | 6 | from twisted.internet.defer import inlineCallbacks, Deferred, returnValue |
3297 | @@ -10,6 +9,7 @@ | |||
3298 | 10 | from juju.charm.directory import CharmDirectory | 9 | from juju.charm.directory import CharmDirectory |
3299 | 11 | from juju.charm.tests import local_charm_id | 10 | from juju.charm.tests import local_charm_id |
3300 | 12 | from juju.charm.tests.test_metadata import test_repository_path | 11 | from juju.charm.tests.test_metadata import test_repository_path |
3301 | 12 | from juju.lib import serializer | ||
3302 | 13 | from juju.machine.tests.test_constraints import ( | 13 | from juju.machine.tests.test_constraints import ( |
3303 | 14 | dummy_constraints, dummy_cs, series_constraints) | 14 | dummy_constraints, dummy_cs, series_constraints) |
3304 | 15 | from juju.lib.pick import pick_attr | 15 | from juju.lib.pick import pick_attr |
3305 | @@ -178,7 +178,7 @@ | |||
3306 | 178 | "service-0000000000", "service-0000000001"]) | 178 | "service-0000000000", "service-0000000001"]) |
3307 | 179 | 179 | ||
3308 | 180 | content, stat = yield self.client.get("/services/service-0000000000") | 180 | content, stat = yield self.client.get("/services/service-0000000000") |
3310 | 181 | details = yaml.load(content) | 181 | details = serializer.load(content) |
3311 | 182 | self.assertTrue(details) | 182 | self.assertTrue(details) |
3312 | 183 | self.assertEquals(details.get("charm"), "local:series/dummy-1") | 183 | self.assertEquals(details.get("charm"), "local:series/dummy-1") |
3313 | 184 | self.assertFalse(isinstance(details.get("charm"), unicode)) | 184 | self.assertFalse(isinstance(details.get("charm"), unicode)) |
3314 | @@ -513,7 +513,7 @@ | |||
3315 | 513 | # role path | 513 | # role path |
3316 | 514 | content, stat = yield self.client.get(role_path) | 514 | content, stat = yield self.client.get(role_path) |
3317 | 515 | self.assertTrue(stat) | 515 | self.assertTrue(stat) |
3319 | 516 | node_info = yaml.load(content) | 516 | node_info = serializer.load(content) |
3320 | 517 | 517 | ||
3321 | 518 | self.assertEqual( | 518 | self.assertEqual( |
3322 | 519 | node_info["name"], | 519 | node_info["name"], |
3323 | @@ -527,7 +527,7 @@ | |||
3324 | 527 | unit_state.internal_id | 527 | unit_state.internal_id |
3325 | 528 | content, stat = yield self.client.get(settings_path) | 528 | content, stat = yield self.client.get(settings_path) |
3326 | 529 | self.assertTrue(stat) | 529 | self.assertTrue(stat) |
3328 | 530 | settings_info = yaml.load(content) | 530 | settings_info = serializer.load(content) |
3329 | 531 | 531 | ||
3330 | 532 | # Verify that private address was set | 532 | # Verify that private address was set |
3331 | 533 | # we verify the content elsewhere | 533 | # we verify the content elsewhere |
3332 | @@ -1383,7 +1383,7 @@ | |||
3333 | 1383 | self.assertIdentical(enabled, True) | 1383 | self.assertIdentical(enabled, True) |
3334 | 1384 | content, stat = yield self.client.get( | 1384 | content, stat = yield self.client.get( |
3335 | 1385 | "/units/%s/debug" % unit_state.internal_id) | 1385 | "/units/%s/debug" % unit_state.internal_id) |
3337 | 1386 | data = yaml.load(content) | 1386 | data = serializer.load(content) |
3338 | 1387 | self.assertEqual(data, {"debug_hooks": ["*"]}) | 1387 | self.assertEqual(data, {"debug_hooks": ["*"]}) |
3339 | 1388 | 1388 | ||
3340 | 1389 | @inlineCallbacks | 1389 | @inlineCallbacks |
3341 | @@ -1396,7 +1396,7 @@ | |||
3342 | 1396 | self.assertIdentical(enabled, True) | 1396 | self.assertIdentical(enabled, True) |
3343 | 1397 | content, stat = yield self.client.get( | 1397 | content, stat = yield self.client.get( |
3344 | 1398 | "/units/%s/debug" % unit_state.internal_id) | 1398 | "/units/%s/debug" % unit_state.internal_id) |
3346 | 1399 | data = yaml.load(content) | 1399 | data = serializer.load(content) |
3347 | 1400 | self.assertEqual(data, {"debug_hooks": | 1400 | self.assertEqual(data, {"debug_hooks": |
3348 | 1401 | ["db-relation-broken", "db-relation-changed"]}) | 1401 | ["db-relation-broken", "db-relation-changed"]}) |
3349 | 1402 | 1402 | ||
3350 | @@ -1434,7 +1434,7 @@ | |||
3351 | 1434 | self.assertIdentical(enabled, True) | 1434 | self.assertIdentical(enabled, True) |
3352 | 1435 | content, stat = yield self.client.get( | 1435 | content, stat = yield self.client.get( |
3353 | 1436 | "/units/%s/debug" % unit_state.internal_id) | 1436 | "/units/%s/debug" % unit_state.internal_id) |
3355 | 1437 | data = yaml.load(content) | 1437 | data = serializer.load(content) |
3356 | 1438 | self.assertEqual(data, {"debug_hooks": ["db-relation-changed"]}) | 1438 | self.assertEqual(data, {"debug_hooks": ["db-relation-changed"]}) |
3357 | 1439 | 1439 | ||
3358 | 1440 | @inlineCallbacks | 1440 | @inlineCallbacks |
3359 | @@ -2495,7 +2495,7 @@ | |||
3360 | 2495 | # The default was never written to storage. | 2495 | # The default was never written to storage. |
3361 | 2496 | data, stat = yield self.client.get( | 2496 | data, stat = yield self.client.get( |
3362 | 2497 | "/services/%s/config" % wordpress.internal_id) | 2497 | "/services/%s/config" % wordpress.internal_id) |
3364 | 2498 | self.assertEqual(yaml.load(data), {"foo": "bar"}) | 2498 | self.assertEqual(serializer.load(data), {"foo": "bar"}) |
3365 | 2499 | 2499 | ||
3366 | 2500 | @inlineCallbacks | 2500 | @inlineCallbacks |
3367 | 2501 | def test_get_charm_state(self): | 2501 | def test_get_charm_state(self): |
3368 | @@ -2761,20 +2761,20 @@ | |||
3369 | 2761 | yield unit_state.open_port(80, "tcp") | 2761 | yield unit_state.open_port(80, "tcp") |
3370 | 2762 | content, stat = yield self.client.get(ports_path) | 2762 | content, stat = yield self.client.get(ports_path) |
3371 | 2763 | self.assertEquals( | 2763 | self.assertEquals( |
3373 | 2764 | yaml.load(content), | 2764 | serializer.load(content), |
3374 | 2765 | {"open": [{"port": 80, "proto": "tcp"}]}) | 2765 | {"open": [{"port": 80, "proto": "tcp"}]}) |
3375 | 2766 | 2766 | ||
3376 | 2767 | yield unit_state.open_port(53, "udp") | 2767 | yield unit_state.open_port(53, "udp") |
3377 | 2768 | content, stat = yield self.client.get(ports_path) | 2768 | content, stat = yield self.client.get(ports_path) |
3378 | 2769 | self.assertEquals( | 2769 | self.assertEquals( |
3380 | 2770 | yaml.load(content), | 2770 | serializer.load(content), |
3381 | 2771 | {"open": [{"port": 80, "proto": "tcp"}, | 2771 | {"open": [{"port": 80, "proto": "tcp"}, |
3382 | 2772 | {"port": 53, "proto": "udp"}]}) | 2772 | {"port": 53, "proto": "udp"}]}) |
3383 | 2773 | 2773 | ||
3384 | 2774 | yield unit_state.open_port(443, "tcp") | 2774 | yield unit_state.open_port(443, "tcp") |
3385 | 2775 | content, stat = yield self.client.get(ports_path) | 2775 | content, stat = yield self.client.get(ports_path) |
3386 | 2776 | self.assertEquals( | 2776 | self.assertEquals( |
3388 | 2777 | yaml.load(content), | 2777 | serializer.load(content), |
3389 | 2778 | {"open": [{"port": 80, "proto": "tcp"}, | 2778 | {"open": [{"port": 80, "proto": "tcp"}, |
3390 | 2779 | {"port": 53, "proto": "udp"}, | 2779 | {"port": 53, "proto": "udp"}, |
3391 | 2780 | {"port": 443, "proto": "tcp"}]}) | 2780 | {"port": 443, "proto": "tcp"}]}) |
3392 | @@ -2782,7 +2782,7 @@ | |||
3393 | 2782 | yield unit_state.close_port(80, "tcp") | 2782 | yield unit_state.close_port(80, "tcp") |
3394 | 2783 | content, stat = yield self.client.get(ports_path) | 2783 | content, stat = yield self.client.get(ports_path) |
3395 | 2784 | self.assertEquals( | 2784 | self.assertEquals( |
3397 | 2785 | yaml.load(content), | 2785 | serializer.load(content), |
3398 | 2786 | {"open": [{"port": 53, "proto": "udp"}, | 2786 | {"open": [{"port": 53, "proto": "udp"}, |
3399 | 2787 | {"port": 443, "proto": "tcp"}]}) | 2787 | {"port": 443, "proto": "tcp"}]}) |
3400 | 2788 | 2788 | ||
3401 | 2789 | 2789 | ||
3402 | === modified file 'juju/state/tests/test_topology.py' | |||
3403 | --- juju/state/tests/test_topology.py 2012-04-12 18:39:20 +0000 | |||
3404 | +++ juju/state/tests/test_topology.py 2012-09-15 19:26:18 +0000 | |||
3405 | @@ -1,6 +1,5 @@ | |||
3406 | 1 | import yaml | ||
3407 | 2 | |||
3408 | 3 | from juju.errors import IncompatibleVersion | 1 | from juju.errors import IncompatibleVersion |
3409 | 2 | from juju.lib import serializer | ||
3410 | 4 | from juju.lib.testing import TestCase | 3 | from juju.lib.testing import TestCase |
3411 | 5 | from juju.state.endpoint import RelationEndpoint | 4 | from juju.state.endpoint import RelationEndpoint |
3412 | 6 | from juju.state.topology import ( | 5 | from juju.state.topology import ( |
3413 | @@ -891,7 +890,7 @@ | |||
3414 | 891 | loaded back. | 890 | loaded back. |
3415 | 892 | """ | 891 | """ |
3416 | 893 | empty_data = self.topology.dump() | 892 | empty_data = self.topology.dump() |
3418 | 894 | self.assertEquals(yaml.load(empty_data), {"version": VERSION}) | 893 | self.assertEquals(serializer.load(empty_data), {"version": VERSION}) |
3419 | 895 | self.topology.add_machine("m-0") | 894 | self.topology.add_machine("m-0") |
3420 | 896 | machine_data = self.topology.dump() | 895 | machine_data = self.topology.dump() |
3421 | 897 | self.topology.parse(empty_data) | 896 | self.topology.parse(empty_data) |
3422 | @@ -902,7 +901,7 @@ | |||
3423 | 902 | def test_incompatible_version(self): | 901 | def test_incompatible_version(self): |
3424 | 903 | """Verify `IncompatibleVersion` raised if using old topology.""" | 902 | """Verify `IncompatibleVersion` raised if using old topology.""" |
3425 | 904 | empty_data = self.topology.dump() | 903 | empty_data = self.topology.dump() |
3427 | 905 | self.assertEquals(yaml.load(empty_data), {"version": VERSION}) | 904 | self.assertEquals(serializer.load(empty_data), {"version": VERSION}) |
3428 | 906 | self.topology.add_machine("m-0") | 905 | self.topology.add_machine("m-0") |
3429 | 907 | machine_data = self.topology.dump() | 906 | machine_data = self.topology.dump() |
3430 | 908 | self.topology.parse(machine_data) | 907 | self.topology.parse(machine_data) |
3431 | @@ -1265,62 +1264,3 @@ | |||
3432 | 1265 | "r-0", "s-0", "riak", "peer") | 1264 | "r-0", "s-0", "riak", "peer") |
3433 | 1266 | self.assertEqual(self.topology.get_relation_between_endpoints( | 1265 | self.assertEqual(self.topology.get_relation_between_endpoints( |
3434 | 1267 | [riak_ep]), "r-0") | 1266 | [riak_ep]), "r-0") |
3435 | 1268 | |||
3436 | 1269 | |||
3437 | 1270 | # Topology migration tests use these. defined at global scope to ease | ||
3438 | 1271 | # string formatting | ||
3439 | 1272 | |||
3440 | 1273 | TOPOLOGY_V1 = """ | ||
3441 | 1274 | relations: | ||
3442 | 1275 | relation-0000000000: | ||
3443 | 1276 | - mysql | ||
3444 | 1277 | - service-0000000000: {name: db, role: client} | ||
3445 | 1278 | service-0000000001: {name: server, role: server} | ||
3446 | 1279 | version: 1 | ||
3447 | 1280 | """ | ||
3448 | 1281 | |||
3449 | 1282 | TOPOLOGY_V2_EXPECTED = """ | ||
3450 | 1283 | relations: | ||
3451 | 1284 | interface: mysql | ||
3452 | 1285 | relation-0000000000: {} | ||
3453 | 1286 | scope: global | ||
3454 | 1287 | services: | ||
3455 | 1288 | service-0000000000: {name: db, role: client} | ||
3456 | 1289 | service-0000000001: {name: server, role: server} | ||
3457 | 1290 | version: 2 | ||
3458 | 1291 | """ | ||
3459 | 1292 | |||
3460 | 1293 | |||
3461 | 1294 | class TestMigrations(TestCase): | ||
3462 | 1295 | |||
3463 | 1296 | # DISABLED: We don't do transparent data migrations, till we | ||
3464 | 1297 | # have explicit juju core code upgrades, else older agents | ||
3465 | 1298 | # will die on new topology formats. | ||
3466 | 1299 | def xtest_migration_v1_to_v2(self): | ||
3467 | 1300 | """Parse a fragment of a version 1 topology | ||
3468 | 1301 | |||
3469 | 1302 | Ensure that a version 2 topology is emitted. | ||
3470 | 1303 | """ | ||
3471 | 1304 | topology = InternalTopology() | ||
3472 | 1305 | topology.parse(TOPOLOGY_V1) | ||
3473 | 1306 | self.assertEqual(topology.get_version(), 2) | ||
3474 | 1307 | self.assertEqual(topology.dump().strip(), | ||
3475 | 1308 | TOPOLOGY_V2_EXPECTED.strip()) | ||
3476 | 1309 | |||
3477 | 1310 | def test_migration_v1_to_unknown(self): | ||
3478 | 1311 | """Parse a fragment of a version 1 topology | ||
3479 | 1312 | |||
3480 | 1313 | Ensure that a version 2 topology is emitted. | ||
3481 | 1314 | """ | ||
3482 | 1315 | topology = InternalTopology() | ||
3483 | 1316 | |||
3484 | 1317 | actual_version = VERSION | ||
3485 | 1318 | import juju | ||
3486 | 1319 | self.patch(juju.state.topology, "VERSION", actual_version + 1) | ||
3487 | 1320 | |||
3488 | 1321 | ex = self.assertRaises(IncompatibleVersion, | ||
3489 | 1322 | topology.parse, TOPOLOGY_V1) | ||
3490 | 1323 | self.assertEqual( | ||
3491 | 1324 | str(ex), | ||
3492 | 1325 | "Incompatible juju protocol versions (found 1, want %d)" % ( | ||
3493 | 1326 | juju.state.topology.VERSION)) | ||
3494 | 1327 | 1267 | ||
3495 | === modified file 'juju/state/tests/test_utils.py' | |||
3496 | --- juju/state/tests/test_utils.py 2012-04-06 14:42:06 +0000 | |||
3497 | +++ juju/state/tests/test_utils.py 2012-09-15 19:26:18 +0000 | |||
3498 | @@ -8,8 +8,8 @@ | |||
3499 | 8 | from twisted.internet import reactor | 8 | from twisted.internet import reactor |
3500 | 9 | from twisted.internet.defer import inlineCallbacks | 9 | from twisted.internet.defer import inlineCallbacks |
3501 | 10 | from twisted.internet.threads import deferToThread | 10 | from twisted.internet.threads import deferToThread |
3502 | 11 | import yaml | ||
3503 | 12 | 11 | ||
3504 | 12 | from juju.lib import serializer | ||
3505 | 13 | from juju.lib.testing import TestCase | 13 | from juju.lib.testing import TestCase |
3506 | 14 | from juju.state.base import StateBase | 14 | from juju.state.base import StateBase |
3507 | 15 | from juju.state.errors import StateChanged, StateNotFound | 15 | from juju.state.errors import StateChanged, StateNotFound |
3508 | @@ -382,7 +382,7 @@ | |||
3509 | 382 | 382 | ||
3510 | 383 | # and a direct look at zk should work as well | 383 | # and a direct look at zk should work as well |
3511 | 384 | zk_data, stat = yield self.client.get(self.path) | 384 | zk_data, stat = yield self.client.get(self.path) |
3513 | 385 | zk_data = yaml.load(zk_data) | 385 | zk_data = serializer.load(zk_data) |
3514 | 386 | self.assertEqual(zk_data, options) | 386 | self.assertEqual(zk_data, options) |
3515 | 387 | 387 | ||
3516 | 388 | @inlineCallbacks | 388 | @inlineCallbacks |
3517 | @@ -465,7 +465,7 @@ | |||
3518 | 465 | 465 | ||
3519 | 466 | # and a direct look at zk should work as well | 466 | # and a direct look at zk should work as well |
3520 | 467 | zk_data, stat = yield self.client.get(self.path) | 467 | zk_data, stat = yield self.client.get(self.path) |
3522 | 468 | zk_data = yaml.load(zk_data) | 468 | zk_data = serializer.load(zk_data) |
3523 | 469 | self.assertEqual(zk_data, options) | 469 | self.assertEqual(zk_data, options) |
3524 | 470 | 470 | ||
3525 | 471 | @inlineCallbacks | 471 | @inlineCallbacks |
3526 | @@ -678,13 +678,14 @@ | |||
3527 | 678 | 678 | ||
3528 | 679 | @inlineCallbacks | 679 | @inlineCallbacks |
3529 | 680 | def test_get_missing(self): | 680 | def test_get_missing(self): |
3531 | 681 | yield self.client.create(self.path, yaml.dump({"foo": "bar"})) | 681 | yield self.client.create(self.path, serializer.dump({"foo": "bar"})) |
3532 | 682 | mixee = TestMixee(self.client, self.path) | 682 | mixee = TestMixee(self.client, self.path) |
3533 | 683 | self.assertEquals((yield mixee.get()), None) | 683 | self.assertEquals((yield mixee.get()), None) |
3534 | 684 | 684 | ||
3535 | 685 | @inlineCallbacks | 685 | @inlineCallbacks |
3536 | 686 | def test_get_exists(self): | 686 | def test_get_exists(self): |
3538 | 687 | yield self.client.create(self.path, yaml.dump({"key": "butterfly"})) | 687 | yield self.client.create( |
3539 | 688 | self.path, serializer.dump({"key": "butterfly"})) | ||
3540 | 688 | mixee = TestMixee(self.client, self.path) | 689 | mixee = TestMixee(self.client, self.path) |
3541 | 689 | self.assertEquals((yield mixee.get()), "butterfly") | 690 | self.assertEquals((yield mixee.get()), "butterfly") |
3542 | 690 | 691 | ||
3543 | @@ -694,13 +695,14 @@ | |||
3544 | 694 | mixee = TestMixee(self.client, self.path) | 695 | mixee = TestMixee(self.client, self.path) |
3545 | 695 | yield mixee.set("caterpillar") | 696 | yield mixee.set("caterpillar") |
3546 | 696 | content, _ = yield self.client.get(self.path) | 697 | content, _ = yield self.client.get(self.path) |
3548 | 697 | self.assertEquals(yaml.load(content), {"key": "caterpillar"}) | 698 | self.assertEquals(serializer.load(content), {"key": "caterpillar"}) |
3549 | 698 | 699 | ||
3550 | 699 | @inlineCallbacks | 700 | @inlineCallbacks |
3551 | 700 | def test_set_safely(self): | 701 | def test_set_safely(self): |
3553 | 701 | yield self.client.create(self.path, yaml.dump({"foo": "bar"})) | 702 | yield self.client.create(self.path, serializer.dump({"foo": "bar"})) |
3554 | 702 | mixee = TestMixee(self.client, self.path) | 703 | mixee = TestMixee(self.client, self.path) |
3555 | 703 | yield mixee.set("cocoon") | 704 | yield mixee.set("cocoon") |
3556 | 704 | content, _ = yield self.client.get(self.path) | 705 | content, _ = yield self.client.get(self.path) |
3558 | 705 | self.assertEquals(yaml.load(content), {"foo": "bar", "key": "cocoon"}) | 706 | self.assertEquals( |
3559 | 707 | serializer.load(content), {"foo": "bar", "key": "cocoon"}) | ||
3560 | 706 | 708 | ||
3561 | 707 | 709 | ||
3562 | === modified file 'juju/state/topology.py' | |||
3563 | --- juju/state/topology.py 2012-04-12 18:39:20 +0000 | |||
3564 | +++ juju/state/topology.py 2012-09-15 19:26:18 +0000 | |||
3565 | @@ -1,7 +1,7 @@ | |||
3567 | 1 | import yaml | 1 | |
3568 | 2 | 2 | ||
3569 | 3 | from juju.errors import IncompatibleVersion | 3 | from juju.errors import IncompatibleVersion |
3571 | 4 | 4 | from juju.lib import serializer | |
3572 | 5 | 5 | ||
3573 | 6 | # The protocol version, which is stored in the /topology node under | 6 | # The protocol version, which is stored in the /topology node under |
3574 | 7 | # the "version" key. The protocol version should *only* be updated | 7 | # the "version" key. The protocol version should *only* be updated |
3575 | @@ -59,7 +59,7 @@ | |||
3576 | 59 | This string may be provided to the :method:`parse` to | 59 | This string may be provided to the :method:`parse` to |
3577 | 60 | reestablish the same topology state back. | 60 | reestablish the same topology state back. |
3578 | 61 | """ | 61 | """ |
3580 | 62 | return yaml.safe_dump(self._state) | 62 | return serializer.dump(self._state) |
3581 | 63 | 63 | ||
3582 | 64 | def parse(self, data): | 64 | def parse(self, data): |
3583 | 65 | """Parse the dumped data provided and restore internal state. | 65 | """Parse the dumped data provided and restore internal state. |
3584 | @@ -67,12 +67,11 @@ | |||
3585 | 67 | The provided data must necessarily have been retrieved by | 67 | The provided data must necessarily have been retrieved by |
3586 | 68 | calling the :method:`dump`. | 68 | calling the :method:`dump`. |
3587 | 69 | """ | 69 | """ |
3589 | 70 | parsed = yaml.load(data) | 70 | parsed = serializer.load(data) |
3590 | 71 | self._state = parsed | 71 | self._state = parsed |
3591 | 72 | version = self.get_version() | 72 | version = self.get_version() |
3592 | 73 | if version != VERSION: | 73 | if version != VERSION: |
3595 | 74 | # This will raise if it cannot update the topology. | 74 | raise IncompatibleVersion(version, VERSION) |
3594 | 75 | migrate_topology(self) | ||
3596 | 76 | 75 | ||
3597 | 77 | def get_version(self): | 76 | def get_version(self): |
3598 | 78 | return self._state.get("version", 0) | 77 | return self._state.get("version", 0) |
3599 | @@ -573,79 +572,3 @@ | |||
3600 | 573 | else: | 572 | else: |
3601 | 574 | return relation_id | 573 | return relation_id |
3602 | 575 | return None | 574 | return None |
3603 | 576 | |||
3604 | 577 | |||
3605 | 578 | def _migrate_version_1(topology): | ||
3606 | 579 | """Migrate topology version 1 to version 2. | ||
3607 | 580 | |||
3608 | 581 | This change includes the transition from:: | ||
3609 | 582 | |||
3610 | 583 | relations: | ||
3611 | 584 | relation-0000000000: | ||
3612 | 585 | - mysql | ||
3613 | 586 | - service-0000000000: {name: db, role: client} | ||
3614 | 587 | service-0000000001: {name: server, role: server} | ||
3615 | 588 | |||
3616 | 589 | to:: | ||
3617 | 590 | |||
3618 | 591 | relations | ||
3619 | 592 | relation-00000001: | ||
3620 | 593 | interface: name | ||
3621 | 594 | scope: name | ||
3622 | 595 | services: | ||
3623 | 596 | service-00000001: {name: name, role: role} | ||
3624 | 597 | service-00000002: {name: name, role: role} | ||
3625 | 598 | |||
3626 | 599 | for all relations. | ||
3627 | 600 | |||
3628 | 601 | """ | ||
3629 | 602 | version = topology.get_version() | ||
3630 | 603 | if version > 1: | ||
3631 | 604 | return topology | ||
3632 | 605 | elif version != 1: | ||
3633 | 606 | raise IncompatibleVersion(version, VERSION) | ||
3634 | 607 | |||
3635 | 608 | relations = topology._state.get("relations") | ||
3636 | 609 | if relations: | ||
3637 | 610 | new_relations = {} | ||
3638 | 611 | for relation, relation_data in relations.items(): | ||
3639 | 612 | new_relations[relation] = {} | ||
3640 | 613 | relation_type, relation_services = relation_data | ||
3641 | 614 | new_relations["interface"] = relation_type | ||
3642 | 615 | new_relations["scope"] = "global" | ||
3643 | 616 | new_relations["services"] = relation_services | ||
3644 | 617 | |||
3645 | 618 | topology._state["relations"] = new_relations | ||
3646 | 619 | |||
3647 | 620 | topology._state["version"] = 2 | ||
3648 | 621 | return topology | ||
3649 | 622 | |||
3650 | 623 | |||
3651 | 624 | # A dict of version migration plans for VERSION n (where n is the key) | ||
3652 | 625 | # to version n + 1. migrate_version will be called until the topology | ||
3653 | 626 | # version is equal to VERSION. If no migration plan exists FAIL | ||
3654 | 627 | _VERSION_MIGRATION = { | ||
3655 | 628 | |||
3656 | 629 | # DISABLED: We can't migrate the topology till we can migrate older | ||
3657 | 630 | # code currently running in the env that depends on a previous format. | ||
3658 | 631 | # 1: _migrate_version_1 | ||
3659 | 632 | } | ||
3660 | 633 | |||
3661 | 634 | |||
3662 | 635 | def migrate_topology(topology): | ||
3663 | 636 | """Migrate topology version to current. | ||
3664 | 637 | |||
3665 | 638 | Does an in-place (destructive) stepwise modification of topology | ||
3666 | 639 | state from its current version to the VERSION represented in this | ||
3667 | 640 | module. | ||
3668 | 641 | """ | ||
3669 | 642 | version = topology.get_version() | ||
3670 | 643 | if version == VERSION: | ||
3671 | 644 | return topology | ||
3672 | 645 | |||
3673 | 646 | current_version = version | ||
3674 | 647 | while current_version < VERSION: | ||
3675 | 648 | if current_version not in _VERSION_MIGRATION: | ||
3676 | 649 | raise IncompatibleVersion(version, VERSION) | ||
3677 | 650 | _VERSION_MIGRATION[current_version](topology) | ||
3678 | 651 | current_version = topology.get_version() | ||
3679 | 652 | 575 | ||
3680 | === modified file 'juju/state/utils.py' | |||
3681 | --- juju/state/utils.py 2012-03-09 13:24:58 +0000 | |||
3682 | +++ juju/state/utils.py 2012-09-15 19:26:18 +0000 | |||
3683 | @@ -7,9 +7,10 @@ | |||
3684 | 7 | from twisted.internet.defer import inlineCallbacks, returnValue | 7 | from twisted.internet.defer import inlineCallbacks, returnValue |
3685 | 8 | from twisted.internet.threads import deferToThread | 8 | from twisted.internet.threads import deferToThread |
3686 | 9 | from txzookeeper.utils import retry_change | 9 | from txzookeeper.utils import retry_change |
3688 | 10 | import yaml | 10 | |
3689 | 11 | import zookeeper | 11 | import zookeeper |
3690 | 12 | 12 | ||
3691 | 13 | from juju.lib import serializer | ||
3692 | 13 | from juju.state.errors import StateChanged | 14 | from juju.state.errors import StateChanged |
3693 | 14 | from juju.state.errors import StateNotFound | 15 | from juju.state.errors import StateNotFound |
3694 | 15 | 16 | ||
3695 | @@ -177,7 +178,7 @@ | |||
3696 | 177 | self._cache = {} | 178 | self._cache = {} |
3697 | 178 | try: | 179 | try: |
3698 | 179 | data, stat = yield self._client.get(self._path) | 180 | data, stat = yield self._client.get(self._path) |
3700 | 180 | data = yaml.load(data) | 181 | data = serializer.load(data) |
3701 | 181 | if data: | 182 | if data: |
3702 | 182 | self._pristine_cache = data | 183 | self._pristine_cache = data |
3703 | 183 | self._cache = data.copy() | 184 | self._cache = data.copy() |
3704 | @@ -228,7 +229,7 @@ | |||
3705 | 228 | def apply_changes(content, stat): | 229 | def apply_changes(content, stat): |
3706 | 229 | """Apply the local state to the Zookeeper node state.""" | 230 | """Apply the local state to the Zookeeper node state.""" |
3707 | 230 | del changes[:] | 231 | del changes[:] |
3709 | 231 | current = yaml.load(content) if content else {} | 232 | current = serializer.load(content) if content else {} |
3710 | 232 | missing = object() | 233 | missing = object() |
3711 | 233 | for key in set(pristine_cache).union(cache): | 234 | for key in set(pristine_cache).union(cache): |
3712 | 234 | old_value = pristine_cache.get(key, missing) | 235 | old_value = pristine_cache.get(key, missing) |
3713 | @@ -244,7 +245,7 @@ | |||
3714 | 244 | elif key in current: | 245 | elif key in current: |
3715 | 245 | del current[key] | 246 | del current[key] |
3716 | 246 | changes.append(DeletedItem(key, old_value)) | 247 | changes.append(DeletedItem(key, old_value)) |
3718 | 247 | return yaml.safe_dump(current) | 248 | return serializer.dump(current) |
3719 | 248 | 249 | ||
3720 | 249 | # Apply the change till it takes. | 250 | # Apply the change till it takes. |
3721 | 250 | yield retry_change(self._client, self._path, apply_changes) | 251 | yield retry_change(self._client, self._path, apply_changes) |
3722 | 251 | 252 | ||
3723 | === modified file 'juju/unit/lifecycle.py' | |||
3724 | --- juju/unit/lifecycle.py 2012-05-01 00:26:25 +0000 | |||
3725 | +++ juju/unit/lifecycle.py 2012-09-15 19:26:18 +0000 | |||
3726 | @@ -2,7 +2,6 @@ | |||
3727 | 2 | import logging | 2 | import logging |
3728 | 3 | import shutil | 3 | import shutil |
3729 | 4 | import tempfile | 4 | import tempfile |
3730 | 5 | import yaml | ||
3731 | 6 | 5 | ||
3732 | 7 | from twisted.internet.defer import ( | 6 | from twisted.internet.defer import ( |
3733 | 8 | inlineCallbacks, DeferredLock, DeferredList, returnValue) | 7 | inlineCallbacks, DeferredLock, DeferredList, returnValue) |
3734 | @@ -10,6 +9,7 @@ | |||
3735 | 10 | from juju.errors import CharmUpgradeError | 9 | from juju.errors import CharmUpgradeError |
3736 | 11 | from juju.hooks.invoker import Invoker | 10 | from juju.hooks.invoker import Invoker |
3737 | 12 | from juju.hooks.scheduler import HookScheduler | 11 | from juju.hooks.scheduler import HookScheduler |
3738 | 12 | from juju.lib import serializer | ||
3739 | 13 | from juju.state.hook import ( | 13 | from juju.state.hook import ( |
3740 | 14 | DepartedRelationHookContext, HookContext, RelationChange) | 14 | DepartedRelationHookContext, HookContext, RelationChange) |
3741 | 15 | from juju.state.errors import StopWatcher, UnitRelationStateNotFound | 15 | from juju.state.errors import StopWatcher, UnitRelationStateNotFound |
3742 | @@ -493,7 +493,7 @@ | |||
3743 | 493 | state_dict = {} | 493 | state_dict = {} |
3744 | 494 | for relation_wf in self._relations.itervalues(): | 494 | for relation_wf in self._relations.itervalues(): |
3745 | 495 | state_dict.update(relation_wf.get_relation_info()) | 495 | state_dict.update(relation_wf.get_relation_info()) |
3747 | 496 | state = yaml.dump(state_dict) | 496 | state = serializer.dump(state_dict) |
3748 | 497 | temp_path = self._known_relations_path + "~" | 497 | temp_path = self._known_relations_path + "~" |
3749 | 498 | 498 | ||
3750 | 499 | with open(temp_path, "w") as f: | 499 | with open(temp_path, "w") as f: |
3751 | @@ -519,7 +519,7 @@ | |||
3752 | 519 | relations_by_id = dict((r.internal_relation_id, r) for r in relations) | 519 | relations_by_id = dict((r.internal_relation_id, r) for r in relations) |
3753 | 520 | 520 | ||
3754 | 521 | with open(self._known_relations_path) as f: | 521 | with open(self._known_relations_path) as f: |
3756 | 522 | known_relations = yaml.load(f.read()) | 522 | known_relations = serializer.load(f.read()) |
3757 | 523 | 523 | ||
3758 | 524 | for relation_id, relation_info in known_relations.items(): | 524 | for relation_id, relation_info in known_relations.items(): |
3759 | 525 | if relation_id in relations_by_id: | 525 | if relation_id in relations_by_id: |
3760 | 526 | 526 | ||
3761 | === modified file 'juju/unit/tests/test_lifecycle.py' | |||
3762 | --- juju/unit/tests/test_lifecycle.py 2012-05-04 03:39:27 +0000 | |||
3763 | +++ juju/unit/tests/test_lifecycle.py 2012-09-15 19:26:18 +0000 | |||
3764 | @@ -6,7 +6,6 @@ | |||
3765 | 6 | import stat | 6 | import stat |
3766 | 7 | import sys | 7 | import sys |
3767 | 8 | 8 | ||
3768 | 9 | import yaml | ||
3769 | 10 | import zookeeper | 9 | import zookeeper |
3770 | 11 | 10 | ||
3771 | 12 | from twisted.internet.defer import (inlineCallbacks, Deferred, | 11 | from twisted.internet.defer import (inlineCallbacks, Deferred, |
3772 | @@ -20,6 +19,7 @@ | |||
3773 | 20 | from juju.errors import CharmInvocationError, CharmError, CharmUpgradeError | 19 | from juju.errors import CharmInvocationError, CharmError, CharmUpgradeError |
3774 | 21 | from juju.hooks.invoker import Invoker | 20 | from juju.hooks.invoker import Invoker |
3775 | 22 | from juju.hooks.executor import HookExecutor | 21 | from juju.hooks.executor import HookExecutor |
3776 | 22 | from juju.lib import serializer | ||
3777 | 23 | from juju.machine.tests.test_constraints import series_constraints | 23 | from juju.machine.tests.test_constraints import series_constraints |
3778 | 24 | 24 | ||
3779 | 25 | from juju.state.endpoint import RelationEndpoint | 25 | from juju.state.endpoint import RelationEndpoint |
3780 | @@ -1083,7 +1083,8 @@ | |||
3781 | 1083 | self.assertTrue(self.lifecycle.watching) | 1083 | self.assertTrue(self.lifecycle.watching) |
3782 | 1084 | self.assertFalse(self.lifecycle.executing) | 1084 | self.assertFalse(self.lifecycle.executing) |
3783 | 1085 | 1085 | ||
3785 | 1086 | rel_states["unit_relation"].set_data(yaml.dump(dict(hello="world"))) | 1086 | rel_states["unit_relation"].set_data( |
3786 | 1087 | serializer.dump(dict(hello="world"))) | ||
3787 | 1087 | # Sleep to give an error a chance. | 1088 | # Sleep to give an error a chance. |
3788 | 1088 | yield self.sleep(0.1) | 1089 | yield self.sleep(0.1) |
3789 | 1089 | self.assertFalse(changed_executed.called) | 1090 | self.assertFalse(changed_executed.called) |
3790 | 1090 | 1091 | ||
3791 | === modified file 'juju/unit/tests/test_workflow.py' | |||
3792 | --- juju/unit/tests/test_workflow.py 2012-04-01 00:48:01 +0000 | |||
3793 | +++ juju/unit/tests/test_workflow.py 2012-09-15 19:26:18 +0000 | |||
3794 | @@ -2,7 +2,6 @@ | |||
3795 | 2 | import itertools | 2 | import itertools |
3796 | 3 | import logging | 3 | import logging |
3797 | 4 | import os | 4 | import os |
3798 | 5 | import yaml | ||
3799 | 6 | 5 | ||
3800 | 7 | from twisted.internet.defer import inlineCallbacks, returnValue | 6 | from twisted.internet.defer import inlineCallbacks, returnValue |
3801 | 8 | 7 | ||
3802 | @@ -12,6 +11,7 @@ | |||
3803 | 12 | 11 | ||
3804 | 13 | from juju.charm.directory import CharmDirectory | 12 | from juju.charm.directory import CharmDirectory |
3805 | 14 | from juju.charm.url import CharmURL | 13 | from juju.charm.url import CharmURL |
3806 | 14 | from juju.lib import serializer | ||
3807 | 15 | from juju.lib.statemachine import WorkflowState | 15 | from juju.lib.statemachine import WorkflowState |
3808 | 16 | from juju.unit.lifecycle import UnitLifecycle, UnitRelationLifecycle | 16 | from juju.unit.lifecycle import UnitLifecycle, UnitRelationLifecycle |
3809 | 17 | from juju.unit.workflow import ( | 17 | from juju.unit.workflow import ( |
3810 | @@ -40,10 +40,10 @@ | |||
3811 | 40 | 40 | ||
3812 | 41 | state = open(workflow.state_file_path).read() | 41 | state = open(workflow.state_file_path).read() |
3813 | 42 | history = open(workflow.state_history_path) | 42 | history = open(workflow.state_history_path) |
3818 | 43 | zk_state = yaml.load(data)["workflow_state"] | 43 | zk_state = serializer.load(data)["workflow_state"] |
3819 | 44 | returnValue((yaml.load(state), | 44 | returnValue((serializer.load(state), |
3820 | 45 | [yaml.load(r[0]) for r in csv.reader(history)], | 45 | [serializer.load(r[0]) for r in csv.reader(history)], |
3821 | 46 | yaml.load(zk_state[history_id]))) | 46 | serializer.load(zk_state[history_id]))) |
3822 | 47 | 47 | ||
3823 | 48 | @inlineCallbacks | 48 | @inlineCallbacks |
3824 | 49 | def assert_history(self, expected, **kwargs): | 49 | def assert_history(self, expected, **kwargs): |
3825 | 50 | 50 | ||
3826 | === modified file 'juju/unit/workflow.py' | |||
3827 | --- juju/unit/workflow.py 2012-03-29 07:52:41 +0000 | |||
3828 | +++ juju/unit/workflow.py 2012-09-15 19:26:18 +0000 | |||
3829 | @@ -1,4 +1,3 @@ | |||
3830 | 1 | import yaml | ||
3831 | 2 | import csv | 1 | import csv |
3832 | 3 | import os | 2 | import os |
3833 | 4 | import logging | 3 | import logging |
3834 | @@ -9,6 +8,7 @@ | |||
3835 | 9 | from txzookeeper.utils import retry_change | 8 | from txzookeeper.utils import retry_change |
3836 | 10 | 9 | ||
3837 | 11 | from juju.errors import CharmError, FileNotFound | 10 | from juju.errors import CharmError, FileNotFound |
3838 | 11 | from juju.lib import serializer | ||
3839 | 12 | from juju.lib.statemachine import ( | 12 | from juju.lib.statemachine import ( |
3840 | 13 | WorkflowState, Workflow, Transition, TransitionError) | 13 | WorkflowState, Workflow, Transition, TransitionError) |
3841 | 14 | 14 | ||
3842 | @@ -223,16 +223,16 @@ | |||
3843 | 223 | @inlineCallbacks | 223 | @inlineCallbacks |
3844 | 224 | def _store(self, state_dict): | 224 | def _store(self, state_dict): |
3845 | 225 | """Store the workflow state dictionary in zookeeper.""" | 225 | """Store the workflow state dictionary in zookeeper.""" |
3847 | 226 | state_serialized = yaml.safe_dump(state_dict) | 226 | state_serialized = serializer.dump(state_dict) |
3848 | 227 | 227 | ||
3849 | 228 | def update_state(content, stat): | 228 | def update_state(content, stat): |
3851 | 229 | unit_data = yaml.load(content) | 229 | unit_data = serializer.load(content) |
3852 | 230 | if not unit_data: | 230 | if not unit_data: |
3853 | 231 | unit_data = {} | 231 | unit_data = {} |
3854 | 232 | 232 | ||
3855 | 233 | persistent_workflow = unit_data.setdefault("workflow_state", {}) | 233 | persistent_workflow = unit_data.setdefault("workflow_state", {}) |
3856 | 234 | persistent_workflow[self.zk_state_id] = state_serialized | 234 | persistent_workflow[self.zk_state_id] = state_serialized |
3858 | 235 | return yaml.dump(unit_data) | 235 | return serializer.dump(unit_data) |
3859 | 236 | 236 | ||
3860 | 237 | yield retry_change(self._client, self.zk_state_path, update_state) | 237 | yield retry_change(self._client, self.zk_state_path, update_state) |
3861 | 238 | yield super(ZookeeperWorkflowState, self)._store( | 238 | yield super(ZookeeperWorkflowState, self)._store( |
3862 | @@ -245,8 +245,8 @@ | |||
3863 | 245 | data, stat = yield self._client.get(self.zk_state_path) | 245 | data, stat = yield self._client.get(self.zk_state_path) |
3864 | 246 | except NoNodeException: | 246 | except NoNodeException: |
3865 | 247 | returnValue({"state": None}) | 247 | returnValue({"state": None}) |
3868 | 248 | unit_data = yaml.load(data) | 248 | unit_data = serializer.load(data) |
3869 | 249 | data = yaml.load(unit_data.get("workflow_state", {}).get( | 249 | data = serializer.load(unit_data.get("workflow_state", {}).get( |
3870 | 250 | self.zk_state_id, "")) | 250 | self.zk_state_id, "")) |
3871 | 251 | returnValue(data) | 251 | returnValue(data) |
3872 | 252 | 252 | ||
3873 | @@ -273,7 +273,7 @@ | |||
3874 | 273 | Internally the history file is stored a csv, with a new | 273 | Internally the history file is stored a csv, with a new |
3875 | 274 | row per entry with CSV escaping. | 274 | row per entry with CSV escaping. |
3876 | 275 | """ | 275 | """ |
3878 | 276 | state_serialized = yaml.safe_dump(state_dict) | 276 | state_serialized = serializer.dump(state_dict) |
3879 | 277 | # State File | 277 | # State File |
3880 | 278 | with open(self.state_file_path, "w") as handle: | 278 | with open(self.state_file_path, "w") as handle: |
3881 | 279 | handle.write(state_serialized) | 279 | handle.write(state_serialized) |
3882 | @@ -295,7 +295,7 @@ | |||
3883 | 295 | content = handle.read() | 295 | content = handle.read() |
3884 | 296 | 296 | ||
3885 | 297 | # TODO load ZK state and overwrite with disk state if different? | 297 | # TODO load ZK state and overwrite with disk state if different? |
3887 | 298 | return yaml.load(content) | 298 | return serializer.load(content) |
3888 | 299 | 299 | ||
3889 | 300 | 300 | ||
3890 | 301 | class WorkflowStateClient(ZookeeperWorkflowState): | 301 | class WorkflowStateClient(ZookeeperWorkflowState): |
Reviewers: mp+123470_ code.launchpad. net,
Message:
Please take a look.
Description:
ensure use of py yaml c extension for speed.
Backwards compatible. Drops test time in half. Should improve speed
across the board, things like status will see marked improvements.
https:/ /code.launchpad .net/~hazmat/ juju/fast- yaml/+merge/ 123470
(do not edit description out of merge proposal)
Please review this at https:/ /codereview. appspot. com/6493100/
Affected files: tests/test_ unit.py config. py metadata. py tests/test_ base.py tests/test_ bundle. py tests/test_ config. py tests/test_ directory. py tests/test_ metadata. py tests/test_ publisher. py config_ set.py constraints_ get.py deploy. py initialize. py status. py tests/test_ add_unit. py tests/test_ bootstrap. py tests/test_ config_ get.py tests/test_ config_ set.py tests/test_ constraints_ get.py tests/test_ deploy. py tests/test_ destroy_ environment. py tests/test_ expose. py tests/test_ initialize. py tests/test_ open_tunnel. py tests/test_ remove_ relation. py tests/test_ scp.py tests/test_ status. py tests/test_ unexpose. py tests/test_ upgrade_ charm.py tests/test_ utils.py t/config. py t/tests/ test_config. py protocol. py scheduler. py tests/test_ cli.py tests/test_ invoker. py tests/test_ scheduler. py serializer. py common/ cloudinit. py common/ state.py common/ tests/test_ cloudinit. py common/ tests/test_ findzookeepers. py common/ tests/test_ state.py common/ tests/test_ utils.py common/ utils.py ec2/tests/ common. py ec2/tests/ test_bootstrap. py ec2/tests/ test_findzookee per.py ec2/tests/ test_launch. py ec2/tests/ test_provider. py ec2/tests/ test_state. py local/files. py local/tests/ test_agent. py local/tests/ test_container. py local/tests/ test_files. py openstack/ tests/test_ bootstrap. py openstack/ tests/test_ launch. py openstack/ tests/test_ state.py orchestra/ tests/common. py orchestra/ tests/test_ bootstrap. py orchestra/ tests/test_ findzookeepers. py orchestra/ tests/test_ state.py environment. py machine. py relation. ...
A [revision details]
M juju/agents/
M juju/charm/
M juju/charm/
M juju/charm/
M juju/charm/
M juju/charm/
M juju/charm/
M juju/charm/
M juju/charm/
M juju/control/
M juju/control/
M juju/control/
M juju/control/
M juju/control/
M juju/control/
M juju/control/
M juju/control/
M juju/control/
M juju/control/
M juju/control/
M juju/control/
M juju/control/
M juju/control/
M juju/control/
M juju/control/
M juju/control/
M juju/control/
M juju/control/
M juju/control/
M juju/control/
M juju/environmen
M juju/environmen
M juju/hooks/
M juju/hooks/
M juju/hooks/
M juju/hooks/
M juju/hooks/
M juju/lib/format.py
A juju/lib/
M juju/providers/
M juju/providers/
M juju/providers/
M juju/providers/
M juju/providers/
M juju/providers/
M juju/providers/
M juju/providers/
M juju/providers/
M juju/providers/
M juju/providers/
M juju/providers/
M juju/providers/
M juju/providers/
M juju/providers/
M juju/providers/
M juju/providers/
M juju/providers/
M juju/providers/
M juju/providers/
M juju/providers/
M juju/providers/
M juju/providers/
M juju/providers/
M juju/state/charm.py
M juju/state/
M juju/state/hook.py
M juju/state/
M juju/state/