~rharding/charms/precise/juju-gui/update-nagios

« back to all changes in this revision

Viewing changes to tests/helpers.py

  • Committer: Rick Harding
  • Date: 2014-01-15 14:50:46 UTC
  • mfrom: (147.1.8 remove-pyjuju)
  • Revision ID: rick.harding@canonical.com-20140115145046-lyh9879k9x8hwb8i
Remove support for PyJuju and rapi from charm.

- Removes the support for running rapi/pyjuju.
- Removes the agent used to communicate with zookeeper.
- Removes anything pertaining to zookeeper.
- Attempts to clean up docs and such to make sense with pure juju-core.

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
import json
22
22
import os
23
23
import random
24
 
import re
25
24
import string
26
25
import subprocess
27
26
import time
172
171
    return json.loads(status)
173
172
 
174
173
 
175
 
_juju_version_expression = re.compile(r"""
176
 
    ^  # Beginning of line.
177
 
    (?:juju\s+)?  # Optional juju prefix.
178
 
    (\d+)\.(\d+)  # Major and minor versions.
179
 
    (?:\.(\d+))?  # Optional patch version.
180
 
    .*  # Optional suffix.
181
 
    $  # End of line.
182
 
""", re.VERBOSE)
183
 
 
184
 
 
185
 
def juju_version():
186
 
    """Return the currently used Juju version.
187
 
 
188
 
    The version is returned as a named tuple (major, minor, patch).
189
 
    If the patch number is missing, it is set to zero.
190
 
    """
191
 
    try:
192
 
        # In pyJuju, version info is printed to stderr.
193
 
        output = subprocess.check_output(
194
 
            ['juju', '--version'], stderr=subprocess.STDOUT)
195
 
    except subprocess.CalledProcessError:
196
 
        # Current juju-core exposes a version subcommand.
197
 
        output = subprocess.check_output(['juju', 'version'])
198
 
    match = _juju_version_expression.match(output)
199
 
    if match is None:
200
 
        raise ValueError('invalid juju version: {!r}'.format(output))
201
 
    to_int = lambda num: 0 if num is None else int(num)
202
 
    return Version._make(map(to_int, match.groups()))
203
 
 
204
 
 
205
174
def make_service_name(prefix='service-'):
206
175
    """Generate a long, random service name."""
207
176
    characters = string.ascii_lowercase