~gnuoy/charms/trusty/percona-cluster/sstpasswd2

« back to all changes in this revision

Viewing changes to hooks/charmhelpers/core/hookenv.py

  • Committer: Edward Hope-Morley
  • Date: 2015-05-06 16:43:56 UTC
  • mfrom: (56.1.1 percona-cluster.lp1451890)
  • Revision ID: edward.hope-morley@canonical.com-20150506164356-fj8iluvq7lufii91
[hopem,r=gnuoy]

Sync charm-helpers to get fix for LP 1451890.

Fixes issue with passwords stored in peer relation.
Upgrading will no longer ignore passwords stored
using old-style keys.

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
# Authors:
21
21
#  Charm Helpers Developers <juju@lists.ubuntu.com>
22
22
 
 
23
from __future__ import print_function
23
24
import os
24
25
import json
25
26
import yaml
26
27
import subprocess
27
28
import sys
 
29
import errno
28
30
from subprocess import CalledProcessError
29
31
 
30
32
import six
87
89
    if not isinstance(message, six.string_types):
88
90
        message = repr(message)
89
91
    command += [message]
90
 
    subprocess.call(command)
 
92
    # Missing juju-log should not cause failures in unit tests
 
93
    # Send log output to stderr
 
94
    try:
 
95
        subprocess.call(command)
 
96
    except OSError as e:
 
97
        if e.errno == errno.ENOENT:
 
98
            if level:
 
99
                message = "{}: {}".format(level, message)
 
100
            message = "juju-log: {}".format(message)
 
101
            print(message, file=sys.stderr)
 
102
        else:
 
103
            raise
91
104
 
92
105
 
93
106
class Serializable(UserDict):
566
579
def charm_dir():
567
580
    """Return the root directory of the current charm"""
568
581
    return os.environ.get('CHARM_DIR')
 
582
 
 
583
 
 
584
@cached
 
585
def action_get(key=None):
 
586
    """Gets the value of an action parameter, or all key/value param pairs"""
 
587
    cmd = ['action-get']
 
588
    if key is not None:
 
589
        cmd.append(key)
 
590
    cmd.append('--format=json')
 
591
    action_data = json.loads(subprocess.check_output(cmd).decode('UTF-8'))
 
592
    return action_data
 
593
 
 
594
 
 
595
def action_set(values):
 
596
    """Sets the values to be returned after the action finishes"""
 
597
    cmd = ['action-set']
 
598
    for k, v in list(values.items()):
 
599
        cmd.append('{}={}'.format(k, v))
 
600
    subprocess.check_call(cmd)
 
601
 
 
602
 
 
603
def action_fail(message):
 
604
    """Sets the action status to failed and sets the error message.
 
605
 
 
606
    The results set by action_set are preserved."""
 
607
    subprocess.check_call(['action-fail', message])