Merge lp:~hazmat/pyjuju/fast-yaml into lp:pyjuju

Proposed by Kapil Thangavelu
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
Reviewer Review Type Date Requested Status
Juju Engineering Pending
Review via email: mp+123470@code.launchpad.net

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.

https://codereview.appspot.com/6493100/

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

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:
   A [revision details]
   M juju/agents/tests/test_unit.py
   M juju/charm/config.py
   M juju/charm/metadata.py
   M juju/charm/tests/test_base.py
   M juju/charm/tests/test_bundle.py
   M juju/charm/tests/test_config.py
   M juju/charm/tests/test_directory.py
   M juju/charm/tests/test_metadata.py
   M juju/charm/tests/test_publisher.py
   M juju/control/config_set.py
   M juju/control/constraints_get.py
   M juju/control/deploy.py
   M juju/control/initialize.py
   M juju/control/status.py
   M juju/control/tests/test_add_unit.py
   M juju/control/tests/test_bootstrap.py
   M juju/control/tests/test_config_get.py
   M juju/control/tests/test_config_set.py
   M juju/control/tests/test_constraints_get.py
   M juju/control/tests/test_deploy.py
   M juju/control/tests/test_destroy_environment.py
   M juju/control/tests/test_expose.py
   M juju/control/tests/test_initialize.py
   M juju/control/tests/test_open_tunnel.py
   M juju/control/tests/test_remove_relation.py
   M juju/control/tests/test_scp.py
   M juju/control/tests/test_status.py
   M juju/control/tests/test_unexpose.py
   M juju/control/tests/test_upgrade_charm.py
   M juju/control/tests/test_utils.py
   M juju/environment/config.py
   M juju/environment/tests/test_config.py
   M juju/hooks/protocol.py
   M juju/hooks/scheduler.py
   M juju/hooks/tests/test_cli.py
   M juju/hooks/tests/test_invoker.py
   M juju/hooks/tests/test_scheduler.py
   M juju/lib/format.py
   A juju/lib/serializer.py
   M juju/providers/common/cloudinit.py
   M juju/providers/common/state.py
   M juju/providers/common/tests/test_cloudinit.py
   M juju/providers/common/tests/test_findzookeepers.py
   M juju/providers/common/tests/test_state.py
   M juju/providers/common/tests/test_utils.py
   M juju/providers/common/utils.py
   M juju/providers/ec2/tests/common.py
   M juju/providers/ec2/tests/test_bootstrap.py
   M juju/providers/ec2/tests/test_findzookeeper.py
   M juju/providers/ec2/tests/test_launch.py
   M juju/providers/ec2/tests/test_provider.py
   M juju/providers/ec2/tests/test_state.py
   M juju/providers/local/files.py
   M juju/providers/local/tests/test_agent.py
   M juju/providers/local/tests/test_container.py
   M juju/providers/local/tests/test_files.py
   M juju/providers/openstack/tests/test_bootstrap.py
   M juju/providers/openstack/tests/test_launch.py
   M juju/providers/openstack/tests/test_state.py
   M juju/providers/orchestra/tests/common.py
   M juju/providers/orchestra/tests/test_bootstrap.py
   M juju/providers/orchestra/tests/test_findzookeepers.py
   M juju/providers/orchestra/tests/test_state.py
   M juju/state/charm.py
   M juju/state/environment.py
   M juju/state/hook.py
   M juju/state/machine.py
   M juju/state/relation....

Read more...

Revision history for this message
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://codereview.appspot.com/6493100/diff/1/juju/charm/config.py
File juju/charm/config.py (right):

https://codereview.appspot.com/6493100/diff/1/juju/charm/config.py#newcode80
juju/charm/config.py:80: raw_data = yaml.load(data,
Loader=yaml.CSafeLoader)
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://codereview.appspot.com/6493100/diff/1/juju/control/constraints_get.py
File juju/control/constraints_get.py (right):

https://codereview.appspot.com/6493100/diff/1/juju/control/constraints_get.py#newcode73
juju/control/constraints_get.py:73: yaml.dump(result, sys.stdout,
Dumper=yaml.CSafeDumper)
I'd dump using the juju.lib function and write to stout separately
afterwards here.

https://codereview.appspot.com/6493100/diff/1/juju/control/status.py
File juju/control/status.py (right):

https://codereview.appspot.com/6493100/diff/1/juju/control/status.py#newcode581
juju/control/status.py:581: data, filelike, default_flow_style=False,
Dumper=yaml.CSafeDumper)
This looks like the only place that really wants extra args to dump,
leaving this as a special case seems fine.

https://codereview.appspot.com/6493100/diff/1/juju/lib/serializer.py
File juju/lib/serializer.py (right):

https://codereview.appspot.com/6493100/diff/1/juju/lib/serializer.py#newcode5
juju/lib/serializer.py:5: def dump(*args, **kw):
I'd be tempted to make this just take a dict rather than passing through
args and kwargs.

https://codereview.appspot.com/6493100/diff/1/juju/lib/serializer.py#newcode9
juju/lib/serializer.py:9: def load(*args, **kw):
Likewise, would make this just take a string.

https://codereview.appspot.com/6493100/

lp:~hazmat/pyjuju/fast-yaml updated
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

Revision history for this message
Kapil Thangavelu (hazmat) wrote :
Revision history for this message
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/CSafeDumper is
used instead of the equivalent juju.lib.serializer wrappers.

https://codereview.appspot.com/6493100/diff/5002/juju/environment/config.py
File juju/environment/config.py (right):

https://codereview.appspot.com/6493100/diff/5002/juju/environment/config.py#newcode178
juju/environment/config.py:178: config = yaml.load(content,
Loader=yaml.CSafeLoader)
Use juju.lib.serializer.load instead

https://codereview.appspot.com/6493100/diff/5002/juju/environment/config.py#newcode313
juju/environment/config.py:313: return yaml.dump(config,
Dumper=yaml.CSafeDumper)
Use juju.lib.serializer.dump instead

https://codereview.appspot.com/6493100/

lp:~hazmat/pyjuju/fast-yaml updated
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

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'juju/agents/tests/test_unit.py'
--- juju/agents/tests/test_unit.py 2012-03-28 18:57:58 +0000
+++ juju/agents/tests/test_unit.py 2012-09-15 19:26:18 +0000
@@ -1,7 +1,6 @@
1import argparse1import argparse
2import logging2import logging
3import os3import os
4import yaml
54
6from twisted.internet.defer import inlineCallbacks, returnValue5from twisted.internet.defer import inlineCallbacks, returnValue
76
@@ -10,6 +9,7 @@
10from juju.charm import get_charm_from_path9from juju.charm import get_charm_from_path
11from juju.charm.url import CharmURL10from juju.charm.url import CharmURL
12from juju.errors import JujuError11from juju.errors import JujuError
12from juju.lib import serializer
13from juju.state.environment import GlobalSettingsStateManager13from juju.state.environment import GlobalSettingsStateManager
14from juju.state.errors import ServiceStateNotFound14from juju.state.errors import ServiceStateNotFound
15from juju.state.service import NO_HOOKS, RETRY_HOOKS15from juju.state.service import NO_HOOKS, RETRY_HOOKS
@@ -375,7 +375,7 @@
375 self.assertEqual(375 self.assertEqual(
376 {"greeting": "hello", "planet": "earth",376 {"greeting": "hello", "planet": "earth",
377 "private-address": "mysql-0.example.com"},377 "private-address": "mysql-0.example.com"},
378 yaml.load(contents))378 serializer.load(contents))
379379
380 self.failUnlessIn("wordpress/0", output)380 self.failUnlessIn("wordpress/0", output)
381381
382382
=== modified file 'juju/charm/config.py'
--- juju/charm/config.py 2012-08-30 03:06:56 +0000
+++ juju/charm/config.py 2012-09-15 19:26:18 +0000
@@ -1,9 +1,9 @@
1import copy1import copy
2import os2import os
3import sys3import sys
4
5import yaml4import yaml
65
6from juju.lib import serializer
7from juju.lib.format import YAMLFormat7from juju.lib.format import YAMLFormat
8from juju.lib.schema import (SchemaError, KeyDict, Dict, String,8from juju.lib.schema import (SchemaError, KeyDict, Dict, String,
9 Constant, OneOf, Int, Float)9 Constant, OneOf, Int, Float)
@@ -78,11 +78,12 @@
78 """78 """
79 if isinstance(data, basestring):79 if isinstance(data, basestring):
80 try:80 try:
81 raw_data = yaml.load(data)81 raw_data = serializer.yaml_load(data)
82 except yaml.MarkedYAMLError, e:82 except yaml.MarkedYAMLError, e:
83 # Capture the path name on the error if present.83 # Capture the path name on the error if present.
84 if pathname is not None:84 if pathname is not None:
85 e.problem_mark.name = pathname85 e.problem_mark = serializer.yaml_mark_with_path(
86 pathname, e.problem_mark)
86 raise87 raise
87 elif isinstance(data, dict):88 elif isinstance(data, dict):
88 raw_data = data89 raw_data = data
8990
=== modified file 'juju/charm/metadata.py'
--- juju/charm/metadata.py 2012-06-14 17:51:48 +0000
+++ juju/charm/metadata.py 2012-09-15 19:26:18 +0000
@@ -5,6 +5,7 @@
55
6from juju.charm.errors import MetaDataError6from juju.charm.errors import MetaDataError
7from juju.errors import FileNotFound7from juju.errors import FileNotFound
8from juju.lib import serializer
8from juju.lib.format import is_valid_charm_format9from juju.lib.format import is_valid_charm_format
9from juju.lib.schema import (10from juju.lib.schema import (
10 SchemaError, Bool, Constant, Dict, Int,11 SchemaError, Bool, Constant, Dict, Int,
@@ -200,11 +201,13 @@
200 @raise MetaDataError: When errors are found in the info data.201 @raise MetaDataError: When errors are found in the info data.
201 """202 """
202 try:203 try:
203 self.parse_serialization_data(yaml.load(content), path)204 self.parse_serialization_data(
205 serializer.yaml_load(content), path)
204 except yaml.MarkedYAMLError, e:206 except yaml.MarkedYAMLError, e:
205 # Capture the path name on the error if present.207 # Capture the path name on the error if present.
206 if path is not None:208 if path is not None:
207 e.problem_mark.name = path209 e.problem_mark = serializer.yaml_mark_with_path(
210 path, e.problem_mark)
208 raise211 raise
209212
210 if "revision" in self._data and path:213 if "revision" in self._data and path:
211214
=== modified file 'juju/charm/tests/test_base.py'
--- juju/charm/tests/test_base.py 2011-10-05 19:12:34 +0000
+++ juju/charm/tests/test_base.py 2012-09-15 19:26:18 +0000
@@ -1,8 +1,7 @@
1import yaml
2
3from juju.charm.base import CharmBase, get_revision1from juju.charm.base import CharmBase, get_revision
4from juju.charm.metadata import MetaData2from juju.charm.metadata import MetaData
5from juju.errors import CharmError3from juju.errors import CharmError
4from juju.lib import serializer
6from juju.lib.testing import TestCase5from juju.lib.testing import TestCase
76
87
@@ -73,6 +72,9 @@
73 def test_metadata_fallback(self):72 def test_metadata_fallback(self):
74 metadata = MetaData()73 metadata = MetaData()
75 self.assertEquals(get_revision(None, metadata, None), None)74 self.assertEquals(get_revision(None, metadata, None), None)
76 metadata.parse(yaml.dump({75 metadata.parse(
77 "name": "x", "summary": "y", "description": "z","revision": 33}))76 serializer.yaml_dump(
77 {"name": "x", "summary": "y", "description": "z","revision": 33},
78 ))
79
78 self.assertEquals(get_revision(None, metadata, None), 33)80 self.assertEquals(get_revision(None, metadata, None), 33)
7981
=== modified file 'juju/charm/tests/test_bundle.py'
--- juju/charm/tests/test_bundle.py 2012-04-04 11:26:08 +0000
+++ juju/charm/tests/test_bundle.py 2012-09-15 19:26:18 +0000
@@ -3,9 +3,9 @@
3import inspect3import inspect
4import shutil4import shutil
5import stat5import stat
6import yaml
7import zipfile6import zipfile
87
8from juju.lib import serializer
9from juju.lib.testing import TestCase9from juju.lib.testing import TestCase
10from juju.lib.filehash import compute_file_hash10from juju.lib.filehash import compute_file_hash
11from juju.charm.metadata import MetaData11from juju.charm.metadata import MetaData
@@ -84,9 +84,9 @@
84 continue84 continue
85 content = zf_src.read(name)85 content = zf_src.read(name)
86 if name == "metadata.yaml":86 if name == "metadata.yaml":
87 data = yaml.load(content)87 data = serializer.yaml_load(content)
88 data["revision"] = 30388 data["revision"] = 303
89 content = yaml.dump(data)89 content = serializer.yaml_dump(data)
90 zf_dst.writestr(name, content)90 zf_dst.writestr(name, content)
91 zf_src.close()91 zf_src.close()
92 zf_dst.close()92 zf_dst.close()
@@ -97,9 +97,9 @@
97 def test_competing_revisions(self):97 def test_competing_revisions(self):
98 zf = zipfile.ZipFile(self.filename, "a")98 zf = zipfile.ZipFile(self.filename, "a")
99 zf.writestr("revision", "999")99 zf.writestr("revision", "999")
100 data = yaml.load(zf.read("metadata.yaml"))100 data = serializer.yaml_load(zf.read("metadata.yaml"))
101 data["revision"] = 303101 data["revision"] = 303
102 zf.writestr("metadata.yaml", yaml.dump(data))102 zf.writestr("metadata.yaml", serializer.yaml_dump(data))
103 zf.close()103 zf.close()
104104
105 charm = CharmBundle(self.filename)105 charm = CharmBundle(self.filename)
106106
=== modified file 'juju/charm/tests/test_config.py'
--- juju/charm/tests/test_config.py 2012-07-02 08:48:19 +0000
+++ juju/charm/tests/test_config.py 2012-09-15 19:26:18 +0000
@@ -3,6 +3,7 @@
33
4import yaml4import yaml
55
6from juju.lib import serializer
6from juju.lib.testing import TestCase7from juju.lib.testing import TestCase
7from juju.charm.config import ConfigOptions8from juju.charm.config import ConfigOptions
8from juju.charm.errors import ServiceConfigError, ServiceConfigValueError9from juju.charm.errors import ServiceConfigError, ServiceConfigValueError
@@ -25,7 +26,7 @@
25 type: int26 type: int
26"""27"""
2728
28sample_yaml_data = yaml.load(sample_configuration)29sample_yaml_data = serializer.yaml_load(sample_configuration)
2930
30sample_config_defaults = {"title": "My Title",31sample_config_defaults = {"title": "My Title",
31 "username": "admin001"}32 "username": "admin001"}
@@ -82,7 +83,7 @@
82 e = self.assertRaises(83 e = self.assertRaises(
83 ServiceConfigValueError,84 ServiceConfigValueError,
84 self.config.parse,85 self.config.parse,
85 yaml.dump(86 serializer.yaml_dump(
86 {"options": {87 {"options": {
87 "foobar": {88 "foobar": {
88 "description": "beyond what?",89 "description": "beyond what?",
@@ -98,8 +99,9 @@
9899
99 # Verify dictionary serialization100 # Verify dictionary serialization
100 schema_dict = self.config.as_dict()101 schema_dict = self.config.as_dict()
101 self.assertEqual(schema_dict,102 self.assertEqual(
102 yaml.load(sample_configuration)["options"])103 schema_dict,
104 serializer.yaml_load(sample_configuration)["options"])
103105
104 # Verify the dictionary is a copy106 # Verify the dictionary is a copy
105 # Poke at embedded objects107 # Poke at embedded objects
@@ -143,7 +145,7 @@
143 ServiceConfigValueError, config.validate, sample_input)145 ServiceConfigValueError, config.validate, sample_input)
144146
145 def test_validate_float(self):147 def test_validate_float(self):
146 self.config.parse(yaml.dump(148 self.config.parse(serializer.yaml_dump(
147 {"options": {149 {"options": {
148 "score": {150 "score": {
149 "description": "A number indicating score.",151 "description": "A number indicating score.",
@@ -166,7 +168,7 @@
166 self.assertEqual(data, {"title": u"Good"})168 self.assertEqual(data, {"title": u"Good"})
167169
168 def test_validate_boolean(self):170 def test_validate_boolean(self):
169 self.config.parse(yaml.dump(171 self.config.parse(serializer.yaml_dump(
170 {"options": {172 {"options": {
171 "active": {173 "active": {
172 "description": "A boolean indicating activity.",174 "description": "A boolean indicating activity.",
@@ -200,9 +202,9 @@
200 'string' now). Remove support for it after a while, and take202 'string' now). Remove support for it after a while, and take
201 this test with it.203 this test with it.
202 """204 """
203 config = yaml.load(sample_configuration)205 config = serializer.yaml_load(sample_configuration)
204 config["options"]["title"]["type"] = "str"206 config["options"]["title"]["type"] = "str"
205 obsolete_config = yaml.dump(config)207 obsolete_config = serializer.yaml_dump(config)
206208
207 sio = StringIO()209 sio = StringIO()
208 self.patch(sys, "stderr", sio)210 self.patch(sys, "stderr", sio)
209211
=== modified file 'juju/charm/tests/test_directory.py'
--- juju/charm/tests/test_directory.py 2012-03-08 02:50:43 +0000
+++ juju/charm/tests/test_directory.py 2012-09-15 19:26:18 +0000
@@ -4,7 +4,6 @@
4import inspect4import inspect
5import shutil5import shutil
6import tempfile6import tempfile
7import yaml
8import zipfile7import zipfile
98
10from juju.errors import CharmError, FileNotFound9from juju.errors import CharmError, FileNotFound
@@ -12,6 +11,7 @@
12from juju.charm.metadata import MetaData11from juju.charm.metadata import MetaData
13from juju.charm.directory import CharmDirectory12from juju.charm.directory import CharmDirectory
14from juju.charm.bundle import CharmBundle13from juju.charm.bundle import CharmBundle
14from juju.lib import serializer
15from juju.lib.filehash import compute_file_hash15from juju.lib.filehash import compute_file_hash
16from juju.charm import tests16from juju.charm import tests
1717
@@ -46,10 +46,10 @@
46 def set_metadata_revision(self, dir_, revision):46 def set_metadata_revision(self, dir_, revision):
47 metadata_path = os.path.join(dir_, "metadata.yaml")47 metadata_path = os.path.join(dir_, "metadata.yaml")
48 with open(metadata_path) as f:48 with open(metadata_path) as f:
49 data = yaml.load(f.read())49 data = serializer.yaml_load(f.read())
50 data["revision"] = 99950 data["revision"] = 999
51 with open(metadata_path, "w") as f:51 with open(metadata_path, "w") as f:
52 f.write(yaml.dump(data))52 f.write(serializer.yaml_dump(data))
5353
54 def test_metadata_is_required(self):54 def test_metadata_is_required(self):
55 directory = self.makeDir()55 directory = self.makeDir()
5656
=== modified file 'juju/charm/tests/test_metadata.py'
--- juju/charm/tests/test_metadata.py 2012-05-25 22:43:52 +0000
+++ juju/charm/tests/test_metadata.py 2012-09-15 19:26:18 +0000
@@ -9,6 +9,7 @@
9 MetaData, MetaDataError, InterfaceExpander, SchemaError)9 MetaData, MetaDataError, InterfaceExpander, SchemaError)
10from juju.errors import FileNotFound10from juju.errors import FileNotFound
11from juju.lib.testing import TestCase11from juju.lib.testing import TestCase
12from juju.lib import serializer
1213
13test_repository_path = os.path.join(14test_repository_path = os.path.join(
14 os.path.dirname(inspect.getabsfile(tests)),15 os.path.dirname(inspect.getabsfile(tests)),
@@ -39,11 +40,11 @@
39 class HackManager(object):40 class HackManager(object):
4041
41 def __enter__(mgr):42 def __enter__(mgr):
42 mgr.data = yaml.load(self.sample)43 mgr.data = serializer.yaml_load(self.sample)
43 return mgr.data44 return mgr.data
4445
45 def __exit__(mgr, exc_type, exc_val, exc_tb):46 def __exit__(mgr, exc_type, exc_val, exc_tb):
46 self.sample = yaml.dump(mgr.data)47 self.sample = serializer.yaml_dump(mgr.data)
47 return False48 return False
48 return HackManager()49 return HackManager()
4950
@@ -145,7 +146,7 @@
145 others.146 others.
146 """147 """
147 serialization_data = {"Hi": "there!"}148 serialization_data = {"Hi": "there!"}
148 yaml_data = yaml.dump(serialization_data)149 yaml_data = serializer.yaml_dump(serialization_data)
149 path = self.makeFile(yaml_data)150 path = self.makeFile(yaml_data)
150 mock = self.mocker.patch(self.metadata)151 mock = self.mocker.patch(self.metadata)
151 mock.parse(yaml_data, path)152 mock.parse(yaml_data, path)
152153
=== modified file 'juju/charm/tests/test_publisher.py'
--- juju/charm/tests/test_publisher.py 2012-04-06 16:35:31 +0000
+++ juju/charm/tests/test_publisher.py 2012-09-15 19:26:18 +0000
@@ -1,6 +1,5 @@
1import fcntl1import fcntl
2import os2import os
3import yaml
4import zookeeper3import zookeeper
54
6from twisted.internet.defer import inlineCallbacks, fail5from twisted.internet.defer import inlineCallbacks, fail
@@ -12,7 +11,7 @@
12from juju.charm.directory import CharmDirectory11from juju.charm.directory import CharmDirectory
13from juju.charm.publisher import CharmPublisher12from juju.charm.publisher import CharmPublisher
14from juju.charm.tests import local_charm_id13from juju.charm.tests import local_charm_id
15from juju.lib import under14from juju.lib import under, serializer
16from juju.providers.dummy import FileStorage15from juju.providers.dummy import FileStorage
17from juju.state.charm import CharmStateManager16from juju.state.charm import CharmStateManager
18from juju.state.errors import StateChanged17from juju.state.errors import StateChanged
@@ -140,7 +139,8 @@
140139
141 # assert the checksum matches the initially published checksum140 # assert the checksum matches the initially published checksum
142 self.assertEqual(141 self.assertEqual(
143 yaml.load(content)["sha256"], self.charm.get_sha256())142 serializer.yaml_load(content)["sha256"],
143 self.charm.get_sha256())
144144
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)
146 self.assertTrue(os.path.exists(store_path))146 self.assertTrue(os.path.exists(store_path))
147147
=== modified file 'juju/control/config_set.py'
--- juju/control/config_set.py 2012-07-02 23:55:27 +0000
+++ juju/control/config_set.py 2012-09-15 19:26:18 +0000
@@ -1,11 +1,11 @@
1import argparse1import argparse
2
3import yaml2import yaml
43
5from twisted.internet.defer import inlineCallbacks4from twisted.internet.defer import inlineCallbacks
65
7from juju.charm.errors import ServiceConfigValueError6from juju.charm.errors import ServiceConfigValueError
8from juju.control.utils import get_environment7from juju.control.utils import get_environment
8from juju.lib import serializer
9from juju.lib.format import get_charm_formatter9from juju.lib.format import get_charm_formatter
10from juju.state.service import ServiceStateManager10from juju.state.service import ServiceStateManager
1111
@@ -62,7 +62,7 @@
6262
63 yaml_data = options.config.read()63 yaml_data = options.config.read()
64 try:64 try:
65 data = yaml.safe_load(yaml_data)65 data = serializer.yaml_load(yaml_data)
66 except yaml.YAMLError:66 except yaml.YAMLError:
67 raise ServiceConfigValueError(67 raise ServiceConfigValueError(
68 "Config file %r not valid YAML" % options.config.name)68 "Config file %r not valid YAML" % options.config.name)
6969
=== modified file 'juju/control/constraints_get.py'
--- juju/control/constraints_get.py 2012-03-30 09:41:54 +0000
+++ juju/control/constraints_get.py 2012-09-15 19:26:18 +0000
@@ -1,10 +1,10 @@
1import argparse1import argparse
2import sys2import sys
3import yaml
43
5from twisted.internet.defer import inlineCallbacks4from twisted.internet.defer import inlineCallbacks
65
7from juju.control.utils import get_environment, sync_environment_state6from juju.control.utils import get_environment, sync_environment_state
7from juju.lib import serializer
8from juju.state.environment import EnvironmentStateManager8from juju.state.environment import EnvironmentStateManager
9from juju.state.machine import MachineStateManager9from juju.state.machine import MachineStateManager
10from juju.state.service import ServiceStateManager10from juju.state.service import ServiceStateManager
@@ -70,6 +70,7 @@
70 log.info("Fetching constraints for environment")70 log.info("Fetching constraints for environment")
71 constraints = yield esm.get_constraints()71 constraints = yield esm.get_constraints()
72 result = dict(constraints)72 result = dict(constraints)
73 yaml.safe_dump(result, sys.stdout)73 contents = serializer.yaml_dump(result)
74 sys.stdout.write(contents)
74 finally:75 finally:
75 yield client.close()76 yield client.close()
7677
=== modified file 'juju/control/deploy.py'
--- juju/control/deploy.py 2012-04-01 00:48:01 +0000
+++ juju/control/deploy.py 2012-09-15 19:26:18 +0000
@@ -1,7 +1,5 @@
1import os1import os
22
3import yaml
4
5from twisted.internet.defer import inlineCallbacks3from twisted.internet.defer import inlineCallbacks
64
7from juju.control import legacy5from juju.control import legacy
@@ -12,6 +10,7 @@
12from juju.charm.publisher import CharmPublisher10from juju.charm.publisher import CharmPublisher
13from juju.charm.repository import resolve11from juju.charm.repository import resolve
14from juju.errors import CharmError12from juju.errors import CharmError
13from juju.lib import serializer
15from juju.state.endpoint import RelationEndpoint14from juju.state.endpoint import RelationEndpoint
16from juju.state.placement import place_unit15from juju.state.placement import place_unit
17from juju.state.relation import RelationStateManager16from juju.state.relation import RelationStateManager
@@ -85,7 +84,9 @@
85 raise ServiceConfigValueError(84 raise ServiceConfigValueError(
86 "Config file %r not accessible." % config_file)85 "Config file %r not accessible." % config_file)
8786
88 options = yaml.load(open(config_file, "r").read())87 with open(config_file) as fh:
88 options = serializer.yaml_load(fh.read())
89
89 if not options or not isinstance(options, dict) or \90 if not options or not isinstance(options, dict) or \
90 service_name not in options:91 service_name not in options:
91 raise ServiceConfigValueError(92 raise ServiceConfigValueError(
9293
=== modified file 'juju/control/initialize.py'
--- juju/control/initialize.py 2012-03-29 01:37:57 +0000
+++ juju/control/initialize.py 2012-09-15 19:26:18 +0000
@@ -1,11 +1,11 @@
1from base64 import b64decode1from base64 import b64decode
2import os2import os
3import yaml
43
5from twisted.internet.defer import inlineCallbacks4from twisted.internet.defer import inlineCallbacks
65
7from txzookeeper import ZookeeperClient6from txzookeeper import ZookeeperClient
87
8from juju.lib import serializer
9from juju.state.initialize import StateHierarchy9from juju.state.initialize import StateHierarchy
1010
1111
@@ -34,7 +34,7 @@
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")
35 client = yield ZookeeperClient(zk_address).connect()35 client = yield ZookeeperClient(zk_address).connect()
36 try:36 try:
37 constraints_data = yaml.load(b64decode(options.constraints_data))37 constraints_data = serializer.load(b64decode(options.constraints_data))
38 hierarchy = StateHierarchy(38 hierarchy = StateHierarchy(
39 client,39 client,
40 options.admin_identity,40 options.admin_identity,
4141
=== modified file 'juju/control/status.py'
--- juju/control/status.py 2012-08-05 00:18:28 +0000
+++ juju/control/status.py 2012-09-15 19:26:18 +0000
@@ -3,12 +3,13 @@
3import functools3import functools
4import json4import json
5import sys5import sys
6import yaml
67
7from twisted.internet.defer import inlineCallbacks, returnValue8from twisted.internet.defer import inlineCallbacks, returnValue
8import yaml
99
10from juju.control.utils import get_environment10from juju.control.utils import get_environment
11from juju.errors import ProviderError11from juju.errors import ProviderError
12
12from juju.state.errors import UnitRelationStateNotFound13from juju.state.errors import UnitRelationStateNotFound
13from juju.state.charm import CharmStateManager14from juju.state.charm import CharmStateManager
14from juju.state.machine import MachineStateManager15from juju.state.machine import MachineStateManager
@@ -576,7 +577,8 @@
576577
577def render_yaml(data, filelike, environment):578def render_yaml(data, filelike, environment):
578 # remove the root nodes empty name579 # remove the root nodes empty name
579 yaml.safe_dump(data, filelike, default_flow_style=False)580 yaml.dump(
581 data, filelike, default_flow_style=False, Dumper=yaml.CSafeDumper)
580582
581renderers["yaml"] = render_yaml583renderers["yaml"] = render_yaml
582584
583585
=== modified file 'juju/control/tests/test_add_unit.py'
--- juju/control/tests/test_add_unit.py 2012-05-04 22:43:40 +0000
+++ juju/control/tests/test_add_unit.py 2012-09-15 19:26:18 +0000
@@ -1,8 +1,7 @@
1from yaml import dump
2
3from twisted.internet.defer import inlineCallbacks1from twisted.internet.defer import inlineCallbacks
42
5from juju.control import main3from juju.control import main
4from juju.lib.serializer import yaml_dump
6from juju.state.environment import EnvironmentStateManager5from juju.state.environment import EnvironmentStateManager
76
8from .common import MachineControlToolTest7from .common import MachineControlToolTest
@@ -184,7 +183,7 @@
184 "environments": {"firstenv": {183 "environments": {"firstenv": {
185 "some-legacy-key": "blah",184 "some-legacy-key": "blah",
186 "type": "dummy"}}}185 "type": "dummy"}}}
187 self.write_config(dump(local_config))186 self.write_config(yaml_dump(local_config))
188 self.config.load()187 self.config.load()
189188
190 finished = self.setup_cli_reactor()189 finished = self.setup_cli_reactor()
191190
=== modified file 'juju/control/tests/test_bootstrap.py'
--- juju/control/tests/test_bootstrap.py 2012-05-04 22:43:40 +0000
+++ juju/control/tests/test_bootstrap.py 2012-09-15 19:26:18 +0000
@@ -1,9 +1,9 @@
11
2from twisted.internet.defer import inlineCallbacks, succeed2from twisted.internet.defer import inlineCallbacks, succeed
3from yaml import dump
43
4from juju.control import main
5from juju.lib.serializer import yaml_dump as dump
5from juju.providers.dummy import MachineProvider6from juju.providers.dummy import MachineProvider
6from juju.control import main
77
8from .common import ControlToolTest8from .common import ControlToolTest
99
1010
=== modified file 'juju/control/tests/test_config_get.py'
--- juju/control/tests/test_config_get.py 2012-09-13 18:31:19 +0000
+++ juju/control/tests/test_config_get.py 2012-09-15 19:26:18 +0000
@@ -1,10 +1,8 @@
1import yaml
2
3from twisted.internet.defer import inlineCallbacks1from twisted.internet.defer import inlineCallbacks
42
5from juju.control import main3from juju.control import main
6
7from juju.charm.tests import local_charm_id4from juju.charm.tests import local_charm_id
5from juju.lib import serializer
8from .common import MachineControlToolTest6from .common import MachineControlToolTest
97
108
@@ -32,7 +30,7 @@
32 main(["get", "wordpress"])30 main(["get", "wordpress"])
3331
34 yield finished32 yield finished
35 data = yaml.load(output.getvalue())33 data = serializer.yaml_load(output.getvalue())
36 self.assertEqual(34 self.assertEqual(
37 {"service": "wordpress",35 {"service": "wordpress",
38 "charm": "local:series/wordpress-3",36 "charm": "local:series/wordpress-3",
@@ -59,7 +57,7 @@
59 main(["get", "dummy"])57 main(["get", "dummy"])
6058
61 yield finished59 yield finished
62 data = yaml.load(output.getvalue())60 data = serializer.yaml_load(output.getvalue())
6361
64 self.assertEqual(62 self.assertEqual(
65 {"service": "dummy",63 {"service": "dummy",
6664
=== modified file 'juju/control/tests/test_config_set.py'
--- juju/control/tests/test_config_set.py 2012-08-30 03:06:56 +0000
+++ juju/control/tests/test_config_set.py 2012-09-15 19:26:18 +0000
@@ -1,9 +1,8 @@
1from yaml import dump
2
3from twisted.internet.defer import inlineCallbacks1from twisted.internet.defer import inlineCallbacks
42
5from juju.control import main3from juju.control import main
6from juju.control.config_set import config_set4from juju.control.config_set import config_set
5from juju.lib import serializer
7from .common import MachineControlToolTest6from .common import MachineControlToolTest
87
98
@@ -38,8 +37,8 @@
38 finished = self.setup_cli_reactor()37 finished = self.setup_cli_reactor()
39 self.setup_exit(0)38 self.setup_exit(0)
40 self.mocker.replay()39 self.mocker.replay()
41 config_file = self.makeFile(dump(dict(40 config_file = self.makeFile(serializer.yaml_dump(
42 wordpress={"blog-title": "Hello World"})))41 dict(wordpress={"blog-title": "Hello World"})))
4342
44 main(["set", "wordpress",43 main(["set", "wordpress",
45 "--config=%s" % config_file])44 "--config=%s" % config_file])
@@ -54,13 +53,13 @@
54 finished = self.setup_cli_reactor()53 finished = self.setup_cli_reactor()
55 self.setup_exit(0)54 self.setup_exit(0)
56 self.mocker.replay()55 self.mocker.replay()
56
57 # missing the service_name dict (will do nothing to values)57 # missing the service_name dict (will do nothing to values)
58 config_file = self.makeFile(dump({"blog-title": "Hello World"}))58 config_file = self.makeFile(
5959 serializer.yaml_dump({"blog-title": "Hello World"}))
60 main(["set", "wordpress",60 main(["set", "wordpress", "--config=%s" % config_file])
61 "--config=%s" % config_file])
62
63 yield finished61 yield finished
62
64 state = yield self.service_state.get_config()63 state = yield self.service_state.get_config()
65 self.assertEqual(state, {'blog-title': 'My Title'})64 self.assertEqual(state, {'blog-title': 'My Title'})
6665
@@ -90,7 +89,7 @@
90 self.mocker.replay()89 self.mocker.replay()
9190
92 # valid file, but incorrect cli usage91 # valid file, but incorrect cli usage
93 config_file = self.makeFile(dump(dict(92 config_file = self.makeFile(serializer.yaml_dump(dict(
94 wordpress={"blog-title": "Hello World"})))93 wordpress={"blog-title": "Hello World"})))
9594
96 main(["-v", "set", "wordpress",95 main(["-v", "set", "wordpress",
9796
=== modified file 'juju/control/tests/test_constraints_get.py'
--- juju/control/tests/test_constraints_get.py 2012-03-30 09:41:54 +0000
+++ juju/control/tests/test_constraints_get.py 2012-09-15 19:26:18 +0000
@@ -1,8 +1,7 @@
1import yaml
2
3from twisted.internet.defer import inlineCallbacks1from twisted.internet.defer import inlineCallbacks
42
5from juju.control import main3from juju.control import main
4from juju.lib import serializer
6from juju.machine.tests.test_constraints import dummy_cs5from juju.machine.tests.test_constraints import dummy_cs
7from juju.state.environment import EnvironmentStateManager6from juju.state.environment import EnvironmentStateManager
87
@@ -65,7 +64,7 @@
65 def test_env(self):64 def test_env(self):
66 main(["get-constraints"])65 main(["get-constraints"])
67 yield self.finished66 yield self.finished
68 result = yaml.load(self.stdout.getvalue())67 result = serializer.load(self.stdout.getvalue())
69 self.assertEquals(result, self.expect_env)68 self.assertEquals(result, self.expect_env)
70 self.assert_messages(env_log)69 self.assert_messages(env_log)
7170
@@ -73,7 +72,7 @@
73 def test_service(self):72 def test_service(self):
74 main(["get-constraints", "mysql"])73 main(["get-constraints", "mysql"])
75 yield self.finished74 yield self.finished
76 result = yaml.load(self.stdout.getvalue())75 result = serializer.load(self.stdout.getvalue())
77 self.assertEquals(result, {"mysql": self.expect_service})76 self.assertEquals(result, {"mysql": self.expect_service})
78 self.assert_messages(service_log)77 self.assert_messages(service_log)
7978
@@ -81,7 +80,7 @@
81 def test_unit(self):80 def test_unit(self):
82 main(["get-constraints", "mysql/0"])81 main(["get-constraints", "mysql/0"])
83 yield self.finished82 yield self.finished
84 result = yaml.load(self.stdout.getvalue())83 result = serializer.load(self.stdout.getvalue())
85 self.assertEquals(result, {"mysql/0": self.expect_unit})84 self.assertEquals(result, {"mysql/0": self.expect_unit})
86 self.assert_messages(unit_log)85 self.assert_messages(unit_log)
8786
@@ -89,7 +88,7 @@
89 def test_machine(self):88 def test_machine(self):
90 main(["get-constraints", "1"])89 main(["get-constraints", "1"])
91 yield self.finished90 yield self.finished
92 result = yaml.load(self.stdout.getvalue())91 result = serializer.load(self.stdout.getvalue())
93 self.assertEquals(result, {"1": self.expect_machine})92 self.assertEquals(result, {"1": self.expect_machine})
94 self.assert_messages(machine_log)93 self.assert_messages(machine_log)
9594
@@ -97,7 +96,7 @@
97 def test_all(self):96 def test_all(self):
98 main(["get-constraints", "mysql", "mysql/0", "1"])97 main(["get-constraints", "mysql", "mysql/0", "1"])
99 yield self.finished98 yield self.finished
100 result = yaml.load(self.stdout.getvalue())99 result = serializer.load(self.stdout.getvalue())
101 expect = {"mysql": self.expect_service,100 expect = {"mysql": self.expect_service,
102 "mysql/0": self.expect_unit,101 "mysql/0": self.expect_unit,
103 "1": self.expect_machine}102 "1": self.expect_machine}
@@ -111,6 +110,6 @@
111 yield self.client.delete("/environment")110 yield self.client.delete("/environment")
112 main(["get-constraints", "mysql/0"])111 main(["get-constraints", "mysql/0"])
113 yield self.finished112 yield self.finished
114 result = yaml.load(self.stdout.getvalue())113 result = serializer.load(self.stdout.getvalue())
115 self.assertEquals(result, {"mysql/0": self.expect_unit})114 self.assertEquals(result, {"mysql/0": self.expect_unit})
116 self.assert_messages(unit_log)115 self.assert_messages(unit_log)
117116
=== modified file 'juju/control/tests/test_deploy.py'
--- juju/control/tests/test_deploy.py 2012-05-04 22:43:40 +0000
+++ juju/control/tests/test_deploy.py 2012-09-15 19:26:18 +0000
@@ -1,7 +1,5 @@
1import logging1import logging
2import os2import os
3import yaml
4
53
6from twisted.internet.defer import inlineCallbacks, succeed4from twisted.internet.defer import inlineCallbacks, succeed
75
@@ -15,6 +13,7 @@
15from juju.charm.repository import RemoteCharmRepository13from juju.charm.repository import RemoteCharmRepository
16from juju.charm.url import CharmURL14from juju.charm.url import CharmURL
17from juju.charm.errors import ServiceConfigValueError15from juju.charm.errors import ServiceConfigValueError
16from juju.lib import serializer
1817
19from juju.state.charm import CharmStateManager18from juju.state.charm import CharmStateManager
20from juju.state.environment import EnvironmentStateManager19from juju.state.environment import EnvironmentStateManager
@@ -58,7 +57,7 @@
58 "secondenv": {57 "secondenv": {
59 "type": "dummy", "admin-secret": "marge"}}}58 "type": "dummy", "admin-secret": "marge"}}}
6059
61 self.write_config(yaml.dump(config))60 self.write_config(serializer.dump(config))
62 stderr = self.capture_logging()61 stderr = self.capture_logging()
63 main(["deploy", "--repository", self.unbundled_repo_path, "mysql"])62 main(["deploy", "--repository", self.unbundled_repo_path, "mysql"])
64 self.assertIn("There are multiple environments", stderr.getvalue())63 self.assertIn("There are multiple environments", stderr.getvalue())
@@ -167,7 +166,7 @@
167 "secondenv": {166 "secondenv": {
168 "type": "dummy", "admin-secret": "marge"}}}167 "type": "dummy", "admin-secret": "marge"}}}
169168
170 self.write_config(yaml.dump(config))169 self.write_config(serializer.dump(config))
171170
172 stderr = self.capture_logging()171 stderr = self.capture_logging()
173 main(["deploy", "--environment", "roman-candle",172 main(["deploy", "--environment", "roman-candle",
@@ -186,7 +185,7 @@
186 "secondenv": {185 "secondenv": {
187 "type": "dummy", "admin-secret": "marge"}}}186 "type": "dummy", "admin-secret": "marge"}}}
188187
189 self.write_config(yaml.dump(config))188 self.write_config(serializer.dump(config))
190189
191 def match_config(config):190 def match_config(config):
192 return isinstance(config, EnvironmentsConfig)191 return isinstance(config, EnvironmentsConfig)
@@ -353,8 +352,8 @@
353 env_state_manager = EnvironmentStateManager(self.client)352 env_state_manager = EnvironmentStateManager(self.client)
354 env_config = yield env_state_manager.get_config()353 env_config = yield env_state_manager.get_config()
355354
356 self.assertEquals(yaml.load(env_config.serialize("firstenv")),355 self.assertEquals(serializer.load(env_config.serialize("firstenv")),
357 yaml.load(self.config.serialize("firstenv")))356 serializer.load(self.config.serialize("firstenv")))
358357
359 @inlineCallbacks358 @inlineCallbacks
360 def test_deploy_reuses_machines(self):359 def test_deploy_reuses_machines(self):
@@ -394,7 +393,7 @@
394 """Valid config options should be available to the deployed393 """Valid config options should be available to the deployed
395 service."""394 service."""
396 config_file = self.makeFile(395 config_file = self.makeFile(
397 yaml.dump(dict(otherservice=dict(application_file="foo"))))396 serializer.dump(dict(otherservice=dict(application_file="foo"))))
398 environment = self.config.get("firstenv")397 environment = self.config.get("firstenv")
399398
400 failure = deploy.deploy(399 failure = deploy.deploy(
@@ -408,7 +407,7 @@
408 def test_deploy_with_invalid_config(self):407 def test_deploy_with_invalid_config(self):
409 """Can't deploy with config that doesn't pass charm validation."""408 """Can't deploy with config that doesn't pass charm validation."""
410 config_file = self.makeFile(409 config_file = self.makeFile(
411 yaml.dump(dict(myblog=dict(application_file="foo"))))410 serializer.dump(dict(myblog=dict(application_file="foo"))))
412 environment = self.config.get("firstenv")411 environment = self.config.get("firstenv")
413412
414 failure = deploy.deploy(413 failure = deploy.deploy(
@@ -426,7 +425,7 @@
426 def test_deploy_with_config(self):425 def test_deploy_with_config(self):
427 """Valid config options should be available to the deployed426 """Valid config options should be available to the deployed
428 service."""427 service."""
429 config_file = self.makeFile(yaml.dump(dict(428 config_file = self.makeFile(serializer.dump(dict(
430 myblog=dict(outlook="sunny",429 myblog=dict(outlook="sunny",
431 username="tester01"))))430 username="tester01"))))
432 environment = self.config.get("firstenv")431 environment = self.config.get("firstenv")
@@ -555,7 +554,7 @@
555 "type": "dummy",554 "type": "dummy",
556 "some-legacy-key": "blah",555 "some-legacy-key": "blah",
557 "default-series": "series"}}}556 "default-series": "series"}}}
558 self.write_config(yaml.dump(local_config))557 self.write_config(serializer.dump(local_config))
559 self.config.load()558 self.config.load()
560 finished = self.setup_cli_reactor()559 finished = self.setup_cli_reactor()
561 self.setup_exit(0)560 self.setup_exit(0)
562561
=== modified file 'juju/control/tests/test_destroy_environment.py'
--- juju/control/tests/test_destroy_environment.py 2012-05-04 22:43:40 +0000
+++ juju/control/tests/test_destroy_environment.py 2012-09-15 19:26:18 +0000
@@ -1,6 +1,6 @@
1from twisted.internet.defer import succeed, inlineCallbacks1from twisted.internet.defer import succeed, inlineCallbacks
2from yaml import dump
32
3from juju.lib.serializer import dump
4from juju.lib.mocker import MATCH4from juju.lib.mocker import MATCH
5from juju.providers.dummy import MachineProvider5from juju.providers.dummy import MachineProvider
6from juju.control import main6from juju.control import main
77
=== modified file 'juju/control/tests/test_expose.py'
--- juju/control/tests/test_expose.py 2012-05-04 22:43:40 +0000
+++ juju/control/tests/test_expose.py 2012-09-15 19:26:18 +0000
@@ -1,8 +1,8 @@
1import yaml
2from twisted.internet.defer import inlineCallbacks1from twisted.internet.defer import inlineCallbacks
32
4from juju.control import main3from juju.control import main
5from juju.control.tests.common import ControlToolTest4from juju.control.tests.common import ControlToolTest
5from juju.lib import serializer
6from juju.state.tests.test_service import ServiceStateManagerTestBase6from juju.state.tests.test_service import ServiceStateManagerTestBase
77
88
@@ -15,7 +15,7 @@
15 config = {15 config = {
16 "environments": {"firstenv": {"type": "dummy"}}}16 "environments": {"firstenv": {"type": "dummy"}}}
1717
18 self.write_config(yaml.dump(config))18 self.write_config(serializer.dump(config))
19 self.config.load()19 self.config.load()
20 self.service_state = yield self.add_service_from_charm("wordpress")20 self.service_state = yield self.add_service_from_charm("wordpress")
21 self.output = self.capture_logging()21 self.output = self.capture_logging()
2222
=== modified file 'juju/control/tests/test_initialize.py'
--- juju/control/tests/test_initialize.py 2012-03-30 09:12:11 +0000
+++ juju/control/tests/test_initialize.py 2012-09-15 19:26:18 +0000
@@ -1,11 +1,11 @@
1from base64 import b64encode1from base64 import b64encode
2from yaml import safe_dump2
33
4from twisted.internet.defer import succeed4from twisted.internet.defer import succeed
55
6from txzookeeper import ZookeeperClient6from txzookeeper import ZookeeperClient
7from juju.state.initialize import StateHierarchy7from juju.state.initialize import StateHierarchy
88from juju.lib.serializer import dump
9from juju.control import admin9from juju.control import admin
10from .common import ControlToolTest10from .common import ControlToolTest
1111
@@ -29,7 +29,7 @@
29 self.setup_exit(0)29 self.setup_exit(0)
30 self.mocker.replay()30 self.mocker.replay()
3131
32 constraints_data = b64encode(safe_dump({32 constraints_data = b64encode(dump({
33 "ubuntu-series": "foo", "provider-type": "bar"}))33 "ubuntu-series": "foo", "provider-type": "bar"}))
3434
35 admin(["initialize",35 admin(["initialize",
3636
=== modified file 'juju/control/tests/test_open_tunnel.py'
--- juju/control/tests/test_open_tunnel.py 2011-09-15 19:24:47 +0000
+++ juju/control/tests/test_open_tunnel.py 2012-09-15 19:26:18 +0000
@@ -1,7 +1,8 @@
1from yaml import dump
21
2from juju.control import main, open_tunnel
3from juju.lib.serializer import dump
3from juju.providers.dummy import MachineProvider4from juju.providers.dummy import MachineProvider
4from juju.control import main, open_tunnel5
56
6from .common import ControlToolTest7from .common import ControlToolTest
78
89
=== modified file 'juju/control/tests/test_remove_relation.py'
--- juju/control/tests/test_remove_relation.py 2012-05-04 22:43:40 +0000
+++ juju/control/tests/test_remove_relation.py 2012-09-15 19:26:18 +0000
@@ -1,12 +1,12 @@
1import logging1import logging
22
3import yaml
43
5from twisted.internet.defer import inlineCallbacks, returnValue4from twisted.internet.defer import inlineCallbacks, returnValue
65
7from juju.charm.tests.test_repository import RepositoryTestBase6from juju.charm.tests.test_repository import RepositoryTestBase
8from juju.control import main, remove_relation7from juju.control import main, remove_relation
9from juju.control.tests.common import ControlToolTest8from juju.control.tests.common import ControlToolTest
9from juju.lib import serializer
10from juju.machine.tests.test_constraints import dummy_constraints10from juju.machine.tests.test_constraints import dummy_constraints
11from juju.state.errors import ServiceStateNotFound11from juju.state.errors import ServiceStateNotFound
12from juju.state.tests.test_service import ServiceStateManagerTestBase12from juju.state.tests.test_service import ServiceStateManagerTestBase
@@ -22,7 +22,7 @@
22 "environments": {22 "environments": {
23 "firstenv": {23 "firstenv": {
24 "type": "dummy", "admin-secret": "homer"}}}24 "type": "dummy", "admin-secret": "homer"}}}
25 self.write_config(yaml.dump(config))25 self.write_config(serializer.dump(config))
26 self.config.load()26 self.config.load()
27 self.output = self.capture_logging()27 self.output = self.capture_logging()
28 self.stderr = self.capture_stream("stderr")28 self.stderr = self.capture_stream("stderr")
2929
=== modified file 'juju/control/tests/test_scp.py'
--- juju/control/tests/test_scp.py 2012-03-27 23:56:09 +0000
+++ juju/control/tests/test_scp.py 2012-09-15 19:26:18 +0000
@@ -1,7 +1,6 @@
1import logging1import logging
2import os2import os
33
4from yaml import dump
54
6from twisted.internet.defer import inlineCallbacks5from twisted.internet.defer import inlineCallbacks
76
87
=== modified file 'juju/control/tests/test_status.py'
--- juju/control/tests/test_status.py 2012-08-09 09:53:55 +0000
+++ juju/control/tests/test_status.py 2012-09-15 19:26:18 +0000
@@ -4,7 +4,7 @@
4import logging4import logging
5import os5import os
6from StringIO import StringIO6from StringIO import StringIO
7import yaml7
88
9from twisted.internet.defer import inlineCallbacks, returnValue9from twisted.internet.defer import inlineCallbacks, returnValue
1010
@@ -13,7 +13,7 @@
13from juju.environment.environment import Environment13from juju.environment.environment import Environment
14from juju.control import status14from juju.control import status
15from juju.control import tests15from juju.control import tests
16from juju.lib.mocker import ANY16from juju.lib import serializer
17from juju.state.endpoint import RelationEndpoint17from juju.state.endpoint import RelationEndpoint
18from juju.state.environment import GlobalSettingsStateManager18from juju.state.environment import GlobalSettingsStateManager
19from juju.state.tests.test_service import ServiceStateManagerTestBase19from juju.state.tests.test_service import ServiceStateManagerTestBase
@@ -24,7 +24,7 @@
2424
25tests_path = os.path.dirname(inspect.getabsfile(tests))25tests_path = os.path.dirname(inspect.getabsfile(tests))
26sample_path = os.path.join(tests_path, "sample_cluster.yaml")26sample_path = os.path.join(tests_path, "sample_cluster.yaml")
27sample_cluster = yaml.load(open(sample_path, "r"))27sample_cluster = serializer.load(open(sample_path, "r"))
2828
2929
30def dump_stringio(stringio, filename):30def dump_stringio(stringio, filename):
@@ -643,7 +643,7 @@
643643
644 yield status.status(self.environment, [],644 yield status.status(self.environment, [],
645 status.render_yaml, self.output, None)645 status.render_yaml, self.output, None)
646 state = yaml.load(self.output.getvalue())646 state = serializer.yaml_load(self.output.getvalue())
647647
648 self.assertEqual(set(state["machines"].keys()),648 self.assertEqual(set(state["machines"].keys()),
649 set([0, 1, 2, 3, 4, 5, 6]))649 set([0, 1, 2, 3, 4, 5, 6]))
@@ -863,7 +863,7 @@
863 yield status.status(self.environment, [],863 yield status.status(self.environment, [],
864 status.render_yaml, self.output, None)864 status.render_yaml, self.output, None)
865865
866 state = yaml.load(self.output.getvalue())866 state = serializer.load(self.output.getvalue())
867867
868 # verify our changes868 # verify our changes
869 log_state = state["services"]["logging"]869 log_state = state["services"]["logging"]
@@ -920,6 +920,6 @@
920 yield status.status(self.environment, [],920 yield status.status(self.environment, [],
921 status.render_yaml, self.output, None)921 status.render_yaml, self.output, None)
922922
923 output = yaml.load(self.output.getvalue())923 output = serializer.load(self.output.getvalue())
924 self.assertNotIn(mu1.unit_name, output["services"]["mysql"]["units"])924 self.assertNotIn(mu1.unit_name, output["services"]["mysql"]["units"])
925 self.assertIn(mu2.unit_name, output["services"]["mysql"]["units"])925 self.assertIn(mu2.unit_name, output["services"]["mysql"]["units"])
926926
=== modified file 'juju/control/tests/test_unexpose.py'
--- juju/control/tests/test_unexpose.py 2012-05-04 22:43:40 +0000
+++ juju/control/tests/test_unexpose.py 2012-09-15 19:26:18 +0000
@@ -1,8 +1,8 @@
1import yaml
2from twisted.internet.defer import inlineCallbacks1from twisted.internet.defer import inlineCallbacks
32
4from juju.control import main3from juju.control import main
5from juju.control.tests.common import ControlToolTest4from juju.control.tests.common import ControlToolTest
5from juju.lib import serializer
6from juju.state.tests.test_service import ServiceStateManagerTestBase6from juju.state.tests.test_service import ServiceStateManagerTestBase
77
88
@@ -15,7 +15,7 @@
15 config = {15 config = {
16 "environments": {"firstenv": {"type": "dummy"}}}16 "environments": {"firstenv": {"type": "dummy"}}}
1717
18 self.write_config(yaml.dump(config))18 self.write_config(serializer.dump(config))
19 self.config.load()19 self.config.load()
20 self.service_state = yield self.add_service_from_charm("wordpress")20 self.service_state = yield self.add_service_from_charm("wordpress")
21 self.output = self.capture_logging()21 self.output = self.capture_logging()
2222
=== modified file 'juju/control/tests/test_upgrade_charm.py'
--- juju/control/tests/test_upgrade_charm.py 2012-08-06 19:29:30 +0000
+++ juju/control/tests/test_upgrade_charm.py 2012-09-15 19:26:18 +0000
@@ -1,6 +1,5 @@
1import json1import json
2import os2import os
3from yaml import dump
43
5from twisted.internet.defer import inlineCallbacks, succeed4from twisted.internet.defer import inlineCallbacks, succeed
65
@@ -11,8 +10,10 @@
11from juju.control import main10from juju.control import main
12from juju.errors import FileNotFound11from juju.errors import FileNotFound
13from juju.environment.environment import Environment12from juju.environment.environment import Environment
13from juju.lib.mocker import ANY
14from juju.lib.serializer import dump
14from juju.unit.workflow import UnitWorkflowState15from juju.unit.workflow import UnitWorkflowState
15from juju.lib.mocker import ANY16
1617
17from .common import MachineControlToolTest18from .common import MachineControlToolTest
1819
1920
=== modified file 'juju/control/tests/test_utils.py'
--- juju/control/tests/test_utils.py 2012-03-27 23:56:09 +0000
+++ juju/control/tests/test_utils.py 2012-09-15 19:26:18 +0000
@@ -1,7 +1,6 @@
1import os1import os
22
3from twisted.internet.defer import inlineCallbacks, returnValue3from twisted.internet.defer import inlineCallbacks, returnValue
4from yaml import dump
54
6from juju.environment.tests.test_config import EnvironmentsConfigTestBase5from juju.environment.tests.test_config import EnvironmentsConfigTestBase
7from juju.control.tests.common import ControlToolTest6from juju.control.tests.common import ControlToolTest
@@ -10,6 +9,7 @@
10 expand_path, parse_passthrough_args, ParseError)9 expand_path, parse_passthrough_args, ParseError)
11from juju.environment.config import EnvironmentsConfig10from juju.environment.config import EnvironmentsConfig
12from juju.environment.errors import EnvironmentsConfigError11from juju.environment.errors import EnvironmentsConfigError
12from juju.lib.serializer import yaml_dump as dump
13from juju.lib.testing import TestCase13from juju.lib.testing import TestCase
14from juju.state.errors import ServiceUnitStateMachineNotAssigned14from juju.state.errors import ServiceUnitStateMachineNotAssigned
15from juju.state.tests.test_service import ServiceStateManagerTestBase15from juju.state.tests.test_service import ServiceStateManagerTestBase
1616
=== modified file 'juju/environment/config.py'
--- juju/environment/config.py 2012-08-31 15:03:31 +0000
+++ juju/environment/config.py 2012-09-15 19:26:18 +0000
@@ -5,6 +5,7 @@
5from juju.environment.environment import Environment5from juju.environment.environment import Environment
6from juju.environment.errors import EnvironmentsConfigError6from juju.environment.errors import EnvironmentsConfigError
7from juju.errors import FileAlreadyExists, FileNotFound7from juju.errors import FileAlreadyExists, FileNotFound
8from juju.lib import serializer
8from juju.lib.schema import (9from juju.lib.schema import (
9 Constant, Dict, Int, KeyDict, OAuthString, OneOf, SchemaError, SelectDict,10 Constant, Dict, Int, KeyDict, OAuthString, OneOf, SchemaError, SelectDict,
10 String, Bool)11 String, Bool)
@@ -174,7 +175,7 @@
174 self._fail("Configuration must be a string", path, repr(content))175 self._fail("Configuration must be a string", path, repr(content))
175176
176 try:177 try:
177 config = yaml.load(content)178 config = serializer.yaml_load(content)
178 except yaml.YAMLError, error:179 except yaml.YAMLError, error:
179 self._fail(error, path=path, content=content)180 self._fail(error, path=path, content=content)
180181
@@ -309,4 +310,4 @@
309 assert data.keys() == [name]310 assert data.keys() == [name]
310 config["environments"].update(data)311 config["environments"].update(data)
311312
312 return yaml.safe_dump(config)313 return serializer.dump(config)
313314
=== modified file 'juju/environment/tests/test_config.py'
--- juju/environment/tests/test_config.py 2012-08-31 15:17:53 +0000
+++ juju/environment/tests/test_config.py 2012-09-15 19:26:18 +0000
@@ -1,5 +1,4 @@
1import os1import os
2import yaml
32
4from twisted.internet.defer import inlineCallbacks3from twisted.internet.defer import inlineCallbacks
54
@@ -8,8 +7,10 @@
8from juju.environment.environment import Environment7from juju.environment.environment import Environment
9from juju.environment.errors import EnvironmentsConfigError8from juju.environment.errors import EnvironmentsConfigError
10from juju.errors import FileNotFound, FileAlreadyExists9from juju.errors import FileNotFound, FileAlreadyExists
10from juju.lib import serializer
11from juju.state.environment import EnvironmentStateManager11from juju.state.environment import EnvironmentStateManager
1212
13
13from juju.lib.testing import TestCase14from juju.lib.testing import TestCase
1415
1516
@@ -102,7 +103,7 @@
102 # self.client.103 # self.client.
103104
104 def push_config(self, name, config):105 def push_config(self, name, config):
105 self.write_config(yaml.dump(config))106 self.write_config(serializer.yaml_dump(config))
106 self.config.load()107 self.config.load()
107 esm = EnvironmentStateManager(self.client)108 esm = EnvironmentStateManager(self.client)
108 return esm.set_config_state(self.config, name)109 return esm.set_config_state(self.config, name)
@@ -129,8 +130,8 @@
129 self.assertEquals(self.config.get_default_path(), self.default_path)130 self.assertEquals(self.config.get_default_path(), self.default_path)
130131
131 def compare_config(self, config1, sample_config2):132 def compare_config(self, config1, sample_config2):
132 config1 = yaml.load(config1)133 config1 = serializer.yaml_load(config1)
133 config2 = yaml.load(134 config2 = serializer.yaml_load(
134 sample_config2 % config1["environments"]["sample"])135 sample_config2 % config1["environments"]["sample"])
135 self.assertEqual(config1, config2)136 self.assertEqual(config1, config2)
136137
@@ -193,7 +194,7 @@
193 self.assertTrue(os.path.isfile(self.default_path))194 self.assertTrue(os.path.isfile(self.default_path))
194195
195 with open(self.default_path) as file:196 with open(self.default_path) as file:
196 config = yaml.load(file.read())197 config = serializer.yaml_load(file.read())
197 self.assertEqual(198 self.assertEqual(
198 config["environments"]["sample"]["type"], "ec2")199 config["environments"]["sample"]["type"], "ec2")
199 self.assertEqual(200 self.assertEqual(
@@ -373,9 +374,9 @@
373 get_default() must return the one defined environment, when it's374 get_default() must return the one defined environment, when it's
374 indeed a single one.375 indeed a single one.
375 """376 """
376 config = yaml.load(SAMPLE_ENV)377 config = serializer.yaml_load(SAMPLE_ENV)
377 del config["environments"]["mysecondenv"]378 del config["environments"]["mysecondenv"]
378 self.write_config(yaml.dump(config))379 self.write_config(serializer.yaml_dump(config))
379 self.config.load()380 self.config.load()
380 env = self.config.get_default()381 env = self.config.get_default()
381 self.assertEquals(env.name, "myfirstenv")382 self.assertEquals(env.name, "myfirstenv")
@@ -385,9 +386,9 @@
385 get_default() must otherwise return the environment named386 get_default() must otherwise return the environment named
386 through the "default:" option.387 through the "default:" option.
387 """388 """
388 config = yaml.load(SAMPLE_ENV)389 config = serializer.yaml_load(SAMPLE_ENV)
389 config["default"] = "mysecondenv"390 config["default"] = "mysecondenv"
390 self.write_config(yaml.dump(config))391 self.write_config(serializer.yaml_dump(config))
391 self.config.load()392 self.config.load()
392 env = self.config.get_default()393 env = self.config.get_default()
393 self.assertEquals(env.name, "mysecondenv")394 self.assertEquals(env.name, "mysecondenv")
@@ -396,9 +397,9 @@
396 """397 """
397 The schema should mention the "default:" option as a string.398 The schema should mention the "default:" option as a string.
398 """399 """
399 config = yaml.load(SAMPLE_ENV)400 config = serializer.yaml_load(SAMPLE_ENV)
400 config["default"] = 1401 config["default"] = 1
401 self.write_config(yaml.dump(config))402 self.write_config(serializer.yaml_dump(config))
402 error = self.assertRaises(EnvironmentsConfigError, self.config.load)403 error = self.assertRaises(EnvironmentsConfigError, self.config.load)
403 self.assertEquals(404 self.assertEquals(
404 str(error),405 str(error),
@@ -410,10 +411,10 @@
410 get_default() must raise an error if the environment named through411 get_default() must raise an error if the environment named through
411 the "default:" option isn't found.412 the "default:" option isn't found.
412 """413 """
413 config = yaml.load(SAMPLE_ENV)414 config = serializer.yaml_load(SAMPLE_ENV)
414 config["default"] = "non-existent"415 config["default"] = "non-existent"
415 # Use a different path to ensure the error message is right.416 # Use a different path to ensure the error message is right.
416 self.write_config(yaml.dump(config), other_path=True)417 self.write_config(serializer.yaml_dump(config), other_path=True)
417 self.config.load(self.other_path)418 self.config.load(self.other_path)
418 try:419 try:
419 self.config.get_default()420 self.config.get_default()
@@ -447,10 +448,10 @@
447 contains a machine provider configuration without any type448 contains a machine provider configuration without any type
448 information.449 information.
449 """450 """
450 config = yaml.load(SAMPLE_ENV)451 config = serializer.yaml_load(SAMPLE_ENV)
451 # Delete the type.452 # Delete the type.
452 del config["environments"]["myfirstenv"]["type"]453 del config["environments"]["myfirstenv"]["type"]
453 self.write_config(yaml.dump(config), other_path=True)454 self.write_config(serializer.yaml_dump(config), other_path=True)
454455
455 try:456 try:
456 self.config.load(self.other_path)457 self.config.load(self.other_path)
@@ -468,12 +469,12 @@
468 self.write_config(SAMPLE_ENV)469 self.write_config(SAMPLE_ENV)
469 self.config.load()470 self.config.load()
470 config = self.config.serialize()471 config = self.config.serialize()
471 serialized = yaml.load(SAMPLE_ENV)472 serialized = serializer.yaml_load(SAMPLE_ENV)
472473
473 for d in serialized["environments"].values():474 for d in serialized["environments"].values():
474 d["dynamicduck"] = "magic"475 d["dynamicduck"] = "magic"
475476
476 self.assertEqual(yaml.load(config), serialized)477 self.assertEqual(serializer.yaml_load(config), serialized)
477478
478 def test_serialize_environment(self):479 def test_serialize_environment(self):
479 """480 """
@@ -484,12 +485,12 @@
484 self.write_config(SAMPLE_ENV)485 self.write_config(SAMPLE_ENV)
485 self.config.load()486 self.config.load()
486487
487 data = yaml.load(SAMPLE_ENV)488 data = serializer.yaml_load(SAMPLE_ENV)
488 del data["environments"]["mysecondenv"]489 del data["environments"]["mysecondenv"]
489 data["environments"]["myfirstenv"]["dynamicduck"] = "magic"490 data["environments"]["myfirstenv"]["dynamicduck"] = "magic"
490491
491 self.assertEqual(492 self.assertEqual(
492 yaml.load(self.config.serialize("myfirstenv")),493 serializer.yaml_load(self.config.serialize("myfirstenv")),
493 data)494 data)
494495
495 def test_load_serialized_environment(self):496 def test_load_serialized_environment(self):
@@ -518,9 +519,9 @@
518519
519 def test_serialize_custom_variables_outside_environment(self):520 def test_serialize_custom_variables_outside_environment(self):
520 """Serializing captures custom variables out of the environment."""521 """Serializing captures custom variables out of the environment."""
521 data = yaml.load(SAMPLE_ENV)522 data = serializer.yaml_load(SAMPLE_ENV)
522 data["default"] = "myfirstenv"523 data["default"] = "myfirstenv"
523 self.write_config(yaml.dump(data))524 self.write_config(serializer.yaml_dump(data))
524 self.config.load()525 self.config.load()
525 serialized = self.config.serialize()526 serialized = self.config.serialize()
526527
@@ -543,17 +544,17 @@
543 self.write_config("\0")544 self.write_config("\0")
544 error = self.assertRaises(EnvironmentsConfigError, self.config.load)545 error = self.assertRaises(EnvironmentsConfigError, self.config.load)
545 self.assertIn(546 self.assertIn(
546 "special characters are not allowed", str(error))547 "control characters are not allowed", str(error))
547548
548 def test_ec2_verifies_region(self):549 def test_ec2_verifies_region(self):
549 # sample doesn't include credentials550 # sample doesn't include credentials
550 self.setup_ec2_credentials()551 self.setup_ec2_credentials()
551 self.config.write_sample()552 self.config.write_sample()
552 with open(self.default_path) as file:553 with open(self.default_path) as file:
553 config = yaml.load(file.read())554 config = serializer.yaml_load(file.read())
554 config["environments"]["sample"]["region"] = "ap-southeast-2"555 config["environments"]["sample"]["region"] = "ap-southeast-2"
555556
556 self.write_config(yaml.dump(config), other_path=True)557 self.write_config(serializer.yaml_dump(config), other_path=True)
557558
558 e = self.assertRaises(EnvironmentsConfigError,559 e = self.assertRaises(EnvironmentsConfigError,
559 self.config.load,560 self.config.load,
@@ -562,11 +563,11 @@
562 str(e))563 str(e))
563564
564 with open(self.default_path) as file:565 with open(self.default_path) as file:
565 config = yaml.load(file.read())566 config = serializer.yaml_load(file.read())
566 # Authorized keys are required for environment serialization.567 # Authorized keys are required for environment serialization.
567 config["environments"]["sample"]["authorized-keys"] = "mickey"568 config["environments"]["sample"]["authorized-keys"] = "mickey"
568 config["environments"]["sample"]["region"] = "ap-southeast-1"569 config["environments"]["sample"]["region"] = "ap-southeast-1"
569 self.write_config(yaml.dump(config), other_path=True)570 self.write_config(serializer.yaml_dump(config), other_path=True)
570571
571 self.config.load(self.other_path)572 self.config.load(self.other_path)
572 data = self.config.get_default().get_serialization_data()573 data = self.config.get_default().get_serialization_data()
@@ -575,9 +576,9 @@
575 def assert_ec2_sample_config(self, delete_key):576 def assert_ec2_sample_config(self, delete_key):
576 self.config.write_sample()577 self.config.write_sample()
577 with open(self.default_path) as file:578 with open(self.default_path) as file:
578 config = yaml.load(file.read())579 config = serializer.yaml_load(file.read())
579 del config["environments"]["sample"][delete_key]580 del config["environments"]["sample"][delete_key]
580 self.write_config(yaml.dump(config), other_path=True)581 self.write_config(serializer.yaml_dump(config), other_path=True)
581582
582 try:583 try:
583 self.config.load(self.other_path)584 self.config.load(self.other_path)
@@ -604,9 +605,9 @@
604 self.setup_ec2_credentials()605 self.setup_ec2_credentials()
605 self.config.write_sample()606 self.config.write_sample()
606 with open(self.default_path) as file:607 with open(self.default_path) as file:
607 config = yaml.load(file.read())608 config = serializer.yaml_load(file.read())
608 config["environments"]["sample"]["placement"] = "random"609 config["environments"]["sample"]["placement"] = "random"
609 self.write_config(yaml.dump(config), other_path=True)610 self.write_config(serializer.yaml_dump(config), other_path=True)
610611
611 e = self.assertRaises(EnvironmentsConfigError,612 e = self.assertRaises(EnvironmentsConfigError,
612 self.config.load,613 self.config.load,
@@ -615,11 +616,11 @@
615 str(e))616 str(e))
616617
617 with open(self.default_path) as file:618 with open(self.default_path) as file:
618 config = yaml.load(file.read())619 config = serializer.yaml_load(file.read())
619 # Authorized keys are required for environment serialization.620 # Authorized keys are required for environment serialization.
620 config["environments"]["sample"]["authorized-keys"] = "mickey"621 config["environments"]["sample"]["authorized-keys"] = "mickey"
621 config["environments"]["sample"]["placement"] = "local"622 config["environments"]["sample"]["placement"] = "local"
622 self.write_config(yaml.dump(config), other_path=True)623 self.write_config(serializer.yaml_dump(config), other_path=True)
623624
624 self.config.load(self.other_path)625 self.config.load(self.other_path)
625 data = self.config.get_default().get_serialization_data()626 data = self.config.get_default().get_serialization_data()
@@ -630,9 +631,9 @@
630 self.setup_ec2_credentials()631 self.setup_ec2_credentials()
631 self.config.write_sample()632 self.config.write_sample()
632 with open(self.default_path) as f:633 with open(self.default_path) as f:
633 config = yaml.load(f.read())634 config = serializer.yaml_load(f.read())
634 config["environments"]["sample"]["default-series"] = "astounding"635 config["environments"]["sample"]["default-series"] = "astounding"
635 self.write_config(yaml.dump(config), other_path=True)636 self.write_config(serializer.yaml_dump(config), other_path=True)
636637
637 self.config.load(self.other_path)638 self.config.load(self.other_path)
638639
@@ -643,9 +644,9 @@
643 self.setup_ec2_credentials()644 self.setup_ec2_credentials()
644 self.config.write_sample()645 self.config.write_sample()
645 with open(self.default_path) as f:646 with open(self.default_path) as f:
646 config = yaml.load(f.read())647 config = serializer.yaml_load(f.read())
647 config["environments"]["sample"]["ssl-hostname-verification"] = True648 config["environments"]["sample"]["ssl-hostname-verification"] = True
648 self.write_config(yaml.dump(config), other_path=True)649 self.write_config(serializer.yaml_dump(config), other_path=True)
649650
650 self.config.load(self.other_path)651 self.config.load(self.other_path)
651652
@@ -658,9 +659,9 @@
658 "admin-secret acquired-mgmt-class available-mgmt-class "659 "admin-secret acquired-mgmt-class available-mgmt-class "
659 "default-series").split()660 "default-series").split()
660 for require in requires:661 for require in requires:
661 config = yaml.load(SAMPLE_ORCHESTRA)662 config = serializer.yaml_load(SAMPLE_ORCHESTRA)
662 del config["environments"]["sample"][require]663 del config["environments"]["sample"][require]
663 self.write_config(yaml.dump(config), other_path=True)664 self.write_config(serializer.yaml_dump(config), other_path=True)
664665
665 try:666 try:
666 self.config.load(self.other_path)667 self.config.load(self.other_path)
@@ -675,25 +676,25 @@
675 % require)676 % require)
676677
677 def test_orchestra_respects_default_series(self):678 def test_orchestra_respects_default_series(self):
678 config = yaml.load(SAMPLE_ORCHESTRA)679 config = serializer.yaml_load(SAMPLE_ORCHESTRA)
679 config["environments"]["sample"]["default-series"] = "magnificent"680 config["environments"]["sample"]["default-series"] = "magnificent"
680 self.write_config(yaml.dump(config), other_path=True)681 self.write_config(serializer.yaml_dump(config), other_path=True)
681 self.config.load(self.other_path)682 self.config.load(self.other_path)
682683
683 provider = self.config.get_default().get_machine_provider()684 provider = self.config.get_default().get_machine_provider()
684 self.assertEqual(provider.config["default-series"], "magnificent")685 self.assertEqual(provider.config["default-series"], "magnificent")
685686
686 def test_orchestra_verifies_placement(self):687 def test_orchestra_verifies_placement(self):
687 config = yaml.load(SAMPLE_ORCHESTRA)688 config = serializer.yaml_load(SAMPLE_ORCHESTRA)
688 config["environments"]["sample"]["placement"] = "random"689 config["environments"]["sample"]["placement"] = "random"
689 self.write_config(yaml.dump(config), other_path=True)690 self.write_config(serializer.yaml_dump(config), other_path=True)
690 e = self.assertRaises(691 e = self.assertRaises(
691 EnvironmentsConfigError, self.config.load, self.other_path)692 EnvironmentsConfigError, self.config.load, self.other_path)
692 self.assertIn("expected 'unassigned', got 'random'",693 self.assertIn("expected 'unassigned', got 'random'",
693 str(e))694 str(e))
694695
695 config["environments"]["sample"]["placement"] = "local"696 config["environments"]["sample"]["placement"] = "local"
696 self.write_config(yaml.dump(config), other_path=True)697 self.write_config(serializer.yaml_dump(config), other_path=True)
697 self.config.load(self.other_path)698 self.config.load(self.other_path)
698699
699 data = self.config.get_default().placement700 data = self.config.get_default().placement
@@ -702,9 +703,9 @@
702 def test_maas_schema_requires(self):703 def test_maas_schema_requires(self):
703 requires = "maas-server maas-oauth admin-secret default-series".split()704 requires = "maas-server maas-oauth admin-secret default-series".split()
704 for require in requires:705 for require in requires:
705 config = yaml.load(SAMPLE_MAAS)706 config = serializer.yaml_load(SAMPLE_MAAS)
706 del config["environments"]["sample"][require]707 del config["environments"]["sample"][require]
707 self.write_config(yaml.dump(config), other_path=True)708 self.write_config(serializer.yaml_dump(config), other_path=True)
708709
709 try:710 try:
710 self.config.load(self.other_path)711 self.config.load(self.other_path)
@@ -719,9 +720,9 @@
719 % require)720 % require)
720721
721 def test_maas_default_series(self):722 def test_maas_default_series(self):
722 config = yaml.load(SAMPLE_MAAS)723 config = serializer.yaml_load(SAMPLE_MAAS)
723 config["environments"]["sample"]["default-series"] = "magnificent"724 config["environments"]["sample"]["default-series"] = "magnificent"
724 self.write_config(yaml.dump(config), other_path=True)725 self.write_config(serializer.yaml_dump(config), other_path=True)
725 e = self.assertRaises(726 e = self.assertRaises(
726 EnvironmentsConfigError, self.config.load, self.other_path)727 EnvironmentsConfigError, self.config.load, self.other_path)
727 self.assertIn(728 self.assertIn(
@@ -730,16 +731,16 @@
730 str(e))731 str(e))
731732
732 def test_maas_verifies_placement(self):733 def test_maas_verifies_placement(self):
733 config = yaml.load(SAMPLE_MAAS)734 config = serializer.yaml_load(SAMPLE_MAAS)
734 config["environments"]["sample"]["placement"] = "random"735 config["environments"]["sample"]["placement"] = "random"
735 self.write_config(yaml.dump(config), other_path=True)736 self.write_config(serializer.yaml_dump(config), other_path=True)
736 e = self.assertRaises(737 e = self.assertRaises(
737 EnvironmentsConfigError, self.config.load, self.other_path)738 EnvironmentsConfigError, self.config.load, self.other_path)
738 self.assertIn("expected 'unassigned', got 'random'",739 self.assertIn("expected 'unassigned', got 'random'",
739 str(e))740 str(e))
740741
741 config["environments"]["sample"]["placement"] = "local"742 config["environments"]["sample"]["placement"] = "local"
742 self.write_config(yaml.dump(config), other_path=True)743 self.write_config(serializer.yaml_dump(config), other_path=True)
743 self.config.load(self.other_path)744 self.config.load(self.other_path)
744745
745 data = self.config.get_default().placement746 data = self.config.get_default().placement
@@ -747,51 +748,51 @@
747748
748 def test_lxc_requires_data_dir(self):749 def test_lxc_requires_data_dir(self):
749 """lxc dev only supports local placement."""750 """lxc dev only supports local placement."""
750 config = yaml.load(SAMPLE_LOCAL)751 config = serializer.yaml_load(SAMPLE_LOCAL)
751 self.write_config(yaml.dump(config), other_path=True)752 self.write_config(serializer.yaml_dump(config), other_path=True)
752 error = self.assertRaises(753 error = self.assertRaises(
753 EnvironmentsConfigError, self.config.load, self.other_path)754 EnvironmentsConfigError, self.config.load, self.other_path)
754 self.assertIn("data-dir: required value not found", str(error))755 self.assertIn("data-dir: required value not found", str(error))
755756
756 def test_lxc_verifies_placement(self):757 def test_lxc_verifies_placement(self):
757 """lxc dev only supports local placement."""758 """lxc dev only supports local placement."""
758 config = yaml.load(SAMPLE_LOCAL)759 config = serializer.yaml_load(SAMPLE_LOCAL)
759 config["environments"]["sample"]["placement"] = "unassigned"760 config["environments"]["sample"]["placement"] = "unassigned"
760 self.write_config(yaml.dump(config), other_path=True)761 self.write_config(serializer.yaml_dump(config), other_path=True)
761 error = self.assertRaises(762 error = self.assertRaises(
762 EnvironmentsConfigError, self.config.load, self.other_path)763 EnvironmentsConfigError, self.config.load, self.other_path)
763 self.assertIn("expected 'local', got 'unassigned'", str(error))764 self.assertIn("expected 'local', got 'unassigned'", str(error))
764765
765 def test_openstack_requires_default_image_id(self):766 def test_openstack_requires_default_image_id(self):
766 """A VM image must be supplied for openstack provider."""767 """A VM image must be supplied for openstack provider."""
767 config = yaml.load(SAMPLE_OPENSTACK)768 config = serializer.yaml_load(SAMPLE_OPENSTACK)
768 del config["environments"]["sample"]["default-image-id"]769 del config["environments"]["sample"]["default-image-id"]
769 self.write_config(yaml.dump(config), other_path=True)770 self.write_config(serializer.yaml_dump(config), other_path=True)
770 error = self.assertRaises(771 error = self.assertRaises(
771 EnvironmentsConfigError, self.config.load, self.other_path)772 EnvironmentsConfigError, self.config.load, self.other_path)
772 self.assertIn("default-image-id: required value not found", str(error))773 self.assertIn("default-image-id: required value not found", str(error))
773774
774 def test_openstack_ignores_placement(self):775 def test_openstack_ignores_placement(self):
775 """The placement config is not verified for openstack provider."""776 """The placement config is not verified for openstack provider."""
776 config = yaml.load(SAMPLE_OPENSTACK)777 config = serializer.yaml_load(SAMPLE_OPENSTACK)
777 config["environments"]["sample"]["placement"] = "whatever"778 config["environments"]["sample"]["placement"] = "whatever"
778 self.write_config(yaml.dump(config), other_path=True)779 self.write_config(serializer.yaml_dump(config), other_path=True)
779 self.config.load(self.other_path)780 self.config.load(self.other_path)
780781
781 def test_openstack_s3_requires_default_image_id(self):782 def test_openstack_s3_requires_default_image_id(self):
782 """A VM image must be supplied for openstack_s3 provider."""783 """A VM image must be supplied for openstack_s3 provider."""
783 config = yaml.load(SAMPLE_OPENSTACK)784 config = serializer.yaml_load(SAMPLE_OPENSTACK)
784 config["environments"]["sample"]["type"] = "openstack_s3"785 config["environments"]["sample"]["type"] = "openstack_s3"
785 del config["environments"]["sample"]["default-image-id"]786 del config["environments"]["sample"]["default-image-id"]
786 self.write_config(yaml.dump(config), other_path=True)787 self.write_config(serializer.yaml_dump(config), other_path=True)
787 error = self.assertRaises(788 error = self.assertRaises(
788 EnvironmentsConfigError, self.config.load, self.other_path)789 EnvironmentsConfigError, self.config.load, self.other_path)
789 self.assertIn("default-image-id: required value not found", str(error))790 self.assertIn("default-image-id: required value not found", str(error))
790791
791 def test_openstack_s3_ignores_placement(self):792 def test_openstack_s3_ignores_placement(self):
792 """The placement config is not verified for openstack_s3 provider."""793 """The placement config is not verified for openstack_s3 provider."""
793 config = yaml.load(SAMPLE_OPENSTACK)794 config = serializer.yaml_load(SAMPLE_OPENSTACK)
794 config["environments"]["sample"]["type"] = "openstack_s3"795 config["environments"]["sample"]["type"] = "openstack_s3"
795 config["environments"]["sample"]["placement"] = "whatever"796 config["environments"]["sample"]["placement"] = "whatever"
796 self.write_config(yaml.dump(config), other_path=True)797 self.write_config(serializer.yaml_dump(config), other_path=True)
797 self.config.load(self.other_path)798 self.config.load(self.other_path)
798799
=== modified file 'juju/hooks/protocol.py'
--- juju/hooks/protocol.py 2012-08-30 03:25:04 +0000
+++ juju/hooks/protocol.py 2012-09-15 19:26:18 +0000
@@ -48,9 +48,10 @@
48from twisted.internet import defer48from twisted.internet import defer
49from twisted.internet import protocol49from twisted.internet import protocol
50from twisted.protocols import amp50from twisted.protocols import amp
51import yaml51
5252
53from juju.errors import JujuError53from juju.errors import JujuError
54from juju.lib import serializer
54from juju.lib.format import get_charm_formatter, get_charm_formatter_from_env55from juju.lib.format import get_charm_formatter, get_charm_formatter_from_env
55from juju.state.errors import UnitRelationStateNotFound56from juju.state.errors import UnitRelationStateNotFound
56from juju.state.hook import RelationHookContext57from juju.state.hook import RelationHookContext
@@ -310,7 +311,7 @@
310311
311 # NOTE: no need to consider charm format for blob here, this312 # NOTE: no need to consider charm format for blob here, this
312 # blob has always been in YAML format313 # blob has always been in YAML format
313 defer.returnValue(dict(data=yaml.safe_dump(options)))314 defer.returnValue(dict(data=serializer.dump(options)))
314315
315 @OpenPortCommand.responder316 @OpenPortCommand.responder
316 @defer.inlineCallbacks317 @defer.inlineCallbacks
@@ -457,7 +458,7 @@
457 client_id=client_id,458 client_id=client_id,
458 option_name=option_name)459 option_name=option_name)
459 # Unbundle and deserialize460 # Unbundle and deserialize
460 result = yaml.safe_load(result["data"])461 result = serializer.load(result["data"])
461 defer.returnValue(result)462 defer.returnValue(result)
462463
463 @defer.inlineCallbacks464 @defer.inlineCallbacks
464465
=== modified file 'juju/hooks/scheduler.py'
--- juju/hooks/scheduler.py 2012-03-30 05:17:34 +0000
+++ juju/hooks/scheduler.py 2012-09-15 19:26:18 +0000
@@ -1,10 +1,11 @@
1import logging1import logging
2import os2import os
3import yaml3
44
5from twisted.internet.defer import (5from twisted.internet.defer import (
6 DeferredQueue, inlineCallbacks, succeed, Deferred,6 DeferredQueue, inlineCallbacks, succeed, Deferred,
7 QueueUnderflow, QueueOverflow)7 QueueUnderflow, QueueOverflow)
8from juju.lib import serializer
8from juju.state.hook import RelationHookContext, RelationChange9from juju.state.hook import RelationHookContext, RelationChange
910
1011
@@ -202,7 +203,7 @@
202203
203 def _load_state(self):204 def _load_state(self):
204 with open(self._state_path) as f:205 with open(self._state_path) as f:
205 state = yaml.load(f.read())206 state = serializer.load(f.read())
206 if not state:207 if not state:
207 return self._create_state()208 return self._create_state()
208 self._context_members = set(state["context_members"])209 self._context_members = set(state["context_members"])
@@ -211,7 +212,7 @@
211 self._run_queue.pending = state["change_queue"]212 self._run_queue.pending = state["change_queue"]
212213
213 def _save_state(self):214 def _save_state(self):
214 state = yaml.dump({215 state = serializer.dump({
215 "context_members": sorted(self._context_members),216 "context_members": sorted(self._context_members),
216 "member_versions": self._member_versions,217 "member_versions": self._member_versions,
217 "change_queue": self._run_queue.pending})218 "change_queue": self._run_queue.pending})
218219
=== modified file 'juju/hooks/tests/test_invoker.py'
--- juju/hooks/tests/test_invoker.py 2012-09-01 05:22:05 +0000
+++ juju/hooks/tests/test_invoker.py 2012-09-15 19:26:18 +0000
@@ -7,7 +7,6 @@
7import os7import os
8import stat8import stat
9import sys9import sys
10import yaml
1110
12from twisted.internet import defer11from twisted.internet import defer
13from twisted.internet.process import Process12from twisted.internet.process import Process
@@ -20,6 +19,7 @@
20from juju.hooks import invoker19from juju.hooks import invoker
21from juju.hooks import commands20from juju.hooks import commands
22from juju.hooks.protocol import UnitSettingsFactory21from juju.hooks.protocol import UnitSettingsFactory
22from juju.lib import serializer
23from juju.lib.mocker import MATCH23from juju.lib.mocker import MATCH
24from juju.lib.twistutils import get_module_directory24from juju.lib.twistutils import get_module_directory
25from juju.state import hook25from juju.state import hook
@@ -728,7 +728,7 @@
728 zk_data = yield self.relation.get_data()728 zk_data = yield self.relation.get_data()
729 self.assertEqual(729 self.assertEqual(
730 {"a": "b", "c": "d", "private-address": "mysql-0.example.com"},730 {"a": "b", "c": "d", "private-address": "mysql-0.example.com"},
731 yaml.load(zk_data))731 serializer.load(zk_data))
732 yield exe.ended732 yield exe.ended
733 self.assertIn(733 self.assertIn(
734 "Flushed values for hook %r on 'database:42'\n"734 "Flushed values for hook %r on 'database:42'\n"
@@ -771,7 +771,7 @@
771 self.assertEqual(771 self.assertEqual(
772 {"new-value": "2", "changed": "abc", "changed2": "xyz",772 {"new-value": "2", "changed": "abc", "changed2": "xyz",
773 "private-address": "mysql-0.example.com"},773 "private-address": "mysql-0.example.com"},
774 yaml.load(zk_data))774 serializer.load(zk_data))
775775
776 # Verify that unicode/strings longer than 100 characters in776 # Verify that unicode/strings longer than 100 characters in
777 # representation (including quotes and the u marker) are cut777 # representation (including quotes and the u marker) are cut
@@ -816,7 +816,7 @@
816 zk_data = yield self.relation.get_data()816 zk_data = yield self.relation.get_data()
817 self.assertEqual({"no-change": "42", "untouched": "xyz",817 self.assertEqual({"no-change": "42", "untouched": "xyz",
818 "private-address": "mysql-0.example.com"},818 "private-address": "mysql-0.example.com"},
819 yaml.load(zk_data))819 serializer.load(zk_data))
820 self.assertNotIn(820 self.assertNotIn(
821 "Flushed values for hook 'set-does-nothing'",821 "Flushed values for hook 'set-does-nothing'",
822 output.getvalue())822 output.getvalue())
@@ -960,7 +960,7 @@
960 internal_unit_id = (yield context.get_local_unit_state()).internal_id960 internal_unit_id = (yield context.get_local_unit_state()).internal_id
961 path = yield context.get_settings_path(internal_unit_id)961 path = yield context.get_settings_path(internal_unit_id)
962 data, stat = yield self.client.get(path)962 data, stat = yield self.client.get(path)
963 self.assertEqual(yaml.load(data), expected)963 self.assertEqual(serializer.load(data), expected)
964964
965 @defer.inlineCallbacks965 @defer.inlineCallbacks
966 def test_implied_relation_hook_context(self):966 def test_implied_relation_hook_context(self):
967967
=== modified file 'juju/hooks/tests/test_scheduler.py'
--- juju/hooks/tests/test_scheduler.py 2012-03-28 02:55:12 +0000
+++ juju/hooks/tests/test_scheduler.py 2012-09-15 19:26:18 +0000
@@ -1,10 +1,9 @@
1import logging1import logging
2import os2import os
3import yaml
43
5from twisted.internet.defer import (4from twisted.internet.defer import (
6 inlineCallbacks, fail, succeed, Deferred, returnValue)5 inlineCallbacks, fail, succeed, Deferred, returnValue)
76from juju.lib import serializer
8from juju.hooks.scheduler import HookScheduler7from juju.hooks.scheduler import HookScheduler
9from juju.state.tests.test_service import ServiceStateManagerTestBase8from juju.state.tests.test_service import ServiceStateManagerTestBase
109
@@ -44,7 +43,7 @@
4443
45 def write_single_unit_state(self):44 def write_single_unit_state(self):
46 with open(self.state_file, "w") as f:45 with open(self.state_file, "w") as f:
47 f.write(yaml.dump({46 f.write(serializer.dump({
48 "context_members": ["u-1"],47 "context_members": ["u-1"],
49 "member_versions": {"u-1": 0},48 "member_versions": {"u-1": 0},
50 "unit_ops": {},49 "unit_ops": {},
@@ -82,7 +81,7 @@
82 yield sched_done81 yield sched_done
83 self.assertFalse(self.scheduler.running)82 self.assertFalse(self.scheduler.running)
84 with open(self.state_file) as f:83 with open(self.state_file) as f:
85 self.assertEquals(yaml.load(f.read()), {84 self.assertEquals(serializer.load(f.read()), {
86 "context_members": ['u-1'],85 "context_members": ['u-1'],
87 "member_versions": {"u-1": 0},86 "member_versions": {"u-1": 0},
88 "change_queue": [87 "change_queue": [
@@ -118,7 +117,7 @@
118 self.assertFalse(collected)117 self.assertFalse(collected)
119118
120 with open(self.state_file) as f:119 with open(self.state_file) as f:
121 self.assertEquals(yaml.load(f.read()), {120 self.assertEquals(serializer.load(f.read()), {
122 "context_members": [],121 "context_members": [],
123 "member_versions": {},122 "member_versions": {},
124 "change_queue": [123 "change_queue": [
@@ -163,7 +162,7 @@
163 self.scheduler.cb_change_members(["u-1"], ["u-2"])162 self.scheduler.cb_change_members(["u-1"], ["u-2"])
164163
165 with open(self.state_file) as f:164 with open(self.state_file) as f:
166 self.assertEquals(yaml.load(f.read()), {165 self.assertEquals(serializer.load(f.read()), {
167 "context_members": ['u-2'],166 "context_members": ['u-2'],
168 "member_versions": {"u-2": 0},167 "member_versions": {"u-2": 0},
169 "change_queue": [168 "change_queue": [
@@ -200,7 +199,7 @@
200 self.assertFalse(self.scheduler.running)199 self.assertFalse(self.scheduler.running)
201200
202 with open(self.state_file) as f:201 with open(self.state_file) as f:
203 self.assertEquals(yaml.load(f.read()), {202 self.assertEquals(serializer.load(f.read()), {
204 "context_members": ['u-2'],203 "context_members": ['u-2'],
205 "member_versions": {"u-2": 0},204 "member_versions": {"u-2": 0},
206 "change_queue": [205 "change_queue": [
@@ -318,7 +317,7 @@
318 ("u-1", "modified", ["u-1"])])317 ("u-1", "modified", ["u-1"])])
319318
320 with open(self.state_file) as f:319 with open(self.state_file) as f:
321 self.assertEquals(yaml.load(f.read()), {320 self.assertEquals(serializer.load(f.read()), {
322 "context_members": ['u-1'],321 "context_members": ['u-1'],
323 "member_versions": {"u-1": 0},322 "member_versions": {"u-1": 0},
324 "change_queue": []})323 "change_queue": []})
@@ -468,7 +467,7 @@
468467
469 def test_empty_state(self):468 def test_empty_state(self):
470 with open(self.state_file, "w") as f:469 with open(self.state_file, "w") as f:
471 f.write(yaml.dump({}))470 f.write(serializer.dump({}))
472471
473 # Induce lazy creation to verify it can still survive472 # Induce lazy creation to verify it can still survive
474 self.scheduler473 self.scheduler
@@ -527,7 +526,7 @@
527 it hasn't previously been given a notify of before.526 it hasn't previously been given a notify of before.
528 """527 """
529 with open(self.state_file, "w") as f:528 with open(self.state_file, "w") as f:
530 f.write(yaml.dump({529 f.write(serializer.dump({
531 "context_members": ["u-1", "u-2"],530 "context_members": ["u-1", "u-2"],
532 "member_versions": {"u-1": 0, "u-2": 0},531 "member_versions": {"u-1": 0, "u-2": 0},
533 "change_queue": []}))532 "change_queue": []}))
@@ -559,7 +558,7 @@
559 self.assertEqual(members, ["u-2", "u-3", "u-4"])558 self.assertEqual(members, ["u-2", "u-3", "u-4"])
560559
561 with open(self.state_file) as f:560 with open(self.state_file) as f:
562 state = yaml.load(f.read())561 state = serializer.load(f.read())
563 self.assertEquals(state, {562 self.assertEquals(state, {
564 "change_queue": [],563 "change_queue": [],
565 "context_members": ["u-2", "u-3", "u-4"],564 "context_members": ["u-2", "u-3", "u-4"],
@@ -568,7 +567,7 @@
568 @inlineCallbacks567 @inlineCallbacks
569 def test_state_is_loaded(self):568 def test_state_is_loaded(self):
570 with open(self.state_file, "w") as f:569 with open(self.state_file, "w") as f:
571 f.write(yaml.dump({570 f.write(serializer.dump({
572 "context_members": ["u-1", "u-2", "u-3"],571 "context_members": ["u-1", "u-2", "u-3"],
573 "member_versions": {"u-1": 5, "u-2": 2, "u-3": 0},572 "member_versions": {"u-1": 5, "u-2": 2, "u-3": 0},
574 "change_queue": [573 "change_queue": [
@@ -594,7 +593,7 @@
594 self.assertEqual(members, ["u-1", "u-2", "u-3"])593 self.assertEqual(members, ["u-1", "u-2", "u-3"])
595594
596 with open(self.state_file) as f:595 with open(self.state_file) as f:
597 state = yaml.load(f.read())596 state = serializer.load(f.read())
598 self.assertEquals(state, {597 self.assertEquals(state, {
599 "context_members": ["u-1", "u-2", "u-3"],598 "context_members": ["u-1", "u-2", "u-3"],
600 "member_versions": {"u-1": 5, "u-2": 2, "u-3": 0},599 "member_versions": {"u-1": 5, "u-2": 2, "u-3": 0},
@@ -602,7 +601,7 @@
602601
603 def test_state_is_stored(self):602 def test_state_is_stored(self):
604 with open(self.state_file, "w") as f:603 with open(self.state_file, "w") as f:
605 f.write(yaml.dump({604 f.write(serializer.dump({
606 "context_members": ["u-1", "u-2"],605 "context_members": ["u-1", "u-2"],
607 "member_versions": {"u-1": 0, "u-2": 2},606 "member_versions": {"u-1": 0, "u-2": 2},
608 "change_queue": []}))607 "change_queue": []}))
@@ -614,7 +613,7 @@
614 self.scheduler.stop()613 self.scheduler.stop()
615614
616 with open(self.state_file) as f:615 with open(self.state_file) as f:
617 state = yaml.load(f.read())616 state = serializer.load(f.read())
618 self.assertEquals(state, {617 self.assertEquals(state, {
619 "context_members": ["u-2", "u-3"],618 "context_members": ["u-2", "u-3"],
620 "member_versions": {"u-2": 3, "u-3": 0},619 "member_versions": {"u-2": 3, "u-3": 0},
@@ -641,7 +640,7 @@
641 self.executor = execute640 self.executor = execute
642641
643 with open(self.state_file, "w") as f:642 with open(self.state_file, "w") as f:
644 f.write(yaml.dump({643 f.write(serializer.dump({
645 "context_members": ["u-1", "u-2"],644 "context_members": ["u-1", "u-2"],
646 "member_versions": {"u-1": 1, "u-2": 0, "u-3": 0},645 "member_versions": {"u-1": 1, "u-2": 0, "u-3": 0},
647 "change_queue": [646 "change_queue": [
@@ -655,7 +654,7 @@
655 yield self.poke_zk()654 yield self.poke_zk()
656 yield self.assertFailure(d, SomeError)655 yield self.assertFailure(d, SomeError)
657 with open(self.state_file) as f:656 with open(self.state_file) as f:
658 self.assertEquals(yaml.load(f.read()), {657 self.assertEquals(serializer.load(f.read()), {
659 "context_members": ["u-1", "u-2"],658 "context_members": ["u-1", "u-2"],
660 "member_versions": {"u-1": 1, "u-2": 0, "u-3": 0},659 "member_versions": {"u-1": 1, "u-2": 0, "u-3": 0},
661 "change_queue": [660 "change_queue": [
@@ -681,14 +680,14 @@
681 "members":["u-1", "u-2", "u-3"]},680 "members":["u-1", "u-2", "u-3"]},
682 ]}681 ]}
683 with open(self.state_file, "w") as f:682 with open(self.state_file, "w") as f:
684 f.write(yaml.dump(initial_state))683 f.write(serializer.dump(initial_state))
685684
686 d = self.scheduler.run()685 d = self.scheduler.run()
687 while not self.execute_called:686 while not self.execute_called:
688 yield self.poke_zk()687 yield self.poke_zk()
689 yield self.assertFailure(d, SomeError)688 yield self.assertFailure(d, SomeError)
690 with open(self.state_file) as f:689 with open(self.state_file) as f:
691 self.assertEquals(yaml.load(f.read()), initial_state)690 self.assertEquals(serializer.load(f.read()), initial_state)
692691
693 def test_ignore_equal_settings_version(self):692 def test_ignore_equal_settings_version(self):
694 """693 """
@@ -718,7 +717,7 @@
718 on old_units.717 on old_units.
719 """718 """
720 with open(self.state_file, "w") as f:719 with open(self.state_file, "w") as f:
721 f.write(yaml.dump({720 f.write(serializer.dump({
722 "context_members": ["u-1", "u-2"],721 "context_members": ["u-1", "u-2"],
723 "member_versions": {"u-1": 0, "u-2": 0},722 "member_versions": {"u-1": 0, "u-2": 0},
724 "change_queue": []}))723 "change_queue": []}))
725724
=== modified file 'juju/lib/format.py'
--- juju/lib/format.py 2012-09-01 05:22:05 +0000
+++ juju/lib/format.py 2012-09-15 19:26:18 +0000
@@ -90,9 +90,9 @@
90 # output format, False90 # output format, False
91 if data is None:91 if data is None:
92 return ""92 return ""
93 serialized = yaml.safe_dump(93 serialized = yaml.dump(
94 data, indent=4, default_flow_style=False, width=80,94 data, indent=4, default_flow_style=False, width=80,
95 allow_unicode=True)95 allow_unicode=True, Dumper=yaml.CSafeDumper)
96 if serialized.endswith("\n...\n"):96 if serialized.endswith("\n...\n"):
97 # Remove explicit doc end sentinel, still valid yaml97 # Remove explicit doc end sentinel, still valid yaml
98 serialized = serialized[0:-5]98 serialized = serialized[0:-5]
@@ -111,7 +111,7 @@
111111
112 def load(self, data):112 def load(self, data):
113 """Loads data safely, ensuring no Python specific type info leaks"""113 """Loads data safely, ensuring no Python specific type info leaks"""
114 return yaml.safe_load(data)114 return yaml.load(data, Loader=yaml.CSafeLoader)
115115
116116
117def is_valid_charm_format(charm_format):117def is_valid_charm_format(charm_format):
118118
=== added file 'juju/lib/serializer.py'
--- juju/lib/serializer.py 1970-01-01 00:00:00 +0000
+++ juju/lib/serializer.py 2012-09-15 19:26:18 +0000
@@ -0,0 +1,21 @@
1from yaml import CSafeLoader, CSafeDumper, Mark
2from yaml import dump as _dump
3from yaml import load as _load
4
5def dump(value):
6 return _dump(value, Dumper=CSafeDumper)
7
8yaml_dump = dump
9
10def load(value):
11 return _load(value, Loader=CSafeLoader)
12
13yaml_load = load
14
15def yaml_mark_with_path(path, mark):
16 # yaml c ext, cant be modded, convert to capture path
17 return Mark(
18 path, mark.index,
19 mark.line, mark.column,
20 mark.buffer, mark.pointer)
21
022
=== modified file 'juju/providers/common/cloudinit.py'
--- juju/providers/common/cloudinit.py 2012-05-29 15:23:08 +0000
+++ juju/providers/common/cloudinit.py 2012-09-15 19:26:18 +0000
@@ -1,9 +1,10 @@
1from base64 import b64encode1from base64 import b64encode
2from subprocess import Popen, PIPE2from subprocess import Popen, PIPE
3from yaml import safe_dump3
44
5from juju.errors import CloudInitError5from juju.errors import CloudInitError
6from juju.lib.upstart import UpstartService6from juju.lib.upstart import UpstartService
7from juju.lib import serializer
7from juju.providers.common.utils import format_cloud_init8from juju.providers.common.utils import format_cloud_init
8from juju.state.auth import make_identity9from juju.state.auth import make_identity
9import juju10import juju
@@ -41,7 +42,7 @@
41 " --constraints-data=%s"42 " --constraints-data=%s"
42 " --provider-type=%s"43 " --provider-type=%s"
43 % (instance_id, make_identity("admin:%s" % secret),44 % (instance_id, make_identity("admin:%s" % secret),
44 b64encode(safe_dump(constraints.data)), provider_type)]45 b64encode(serializer.dump(constraints.data)), provider_type)]
4546
4647
47def _machine_scripts(machine_id, zookeeper_hosts):48def _machine_scripts(machine_id, zookeeper_hosts):
4849
=== modified file 'juju/providers/common/state.py'
--- juju/providers/common/state.py 2011-09-15 18:50:23 +0000
+++ juju/providers/common/state.py 2012-09-15 19:26:18 +0000
@@ -1,5 +1,6 @@
1from cStringIO import StringIO1from cStringIO import StringIO
2from yaml import safe_dump, load2from juju.lib import serializer
3
34
4from juju.errors import FileNotFound5from juju.errors import FileNotFound
56
@@ -28,7 +29,7 @@
28 return d29 return d
2930
30 def _deserialize(self, data):31 def _deserialize(self, data):
31 return load(data.read()) or False32 return serializer.load(data.read()) or False
3233
33 def _no_data(self, failure):34 def _no_data(self, failure):
34 failure.trap(FileNotFound)35 failure.trap(FileNotFound)
@@ -51,5 +52,5 @@
51 :param dict state: state to save.52 :param dict state: state to save.
52 """53 """
53 storage = self._provider.get_file_storage()54 storage = self._provider.get_file_storage()
54 data = safe_dump(state)55 data = serializer.dump(state)
55 return storage.put(_STATE_FILE, StringIO(data))56 return storage.put(_STATE_FILE, StringIO(data))
5657
=== modified file 'juju/providers/common/tests/test_cloudinit.py'
--- juju/providers/common/tests/test_cloudinit.py 2012-05-22 22:08:15 +0000
+++ juju/providers/common/tests/test_cloudinit.py 2012-09-15 19:26:18 +0000
@@ -1,9 +1,9 @@
1import os1import os
2import stat2import stat
33
4import yaml
54
6from juju.errors import CloudInitError5from juju.errors import CloudInitError
6from juju.lib import serializer
7from juju.lib.testing import TestCase7from juju.lib.testing import TestCase
8from juju.machine.tests.test_constraints import dummy_cs8from juju.machine.tests.test_constraints import dummy_cs
9from juju.providers.common.cloudinit import (9from juju.providers.common.cloudinit import (
@@ -46,10 +46,10 @@
4646
47 def assert_render(self, cloud_init, name):47 def assert_render(self, cloud_init, name):
48 with open(os.path.join(DATA_DIR, name)) as f:48 with open(os.path.join(DATA_DIR, name)) as f:
49 expected = yaml.load(f.read())49 expected = serializer.load(f.read())
50 rendered = cloud_init.render()50 rendered = cloud_init.render()
51 self.assertTrue(rendered.startswith("#cloud-config"))51 self.assertTrue(rendered.startswith("#cloud-config"))
52 self.assertEquals(yaml.load(rendered), expected)52 self.assertEquals(serializer.load(rendered), expected)
5353
54 def test_render_validate_normal(self):54 def test_render_validate_normal(self):
55 cloud_init = CloudInit()55 cloud_init = CloudInit()
5656
=== modified file 'juju/providers/common/tests/test_findzookeepers.py'
--- juju/providers/common/tests/test_findzookeepers.py 2012-07-18 19:46:53 +0000
+++ juju/providers/common/tests/test_findzookeepers.py 2012-09-15 19:26:18 +0000
@@ -1,9 +1,9 @@
1from cStringIO import StringIO1from cStringIO import StringIO
2from yaml import dump
32
4from twisted.internet.defer import fail, succeed3from twisted.internet.defer import fail, succeed
54
6from juju.errors import EnvironmentNotFound, MachinesNotFound5from juju.errors import EnvironmentNotFound, MachinesNotFound
6from juju.lib import serializer
7from juju.lib.testing import TestCase7from juju.lib.testing import TestCase
8from juju.providers.common.base import MachineProviderBase8from juju.providers.common.base import MachineProviderBase
99
@@ -21,7 +21,7 @@
2121
22 def get(self, path):22 def get(self, path):
23 test.assertEquals(path, "provider-state")23 test.assertEquals(path, "provider-state")
24 return succeed(StringIO(dump(state)))24 return succeed(StringIO(serializer.dump(state)))
2525
26 class DummyProvider(MachineProviderBase):26 class DummyProvider(MachineProviderBase):
2727
2828
=== modified file 'juju/providers/common/tests/test_state.py'
--- juju/providers/common/tests/test_state.py 2011-09-15 18:50:23 +0000
+++ juju/providers/common/tests/test_state.py 2012-09-15 19:26:18 +0000
@@ -1,10 +1,10 @@
1from cStringIO import StringIO1from cStringIO import StringIO
2from yaml import dump
32
4from twisted.internet.defer import fail, succeed3from twisted.internet.defer import fail, succeed
54
6from juju.errors import FileNotFound5from juju.errors import FileNotFound
7from juju.lib.mocker import MATCH6from juju.lib.mocker import MATCH
7from juju.lib import serializer
8from juju.lib.testing import TestCase8from juju.lib.testing import TestCase
9from juju.providers.common.base import MachineProviderBase9from juju.providers.common.base import MachineProviderBase
10from juju.providers.common.state import LoadState, SaveState10from juju.providers.common.state import LoadState, SaveState
@@ -39,7 +39,8 @@
39 return load_state.run()39 return load_state.run()
4040
41 def test_load_state(self):41 def test_load_state(self):
42 d = self.mock_get(succeed(StringIO(dump({"some": "thing"}))))42 d = self.mock_get(succeed(StringIO(
43 serializer.dump({"some": "thing"}))))
4344
44 def verify(result):45 def verify(result):
45 self.assertEquals(result, {"some": "thing"})46 self.assertEquals(result, {"some": "thing"})
@@ -74,7 +75,7 @@
74class SaveStateTest(TestCase):75class SaveStateTest(TestCase):
7576
76 def is_expected_yaml(self, result):77 def is_expected_yaml(self, result):
77 return result.read() == dump({"some": "thing"})78 return result.read() == serializer.dump({"some": "thing"})
7879
79 def test_save(self):80 def test_save(self):
80 put = self.mocker.mock()81 put = self.mocker.mock()
8182
=== modified file 'juju/providers/common/tests/test_utils.py'
--- juju/providers/common/tests/test_utils.py 2012-08-23 16:14:42 +0000
+++ juju/providers/common/tests/test_utils.py 2012-09-15 19:26:18 +0000
@@ -1,10 +1,10 @@
1import os1import os
2from yaml import load
32
4from twisted.python.failure import Failure3from twisted.python.failure import Failure
54
6from juju.environment.tests.test_config import EnvironmentsConfigTestBase5from juju.environment.tests.test_config import EnvironmentsConfigTestBase
7from juju.errors import ProviderInteractionError, JujuError6from juju.errors import ProviderInteractionError, JujuError
7from juju.lib import serializer
8from juju.lib.testing import TestCase8from juju.lib.testing import TestCase
9from juju.providers.common.utils import (9from juju.providers.common.utils import (
10 convert_unknown_error, format_cloud_init, get_user_authorized_keys)10 convert_unknown_error, format_cloud_init, get_user_authorized_keys)
@@ -107,7 +107,7 @@
107107
108 lines = output.split("\n")108 lines = output.split("\n")
109 self.assertEqual(lines.pop(0), "#cloud-config")109 self.assertEqual(lines.pop(0), "#cloud-config")
110 config = load("\n".join(lines))110 config = serializer.load("\n".join(lines))
111 self.assertEqual(config["ssh_authorized_keys"], ["zebra"])111 self.assertEqual(config["ssh_authorized_keys"], ["zebra"])
112 self.assertTrue(config["apt_update"])112 self.assertTrue(config["apt_update"])
113 self.assertTrue(config["apt_upgrade"])113 self.assertTrue(config["apt_upgrade"])
114114
=== modified file 'juju/providers/common/utils.py'
--- juju/providers/common/utils.py 2012-08-23 16:14:42 +0000
+++ juju/providers/common/utils.py 2012-09-15 19:26:18 +0000
@@ -1,9 +1,10 @@
1import logging1import logging
2import os2import os
3from yaml import safe_dump3
44
5from twisted.python.failure import Failure5from twisted.python.failure import Failure
66
7from juju.lib import serializer
7from juju.errors import JujuError, ProviderInteractionError8from juju.errors import JujuError, ProviderInteractionError
89
9log = logging.getLogger("juju.common")10log = logging.getLogger("juju.common")
@@ -136,6 +137,6 @@
136 if scripts:137 if scripts:
137 cloud_config["runcmd"] = scripts138 cloud_config["runcmd"] = scripts
138139
139 output = safe_dump(cloud_config)140 output = serializer.dump(cloud_config)
140 output = "#cloud-config\n%s" % (output)141 output = "#cloud-config\n%s" % (output)
141 return output142 return output
142143
=== modified file 'juju/providers/ec2/tests/common.py'
--- juju/providers/ec2/tests/common.py 2012-07-05 21:49:12 +0000
+++ juju/providers/ec2/tests/common.py 2012-09-15 19:26:18 +0000
@@ -1,4 +1,3 @@
1from yaml import dump
21
3from twisted.internet.defer import fail, succeed, inlineCallbacks, returnValue2from twisted.internet.defer import fail, succeed, inlineCallbacks, returnValue
43
@@ -8,6 +7,7 @@
8from txaws.ec2.exception import EC2Error7from txaws.ec2.exception import EC2Error
9from txaws.ec2.model import Instance, Reservation, SecurityGroup8from txaws.ec2.model import Instance, Reservation, SecurityGroup
109
10from juju.lib import serializer
11from juju.lib.mocker import KWARGS, MATCH11from juju.lib.mocker import KWARGS, MATCH
12from juju.providers.ec2 import MachineProvider12from juju.providers.ec2 import MachineProvider
13from juju.providers.ec2.machine import EC2ProviderMachine13from juju.providers.ec2.machine import EC2ProviderMachine
@@ -156,7 +156,7 @@
156 self.mocker.result(fail(error))156 self.mocker.result(fail(error))
157 return157 return
158158
159 state = dump({159 state = serializer.dump({
160 "zookeeper-instances":160 "zookeeper-instances":
161 [i.instance_id for i in hosts]})161 [i.instance_id for i in hosts]})
162162
163163
=== modified file 'juju/providers/ec2/tests/test_bootstrap.py'
--- juju/providers/ec2/tests/test_bootstrap.py 2012-03-29 01:37:57 +0000
+++ juju/providers/ec2/tests/test_bootstrap.py 2012-09-15 19:26:18 +0000
@@ -1,12 +1,11 @@
1import logging1import logging
2import os2import os
33
4import yaml
5
6from twisted.internet.defer import succeed, inlineCallbacks4from twisted.internet.defer import succeed, inlineCallbacks
75
8from txaws.ec2.model import SecurityGroup6from txaws.ec2.model import SecurityGroup
97
8from juju.lib import serializer
10from juju.lib.mocker import MATCH9from juju.lib.mocker import MATCH
11from juju.lib.testing import TestCase10from juju.lib.testing import TestCase
12from juju.providers.ec2.machine import EC2ProviderMachine11from juju.providers.ec2.machine import EC2ProviderMachine
@@ -40,8 +39,8 @@
40 def verify_user_data(data):39 def verify_user_data(data):
41 expect_path = os.path.join(DATA_DIR, "bootstrap_cloud_init")40 expect_path = os.path.join(DATA_DIR, "bootstrap_cloud_init")
42 with open(expect_path) as f:41 with open(expect_path) as f:
43 expect_cloud_init = yaml.load(f.read())42 expect_cloud_init = serializer.load(f.read())
44 self.assertEquals(yaml.load(data), expect_cloud_init)43 self.assertEquals(serializer.load(data), expect_cloud_init)
45 return True44 return True
4645
47 self.ec2.run_instances(46 self.ec2.run_instances(
@@ -109,7 +108,7 @@
109 If the provider bootstrap is run when there is already a running108 If the provider bootstrap is run when there is already a running
110 bootstrap instance, it will just return the existing machine.109 bootstrap instance, it will just return the existing machine.
111 """110 """
112 state = yaml.dump({"zookeeper-instances": ["i-foobar"]})111 state = serializer.dump({"zookeeper-instances": ["i-foobar"]})
113 self.s3.get_object(self.env_name, "provider-state")112 self.s3.get_object(self.env_name, "provider-state")
114 self.mocker.result(succeed(state))113 self.mocker.result(succeed(state))
115 self.ec2.describe_instances("i-foobar")114 self.ec2.describe_instances("i-foobar")
116115
=== modified file 'juju/providers/ec2/tests/test_findzookeeper.py'
--- juju/providers/ec2/tests/test_findzookeeper.py 2011-09-15 18:50:23 +0000
+++ juju/providers/ec2/tests/test_findzookeeper.py 2012-09-15 19:26:18 +0000
@@ -3,9 +3,8 @@
3from txaws.ec2.exception import EC2Error3from txaws.ec2.exception import EC2Error
4from txaws.s3.exception import S3Error4from txaws.s3.exception import S3Error
55
6from yaml import dump
7
8from juju.errors import EnvironmentNotFound6from juju.errors import EnvironmentNotFound
7from juju.lib.serializer import dump
9from juju.lib.testing import TestCase8from juju.lib.testing import TestCase
10from juju.providers.ec2.machine import EC2ProviderMachine9from juju.providers.ec2.machine import EC2ProviderMachine
11from juju.providers.ec2.tests.common import EC2TestMixin10from juju.providers.ec2.tests.common import EC2TestMixin
1211
=== modified file 'juju/providers/ec2/tests/test_launch.py'
--- juju/providers/ec2/tests/test_launch.py 2012-07-18 20:04:16 +0000
+++ juju/providers/ec2/tests/test_launch.py 2012-09-15 19:26:18 +0000
@@ -1,7 +1,5 @@
1import os1import os
22
3import yaml
4
5from twisted.internet.defer import inlineCallbacks, succeed3from twisted.internet.defer import inlineCallbacks, succeed
64
7from txaws.ec2.model import Instance, SecurityGroup5from txaws.ec2.model import Instance, SecurityGroup
@@ -9,6 +7,7 @@
9from juju.errors import EnvironmentNotFound, ProviderError7from juju.errors import EnvironmentNotFound, ProviderError
10from juju.providers.ec2.machine import EC2ProviderMachine8from juju.providers.ec2.machine import EC2ProviderMachine
119
10from juju.lib import serializer
12from juju.lib.testing import TestCase11from juju.lib.testing import TestCase
13from juju.lib.mocker import MATCH12from juju.lib.mocker import MATCH
1413
@@ -37,8 +36,8 @@
37 def verify_user_data(data):36 def verify_user_data(data):
38 expect_path = os.path.join(DATA_DIR, cloud_init)37 expect_path = os.path.join(DATA_DIR, cloud_init)
39 with open(expect_path) as f:38 with open(expect_path) as f:
40 expect_cloud_init = yaml.load(f.read())39 expect_cloud_init = serializer.load(f.read())
41 self.assertEquals(yaml.load(data), expect_cloud_init)40 self.assertEquals(serializer.load(data), expect_cloud_init)
42 return True41 return True
4342
44 self.ec2.run_instances(43 self.ec2.run_instances(
4544
=== modified file 'juju/providers/ec2/tests/test_provider.py'
--- juju/providers/ec2/tests/test_provider.py 2012-08-29 16:36:54 +0000
+++ juju/providers/ec2/tests/test_provider.py 2012-09-15 19:26:18 +0000
@@ -7,6 +7,7 @@
7from juju.providers import ec2 as _mod_provider7from juju.providers import ec2 as _mod_provider
8from juju.providers.ec2 import MachineProvider8from juju.providers.ec2 import MachineProvider
9from juju.providers.ec2.files import FileStorage9from juju.providers.ec2.files import FileStorage
10
10import logging11import logging
1112
12from .common import EC2TestMixin13from .common import EC2TestMixin
1314
=== modified file 'juju/providers/ec2/tests/test_state.py'
--- juju/providers/ec2/tests/test_state.py 2011-09-15 18:50:23 +0000
+++ juju/providers/ec2/tests/test_state.py 2012-09-15 19:26:18 +0000
@@ -1,9 +1,8 @@
1from yaml import dump
2
3from twisted.internet.defer import succeed, fail1from twisted.internet.defer import succeed, fail
42
5from txaws.s3.exception import S3Error3from txaws.s3.exception import S3Error
64
5from juju.lib import serializer
7from juju.lib.testing import TestCase6from juju.lib.testing import TestCase
8from juju.providers.ec2.tests.common import EC2TestMixin7from juju.providers.ec2.tests.common import EC2TestMixin
98
@@ -20,7 +19,7 @@
20 the machine, it will serialize the data to an s3 bucket.19 the machine, it will serialize the data to an s3 bucket.
21 """20 """
22 instances = [self.get_instance("i-foobar", dns_name="x1.example.com")]21 instances = [self.get_instance("i-foobar", dns_name="x1.example.com")]
23 state = dump(22 state = serializer.dump(
24 {"zookeeper-instances":23 {"zookeeper-instances":
25 [[i.instance_id, i.dns_name] for i in instances]})24 [[i.instance_id, i.dns_name] for i in instances]})
26 self.s3.put_object(25 self.s3.put_object(
@@ -46,7 +45,7 @@
46 already exist.45 already exist.
47 """46 """
48 instances = [self.get_instance("i-foobar", dns_name="x1.example.com")]47 instances = [self.get_instance("i-foobar", dns_name="x1.example.com")]
49 state = dump(48 state = serializer.dump(
50 {"zookeeper-instances":49 {"zookeeper-instances":
51 [[i.instance_id, i.dns_name] for i in instances]})50 [[i.instance_id, i.dns_name] for i in instances]})
52 self.s3.put_object(51 self.s3.put_object(
@@ -78,7 +77,8 @@
78 s3.77 s3.
79 """78 """
80 self.s3.get_object(self.env_name, "provider-state")79 self.s3.get_object(self.env_name, "provider-state")
81 self.mocker.result(succeed(dump({"zookeeper-instances": []})))80 self.mocker.result(
81 succeed(serializer.dump({"zookeeper-instances": []})))
82 self.mocker.replay()82 self.mocker.replay()
8383
84 provider = self.get_provider()84 provider = self.get_provider()
@@ -116,7 +116,7 @@
116 handles the scenario where there is no saved state.116 handles the scenario where there is no saved state.
117 """117 """
118 self.s3.get_object(self.env_name, "provider-state")118 self.s3.get_object(self.env_name, "provider-state")
119 self.mocker.result(succeed(dump([])))119 self.mocker.result(succeed(serializer.dump([])))
120 self.mocker.replay()120 self.mocker.replay()
121121
122 provider = self.get_provider()122 provider = self.get_provider()
123123
=== modified file 'juju/providers/local/files.py'
--- juju/providers/local/files.py 2012-01-13 00:15:07 +0000
+++ juju/providers/local/files.py 2012-09-15 19:26:18 +0000
@@ -1,13 +1,12 @@
1from getpass import getuser
2import os1import os
3from StringIO import StringIO2from StringIO import StringIO
4import yaml
53
6from twisted.internet.defer import inlineCallbacks, returnValue4from twisted.internet.defer import inlineCallbacks, returnValue
7from twisted.internet.error import ConnectionRefusedError5from twisted.internet.error import ConnectionRefusedError
8from twisted.web.client import getPage6from twisted.web.client import getPage
97
10from juju.errors import ProviderError, FileNotFound8from juju.errors import ProviderError, FileNotFound
9from juju.lib import serializer
11from juju.lib.upstart import UpstartService10from juju.lib.upstart import UpstartService
12from juju.providers.common.files import FileStorage11from juju.providers.common.files import FileStorage
1312
@@ -79,7 +78,7 @@
79 storage = LocalStorage(self._storage_dir)78 storage = LocalStorage(self._storage_dir)
80 yield storage.put(79 yield storage.put(
81 SERVER_URL_KEY,80 SERVER_URL_KEY,
82 StringIO(yaml.safe_dump(81 StringIO(serializer.dump(
83 {"storage-url": "http://%s:%s/" % (self._host, self._port)})))82 {"storage-url": "http://%s:%s/" % (self._host, self._port)})))
8483
85 self._service.set_command(" ".join(self._service_args))84 self._service.set_command(" ".join(self._service_args))
@@ -112,5 +111,5 @@
112111
113 if not storage_data or not "storage-url" in storage_data:112 if not storage_data or not "storage-url" in storage_data:
114 raise ProviderError("Storage not initialized")113 raise ProviderError("Storage not initialized")
115 url = yaml.load(storage_data)["storage-url"]114 url = serializer.load(storage_data)["storage-url"]
116 returnValue(url + key)115 returnValue(url + key)
117116
=== modified file 'juju/providers/local/tests/test_agent.py'
--- juju/providers/local/tests/test_agent.py 2012-08-03 12:28:29 +0000
+++ juju/providers/local/tests/test_agent.py 2012-09-15 19:26:18 +0000
@@ -1,9 +1,8 @@
1import os1import os
2import tempfile2import tempfile
3import subprocess3import subprocess
4import sys
54
6from twisted.internet.defer import inlineCallbacks, succeed5from twisted.internet.defer import inlineCallbacks
76
8from juju.lib.lxc.tests.test_lxc import uses_sudo7from juju.lib.lxc.tests.test_lxc import uses_sudo
9from juju.lib.testing import TestCase8from juju.lib.testing import TestCase
109
=== modified file 'juju/providers/local/tests/test_container.py'
--- juju/providers/local/tests/test_container.py 2011-09-30 03:20:11 +0000
+++ juju/providers/local/tests/test_container.py 2012-09-15 19:26:18 +0000
@@ -3,6 +3,7 @@
3from juju.lib.testing import TestCase3from juju.lib.testing import TestCase
4from juju.lib.lxc import get_containers4from juju.lib.lxc import get_containers
5from juju.lib import lxc5from juju.lib import lxc
6
6lxc_output_sample = "\7lxc_output_sample = "\
7calendarserver\ncaprica\ngemini\nreconnoiter\nvirgo\ncalendarserver\n"8calendarserver\ncaprica\ngemini\nreconnoiter\nvirgo\ncalendarserver\n"
89
910
=== modified file 'juju/providers/local/tests/test_files.py'
--- juju/providers/local/tests/test_files.py 2012-01-27 17:02:48 +0000
+++ juju/providers/local/tests/test_files.py 2012-09-15 19:26:18 +0000
@@ -2,12 +2,12 @@
2import signal2import signal
3from StringIO import StringIO3from StringIO import StringIO
4import subprocess4import subprocess
5import yaml
65
7from twisted.internet.defer import inlineCallbacks, succeed6from twisted.internet.defer import inlineCallbacks, succeed
8from twisted.web.client import getPage7from twisted.web.client import getPage
98
10from juju.errors import ProviderError, ServiceError9from juju.errors import ProviderError, ServiceError
10from juju.lib import serializer
11from juju.lib.lxc.tests.test_lxc import uses_sudo11from juju.lib.lxc.tests.test_lxc import uses_sudo
12from juju.lib.testing import TestCase12from juju.lib.testing import TestCase
13from juju.lib.upstart import UpstartService13from juju.lib.upstart import UpstartService
@@ -177,7 +177,8 @@
177 yield self.assertFailure(self._storage.get_url("abc"), ProviderError)177 yield self.assertFailure(self._storage.get_url("abc"), ProviderError)
178 self._storage.put(178 self._storage.put(
179 SERVER_URL_KEY,179 SERVER_URL_KEY,
180 StringIO(yaml.dump({"storage-url": "http://localhost/"})))180 StringIO(
181 serializer.dump({"storage-url": "http://localhost/"})))
181182
182 self.assertEqual((yield self._storage.get_url("abc")),183 self.assertEqual((yield self._storage.get_url("abc")),
183 "http://localhost/abc")184 "http://localhost/abc")
184185
=== modified file 'juju/providers/openstack/tests/test_bootstrap.py'
--- juju/providers/openstack/tests/test_bootstrap.py 2012-07-20 15:45:56 +0000
+++ juju/providers/openstack/tests/test_bootstrap.py 2012-09-15 19:26:18 +0000
@@ -6,12 +6,8 @@
6"""6"""
77
8import logging8import logging
9import yaml
109
11from juju.lib import (10from juju.lib import mocker, testing, serializer
12 mocker,
13 testing,
14 )
1511
16from juju.providers.openstack.machine import NovaProviderMachine12from juju.providers.openstack.machine import NovaProviderMachine
17from juju.providers.openstack.tests import OpenStackTestMixin13from juju.providers.openstack.tests import OpenStackTestMixin
@@ -104,7 +100,7 @@
104 self.expect_nova_post("servers/1000/action",100 self.expect_nova_post("servers/1000/action",
105 {"addFloatingIp": {"address": "8.8.8.8"}}, code=202)101 {"addFloatingIp": {"address": "8.8.8.8"}}, code=202)
106 self.expect_swift_put("testing/provider-state",102 self.expect_swift_put("testing/provider-state",
107 yaml.dump({'zookeeper-instances': ['1000']}))103 serializer.dump({'zookeeper-instances': ['1000']}))
108104
109 def _check_machine(self, machine_list):105 def _check_machine(self, machine_list):
110 [machine] = machine_list106 [machine] = machine_list
@@ -165,7 +161,7 @@
165 def test_existing_machine(self):161 def test_existing_machine(self):
166 """A preexisting zookeeper instance is returned if present"""162 """A preexisting zookeeper instance is returned if present"""
167 self.expect_swift_get("testing/provider-state",163 self.expect_swift_get("testing/provider-state",
168 response=yaml.dump({'zookeeper-instances': ['1000']}))164 response=serializer.dump({'zookeeper-instances': ['1000']}))
169 self.expect_nova_get("servers/1000",165 self.expect_nova_get("servers/1000",
170 response={'server': {166 response={'server': {
171 'id': '1000',167 'id': '1000',
@@ -187,7 +183,7 @@
187 def test_existing_machine_missing(self):183 def test_existing_machine_missing(self):
188 """Bootstrap overwrites existing zookeeper if instance is present"""184 """Bootstrap overwrites existing zookeeper if instance is present"""
189 self.expect_swift_get("testing/provider-state",185 self.expect_swift_get("testing/provider-state",
190 response=yaml.dump({'zookeeper-instances': [3000]}))186 response=serializer.dump({'zookeeper-instances': [3000]}))
191 self.expect_nova_get("servers/3000", code=404,187 self.expect_nova_get("servers/3000", code=404,
192 response={'itemNotFound':188 response={'itemNotFound':
193 {'message': "The resource could not be found.", 'code': 404}189 {'message': "The resource could not be found.", 'code': 404}
194190
=== modified file 'juju/providers/openstack/tests/test_launch.py'
--- juju/providers/openstack/tests/test_launch.py 2012-08-24 14:21:57 +0000
+++ juju/providers/openstack/tests/test_launch.py 2012-09-15 19:26:18 +0000
@@ -1,10 +1,10 @@
1"""Tests for launching a new server customised for juju using Nova"""1"""Tests for launching a new server customised for juju using Nova"""
22
3import yaml
43
5from twisted.internet.defer import succeed4from twisted.internet.defer import succeed
65
7from juju import errors6from juju import errors
7from juju.lib import serializer
8from juju.lib.mocker import MATCH8from juju.lib.mocker import MATCH
9from juju.lib.testing import TestCase9from juju.lib.testing import TestCase
1010
@@ -68,7 +68,7 @@
68 def match(self, user_data):68 def match(self, user_data):
69 """Check contents of user_data but always match if assertions pass"""69 """Check contents of user_data but always match if assertions pass"""
70 self._case.assertEqual("#cloud-config", user_data.split("\n", 1)[0])70 self._case.assertEqual("#cloud-config", user_data.split("\n", 1)[0])
71 cc = yaml.safe_load(user_data)71 cc = serializer.load(user_data)
72 if self.is_master:72 if self.is_master:
73 zookeeper_hosts = "localhost:2181"73 zookeeper_hosts = "localhost:2181"
74 else:74 else:
7575
=== modified file 'juju/providers/openstack/tests/test_state.py'
--- juju/providers/openstack/tests/test_state.py 2012-06-18 15:03:50 +0000
+++ juju/providers/openstack/tests/test_state.py 2012-09-15 19:26:18 +0000
@@ -4,8 +4,7 @@
4state handling is a pretty thin layer over the file storage.4state handling is a pretty thin layer over the file storage.
5"""5"""
66
7import yaml7from juju.lib import serializer
8
9from juju.lib.testing import TestCase8from juju.lib.testing import TestCase
10from juju.providers.openstack.tests import OpenStackTestMixin9from juju.providers.openstack.tests import OpenStackTestMixin
1110
@@ -17,7 +16,7 @@
17 state = {"zookeeper-instances": [16 state = {"zookeeper-instances": [
18 [1000, "x1.example.com"],17 [1000, "x1.example.com"],
19 ]}18 ]}
20 self.expect_swift_put("testing/provider-state", yaml.dump(state))19 self.expect_swift_put("testing/provider-state", serializer.dump(state))
21 self.mocker.replay()20 self.mocker.replay()
22 return self.get_provider().save_state(state)21 return self.get_provider().save_state(state)
2322
@@ -26,7 +25,7 @@
26 state = {"zookeeper-instances": [25 state = {"zookeeper-instances": [
27 [1000, "x1.example.com"],26 [1000, "x1.example.com"],
28 ]}27 ]}
29 state_bytes = yaml.dump(state)28 state_bytes = serializer.dump(state)
30 self.expect_swift_put("testing/provider-state", state_bytes, code=404)29 self.expect_swift_put("testing/provider-state", state_bytes, code=404)
31 self.expect_swift_put_container("testing")30 self.expect_swift_put_container("testing")
32 self.expect_swift_put("testing/provider-state", state_bytes)31 self.expect_swift_put("testing/provider-state", state_bytes)
@@ -37,7 +36,7 @@
37 """Loading deserializes yaml from provider-state to a python dict"""36 """Loading deserializes yaml from provider-state to a python dict"""
38 state = {"zookeeper-instances": []}37 state = {"zookeeper-instances": []}
39 self.expect_swift_get("testing/provider-state",38 self.expect_swift_get("testing/provider-state",
40 response=yaml.dump(state))39 response=serializer.dump(state))
41 self.mocker.replay()40 self.mocker.replay()
42 deferred = self.get_provider().load_state()41 deferred = self.get_provider().load_state()
43 return deferred.addCallback(self.assertEqual, state)42 return deferred.addCallback(self.assertEqual, state)
4443
=== modified file 'juju/providers/orchestra/tests/common.py'
--- juju/providers/orchestra/tests/common.py 2012-04-12 01:01:57 +0000
+++ juju/providers/orchestra/tests/common.py 2012-09-15 19:26:18 +0000
@@ -1,12 +1,13 @@
1from base64 import b64decode1from base64 import b64decode
2import os2import os
3from xmlrpclib import Fault3from xmlrpclib import Fault
4from yaml import dump, load4
55
6from twisted.internet.defer import fail, succeed6from twisted.internet.defer import fail, succeed
7from twisted.web.error import Error7from twisted.web.error import Error
8from twisted.web.xmlrpc import Proxy8from twisted.web.xmlrpc import Proxy
99
10from juju.lib.serializer import dump, load
10from juju.lib.mocker import ANY, MATCH11from juju.lib.mocker import ANY, MATCH
11from juju.providers.orchestra import MachineProvider12from juju.providers.orchestra import MachineProvider
1213
1314
=== modified file 'juju/providers/orchestra/tests/test_bootstrap.py'
--- juju/providers/orchestra/tests/test_bootstrap.py 2012-04-12 01:01:57 +0000
+++ juju/providers/orchestra/tests/test_bootstrap.py 2012-09-15 19:26:18 +0000
@@ -1,9 +1,9 @@
1from xmlrpclib import Fault1from xmlrpclib import Fault
2from yaml import dump
32
4from twisted.internet.defer import succeed, inlineCallbacks3from twisted.internet.defer import succeed, inlineCallbacks
54
6from juju.errors import ProviderError5from juju.errors import ProviderError
6from juju.lib.serializer import dump
7from juju.lib.testing import TestCase7from juju.lib.testing import TestCase
8from juju.providers.orchestra.machine import OrchestraMachine8from juju.providers.orchestra.machine import OrchestraMachine
9from juju.providers.orchestra.tests.common import OrchestraTestMixin9from juju.providers.orchestra.tests.common import OrchestraTestMixin
1010
=== modified file 'juju/providers/orchestra/tests/test_findzookeepers.py'
--- juju/providers/orchestra/tests/test_findzookeepers.py 2011-10-17 13:49:47 +0000
+++ juju/providers/orchestra/tests/test_findzookeepers.py 2012-09-15 19:26:18 +0000
@@ -1,8 +1,7 @@
1from yaml import dump
2
3from twisted.internet.defer import succeed1from twisted.internet.defer import succeed
42
5from juju.errors import EnvironmentNotFound3from juju.errors import EnvironmentNotFound
4from juju.lib.serializer import dump
6from juju.lib.testing import TestCase5from juju.lib.testing import TestCase
7from juju.providers.orchestra import MachineProvider6from juju.providers.orchestra import MachineProvider
8from juju.providers.orchestra.machine import OrchestraMachine7from juju.providers.orchestra.machine import OrchestraMachine
98
=== modified file 'juju/providers/orchestra/tests/test_state.py'
--- juju/providers/orchestra/tests/test_state.py 2011-10-10 07:18:11 +0000
+++ juju/providers/orchestra/tests/test_state.py 2012-09-15 19:26:18 +0000
@@ -1,5 +1,5 @@
1from yaml import dump
21
2from juju.lib.serializer import dump
3from juju.lib.testing import TestCase3from juju.lib.testing import TestCase
4from juju.providers.orchestra import MachineProvider4from juju.providers.orchestra import MachineProvider
55
66
=== modified file 'juju/state/charm.py'
--- juju/state/charm.py 2012-04-01 03:53:48 +0000
+++ juju/state/charm.py 2012-09-15 19:26:18 +0000
@@ -1,4 +1,4 @@
1import yaml1
22
3from twisted.internet.defer import (3from twisted.internet.defer import (
4 inlineCallbacks, returnValue, succeed)4 inlineCallbacks, returnValue, succeed)
@@ -8,7 +8,7 @@
8from juju.charm.config import ConfigOptions8from juju.charm.config import ConfigOptions
9from juju.charm.metadata import MetaData9from juju.charm.metadata import MetaData
10from juju.charm.url import CharmURL10from juju.charm.url import CharmURL
11from juju.lib import under11from juju.lib import under, serializer
12from juju.state.base import StateBase12from juju.state.base import StateBase
13from juju.state.errors import CharmStateNotFound13from juju.state.errors import CharmStateNotFound
1414
@@ -41,7 +41,7 @@
41 # replacements here. For now this will do, and will41 # replacements here. For now this will do, and will
42 # explode reliably in case of conflicts.42 # explode reliably in case of conflicts.
43 yield self._client.create(43 yield self._client.create(
44 _charm_path(charm_id), yaml.safe_dump(charm_data))44 _charm_path(charm_id), serializer.dump(charm_data))
45 charm_state = CharmState(self._client, charm_id, charm_data)45 charm_state = CharmState(self._client, charm_id, charm_data)
46 returnValue(charm_state)46 returnValue(charm_state)
4747
@@ -52,7 +52,7 @@
52 content, stat = yield self._client.get(_charm_path(charm_id))52 content, stat = yield self._client.get(_charm_path(charm_id))
53 except NoNodeException:53 except NoNodeException:
54 raise CharmStateNotFound(charm_id)54 raise CharmStateNotFound(charm_id)
55 charm_data = yaml.load(content)55 charm_data = serializer.load(content)
56 charm_state = CharmState(self._client, charm_id, charm_data)56 charm_state = CharmState(self._client, charm_id, charm_data)
57 returnValue(charm_state)57 returnValue(charm_state)
5858
5959
=== modified file 'juju/state/environment.py'
--- juju/state/environment.py 2012-03-30 08:26:21 +0000
+++ juju/state/environment.py 2012-09-15 19:26:18 +0000
@@ -1,11 +1,12 @@
1import zookeeper1import zookeeper
2import yaml2
33
4from twisted.internet.defer import inlineCallbacks, returnValue4from twisted.internet.defer import inlineCallbacks, returnValue
55
6from txzookeeper.utils import retry_change6from txzookeeper.utils import retry_change
77
8from juju.environment.config import EnvironmentsConfig8from juju.environment.config import EnvironmentsConfig
9from juju.lib import serializer
9from juju.state.errors import EnvironmentStateNotFound10from juju.state.errors import EnvironmentStateNotFound
10from juju.state.base import StateBase11from juju.state.base import StateBase
1112
@@ -45,7 +46,7 @@
45 """46 """
46 data = constraints.data47 data = constraints.data
47 data.pop("ubuntu-series", None)48 data.pop("ubuntu-series", None)
48 return self._force("/constraints", yaml.safe_dump(data))49 return self._force("/constraints", serializer.dump(data))
4950
50 @inlineCallbacks51 @inlineCallbacks
51 def get_constraint_set(self):52 def get_constraint_set(self):
@@ -66,7 +67,7 @@
66 constraint_set = yield self.get_constraint_set()67 constraint_set = yield self.get_constraint_set()
67 try:68 try:
68 content, stat = yield self._client.get("/constraints")69 content, stat = yield self._client.get("/constraints")
69 data = yaml.load(content)70 data = serializer.load(content)
70 except zookeeper.NoNodeException:71 except zookeeper.NoNodeException:
71 data = {}72 data = {}
72 returnValue(constraint_set.load(data))73 returnValue(constraint_set.load(data))
@@ -107,7 +108,7 @@
107 content, stat = yield self._client.get(SETTINGS_PATH)108 content, stat = yield self._client.get(SETTINGS_PATH)
108 except zookeeper.NoNodeException:109 except zookeeper.NoNodeException:
109 returnValue(default)110 returnValue(default)
110 data = yaml.load(content)111 data = serializer.load(content)
111 returnValue(data.get(key, default))112 returnValue(data.get(key, default))
112113
113 def _set_value(self, key, value):114 def _set_value(self, key, value):
@@ -116,9 +117,9 @@
116 if not old_content:117 if not old_content:
117 data = {}118 data = {}
118 else:119 else:
119 data = yaml.load(old_content)120 data = serializer.load(old_content)
120 data[key] = value121 data[key] = value
121 return yaml.safe_dump(data)122 return serializer.dump(data)
122123
123 return retry_change(self._client, SETTINGS_PATH, set_value)124 return retry_change(self._client, SETTINGS_PATH, set_value)
124125
125126
=== modified file 'juju/state/hook.py'
--- juju/state/hook.py 2012-04-09 19:40:57 +0000
+++ juju/state/hook.py 2012-09-15 19:26:18 +0000
@@ -6,8 +6,7 @@
6from juju.state.errors import (6from juju.state.errors import (
7 UnitRelationStateNotFound, StateNotFound, RelationBrokenContextError,7 UnitRelationStateNotFound, StateNotFound, RelationBrokenContextError,
8 RelationStateNotFound, InvalidRelationIdentity, StateChanged)8 RelationStateNotFound, InvalidRelationIdentity, StateChanged)
9from juju.state.relation import (9from juju.state.relation import ServiceRelationState, UnitRelationState
10 RelationStateManager, ServiceRelationState, UnitRelationState)
11from juju.state.service import ServiceStateManager, parse_service_name10from juju.state.service import ServiceStateManager, parse_service_name
12from juju.state.utils import YAMLState11from juju.state.utils import YAMLState
1312
1413
=== modified file 'juju/state/machine.py'
--- juju/state/machine.py 2012-04-02 23:33:39 +0000
+++ juju/state/machine.py 2012-09-15 19:26:18 +0000
@@ -1,9 +1,9 @@
1import yaml
2import zookeeper1import zookeeper
32
4from twisted.internet.defer import inlineCallbacks, returnValue3from twisted.internet.defer import inlineCallbacks, returnValue
54
6from juju.errors import ConstraintError5from juju.errors import ConstraintError
6from juju.lib import serializer
7from juju.state.agent import AgentStateMixin7from juju.state.agent import AgentStateMixin
8from juju.state.environment import EnvironmentStateManager8from juju.state.environment import EnvironmentStateManager
9from juju.state.errors import MachineStateNotFound, MachineStateInUse9from juju.state.errors import MachineStateNotFound, MachineStateInUse
@@ -25,7 +25,7 @@
25 "Unprovisionable machine: incomplete constraints")25 "Unprovisionable machine: incomplete constraints")
26 machine_data = {"constraints": constraints.data}26 machine_data = {"constraints": constraints.data}
27 path = yield self._client.create(27 path = yield self._client.create(
28 "/machines/machine-", yaml.dump(machine_data),28 "/machines/machine-", serializer.dump(machine_data),
29 flags=zookeeper.SEQUENCE)29 flags=zookeeper.SEQUENCE)
30 _, internal_id = path.rsplit("/", 1)30 _, internal_id = path.rsplit("/", 1)
3131
3232
=== modified file 'juju/state/relation.py'
--- juju/state/relation.py 2012-05-15 19:07:47 +0000
+++ juju/state/relation.py 2012-09-15 19:26:18 +0000
@@ -1,7 +1,6 @@
1import logging1import logging
2from os.path import basename, dirname2from os.path import basename, dirname
33
4import yaml
5import zookeeper4import zookeeper
65
7from twisted.internet.defer import (6from twisted.internet.defer import (
@@ -9,6 +8,7 @@
98
10from txzookeeper.utils import retry_change9from txzookeeper.utils import retry_change
1110
11from juju.lib import serializer
12from juju.state.base import StateBase12from juju.state.base import StateBase
13from juju.state.errors import (13from juju.state.errors import (
14 DuplicateEndpoints, IncompatibleEndpoints, RelationAlreadyExists,14 DuplicateEndpoints, IncompatibleEndpoints, RelationAlreadyExists,
@@ -310,7 +310,7 @@
310 except zookeeper.NodeExistsException:310 except zookeeper.NodeExistsException:
311 pass311 pass
312312
313 node_data = yaml.safe_dump(relation_data)313 node_data = serializer.dump(relation_data)
314 role_path = "%s/%s" % (scope_path, relation_data["role"])314 role_path = "%s/%s" % (scope_path, relation_data["role"])
315315
316 yield retry_change(316 yield retry_change(
@@ -346,18 +346,18 @@
346 def update_address(content, stat):346 def update_address(content, stat):
347 unit_map = None347 unit_map = None
348 if content:348 if content:
349 unit_map = yaml.load(content)349 unit_map = serializer.load(content)
350 if not unit_map:350 if not unit_map:
351 unit_map = {}351 unit_map = {}
352 unit_map["private-address"] = private_address352 unit_map["private-address"] = private_address
353 return yaml.safe_dump(unit_map)353 return serializer.dump(unit_map)
354354
355 yield retry_change(self._client, settings_path, update_address)355 yield retry_change(self._client, settings_path, update_address)
356356
357 # Update the unit name -> id mapping on the relation node357 # Update the unit name -> id mapping on the relation node
358 def update_unit_mapping(content, stat):358 def update_unit_mapping(content, stat):
359 if content:359 if content:
360 unit_map = yaml.load(content)360 unit_map = serializer.load(content)
361 else:361 else:
362 unit_map = {}362 unit_map = {}
363 # If it's already present, we're done, just return the363 # If it's already present, we're done, just return the
@@ -366,7 +366,7 @@
366 if unit_state.internal_id in unit_map:366 if unit_state.internal_id in unit_map:
367 return content367 return content
368 unit_map[unit_state.internal_id] = unit_state.unit_name368 unit_map[unit_state.internal_id] = unit_state.unit_name
369 return yaml.dump(unit_map)369 return serializer.dump(unit_map)
370370
371 yield retry_change(self._client,371 yield retry_change(self._client,
372 "/relations/%s" % self._relation_id,372 "/relations/%s" % self._relation_id,
@@ -481,7 +481,7 @@
481 """481 """
482 path = yield self.get_settings_path()482 path = yield self.get_settings_path()
483 # encode as a YAML string483 # encode as a YAML string
484 data = yaml.safe_dump(data)484 data = serializer.dump(data)
485485
486 yield retry_change(486 yield retry_change(
487 self._client, path, lambda content, stat: data)487 self._client, path, lambda content, stat: data)
@@ -724,7 +724,7 @@
724 if self._relation_scope == "container":724 if self._relation_scope == "container":
725 relation_path = dirname(relation_path)725 relation_path = dirname(relation_path)
726 content, stat = yield self._client.get(relation_path)726 content, stat = yield self._client.get(relation_path)
727 self._unit_name_map = yaml.load(content)727 self._unit_name_map = serializer.load(content)
728 results = []728 results = []
729 for unit_id_list in unit_ids:729 for unit_id_list in unit_ids:
730 names = []730 names = []
731731
=== modified file 'juju/state/security.py'
--- juju/state/security.py 2011-09-15 18:50:23 +0000
+++ juju/state/security.py 2012-09-15 19:26:18 +0000
@@ -1,7 +1,7 @@
1import base641import base64
2import random2import random
3import string3import string
4import yaml4
55
6from zookeeper import (6from zookeeper import (
7 BadArgumentsException, BadVersionException,7 BadArgumentsException, BadVersionException,
@@ -10,6 +10,7 @@
10from twisted.internet.defer import inlineCallbacks, returnValue10from twisted.internet.defer import inlineCallbacks, returnValue
11from txzookeeper.client import ZOO_OPEN_ACL_UNSAFE, ZookeeperClient11from txzookeeper.client import ZOO_OPEN_ACL_UNSAFE, ZookeeperClient
1212
13from juju.lib import serializer
13from juju.state.auth import make_identity, make_ace14from juju.state.auth import make_identity, make_ace
14from juju.state.errors import (15from juju.state.errors import (
15 StateNotFound, PrincipalNotFound)16 StateNotFound, PrincipalNotFound)
@@ -74,7 +75,7 @@
74 except NoNodeException:75 except NoNodeException:
75 raise StateNotFound("Group does not exist at %r" % self._path)76 raise StateNotFound("Group does not exist at %r" % self._path)
7677
77 credentials = yaml.load(data)78 credentials = serializer.load(data)
78 self._name = credentials["name"]79 self._name = credentials["name"]
79 self._password = credentials["password"]80 self._password = credentials["password"]
8081
@@ -108,7 +109,7 @@
108 try:109 try:
109 yield self._client.create(110 yield self._client.create(
110 self._path,111 self._path,
111 yaml.safe_dump(dict(name=name, password=password)))112 serializer.dump(dict(name=name, password=password)))
112 except NodeExistsException:113 except NodeExistsException:
113 raise RuntimeError("Group already exists at %r" % self._path)114 raise RuntimeError("Group already exists at %r" % self._path)
114 self._name = name115 self._name = name
@@ -211,7 +212,7 @@
211 yield client.add_auth("digest", credentials)212 yield client.add_auth("digest", credentials)
212 # Load the otp principal data213 # Load the otp principal data
213 data, stat = yield client.get(path)214 data, stat = yield client.get(path)
214 principal_data = yaml.load(data)215 principal_data = serializer.load(data)
215 # Consume the otp node216 # Consume the otp node
216 yield client.delete(path)217 yield client.delete(path)
217 returnValue((principal_data["name"], principal_data["password"]))218 returnValue((principal_data["name"], principal_data["password"]))
@@ -237,7 +238,7 @@
237238
238 self._path = yield self._client.create(239 self._path = yield self._client.create(
239 self._path,240 self._path,
240 yaml.safe_dump(dict(name=name, password=password)),241 serializer.dump(dict(name=name, password=password)),
241 acls=acl,242 acls=acl,
242 flags=SEQUENCE)243 flags=SEQUENCE)
243244
244245
=== modified file 'juju/state/service.py'
--- juju/state/service.py 2012-04-05 22:27:11 +0000
+++ juju/state/service.py 2012-09-15 19:26:18 +0000
@@ -1,4 +1,3 @@
1import yaml
2import zookeeper1import zookeeper
32
4from twisted.internet.defer import (3from twisted.internet.defer import (
@@ -7,6 +6,7 @@
7from txzookeeper.utils import retry_change6from txzookeeper.utils import retry_change
87
9from juju.charm.url import CharmURL8from juju.charm.url import CharmURL
9from juju.lib import serializer
10from juju.state.agent import AgentStateMixin10from juju.state.agent import AgentStateMixin
11from juju.state.base import log, StateBase11from juju.state.base import log, StateBase
12from juju.state.endpoint import RelationEndpoint12from juju.state.endpoint import RelationEndpoint
@@ -55,13 +55,14 @@
55 "charm": charm_id, "constraints": constraints.data}55 "charm": charm_id, "constraints": constraints.data}
56 # charm metadata is always decoded into unicode, ensure any56 # charm metadata is always decoded into unicode, ensure any
57 # serialized state references strings to avoid tying to py runtime.57 # serialized state references strings to avoid tying to py runtime.
58 node_data = yaml.safe_dump(service_details)58 node_data = serializer.dump(service_details)
59 path = yield self._client.create("/services/service-", node_data,59 path = yield self._client.create("/services/service-", node_data,
60 flags=zookeeper.SEQUENCE)60 flags=zookeeper.SEQUENCE)
61 internal_id = path.rsplit("/", 1)[1]61 internal_id = path.rsplit("/", 1)[1]
6262
63 # create a child node for configuration options63 # create a child node for configuration options
64 yield self._client.create("%s/config" % path, yaml.dump({}))64 yield self._client.create(
65 "%s/config" % path, serializer.dump({}))
6566
66 def add_service(topology):67 def add_service(topology):
67 if topology.find_service_with_name(service_name):68 if topology.find_service_with_name(service_name):
@@ -416,7 +417,9 @@
416 charm_id = yield self.get_charm_id()417 charm_id = yield self.get_charm_id()
417 unit_data = {"charm": charm_id, "constraints": constraints.data}418 unit_data = {"charm": charm_id, "constraints": constraints.data}
418 path = yield self._client.create(419 path = yield self._client.create(
419 "/units/unit-", yaml.dump(unit_data), flags=zookeeper.SEQUENCE)420 "/units/unit-",
421 serializer.dump(unit_data),
422 flags=zookeeper.SEQUENCE)
420423
421 internal_unit_id = path.rsplit("/", 1)[1]424 internal_unit_id = path.rsplit("/", 1)[1]
422425
@@ -1094,7 +1097,7 @@
1094 try:1097 try:
1095 yield self._client.create(1098 yield self._client.create(
1096 self._hook_debug_path,1099 self._hook_debug_path,
1097 yaml.safe_dump({"debug_hooks": hook_names}),1100 serializer.dump({"debug_hooks": hook_names}),
1098 flags=zookeeper.EPHEMERAL)1101 flags=zookeeper.EPHEMERAL)
1099 except zookeeper.NodeExistsException:1102 except zookeeper.NodeExistsException:
1100 raise ServiceUnitDebugAlreadyEnabled(self.unit_name)1103 raise ServiceUnitDebugAlreadyEnabled(self.unit_name)
@@ -1125,7 +1128,7 @@
1125 except zookeeper.NoNodeException:1128 except zookeeper.NoNodeException:
1126 # We get to the same end state.1129 # We get to the same end state.
1127 returnValue(None)1130 returnValue(None)
1128 returnValue(yaml.load(content))1131 returnValue(serializer.load(content))
11291132
1130 @inlineCallbacks1133 @inlineCallbacks
1131 def watch_hook_debug(self, callback, permanent=True):1134 def watch_hook_debug(self, callback, permanent=True):
@@ -1179,12 +1182,12 @@
1179 def update(content, stat):1182 def update(content, stat):
1180 if not content:1183 if not content:
1181 flags = dict(force=force)1184 flags = dict(force=force)
1182 return yaml.dump(flags)1185 return serializer.dump(flags)
11831186
1184 flags = yaml.load(content)1187 flags = serializer.load(content)
1185 if not isinstance(flags, dict):1188 if not isinstance(flags, dict):
1186 flags = dict(force=force)1189 flags = dict(force=force)
1187 return yaml.dump(flags)1190 return serializer.dump(flags)
11881191
1189 if flags['force'] != force:1192 if flags['force'] != force:
1190 raise ServiceUnitUpgradeAlreadyEnabled(self.unit_name)1193 raise ServiceUnitUpgradeAlreadyEnabled(self.unit_name)
@@ -1205,7 +1208,7 @@
1205 returnValue(False)1208 returnValue(False)
1206 except zookeeper.NoNodeException:1209 except zookeeper.NoNodeException:
1207 returnValue(False)1210 returnValue(False)
1208 returnValue(yaml.load(content))1211 returnValue(serializer.load(content))
12091212
1210 @inlineCallbacks1213 @inlineCallbacks
1211 def clear_upgrade_flag(self):1214 def clear_upgrade_flag(self):
@@ -1282,7 +1285,7 @@
12821285
1283 try:1286 try:
1284 yield self._client.create(1287 yield self._client.create(
1285 self._unit_resolved_path, yaml.safe_dump({"retry": retry}))1288 self._unit_resolved_path, serializer.dump({"retry": retry}))
1286 except zookeeper.NodeExistsException:1289 except zookeeper.NodeExistsException:
1287 raise ServiceUnitResolvedAlreadyEnabled(self.unit_name)1290 raise ServiceUnitResolvedAlreadyEnabled(self.unit_name)
12881291
@@ -1299,7 +1302,7 @@
1299 except zookeeper.NoNodeException:1302 except zookeeper.NoNodeException:
1300 # Return a default value.1303 # Return a default value.
1301 returnValue(None)1304 returnValue(None)
1302 returnValue(yaml.load(content))1305 returnValue(serializer.load(content))
13031306
1304 @inlineCallbacks1307 @inlineCallbacks
1305 def clear_resolved(self):1308 def clear_resolved(self):
@@ -1392,10 +1395,10 @@
13921395
1393 def update_relation_resolved(content, stat):1396 def update_relation_resolved(content, stat):
1394 if not content:1397 if not content:
1395 return yaml.safe_dump(relation_map)1398 return serializer.dump(relation_map)
13961399
1397 content = yaml.safe_dump(1400 content = serializer.dump(
1398 dict_merge(yaml.load(content), relation_map))1401 dict_merge(serializer.load(content), relation_map))
1399 return content1402 return content
14001403
1401 try:1404 try:
@@ -1416,7 +1419,7 @@
1416 self._relation_resolved_path)1419 self._relation_resolved_path)
1417 except zookeeper.NoNodeException:1420 except zookeeper.NoNodeException:
1418 returnValue(None)1421 returnValue(None)
1419 returnValue(yaml.load(content))1422 returnValue(serializer.load(content))
14201423
1421 @inlineCallbacks1424 @inlineCallbacks
1422 def clear_relation_resolved(self):1425 def clear_relation_resolved(self):
@@ -1477,14 +1480,14 @@
1477 if content is None:1480 if content is None:
1478 data = {}1481 data = {}
1479 else:1482 else:
1480 data = yaml.load(content)1483 data = serializer.load(content)
1481 if data is None:1484 if data is None:
1482 data = {}1485 data = {}
1483 open_ports = data.setdefault("open", [])1486 open_ports = data.setdefault("open", [])
1484 port_proto = dict(port=port, proto=proto)1487 port_proto = dict(port=port, proto=proto)
1485 if port_proto not in open_ports:1488 if port_proto not in open_ports:
1486 open_ports.append(port_proto)1489 open_ports.append(port_proto)
1487 return yaml.safe_dump(data)1490 return serializer.dump(data)
14881491
1489 yield retry_change(self._client, self._ports_path, zk_open_port)1492 yield retry_change(self._client, self._ports_path, zk_open_port)
14901493
@@ -1499,14 +1502,14 @@
1499 if content is None:1502 if content is None:
1500 data = {}1503 data = {}
1501 else:1504 else:
1502 data = yaml.load(content)1505 data = serializer.load(content)
1503 if data is None:1506 if data is None:
1504 data = {}1507 data = {}
1505 open_ports = data.setdefault("open", [])1508 open_ports = data.setdefault("open", [])
1506 port_proto = dict(port=port, proto=proto)1509 port_proto = dict(port=port, proto=proto)
1507 if port_proto in open_ports:1510 if port_proto in open_ports:
1508 open_ports.remove(port_proto)1511 open_ports.remove(port_proto)
1509 return yaml.dump(data)1512 return serializer.dump(data)
15101513
1511 yield retry_change(1514 yield retry_change(
1512 self._client, self._ports_path, zk_close_port)1515 self._client, self._ports_path, zk_close_port)
@@ -1524,7 +1527,7 @@
1524 content, stat = yield self._client.get(self._ports_path)1527 content, stat = yield self._client.get(self._ports_path)
1525 except zookeeper.NoNodeException:1528 except zookeeper.NoNodeException:
1526 returnValue([])1529 returnValue([])
1527 data = yaml.load(content)1530 data = serializer.load(content)
1528 if data is None:1531 if data is None:
1529 returnValue(())1532 returnValue(())
1530 returnValue(data.get("open", ()))1533 returnValue(data.get("open", ()))
15311534
=== modified file 'juju/state/tests/test_charm.py'
--- juju/state/tests/test_charm.py 2012-03-29 08:26:36 +0000
+++ juju/state/tests/test_charm.py 2012-09-15 19:26:18 +0000
@@ -1,7 +1,6 @@
1import os1import os
2import shutil2import shutil
33
4import yaml
54
6from twisted.internet.defer import inlineCallbacks5from twisted.internet.defer import inlineCallbacks
76
@@ -10,6 +9,8 @@
10from juju.charm.tests.test_directory import sample_directory9from juju.charm.tests.test_directory import sample_directory
11from juju.charm.tests.test_repository import unbundled_repository10from juju.charm.tests.test_repository import unbundled_repository
1211
12from juju.lib import serializer
13
13from juju.state.charm import CharmStateManager14from juju.state.charm import CharmStateManager
14from juju.state.errors import CharmStateNotFound15from juju.state.errors import CharmStateNotFound
15from juju.state.tests.common import StateTestBase16from juju.state.tests.common import StateTestBase
@@ -44,7 +45,7 @@
44 content, stat = yield self.client.get(45 content, stat = yield self.client.get(
45 "/charms/local_3a_series_2f_dummy-1")46 "/charms/local_3a_series_2f_dummy-1")
4647
47 charm_data = yaml.load(content)48 charm_data = serializer.load(content)
48 self.assertEquals(charm_data, {49 self.assertEquals(charm_data, {
49 "metadata": self.charm.metadata.get_serialization_data(),50 "metadata": self.charm.metadata.get_serialization_data(),
50 "config": self.charm.config.get_serialization_data(),51 "config": self.charm.config.get_serialization_data(),
5152
=== modified file 'juju/state/tests/test_environment.py'
--- juju/state/tests/test_environment.py 2012-03-29 01:37:57 +0000
+++ juju/state/tests/test_environment.py 2012-09-15 19:26:18 +0000
@@ -1,10 +1,9 @@
1import yaml
2
3from twisted.internet.defer import inlineCallbacks, Deferred1from twisted.internet.defer import inlineCallbacks, Deferred
42
5from juju.environment.tests.test_config import (3from juju.environment.tests.test_config import (
6 EnvironmentsConfigTestBase, SAMPLE_ENV)4 EnvironmentsConfigTestBase, SAMPLE_ENV)
7from juju.machine.tests.test_constraints import dummy_cs5from juju.machine.tests.test_constraints import dummy_cs
6from juju.lib import serializer
8from juju.state.errors import EnvironmentStateNotFound7from juju.state.errors import EnvironmentStateNotFound
9from juju.state.environment import (8from juju.state.environment import (
10 EnvironmentStateManager, GlobalSettingsStateManager, SETTINGS_PATH)9 EnvironmentStateManager, GlobalSettingsStateManager, SETTINGS_PATH)
@@ -38,7 +37,8 @@
3837
39 serialized = self.config.serialize("myfirstenv")38 serialized = self.config.serialize("myfirstenv")
40 content, stat = yield self.client.get("/environment")39 content, stat = yield self.client.get("/environment")
41 self.assertEquals(yaml.load(content), yaml.load(serialized))40 self.assertEquals(serializer.load(content),
41 serializer.load(serialized))
4242
43 @inlineCallbacks43 @inlineCallbacks
44 def test_set_config_state_replaces_environment(self):44 def test_set_config_state_replaces_environment(self):
@@ -53,7 +53,8 @@
5353
54 serialized = self.config.serialize("myfirstenv")54 serialized = self.config.serialize("myfirstenv")
55 content, stat = yield self.client.get("/environment")55 content, stat = yield self.client.get("/environment")
56 self.assertEquals(yaml.load(content), yaml.load(serialized))56 self.assertEquals(serializer.load(content),
57 serializer.load(serialized))
5758
58 @inlineCallbacks59 @inlineCallbacks
59 def test_get_config(self):60 def test_get_config(self):
@@ -65,7 +66,8 @@
65 config = yield manager.get_config()66 config = yield manager.get_config()
66 serialized1 = self.config.serialize("myfirstenv")67 serialized1 = self.config.serialize("myfirstenv")
67 serialized2 = config.serialize("myfirstenv")68 serialized2 = config.serialize("myfirstenv")
68 self.assertEquals(yaml.load(serialized1), yaml.load(serialized2))69 self.assertEquals(serializer.load(serialized1),
70 serializer.load(serialized2))
6971
70 def test_get_config_when_missing(self):72 def test_get_config_when_missing(self):
71 """73 """
@@ -140,7 +142,7 @@
140 yield self.manager.set_provider_type("ec2")142 yield self.manager.set_provider_type("ec2")
141 self.assertEqual((yield self.manager.get_provider_type()), "ec2")143 self.assertEqual((yield self.manager.get_provider_type()), "ec2")
142 content, stat = yield self.client.get("/settings")144 content, stat = yield self.client.get("/settings")
143 self.assertEqual(yaml.load(content),145 self.assertEqual(serializer.load(content),
144 {"provider-type": "ec2"})146 {"provider-type": "ec2"})
145147
146 @inlineCallbacks148 @inlineCallbacks
@@ -211,7 +213,7 @@
211213
212 data = dict(x=1, y=2, z=3, moose=u"moon")214 data = dict(x=1, y=2, z=3, moose=u"moon")
213 yield self.client.set(215 yield self.client.set(
214 SETTINGS_PATH, yaml.safe_dump(data))216 SETTINGS_PATH, serializer.dump(data))
215 value = yield callbacks[1]217 value = yield callbacks[1]
216 self.assertEqual(value.type_name, "changed")218 self.assertEqual(value.type_name, "changed")
217219
218220
=== modified file 'juju/state/tests/test_hook.py'
--- juju/state/tests/test_hook.py 2012-04-09 19:40:57 +0000
+++ juju/state/tests/test_hook.py 2012-09-15 19:26:18 +0000
@@ -1,7 +1,6 @@
1import yaml
2
3from twisted.internet.defer import inlineCallbacks, returnValue1from twisted.internet.defer import inlineCallbacks, returnValue
4from juju.lib.pick import pick_attr2from juju.lib.pick import pick_attr
3from juju.lib import serializer
5from juju.lib.testing import TestCase4from juju.lib.testing import TestCase
65
7from juju.state.endpoint import RelationEndpoint6from juju.state.endpoint import RelationEndpoint
@@ -218,7 +217,7 @@
218 self.assertNotEqual(current_data, data)217 self.assertNotEqual(current_data, data)
219218
220 self.client.set(self.get_unit_settings_path(self.mysql_states),219 self.client.set(self.get_unit_settings_path(self.mysql_states),
221 yaml.dump({"hello": "world"}))220 serializer.dump({"hello": "world"}))
222 data = yield self.context.get("mysql/0")221 data = yield self.context.get("mysql/0")
223 data["abc"] = 1222 data["abc"] = 1
224223
@@ -286,7 +285,7 @@
286 content, stat = yield self.client.get(285 content, stat = yield self.client.get(
287 self.get_unit_settings_path(self.wordpress_states))286 self.get_unit_settings_path(self.wordpress_states))
288 data["private-address"] = "wordpress-0.example.com"287 data["private-address"] = "wordpress-0.example.com"
289 self.assertEqual(yaml.load(content), data)288 self.assertEqual(serializer.load(content), data)
290 self.assertEqual(changes,289 self.assertEqual(changes,
291 [AddedItem("abc", 12), AddedItem("bar", "21")])290 [AddedItem("abc", 12), AddedItem("bar", "21")])
292291
@@ -297,7 +296,7 @@
297 yield self.context.set_value("donkey", u"abc")296 yield self.context.set_value("donkey", u"abc")
298 data, stat = yield self.client.get(297 data, stat = yield self.client.get(
299 self.get_unit_settings_path(self.wordpress_states))298 self.get_unit_settings_path(self.wordpress_states))
300 self.assertEqual(yaml.load(data),299 self.assertEqual(serializer.load(data),
301 {"private-address": "wordpress-0.example.com"})300 {"private-address": "wordpress-0.example.com"})
302301
303 changes = yield self.context.flush()302 changes = yield self.context.flush()
@@ -305,7 +304,7 @@
305 self.get_unit_settings_path(self.wordpress_states))304 self.get_unit_settings_path(self.wordpress_states))
306305
307 self.assertEqual(306 self.assertEqual(
308 yaml.load(data),307 serializer.load(data),
309 {"zebra": 12, "donkey": "abc",308 {"zebra": 12, "donkey": "abc",
310 "private-address": "wordpress-0.example.com"})309 "private-address": "wordpress-0.example.com"})
311310
@@ -320,14 +319,14 @@
320 yield self.client.set(319 yield self.client.set(
321 self.get_unit_settings_path(320 self.get_unit_settings_path(
322 self.wordpress_states),321 self.wordpress_states),
323 yaml.dump({"key": "secret"}))322 serializer.dump({"key": "secret"}))
324323
325 yield self.context.delete_value("key")324 yield self.context.delete_value("key")
326 changes = yield self.context.flush()325 changes = yield self.context.flush()
327 data, stat = yield self.client.get(326 data, stat = yield self.client.get(
328 self.get_unit_settings_path(self.wordpress_states))327 self.get_unit_settings_path(self.wordpress_states))
329328
330 self.assertNotIn("key", yaml.load(data))329 self.assertNotIn("key", serializer.load(data))
331 self.assertEqual(changes, [DeletedItem("key", "secret")])330 self.assertEqual(changes, [DeletedItem("key", "secret")])
332331
333 @inlineCallbacks332 @inlineCallbacks
@@ -336,14 +335,14 @@
336 """335 """
337 yield self.client.set(336 yield self.client.set(
338 self.get_unit_settings_path(self.wordpress_states),337 self.get_unit_settings_path(self.wordpress_states),
339 yaml.dump({"lantern": "green"}))338 serializer.dump({"lantern": "green"}))
340339
341 yield self.context.delete_value("key")340 yield self.context.delete_value("key")
342 changes = yield self.context.flush()341 changes = yield self.context.flush()
343 data, stat = yield self.client.get(342 data, stat = yield self.client.get(
344 self.get_unit_settings_path(self.wordpress_states))343 self.get_unit_settings_path(self.wordpress_states))
345344
346 self.assertEqual(yaml.load(data), {"lantern": "green"})345 self.assertEqual(serializer.load(data), {"lantern": "green"})
347 self.assertEqual(changes, [])346 self.assertEqual(changes, [])
348347
349 @inlineCallbacks348 @inlineCallbacks
@@ -351,12 +350,12 @@
351 """Flushing a context which has no writes is a noop."""350 """Flushing a context which has no writes is a noop."""
352 yield self.client.set(351 yield self.client.set(
353 self.get_unit_settings_path(self.wordpress_states),352 self.get_unit_settings_path(self.wordpress_states),
354 yaml.dump({"key": "secret"}))353 serializer.dump({"key": "secret"}))
355 changes = yield self.context.flush()354 changes = yield self.context.flush()
356 data, stat = yield self.client.get(355 data, stat = yield self.client.get(
357 self.get_unit_settings_path(self.wordpress_states))356 self.get_unit_settings_path(self.wordpress_states))
358357
359 self.assertEqual(yaml.load(data),358 self.assertEqual(serializer.load(data),
360 {"key": "secret"})359 {"key": "secret"})
361 self.assertEqual(changes, [])360 self.assertEqual(changes, [])
362361
@@ -378,7 +377,7 @@
378377
379 yield self.client.set(378 yield self.client.set(
380 self.get_unit_settings_path(self.wordpress_states),379 self.get_unit_settings_path(self.wordpress_states),
381 yaml.dump(data))380 serializer.dump(data))
382381
383 # On the context:382 # On the context:
384 # - add a new key383 # - add a new key
@@ -406,7 +405,7 @@
406405
407 yield self.client.set(406 yield self.client.set(
408 self.get_unit_settings_path(self.wordpress_states),407 self.get_unit_settings_path(self.wordpress_states),
409 yaml.dump(data))408 serializer.dump(data))
410409
411 changes = yield self.context.flush()410 changes = yield self.context.flush()
412411
@@ -414,7 +413,7 @@
414 self.get_unit_settings_path(self.wordpress_states))413 self.get_unit_settings_path(self.wordpress_states))
415414
416 self.assertEqual(415 self.assertEqual(
417 yaml.load(data),416 serializer.load(data),
418 {"port": 22, "host": "xe2.example.com", "db": 21, "home": "good",417 {"port": 22, "host": "xe2.example.com", "db": 21, "home": "good",
419 "tower": "rock", "zoo": "keeper"})418 "tower": "rock", "zoo": "keeper"})
420 self.assertEqual(419 self.assertEqual(
@@ -430,7 +429,7 @@
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."""
431 yield self.client.set(430 yield self.client.set(
432 self.get_unit_settings_path(self.wordpress_states),431 self.get_unit_settings_path(self.wordpress_states),
433 yaml.dump({"key": "secret"}))432 serializer.dump({"key": "secret"}))
434 yield self.context.set_value("magic", "room")433 yield self.context.set_value("magic", "room")
435 value = yield self.context.get_value("wordpress/0", "key")434 value = yield self.context.get_value("wordpress/0", "key")
436 self.assertEqual(value, "secret")435 self.assertEqual(value, "secret")
@@ -675,7 +674,7 @@
675 def test_get_self(self):674 def test_get_self(self):
676 """Own settings can be retrieved."""675 """Own settings can be retrieved."""
677 self.client.set(self.get_unit_settings_path(self.wordpress_states),676 self.client.set(self.get_unit_settings_path(self.wordpress_states),
678 yaml.dump({"hello": "world"}))677 serializer.dump({"hello": "world"}))
679 data = yield self.context.get(None)678 data = yield self.context.get(None)
680 self.assertEquals(data, {"hello": "world"})679 self.assertEquals(data, {"hello": "world"})
681680
@@ -683,7 +682,7 @@
683 def test_get_self_by_name(self):682 def test_get_self_by_name(self):
684 """Own settings can be retrieved by name."""683 """Own settings can be retrieved by name."""
685 self.client.set(self.get_unit_settings_path(self.wordpress_states),684 self.client.set(self.get_unit_settings_path(self.wordpress_states),
686 yaml.dump({"hello": "world"}))685 serializer.dump({"hello": "world"}))
687 data = yield self.context.get("wordpress/0")686 data = yield self.context.get("wordpress/0")
688 self.assertEquals(data, {"hello": "world"})687 self.assertEquals(data, {"hello": "world"})
689688
@@ -699,7 +698,7 @@
699 def test_get_value_self(self):698 def test_get_value_self(self):
700 """Own settings can be retrieved."""699 """Own settings can be retrieved."""
701 self.client.set(self.get_unit_settings_path(self.wordpress_states),700 self.client.set(self.get_unit_settings_path(self.wordpress_states),
702 yaml.dump({"hello": "world"}))701 serializer.dump({"hello": "world"}))
703 self.assertEquals(702 self.assertEquals(
704 (yield self.context.get_value("wordpress/0", "hello")), "world")703 (yield self.context.get_value("wordpress/0", "hello")), "world")
705 self.assertEquals(704 self.assertEquals(
@@ -847,7 +846,7 @@
847 self.unit,846 self.unit,
848 self.container_unit)847 self.container_unit)
849 self.client.set(settings_path,848 self.client.set(settings_path,
850 yaml.dump({"hello": "world"}))849 serializer.dump({"hello": "world"}))
851 data = yield self.context.get(None)850 data = yield self.context.get(None)
852 self.assertEquals(data, {"hello": "world"})851 self.assertEquals(data, {"hello": "world"})
853852
854853
=== modified file 'juju/state/tests/test_machine.py'
--- juju/state/tests/test_machine.py 2012-03-28 00:38:16 +0000
+++ juju/state/tests/test_machine.py 2012-09-15 19:26:18 +0000
@@ -1,11 +1,10 @@
1import functools1import functools
22
3import yaml
4
5from twisted.internet.defer import inlineCallbacks, Deferred, returnValue3from twisted.internet.defer import inlineCallbacks, Deferred, returnValue
64
7from juju.charm.tests import local_charm_id5from juju.charm.tests import local_charm_id
8from juju.errors import ConstraintError6from juju.errors import ConstraintError
7from juju.lib import serializer
9from juju.machine.tests.test_constraints import (8from juju.machine.tests.test_constraints import (
10 dummy_constraints, series_constraints)9 dummy_constraints, series_constraints)
11from juju.state.charm import CharmStateManager10from juju.state.charm import CharmStateManager
@@ -237,7 +236,7 @@
237236
238 content, stat = yield self.client.get("/machines/machine-0000000000")237 content, stat = yield self.client.get("/machines/machine-0000000000")
239 self.assertEquals(238 self.assertEquals(
240 yaml.load(content)["provider-machine-id"], "custom-id")239 serializer.load(content)["provider-machine-id"], "custom-id")
241240
242 @inlineCallbacks241 @inlineCallbacks
243 def test_set_instance_id_preserves_existing_data(self):242 def test_set_instance_id_preserves_existing_data(self):
@@ -246,11 +245,11 @@
246 """245 """
247 machine_state = yield self.add_machine_state()246 machine_state = yield self.add_machine_state()
248 yield self.client.set("/machines/machine-0000000000",247 yield self.client.set("/machines/machine-0000000000",
249 yaml.dump({"foo": "bar"}))248 serializer.dump({"foo": "bar"}))
250 yield machine_state.set_instance_id("custom-id")249 yield machine_state.set_instance_id("custom-id")
251250
252 content, stat = yield self.client.get("/machines/machine-0000000000")251 content, stat = yield self.client.get("/machines/machine-0000000000")
253 self.assertEquals(yaml.load(content),252 self.assertEquals(serializer.load(content),
254 {"provider-machine-id": "custom-id",253 {"provider-machine-id": "custom-id",
255 "foo": "bar"})254 "foo": "bar"})
256255
@@ -299,7 +298,7 @@
299 """298 """
300 machine_state = yield self.add_machine_state()299 machine_state = yield self.add_machine_state()
301 yield self.client.set("/machines/machine-0000000000",300 yield self.client.set("/machines/machine-0000000000",
302 yaml.dump({"foo": "bar"}))301 serializer.dump({"foo": "bar"}))
303302
304 instance_id = yield machine_state.get_instance_id()303 instance_id = yield machine_state.get_instance_id()
305 self.assertEquals(instance_id, None)304 self.assertEquals(instance_id, None)
306305
=== modified file 'juju/state/tests/test_relation.py'
--- juju/state/tests/test_relation.py 2012-06-01 22:50:44 +0000
+++ juju/state/tests/test_relation.py 2012-09-15 19:26:18 +0000
@@ -2,15 +2,14 @@
2import os2import os
3import time3import time
44
5import yaml
6import zookeeper5import zookeeper
76
8
9from twisted.internet.defer import (7from twisted.internet.defer import (
10 inlineCallbacks, returnValue, Deferred, fail, succeed)8 inlineCallbacks, returnValue, Deferred, fail, succeed)
119
12from juju.charm.directory import CharmDirectory10from juju.charm.directory import CharmDirectory
13from juju.charm.tests import local_charm_id11from juju.charm.tests import local_charm_id
12from juju.lib import serializer
14from juju.machine.tests.test_constraints import dummy_constraints13from juju.machine.tests.test_constraints import dummy_constraints
15from juju.charm.tests.test_metadata import test_repository_path14from juju.charm.tests.test_metadata import test_repository_path
16from juju.charm.tests.test_repository import unbundled_repository15from juju.charm.tests.test_repository import unbundled_repository
@@ -803,14 +802,14 @@
803 # Verify the unit mapping802 # Verify the unit mapping
804 unit_map_data, stat = yield self.client.get("/relations/%s" % (803 unit_map_data, stat = yield self.client.get("/relations/%s" % (
805 self.relation_state.internal_id))804 self.relation_state.internal_id))
806 unit_map = yaml.load(unit_map_data)805 unit_map = serializer.load(unit_map_data)
807 self.assertEqual(806 self.assertEqual(
808 unit_map,807 unit_map,
809 {unit_state.internal_id: unit_state.unit_name})808 {unit_state.internal_id: unit_state.unit_name})
810809
811 content, stat = yield self.client.get(settings_path)810 content, stat = yield self.client.get(settings_path)
812 self.assertEqual(811 self.assertEqual(
813 yaml.load(content), {"private-address": "foobar.local"})812 serializer.load(content), {"private-address": "foobar.local"})
814813
815 @inlineCallbacks814 @inlineCallbacks
816 def test_add_unit_state_scope_container_relation(self):815 def test_add_unit_state_scope_container_relation(self):
@@ -930,7 +929,7 @@
930 unit_state.internal_id)929 unit_state.internal_id)
931930
932 data = {"hello": "world", "private-address": "foobar.local"}931 data = {"hello": "world", "private-address": "foobar.local"}
933 yield self.client.create(settings_path, yaml.dump(data))932 yield self.client.create(settings_path, serializer.dump(data))
934933
935 yield unit_state.set_private_address("northwest.local")934 yield unit_state.set_private_address("northwest.local")
936 yield self.service1_relation.add_unit_state(unit_state)935 yield self.service1_relation.add_unit_state(unit_state)
@@ -939,11 +938,11 @@
939938
940 # The unit address has been updated to current939 # The unit address has been updated to current
941 data["private-address"] = "northwest.local"940 data["private-address"] = "northwest.local"
942 self.assertEqual(node_data, yaml.dump(data))941 self.assertEqual(node_data, serializer.dump(data))
943942
944 data, stat = yield self.client.get(943 data, stat = yield self.client.get(
945 "/relations/%s" % self.relation_state.internal_id)944 "/relations/%s" % self.relation_state.internal_id)
946 unit_map = yaml.load(data)945 unit_map = serializer.load(data)
947 self.assertEqual(unit_map,946 self.assertEqual(unit_map,
948 {unit_state.internal_id: unit_state.unit_name})947 {unit_state.internal_id: unit_state.unit_name})
949948
@@ -1094,13 +1093,14 @@
1094 unit_relation = states["unit_relation"]1093 unit_relation = states["unit_relation"]
10951094
1096 data = yield unit_relation.get_data()1095 data = yield unit_relation.get_data()
1097 self.assertEqual(yaml.load(data), {"private-address": None})1096 self.assertEqual(serializer.load(data), {"private-address": None})
10981097
1099 unit_relation_path = self.get_unit_settings_path(states)1098 unit_relation_path = self.get_unit_settings_path(states)
1100 self.client.set(unit_relation_path, yaml.dump(dict(hello="world")))1099 self.client.set(
1100 unit_relation_path, serializer.dump(dict(hello="world")))
11011101
1102 data = yield unit_relation.get_data()1102 data = yield unit_relation.get_data()
1103 self.assertEqual(data, yaml.dump(dict(hello="world")))1103 self.assertEqual(data, serializer.dump(dict(hello="world")))
11041104
1105 @inlineCallbacks1105 @inlineCallbacks
1106 def test_set_data(self):1106 def test_set_data(self):
@@ -1109,7 +1109,7 @@
1109 unit_relation_path = self.get_unit_settings_path(states)1109 unit_relation_path = self.get_unit_settings_path(states)
1110 yield unit_relation.set_data(dict(hello="world"))1110 yield unit_relation.set_data(dict(hello="world"))
1111 data, stat = yield self.client.get(unit_relation_path)1111 data, stat = yield self.client.get(unit_relation_path)
1112 self.assertEqual(data, yaml.dump(dict(hello="world")))1112 self.assertEqual(data, serializer.dump(dict(hello="world")))
11131113
1114 @inlineCallbacks1114 @inlineCallbacks
1115 def test_get_relation_role(self):1115 def test_get_relation_role(self):
@@ -1137,7 +1137,7 @@
1137 yield self.service_manager.remove_service_state(states["service"])1137 yield self.service_manager.remove_service_state(states["service"])
1138 yield self.assertFailure(1138 yield self.assertFailure(
1139 states["unit_relation"].get_relation_role(), StateChanged)1139 states["unit_relation"].get_relation_role(), StateChanged)
1140 1140
1141 @inlineCallbacks1141 @inlineCallbacks
1142 def test_get_related_unit_container(self):1142 def test_get_related_unit_container(self):
1143 """Retrieve the container path of the related units."""1143 """Retrieve the container path of the related units."""
11441144
=== modified file 'juju/state/tests/test_security.py'
--- juju/state/tests/test_security.py 2012-02-22 09:23:16 +0000
+++ juju/state/tests/test_security.py 2012-09-15 19:26:18 +0000
@@ -1,5 +1,4 @@
1import base641import base64
2import yaml
3import zookeeper2import zookeeper
43
5from twisted.internet.defer import inlineCallbacks, succeed4from twisted.internet.defer import inlineCallbacks, succeed
@@ -11,6 +10,7 @@
11 ACL, Principal, GroupPrincipal, OTPPrincipal, TokenDatabase,10 ACL, Principal, GroupPrincipal, OTPPrincipal, TokenDatabase,
12 SecurityPolicy, SecurityPolicyConnection)11 SecurityPolicy, SecurityPolicyConnection)
1312
13from juju.lib import serializer
14from juju.lib.testing import TestCase14from juju.lib.testing import TestCase
15from juju.tests.common import get_test_zookeeper_address15from juju.tests.common import get_test_zookeeper_address
1616
@@ -230,7 +230,7 @@
230230
231 data, stat = yield self.client.get(otp_path)231 data, stat = yield self.client.get(otp_path)
232232
233 credentials = yaml.load(data)233 credentials = serializer.load(data)
234 self.assertEqual(credentials["name"], "foobar")234 self.assertEqual(credentials["name"], "foobar")
235 self.assertEqual(credentials["password"], "secret")235 self.assertEqual(credentials["password"], "secret")
236236
@@ -291,7 +291,7 @@
291 principal = Principal("zebra", "zoo")291 principal = Principal("zebra", "zoo")
292 yield self.db.add(principal)292 yield self.db.add(principal)
293 content, stat = yield self.client.get("/token-test")293 content, stat = yield self.client.get("/token-test")
294 data = yaml.load(content)294 data = serializer.load(content)
295 self.assertEqual(data, {"zebra": principal.get_token()})295 self.assertEqual(data, {"zebra": principal.get_token()})
296296
297 @inlineCallbacks297 @inlineCallbacks
@@ -300,7 +300,7 @@
300 yield self.db.add(principal)300 yield self.db.add(principal)
301 yield self.db.remove(principal)301 yield self.db.remove(principal)
302 content, stat = yield self.client.get("/token-test")302 content, stat = yield self.client.get("/token-test")
303 data = yaml.load(content)303 data = serializer.load(content)
304 self.assertEqual(data, {"zebra": principal.get_token()})304 self.assertEqual(data, {"zebra": principal.get_token()})
305305
306 @inlineCallbacks306 @inlineCallbacks
307307
=== modified file 'juju/state/tests/test_service.py'
--- juju/state/tests/test_service.py 2012-07-03 07:30:53 +0000
+++ juju/state/tests/test_service.py 2012-09-15 19:26:18 +0000
@@ -1,7 +1,6 @@
1import os1import os
2import shutil2import shutil
33
4import yaml
5import zookeeper4import zookeeper
65
7from twisted.internet.defer import inlineCallbacks, Deferred, returnValue6from twisted.internet.defer import inlineCallbacks, Deferred, returnValue
@@ -10,6 +9,7 @@
10from juju.charm.directory import CharmDirectory9from juju.charm.directory import CharmDirectory
11from juju.charm.tests import local_charm_id10from juju.charm.tests import local_charm_id
12from juju.charm.tests.test_metadata import test_repository_path11from juju.charm.tests.test_metadata import test_repository_path
12from juju.lib import serializer
13from juju.machine.tests.test_constraints import (13from juju.machine.tests.test_constraints import (
14 dummy_constraints, dummy_cs, series_constraints)14 dummy_constraints, dummy_cs, series_constraints)
15from juju.lib.pick import pick_attr15from juju.lib.pick import pick_attr
@@ -178,7 +178,7 @@
178 "service-0000000000", "service-0000000001"])178 "service-0000000000", "service-0000000001"])
179179
180 content, stat = yield self.client.get("/services/service-0000000000")180 content, stat = yield self.client.get("/services/service-0000000000")
181 details = yaml.load(content)181 details = serializer.load(content)
182 self.assertTrue(details)182 self.assertTrue(details)
183 self.assertEquals(details.get("charm"), "local:series/dummy-1")183 self.assertEquals(details.get("charm"), "local:series/dummy-1")
184 self.assertFalse(isinstance(details.get("charm"), unicode))184 self.assertFalse(isinstance(details.get("charm"), unicode))
@@ -513,7 +513,7 @@
513 # role path513 # role path
514 content, stat = yield self.client.get(role_path)514 content, stat = yield self.client.get(role_path)
515 self.assertTrue(stat)515 self.assertTrue(stat)
516 node_info = yaml.load(content)516 node_info = serializer.load(content)
517517
518 self.assertEqual(518 self.assertEqual(
519 node_info["name"],519 node_info["name"],
@@ -527,7 +527,7 @@
527 unit_state.internal_id527 unit_state.internal_id
528 content, stat = yield self.client.get(settings_path)528 content, stat = yield self.client.get(settings_path)
529 self.assertTrue(stat)529 self.assertTrue(stat)
530 settings_info = yaml.load(content)530 settings_info = serializer.load(content)
531531
532 # Verify that private address was set532 # Verify that private address was set
533 # we verify the content elsewhere533 # we verify the content elsewhere
@@ -1383,7 +1383,7 @@
1383 self.assertIdentical(enabled, True)1383 self.assertIdentical(enabled, True)
1384 content, stat = yield self.client.get(1384 content, stat = yield self.client.get(
1385 "/units/%s/debug" % unit_state.internal_id)1385 "/units/%s/debug" % unit_state.internal_id)
1386 data = yaml.load(content)1386 data = serializer.load(content)
1387 self.assertEqual(data, {"debug_hooks": ["*"]})1387 self.assertEqual(data, {"debug_hooks": ["*"]})
13881388
1389 @inlineCallbacks1389 @inlineCallbacks
@@ -1396,7 +1396,7 @@
1396 self.assertIdentical(enabled, True)1396 self.assertIdentical(enabled, True)
1397 content, stat = yield self.client.get(1397 content, stat = yield self.client.get(
1398 "/units/%s/debug" % unit_state.internal_id)1398 "/units/%s/debug" % unit_state.internal_id)
1399 data = yaml.load(content)1399 data = serializer.load(content)
1400 self.assertEqual(data, {"debug_hooks":1400 self.assertEqual(data, {"debug_hooks":
1401 ["db-relation-broken", "db-relation-changed"]})1401 ["db-relation-broken", "db-relation-changed"]})
14021402
@@ -1434,7 +1434,7 @@
1434 self.assertIdentical(enabled, True)1434 self.assertIdentical(enabled, True)
1435 content, stat = yield self.client.get(1435 content, stat = yield self.client.get(
1436 "/units/%s/debug" % unit_state.internal_id)1436 "/units/%s/debug" % unit_state.internal_id)
1437 data = yaml.load(content)1437 data = serializer.load(content)
1438 self.assertEqual(data, {"debug_hooks": ["db-relation-changed"]})1438 self.assertEqual(data, {"debug_hooks": ["db-relation-changed"]})
14391439
1440 @inlineCallbacks1440 @inlineCallbacks
@@ -2495,7 +2495,7 @@
2495 # The default was never written to storage.2495 # The default was never written to storage.
2496 data, stat = yield self.client.get(2496 data, stat = yield self.client.get(
2497 "/services/%s/config" % wordpress.internal_id)2497 "/services/%s/config" % wordpress.internal_id)
2498 self.assertEqual(yaml.load(data), {"foo": "bar"})2498 self.assertEqual(serializer.load(data), {"foo": "bar"})
24992499
2500 @inlineCallbacks2500 @inlineCallbacks
2501 def test_get_charm_state(self):2501 def test_get_charm_state(self):
@@ -2761,20 +2761,20 @@
2761 yield unit_state.open_port(80, "tcp")2761 yield unit_state.open_port(80, "tcp")
2762 content, stat = yield self.client.get(ports_path)2762 content, stat = yield self.client.get(ports_path)
2763 self.assertEquals(2763 self.assertEquals(
2764 yaml.load(content),2764 serializer.load(content),
2765 {"open": [{"port": 80, "proto": "tcp"}]})2765 {"open": [{"port": 80, "proto": "tcp"}]})
27662766
2767 yield unit_state.open_port(53, "udp")2767 yield unit_state.open_port(53, "udp")
2768 content, stat = yield self.client.get(ports_path)2768 content, stat = yield self.client.get(ports_path)
2769 self.assertEquals(2769 self.assertEquals(
2770 yaml.load(content),2770 serializer.load(content),
2771 {"open": [{"port": 80, "proto": "tcp"},2771 {"open": [{"port": 80, "proto": "tcp"},
2772 {"port": 53, "proto": "udp"}]})2772 {"port": 53, "proto": "udp"}]})
27732773
2774 yield unit_state.open_port(443, "tcp")2774 yield unit_state.open_port(443, "tcp")
2775 content, stat = yield self.client.get(ports_path)2775 content, stat = yield self.client.get(ports_path)
2776 self.assertEquals(2776 self.assertEquals(
2777 yaml.load(content),2777 serializer.load(content),
2778 {"open": [{"port": 80, "proto": "tcp"},2778 {"open": [{"port": 80, "proto": "tcp"},
2779 {"port": 53, "proto": "udp"},2779 {"port": 53, "proto": "udp"},
2780 {"port": 443, "proto": "tcp"}]})2780 {"port": 443, "proto": "tcp"}]})
@@ -2782,7 +2782,7 @@
2782 yield unit_state.close_port(80, "tcp")2782 yield unit_state.close_port(80, "tcp")
2783 content, stat = yield self.client.get(ports_path)2783 content, stat = yield self.client.get(ports_path)
2784 self.assertEquals(2784 self.assertEquals(
2785 yaml.load(content),2785 serializer.load(content),
2786 {"open": [{"port": 53, "proto": "udp"},2786 {"open": [{"port": 53, "proto": "udp"},
2787 {"port": 443, "proto": "tcp"}]})2787 {"port": 443, "proto": "tcp"}]})
27882788
27892789
=== modified file 'juju/state/tests/test_topology.py'
--- juju/state/tests/test_topology.py 2012-04-12 18:39:20 +0000
+++ juju/state/tests/test_topology.py 2012-09-15 19:26:18 +0000
@@ -1,6 +1,5 @@
1import yaml
2
3from juju.errors import IncompatibleVersion1from juju.errors import IncompatibleVersion
2from juju.lib import serializer
4from juju.lib.testing import TestCase3from juju.lib.testing import TestCase
5from juju.state.endpoint import RelationEndpoint4from juju.state.endpoint import RelationEndpoint
6from juju.state.topology import (5from juju.state.topology import (
@@ -891,7 +890,7 @@
891 loaded back.890 loaded back.
892 """891 """
893 empty_data = self.topology.dump()892 empty_data = self.topology.dump()
894 self.assertEquals(yaml.load(empty_data), {"version": VERSION})893 self.assertEquals(serializer.load(empty_data), {"version": VERSION})
895 self.topology.add_machine("m-0")894 self.topology.add_machine("m-0")
896 machine_data = self.topology.dump()895 machine_data = self.topology.dump()
897 self.topology.parse(empty_data)896 self.topology.parse(empty_data)
@@ -902,7 +901,7 @@
902 def test_incompatible_version(self):901 def test_incompatible_version(self):
903 """Verify `IncompatibleVersion` raised if using old topology."""902 """Verify `IncompatibleVersion` raised if using old topology."""
904 empty_data = self.topology.dump()903 empty_data = self.topology.dump()
905 self.assertEquals(yaml.load(empty_data), {"version": VERSION})904 self.assertEquals(serializer.load(empty_data), {"version": VERSION})
906 self.topology.add_machine("m-0")905 self.topology.add_machine("m-0")
907 machine_data = self.topology.dump()906 machine_data = self.topology.dump()
908 self.topology.parse(machine_data)907 self.topology.parse(machine_data)
@@ -1265,62 +1264,3 @@
1265 "r-0", "s-0", "riak", "peer")1264 "r-0", "s-0", "riak", "peer")
1266 self.assertEqual(self.topology.get_relation_between_endpoints(1265 self.assertEqual(self.topology.get_relation_between_endpoints(
1267 [riak_ep]), "r-0")1266 [riak_ep]), "r-0")
1268
1269
1270# Topology migration tests use these. defined at global scope to ease
1271# string formatting
1272
1273TOPOLOGY_V1 = """
1274relations:
1275 relation-0000000000:
1276 - mysql
1277 - service-0000000000: {name: db, role: client}
1278 service-0000000001: {name: server, role: server}
1279version: 1
1280"""
1281
1282TOPOLOGY_V2_EXPECTED = """
1283relations:
1284 interface: mysql
1285 relation-0000000000: {}
1286 scope: global
1287 services:
1288 service-0000000000: {name: db, role: client}
1289 service-0000000001: {name: server, role: server}
1290version: 2
1291"""
1292
1293
1294class TestMigrations(TestCase):
1295
1296 # DISABLED: We don't do transparent data migrations, till we
1297 # have explicit juju core code upgrades, else older agents
1298 # will die on new topology formats.
1299 def xtest_migration_v1_to_v2(self):
1300 """Parse a fragment of a version 1 topology
1301
1302 Ensure that a version 2 topology is emitted.
1303 """
1304 topology = InternalTopology()
1305 topology.parse(TOPOLOGY_V1)
1306 self.assertEqual(topology.get_version(), 2)
1307 self.assertEqual(topology.dump().strip(),
1308 TOPOLOGY_V2_EXPECTED.strip())
1309
1310 def test_migration_v1_to_unknown(self):
1311 """Parse a fragment of a version 1 topology
1312
1313 Ensure that a version 2 topology is emitted.
1314 """
1315 topology = InternalTopology()
1316
1317 actual_version = VERSION
1318 import juju
1319 self.patch(juju.state.topology, "VERSION", actual_version + 1)
1320
1321 ex = self.assertRaises(IncompatibleVersion,
1322 topology.parse, TOPOLOGY_V1)
1323 self.assertEqual(
1324 str(ex),
1325 "Incompatible juju protocol versions (found 1, want %d)" % (
1326 juju.state.topology.VERSION))
13271267
=== modified file 'juju/state/tests/test_utils.py'
--- juju/state/tests/test_utils.py 2012-04-06 14:42:06 +0000
+++ juju/state/tests/test_utils.py 2012-09-15 19:26:18 +0000
@@ -8,8 +8,8 @@
8from twisted.internet import reactor8from twisted.internet import reactor
9from twisted.internet.defer import inlineCallbacks9from twisted.internet.defer import inlineCallbacks
10from twisted.internet.threads import deferToThread10from twisted.internet.threads import deferToThread
11import yaml
1211
12from juju.lib import serializer
13from juju.lib.testing import TestCase13from juju.lib.testing import TestCase
14from juju.state.base import StateBase14from juju.state.base import StateBase
15from juju.state.errors import StateChanged, StateNotFound15from juju.state.errors import StateChanged, StateNotFound
@@ -382,7 +382,7 @@
382382
383 # and a direct look at zk should work as well383 # and a direct look at zk should work as well
384 zk_data, stat = yield self.client.get(self.path)384 zk_data, stat = yield self.client.get(self.path)
385 zk_data = yaml.load(zk_data)385 zk_data = serializer.load(zk_data)
386 self.assertEqual(zk_data, options)386 self.assertEqual(zk_data, options)
387387
388 @inlineCallbacks388 @inlineCallbacks
@@ -465,7 +465,7 @@
465465
466 # and a direct look at zk should work as well466 # and a direct look at zk should work as well
467 zk_data, stat = yield self.client.get(self.path)467 zk_data, stat = yield self.client.get(self.path)
468 zk_data = yaml.load(zk_data)468 zk_data = serializer.load(zk_data)
469 self.assertEqual(zk_data, options)469 self.assertEqual(zk_data, options)
470470
471 @inlineCallbacks471 @inlineCallbacks
@@ -678,13 +678,14 @@
678678
679 @inlineCallbacks679 @inlineCallbacks
680 def test_get_missing(self):680 def test_get_missing(self):
681 yield self.client.create(self.path, yaml.dump({"foo": "bar"}))681 yield self.client.create(self.path, serializer.dump({"foo": "bar"}))
682 mixee = TestMixee(self.client, self.path)682 mixee = TestMixee(self.client, self.path)
683 self.assertEquals((yield mixee.get()), None)683 self.assertEquals((yield mixee.get()), None)
684684
685 @inlineCallbacks685 @inlineCallbacks
686 def test_get_exists(self):686 def test_get_exists(self):
687 yield self.client.create(self.path, yaml.dump({"key": "butterfly"}))687 yield self.client.create(
688 self.path, serializer.dump({"key": "butterfly"}))
688 mixee = TestMixee(self.client, self.path)689 mixee = TestMixee(self.client, self.path)
689 self.assertEquals((yield mixee.get()), "butterfly")690 self.assertEquals((yield mixee.get()), "butterfly")
690691
@@ -694,13 +695,14 @@
694 mixee = TestMixee(self.client, self.path)695 mixee = TestMixee(self.client, self.path)
695 yield mixee.set("caterpillar")696 yield mixee.set("caterpillar")
696 content, _ = yield self.client.get(self.path)697 content, _ = yield self.client.get(self.path)
697 self.assertEquals(yaml.load(content), {"key": "caterpillar"})698 self.assertEquals(serializer.load(content), {"key": "caterpillar"})
698699
699 @inlineCallbacks700 @inlineCallbacks
700 def test_set_safely(self):701 def test_set_safely(self):
701 yield self.client.create(self.path, yaml.dump({"foo": "bar"}))702 yield self.client.create(self.path, serializer.dump({"foo": "bar"}))
702 mixee = TestMixee(self.client, self.path)703 mixee = TestMixee(self.client, self.path)
703 yield mixee.set("cocoon")704 yield mixee.set("cocoon")
704 content, _ = yield self.client.get(self.path)705 content, _ = yield self.client.get(self.path)
705 self.assertEquals(yaml.load(content), {"foo": "bar", "key": "cocoon"})706 self.assertEquals(
707 serializer.load(content), {"foo": "bar", "key": "cocoon"})
706708
707709
=== modified file 'juju/state/topology.py'
--- juju/state/topology.py 2012-04-12 18:39:20 +0000
+++ juju/state/topology.py 2012-09-15 19:26:18 +0000
@@ -1,7 +1,7 @@
1import yaml1
22
3from juju.errors import IncompatibleVersion3from juju.errors import IncompatibleVersion
44from juju.lib import serializer
55
6# The protocol version, which is stored in the /topology node under6# The protocol version, which is stored in the /topology node under
7# the "version" key. The protocol version should *only* be updated7# the "version" key. The protocol version should *only* be updated
@@ -59,7 +59,7 @@
59 This string may be provided to the :method:`parse` to59 This string may be provided to the :method:`parse` to
60 reestablish the same topology state back.60 reestablish the same topology state back.
61 """61 """
62 return yaml.safe_dump(self._state)62 return serializer.dump(self._state)
6363
64 def parse(self, data):64 def parse(self, data):
65 """Parse the dumped data provided and restore internal state.65 """Parse the dumped data provided and restore internal state.
@@ -67,12 +67,11 @@
67 The provided data must necessarily have been retrieved by67 The provided data must necessarily have been retrieved by
68 calling the :method:`dump`.68 calling the :method:`dump`.
69 """69 """
70 parsed = yaml.load(data)70 parsed = serializer.load(data)
71 self._state = parsed71 self._state = parsed
72 version = self.get_version()72 version = self.get_version()
73 if version != VERSION:73 if version != VERSION:
74 # This will raise if it cannot update the topology.74 raise IncompatibleVersion(version, VERSION)
75 migrate_topology(self)
7675
77 def get_version(self):76 def get_version(self):
78 return self._state.get("version", 0)77 return self._state.get("version", 0)
@@ -573,79 +572,3 @@
573 else:572 else:
574 return relation_id573 return relation_id
575 return None574 return None
576
577
578def _migrate_version_1(topology):
579 """Migrate topology version 1 to version 2.
580
581 This change includes the transition from::
582
583 relations:
584 relation-0000000000:
585 - mysql
586 - service-0000000000: {name: db, role: client}
587 service-0000000001: {name: server, role: server}
588
589 to::
590
591 relations
592 relation-00000001:
593 interface: name
594 scope: name
595 services:
596 service-00000001: {name: name, role: role}
597 service-00000002: {name: name, role: role}
598
599 for all relations.
600
601 """
602 version = topology.get_version()
603 if version > 1:
604 return topology
605 elif version != 1:
606 raise IncompatibleVersion(version, VERSION)
607
608 relations = topology._state.get("relations")
609 if relations:
610 new_relations = {}
611 for relation, relation_data in relations.items():
612 new_relations[relation] = {}
613 relation_type, relation_services = relation_data
614 new_relations["interface"] = relation_type
615 new_relations["scope"] = "global"
616 new_relations["services"] = relation_services
617
618 topology._state["relations"] = new_relations
619
620 topology._state["version"] = 2
621 return topology
622
623
624# A dict of version migration plans for VERSION n (where n is the key)
625# to version n + 1. migrate_version will be called until the topology
626# version is equal to VERSION. If no migration plan exists FAIL
627_VERSION_MIGRATION = {
628
629# DISABLED: We can't migrate the topology till we can migrate older
630# code currently running in the env that depends on a previous format.
631# 1: _migrate_version_1
632}
633
634
635def migrate_topology(topology):
636 """Migrate topology version to current.
637
638 Does an in-place (destructive) stepwise modification of topology
639 state from its current version to the VERSION represented in this
640 module.
641 """
642 version = topology.get_version()
643 if version == VERSION:
644 return topology
645
646 current_version = version
647 while current_version < VERSION:
648 if current_version not in _VERSION_MIGRATION:
649 raise IncompatibleVersion(version, VERSION)
650 _VERSION_MIGRATION[current_version](topology)
651 current_version = topology.get_version()
652575
=== modified file 'juju/state/utils.py'
--- juju/state/utils.py 2012-03-09 13:24:58 +0000
+++ juju/state/utils.py 2012-09-15 19:26:18 +0000
@@ -7,9 +7,10 @@
7from twisted.internet.defer import inlineCallbacks, returnValue7from twisted.internet.defer import inlineCallbacks, returnValue
8from twisted.internet.threads import deferToThread8from twisted.internet.threads import deferToThread
9from txzookeeper.utils import retry_change9from txzookeeper.utils import retry_change
10import yaml10
11import zookeeper11import zookeeper
1212
13from juju.lib import serializer
13from juju.state.errors import StateChanged14from juju.state.errors import StateChanged
14from juju.state.errors import StateNotFound15from juju.state.errors import StateNotFound
1516
@@ -177,7 +178,7 @@
177 self._cache = {}178 self._cache = {}
178 try:179 try:
179 data, stat = yield self._client.get(self._path)180 data, stat = yield self._client.get(self._path)
180 data = yaml.load(data)181 data = serializer.load(data)
181 if data:182 if data:
182 self._pristine_cache = data183 self._pristine_cache = data
183 self._cache = data.copy()184 self._cache = data.copy()
@@ -228,7 +229,7 @@
228 def apply_changes(content, stat):229 def apply_changes(content, stat):
229 """Apply the local state to the Zookeeper node state."""230 """Apply the local state to the Zookeeper node state."""
230 del changes[:]231 del changes[:]
231 current = yaml.load(content) if content else {}232 current = serializer.load(content) if content else {}
232 missing = object()233 missing = object()
233 for key in set(pristine_cache).union(cache):234 for key in set(pristine_cache).union(cache):
234 old_value = pristine_cache.get(key, missing)235 old_value = pristine_cache.get(key, missing)
@@ -244,7 +245,7 @@
244 elif key in current:245 elif key in current:
245 del current[key]246 del current[key]
246 changes.append(DeletedItem(key, old_value))247 changes.append(DeletedItem(key, old_value))
247 return yaml.safe_dump(current)248 return serializer.dump(current)
248249
249 # Apply the change till it takes.250 # Apply the change till it takes.
250 yield retry_change(self._client, self._path, apply_changes)251 yield retry_change(self._client, self._path, apply_changes)
251252
=== modified file 'juju/unit/lifecycle.py'
--- juju/unit/lifecycle.py 2012-05-01 00:26:25 +0000
+++ juju/unit/lifecycle.py 2012-09-15 19:26:18 +0000
@@ -2,7 +2,6 @@
2import logging2import logging
3import shutil3import shutil
4import tempfile4import tempfile
5import yaml
65
7from twisted.internet.defer import (6from twisted.internet.defer import (
8 inlineCallbacks, DeferredLock, DeferredList, returnValue)7 inlineCallbacks, DeferredLock, DeferredList, returnValue)
@@ -10,6 +9,7 @@
10from juju.errors import CharmUpgradeError9from juju.errors import CharmUpgradeError
11from juju.hooks.invoker import Invoker10from juju.hooks.invoker import Invoker
12from juju.hooks.scheduler import HookScheduler11from juju.hooks.scheduler import HookScheduler
12from juju.lib import serializer
13from juju.state.hook import (13from juju.state.hook import (
14 DepartedRelationHookContext, HookContext, RelationChange)14 DepartedRelationHookContext, HookContext, RelationChange)
15from juju.state.errors import StopWatcher, UnitRelationStateNotFound15from juju.state.errors import StopWatcher, UnitRelationStateNotFound
@@ -493,7 +493,7 @@
493 state_dict = {}493 state_dict = {}
494 for relation_wf in self._relations.itervalues():494 for relation_wf in self._relations.itervalues():
495 state_dict.update(relation_wf.get_relation_info())495 state_dict.update(relation_wf.get_relation_info())
496 state = yaml.dump(state_dict)496 state = serializer.dump(state_dict)
497 temp_path = self._known_relations_path + "~"497 temp_path = self._known_relations_path + "~"
498498
499 with open(temp_path, "w") as f:499 with open(temp_path, "w") as f:
@@ -519,7 +519,7 @@
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)
520520
521 with open(self._known_relations_path) as f:521 with open(self._known_relations_path) as f:
522 known_relations = yaml.load(f.read())522 known_relations = serializer.load(f.read())
523523
524 for relation_id, relation_info in known_relations.items():524 for relation_id, relation_info in known_relations.items():
525 if relation_id in relations_by_id:525 if relation_id in relations_by_id:
526526
=== modified file 'juju/unit/tests/test_lifecycle.py'
--- juju/unit/tests/test_lifecycle.py 2012-05-04 03:39:27 +0000
+++ juju/unit/tests/test_lifecycle.py 2012-09-15 19:26:18 +0000
@@ -6,7 +6,6 @@
6import stat6import stat
7import sys7import sys
88
9import yaml
10import zookeeper9import zookeeper
1110
12from twisted.internet.defer import (inlineCallbacks, Deferred,11from twisted.internet.defer import (inlineCallbacks, Deferred,
@@ -20,6 +19,7 @@
20from juju.errors import CharmInvocationError, CharmError, CharmUpgradeError19from juju.errors import CharmInvocationError, CharmError, CharmUpgradeError
21from juju.hooks.invoker import Invoker20from juju.hooks.invoker import Invoker
22from juju.hooks.executor import HookExecutor21from juju.hooks.executor import HookExecutor
22from juju.lib import serializer
23from juju.machine.tests.test_constraints import series_constraints23from juju.machine.tests.test_constraints import series_constraints
2424
25from juju.state.endpoint import RelationEndpoint25from juju.state.endpoint import RelationEndpoint
@@ -1083,7 +1083,8 @@
1083 self.assertTrue(self.lifecycle.watching)1083 self.assertTrue(self.lifecycle.watching)
1084 self.assertFalse(self.lifecycle.executing)1084 self.assertFalse(self.lifecycle.executing)
10851085
1086 rel_states["unit_relation"].set_data(yaml.dump(dict(hello="world")))1086 rel_states["unit_relation"].set_data(
1087 serializer.dump(dict(hello="world")))
1087 # Sleep to give an error a chance.1088 # Sleep to give an error a chance.
1088 yield self.sleep(0.1)1089 yield self.sleep(0.1)
1089 self.assertFalse(changed_executed.called)1090 self.assertFalse(changed_executed.called)
10901091
=== modified file 'juju/unit/tests/test_workflow.py'
--- juju/unit/tests/test_workflow.py 2012-04-01 00:48:01 +0000
+++ juju/unit/tests/test_workflow.py 2012-09-15 19:26:18 +0000
@@ -2,7 +2,6 @@
2import itertools2import itertools
3import logging3import logging
4import os4import os
5import yaml
65
7from twisted.internet.defer import inlineCallbacks, returnValue6from twisted.internet.defer import inlineCallbacks, returnValue
87
@@ -12,6 +11,7 @@
1211
13from juju.charm.directory import CharmDirectory12from juju.charm.directory import CharmDirectory
14from juju.charm.url import CharmURL13from juju.charm.url import CharmURL
14from juju.lib import serializer
15from juju.lib.statemachine import WorkflowState15from juju.lib.statemachine import WorkflowState
16from juju.unit.lifecycle import UnitLifecycle, UnitRelationLifecycle16from juju.unit.lifecycle import UnitLifecycle, UnitRelationLifecycle
17from juju.unit.workflow import (17from juju.unit.workflow import (
@@ -40,10 +40,10 @@
4040
41 state = open(workflow.state_file_path).read()41 state = open(workflow.state_file_path).read()
42 history = open(workflow.state_history_path)42 history = open(workflow.state_history_path)
43 zk_state = yaml.load(data)["workflow_state"]43 zk_state = serializer.load(data)["workflow_state"]
44 returnValue((yaml.load(state),44 returnValue((serializer.load(state),
45 [yaml.load(r[0]) for r in csv.reader(history)],45 [serializer.load(r[0]) for r in csv.reader(history)],
46 yaml.load(zk_state[history_id])))46 serializer.load(zk_state[history_id])))
4747
48 @inlineCallbacks48 @inlineCallbacks
49 def assert_history(self, expected, **kwargs):49 def assert_history(self, expected, **kwargs):
5050
=== modified file 'juju/unit/workflow.py'
--- juju/unit/workflow.py 2012-03-29 07:52:41 +0000
+++ juju/unit/workflow.py 2012-09-15 19:26:18 +0000
@@ -1,4 +1,3 @@
1import yaml
2import csv1import csv
3import os2import os
4import logging3import logging
@@ -9,6 +8,7 @@
9from txzookeeper.utils import retry_change8from txzookeeper.utils import retry_change
109
11from juju.errors import CharmError, FileNotFound10from juju.errors import CharmError, FileNotFound
11from juju.lib import serializer
12from juju.lib.statemachine import (12from juju.lib.statemachine import (
13 WorkflowState, Workflow, Transition, TransitionError)13 WorkflowState, Workflow, Transition, TransitionError)
1414
@@ -223,16 +223,16 @@
223 @inlineCallbacks223 @inlineCallbacks
224 def _store(self, state_dict):224 def _store(self, state_dict):
225 """Store the workflow state dictionary in zookeeper."""225 """Store the workflow state dictionary in zookeeper."""
226 state_serialized = yaml.safe_dump(state_dict)226 state_serialized = serializer.dump(state_dict)
227227
228 def update_state(content, stat):228 def update_state(content, stat):
229 unit_data = yaml.load(content)229 unit_data = serializer.load(content)
230 if not unit_data:230 if not unit_data:
231 unit_data = {}231 unit_data = {}
232232
233 persistent_workflow = unit_data.setdefault("workflow_state", {})233 persistent_workflow = unit_data.setdefault("workflow_state", {})
234 persistent_workflow[self.zk_state_id] = state_serialized234 persistent_workflow[self.zk_state_id] = state_serialized
235 return yaml.dump(unit_data)235 return serializer.dump(unit_data)
236236
237 yield retry_change(self._client, self.zk_state_path, update_state)237 yield retry_change(self._client, self.zk_state_path, update_state)
238 yield super(ZookeeperWorkflowState, self)._store(238 yield super(ZookeeperWorkflowState, self)._store(
@@ -245,8 +245,8 @@
245 data, stat = yield self._client.get(self.zk_state_path)245 data, stat = yield self._client.get(self.zk_state_path)
246 except NoNodeException:246 except NoNodeException:
247 returnValue({"state": None})247 returnValue({"state": None})
248 unit_data = yaml.load(data)248 unit_data = serializer.load(data)
249 data = yaml.load(unit_data.get("workflow_state", {}).get(249 data = serializer.load(unit_data.get("workflow_state", {}).get(
250 self.zk_state_id, ""))250 self.zk_state_id, ""))
251 returnValue(data)251 returnValue(data)
252252
@@ -273,7 +273,7 @@
273 Internally the history file is stored a csv, with a new273 Internally the history file is stored a csv, with a new
274 row per entry with CSV escaping.274 row per entry with CSV escaping.
275 """275 """
276 state_serialized = yaml.safe_dump(state_dict)276 state_serialized = serializer.dump(state_dict)
277 # State File277 # State File
278 with open(self.state_file_path, "w") as handle:278 with open(self.state_file_path, "w") as handle:
279 handle.write(state_serialized)279 handle.write(state_serialized)
@@ -295,7 +295,7 @@
295 content = handle.read()295 content = handle.read()
296296
297 # TODO load ZK state and overwrite with disk state if different?297 # TODO load ZK state and overwrite with disk state if different?
298 return yaml.load(content)298 return serializer.load(content)
299299
300300
301class WorkflowStateClient(ZookeeperWorkflowState):301class WorkflowStateClient(ZookeeperWorkflowState):

Subscribers

People subscribed via source and target branches

to status/vote changes: