~hazmat/pyjuju/rapi-delta

« back to all changes in this revision

Viewing changes to juju/unit/workflow.py

  • Committer: Kapil Thangavelu
  • Date: 2012-09-19 20:38:44 UTC
  • mfrom: (573.1.6 rest-context)
  • Revision ID: kapil@canonical.com-20120919203844-dc2pf82ttm7xj3xs
Merged rest-context into rapi-delta.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
import yaml
2
1
import csv
3
2
import os
4
3
import logging
9
8
from txzookeeper.utils import retry_change
10
9
 
11
10
from juju.errors import CharmError, FileNotFound
 
11
from juju.lib import serializer
12
12
from juju.lib.statemachine import (
13
13
    WorkflowState, Workflow, Transition, TransitionError)
14
14
 
223
223
    @inlineCallbacks
224
224
    def _store(self, state_dict):
225
225
        """Store the workflow state dictionary in zookeeper."""
226
 
        state_serialized = yaml.safe_dump(state_dict)
 
226
        state_serialized = serializer.dump(state_dict)
227
227
 
228
228
        def update_state(content, stat):
229
 
            unit_data = yaml.load(content)
 
229
            unit_data = serializer.load(content)
230
230
            if not unit_data:
231
231
                unit_data = {}
232
232
 
233
233
            persistent_workflow = unit_data.setdefault("workflow_state", {})
234
234
            persistent_workflow[self.zk_state_id] = state_serialized
235
 
            return yaml.dump(unit_data)
 
235
            return serializer.dump(unit_data)
236
236
 
237
237
        yield retry_change(self._client, self.zk_state_path, update_state)
238
238
        yield super(ZookeeperWorkflowState, self)._store(
245
245
            data, stat = yield self._client.get(self.zk_state_path)
246
246
        except NoNodeException:
247
247
            returnValue({"state": None})
248
 
        unit_data = yaml.load(data)
249
 
        data = yaml.load(unit_data.get("workflow_state", {}).get(
 
248
        unit_data = serializer.load(data)
 
249
        data = serializer.load(unit_data.get("workflow_state", {}).get(
250
250
                self.zk_state_id, ""))
251
251
        returnValue(data)
252
252
 
273
273
        Internally the history file is stored a csv, with a new
274
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
277
        # State File
278
278
        with open(self.state_file_path, "w") as handle:
279
279
            handle.write(state_serialized)
295
295
            content = handle.read()
296
296
 
297
297
        # TODO load ZK state and overwrite with disk state if different?
298
 
        return yaml.load(content)
 
298
        return serializer.load(content)
299
299
 
300
300
 
301
301
class WorkflowStateClient(ZookeeperWorkflowState):