Esempio n. 1
0
def relation_list(rid=None):
    cmd = command('relation-list')
    args = []
    if rid:
        args.append('-r')
        args.append(rid)
    return cmd(*args).split()
Esempio n. 2
0
def relation_list(rid=None):
    cmd = command('relation-list')
    args = []
    if rid:
        args.append('-r')
        args.append(rid)
    return cmd(*args).split()
Esempio n. 3
0
def setup_gui(release_tarball):
    """Set up Juju GUI."""
    # Uncompress the release tarball.
    log('Installing Juju GUI.')
    release_dir = os.path.join(CURRENT_DIR, 'release')
    cmd_log(run('rm', '-rf', release_dir))
    os.mkdir(release_dir)
    uncompress = command('tar', '-x', '-z', '-C', release_dir, '-f')
    cmd_log(uncompress(release_tarball))
    # Link the Juju GUI dir to the contents of the release tarball.
    cmd_log(run('ln', '-sf', first_path_in_dir(release_dir), JUJU_GUI_DIR))
Esempio n. 4
0
def setup_gui(release_tarball):
    """Set up Juju GUI."""
    # Uncompress the release tarball.
    log('Installing Juju GUI.')
    release_dir = os.path.join(BASE_DIR, 'release')
    cmd_log(run('rm', '-rf', release_dir))
    os.mkdir(release_dir)
    uncompress = command('tar', '-x', '-a', '-C', release_dir, '-f')
    cmd_log(uncompress(release_tarball))
    # Link the Juju GUI dir to the contents of the release tarball.
    cmd_log(run('ln', '-sf', first_path_in_dir(release_dir), JUJU_GUI_DIR))
Esempio n. 5
0
def relation_get(attribute=None, unit=None, rid=None):
    cmd = command('relation-get')
    if attribute is None and unit is None and rid is None:
        return cmd().strip()
    _args = []
    if rid:
        _args.append('-r')
        _args.append(rid)
    if attribute is not None:
        _args.append(attribute)
    if unit:
        _args.append(unit)
    return cmd(*_args).strip()
Esempio n. 6
0
def service_control(service_name, action):
    cmd = command('service')
    args = [service_name, action]
    try:
        if action == RESTART:
            try:
                cmd(*args)
            except CalledProcessError:
                service_control(service_name, START)
        else:
            cmd(*args)
    except CalledProcessError:
        log("Failed to perform {} on service {}".format(action, service_name))
Esempio n. 7
0
def relation_get(attribute=None, unit=None, rid=None):
    cmd = command('relation-get')
    if attribute is None and unit is None and rid is None:
        return cmd().strip()
    _args = []
    if rid:
        _args.append('-r')
        _args.append(rid)
    if attribute is not None:
        _args.append(attribute)
    if unit:
        _args.append(unit)
    return cmd(*_args).strip()
Esempio n. 8
0
def service_control(service_name, action):
    cmd = command('service')
    args = [service_name, action]
    try:
        if action == RESTART:
            try:
                cmd(*args)
            except CalledProcessError:
                service_control(service_name, START)
        else:
            cmd(*args)
    except CalledProcessError:
        log("Failed to perform {} on service {}".format(action, service_name))
Esempio n. 9
0
def fetch_gui_from_branch(branch_url, revision, logpath):
    """Retrieve the Juju GUI from a branch and build a release archive."""
    # Inject NPM packages into the cache for faster building.
    prime_npm_cache(get_npm_cache_archive_url())

    # Create a release starting from a branch.
    juju_gui_source_dir = os.path.join(CURRENT_DIR, 'juju-gui-source')
    cmd_log(run('rm', '-rf', juju_gui_source_dir))
    git_clone = command('git', 'clone')

    if revision is None:
        log('Retrieving Juju GUI source from {} (default trunk).'.format(
            branch_url))
        cmd_log(git_clone('--depth', '1', branch_url, juju_gui_source_dir))
    elif revision.startswith('@'):
        log('Retrieving Juju GUI source from {} (commit: {}).'.format(
            branch_url, revision[1:]))
        # Retrieve a full clone and then checkout the specific commit.
        git_dir = os.path.join(juju_gui_source_dir, '.git')
        cmd_log(git_clone(branch_url, juju_gui_source_dir))
        cmd_log(
            run('git', '--git-dir', git_dir, '--work-tree',
                juju_gui_source_dir, 'checkout', revision[1:]))
    else:
        log('Retrieving Juju GUI source from {} (branch: {}).'.format(
            branch_url, revision))
        cmd_log(
            git_clone('--depth', '1', '-b', revision, branch_url,
                      juju_gui_source_dir))

    log('Preparing a Juju GUI release.')
    logdir = os.path.dirname(logpath)

    fd, name = tempfile.mkstemp(prefix='make-distfile-', dir=logdir)
    log('Output from "make distfile" sent to %s' % name)

    # Passing HOME is required by node during npm packages installation.
    run('make',
        '-C',
        juju_gui_source_dir,
        'distfile',
        'BRANCH_IS_GOOD=true',
        'HOME={}'.format(os.path.expanduser('~')),
        stdout=fd,
        stderr=fd)

    return first_path_in_dir(os.path.join(juju_gui_source_dir, 'releases'))
Esempio n. 10
0

def prime_npm_cache(npm_cache_url):
    """Download NPM cache archive and prime the NPM cache with it."""
    # Download the cache archive and then uncompress it into the NPM cache.
    npm_cache_archive = os.path.join(CURRENT_DIR, 'npm-cache.tgz')
    cmd_log(run('curl', '-L', '-o', npm_cache_archive, npm_cache_url))
    npm_cache_dir = os.path.expanduser('~/.npm')
    # The NPM cache directory probably does not exist, so make it if not.
    try:
        os.mkdir(npm_cache_dir)
    except OSError, e:
        # If the directory already exists then ignore the error.
        if e.errno != errno.EEXIST:  # File exists.
            raise
    uncompress = command('tar', '-x', '-z', '-C', npm_cache_dir, '-f')
    cmd_log(uncompress(npm_cache_archive))


def fetch_gui_from_branch(branch_url, revision, logpath):
    """Retrieve the Juju GUI from a branch and build a release archive."""
    # Inject NPM packages into the cache for faster building.
    prime_npm_cache(get_npm_cache_archive_url())

    # Create a release starting from a branch.
    juju_gui_source_dir = os.path.join(CURRENT_DIR, 'juju-gui-source')
    cmd_log(run('rm', '-rf', juju_gui_source_dir))
    git_clone = command('git', 'clone')

    if revision is None:
        log('Retrieving Juju GUI source from {} (default trunk).'.format(
Esempio n. 11
0
def close_port(port, protocol="TCP"):
    cmd = command('close-port')
    args = ['{}/{}'.format(port, protocol)]
    cmd(*args)
Esempio n. 12
0
def open_port(port, protocol="TCP"):
    cmd = command('open-port')
    args = ['{}/{}'.format(port, protocol)]
    cmd(*args)
Esempio n. 13
0
def relation_get(*args):
    cmd = command('relation-get')
    return cmd(*args).strip()
Esempio n. 14
0
def relation_get(*args):
    cmd = command('relation-get')
    return cmd(*args).strip()
Esempio n. 15
0
from contextlib import contextmanager
import json
import operator
from shelltoolbox import (
    command,
    run,
    script_name)
import os
import tempfile
import time
import urllib2
import yaml


log = command('juju-log')


def log_entry():
    log("--> Entering {}".format(script_name()))


def log_exit():
    log("<-- Exiting {}".format(script_name()))


def get_config():
    config_get = command('config-get', '--format=json')
    return json.loads(config_get())

Esempio n. 16
0
def relation_ids(relation_name):
    cmd = command('relation-ids')
    args = [relation_name]
    return cmd(*args).split()
Esempio n. 17
0
def log(message, juju_log=command('juju-log')):
    return juju_log('--', message)
Esempio n. 18
0
import shelltoolbox


# Utility function to print to stderr.
printerr = partial(print, file=sys.stderr)

# Add ../lib to sys.path to get the retry module.
root_path = os.path.dirname(os.path.dirname(os.path.normpath(__file__)))
lib_path = os.path.join(root_path, "lib")
if lib_path not in sys.path:
    sys.path.append(lib_path)

from retry import retry


juju = shelltoolbox.command("juju")
ssh = shelltoolbox.command("ssh")

# Given the limited capabilities that the credentials impart (primarily the
# ability to run a web browser via Sauce Labs) and that anyone can sign up for
# their own credentials at no cost, it seems like an appropriate handling of
# the credentials to just include them here.
config = {"username": "******", "access-key": "0a3b7821-93ed-4a2d-abdb-f34854eeaba3"}

credentials = ":".join([config["username"], config["access-key"]])
encoded_credentials = base64.encodestring(credentials)[:-1]
# This is saucelabs.com credentials and API endpoint rolled into a URL.
command_executor = "http://%[email protected]:80/wd/hub" % credentials
internal_ip = None
if os.path.exists("juju-internal-ip"):
    with open("juju-internal-ip") as fp:
Esempio n. 19
0
def log(message, juju_log=command('juju-log')):
    return juju_log('--', message)
Esempio n. 20
0
def close_port(port, protocol="TCP"):
    cmd = command('close-port')
    args = ['{}/{}'.format(port, protocol)]
    cmd(*args)
Esempio n. 21
0
def open_port(port, protocol="TCP"):
    cmd = command('open-port')
    args = ['{}/{}'.format(port, protocol)]
    cmd(*args)
Esempio n. 22
0
def unit_get(attribute):
    cmd = command('unit-get')
    args = [attribute]
    return cmd(*args).strip()
Esempio n. 23
0
def config_get(attribute):
    cmd = command('config-get')
    args = [attribute]
    return cmd(*args).strip()
Esempio n. 24
0

def prime_npm_cache(npm_cache_url):
    """Download NPM cache archive and prime the NPM cache with it."""
    # Download the cache archive and then uncompress it into the NPM cache.
    npm_cache_archive = os.path.join(CURRENT_DIR, 'npm-cache.tgz')
    cmd_log(run('curl', '-L', '-o', npm_cache_archive, npm_cache_url))
    npm_cache_dir = os.path.expanduser('~/.npm')
    # The NPM cache directory probably does not exist, so make it if not.
    try:
        os.mkdir(npm_cache_dir)
    except OSError, e:
        # If the directory already exists then ignore the error.
        if e.errno != errno.EEXIST:  # File exists.
            raise
    uncompress = command('tar', '-x', '-z', '-C', npm_cache_dir, '-f')
    cmd_log(uncompress(npm_cache_archive))


def get_release_file_path(version=None):
    """Return the local path of the release file with the given version.

    If version is None, return the path of the last release.
    Raise a ValueError if no releases are found in the local repository.
    """
    version_path_map = {}
    # Collect the locally stored releases.
    for filename in os.listdir(RELEASES_DIR):
        match = release_expression.match(filename)
        if match is not None:
            release_version = match.groups()[0]
Esempio n. 25
0
import shelltoolbox


# Utility function to print to stderr.
printerr = partial(print, file=sys.stderr)

# Add ../lib to sys.path to get the retry module.
root_path = os.path.dirname(os.path.dirname(os.path.normpath(__file__)))
lib_path = os.path.join(root_path, 'lib')
if lib_path not in sys.path:
    sys.path.append(lib_path)

from retry import retry


juju = shelltoolbox.command('juju')
ssh = shelltoolbox.command('ssh')

# Given the limited capabilities that the credentials impart (primarily the
# ability to run a web browser via Sauce Labs) and that anyone can sign up for
# their own credentials at no cost, it seems like an appropriate handling of
# the credentials to just include them here.
config = {
    'username': '******',
    'access-key': '0a3b7821-93ed-4a2d-abdb-f34854eeaba3',
}

credentials = ':'.join([config['username'], config['access-key']])
encoded_credentials = base64.encodestring(credentials)[:-1]
# This is saucelabs.com credentials and API endpoint rolled into a URL.
command_executor = 'http://%[email protected]:80/wd/hub' % credentials
Esempio n. 26
0
def get_config():
    _config_get = command('config-get', '--format=json')
    return json.loads(_config_get())
Esempio n. 27
0
from shelltoolbox import (
    command,
    script_name,
    run,
)
import tempfile
import time
import urllib2
import yaml
from subprocess import CalledProcessError

SLEEP_AMOUNT = 0.1
Env = namedtuple('Env', 'uid gid home')
# We create a juju_status Command here because it makes testing much,
# much easier.
juju_status = lambda: command('juju')('status')


def log(message, juju_log=command('juju-log')):
    return juju_log('--', message)


def log_entry():
    log("--> Entering {}".format(script_name()))


def log_exit():
    log("<-- Exiting {}".format(script_name()))


def get_config():
Esempio n. 28
0
JUJU_GUI_PORTS = '/etc/apache2/ports.conf'
JUJU_PEM = 'juju.includes-private-key.pem'
BUILD_REPOSITORIES = ('ppa:chris-lea/node.js-legacy', )
DEB_BUILD_DEPENDENCIES = (
    'bzr',
    'imagemagick',
    'make',
    'nodejs',
    'npm',
)
DEB_STAGE_DEPENDENCIES = ('zookeeper', )

# Store the configuration from on invocation to the next.
config_json = Serializer('/tmp/config.json')
# Bazaar checkout command.
bzr_checkout = command('bzr', 'co', '--lightweight')
# Whether or not the charm is deployed using juju-core.
# If juju-core has been used to deploy the charm, an agent.conf file must
# be present in the charm parent directory.
legacy_juju = lambda: not os.path.exists(
    os.path.join(CURRENT_DIR, '..', 'agent.conf'))


def _get_build_dependencies():
    """Install deb dependencies for building."""
    log('Installing build dependencies.')
    cmd_log(install_extra_repositories(*BUILD_REPOSITORIES))
    cmd_log(apt_get_install(*DEB_BUILD_DEPENDENCIES))


def get_api_address(unit_dir):
Esempio n. 29
0
def relation_set(**kwargs):
    cmd = command('relation-set')
    args = ['{}={}'.format(k, v) for k, v in kwargs.items()]
    cmd(*args)
Esempio n. 30
0
SYS_INIT_DIR = os.path.join(os.path.sep, 'etc', 'init')
AGENT_INIT_PATH = os.path.join(SYS_INIT_DIR, 'juju-api-agent.conf')
GUISERVER_INIT_PATH = os.path.join(SYS_INIT_DIR, 'guiserver.conf')
HAPROXY_INIT_PATH = os.path.join(SYS_INIT_DIR, 'haproxy.conf')
IMPROV_INIT_PATH = os.path.join(SYS_INIT_DIR, 'juju-api-improv.conf')

JUJU_PEM = 'juju.includes-private-key.pem'
DEB_BUILD_DEPENDENCIES = (
    'bzr', 'g++', 'imagemagick', 'make',  'nodejs', 'npm',
)


# Store the configuration from on invocation to the next.
config_json = Serializer(os.path.join(os.path.sep, 'tmp', 'config.json'))
# Bazaar checkout command.
bzr_checkout = command('bzr', 'co', '--lightweight')
# Whether or not the charm is deployed using juju-core.
# If juju-core has been used to deploy the charm, an agent.conf file must
# be present in the charm parent directory.
legacy_juju = lambda: not os.path.exists(
    os.path.join(CURRENT_DIR, '..', 'agent.conf'))

bzr_url_expression = re.compile(r"""
    ^  # Beginning of line.
    ((?:lp:|http:\/\/)[^:]+)  # Branch URL (scheme + domain/path).
    (?::(\d+))?  # Optional branch revision.
    $  # End of line.
""", re.VERBOSE)
release_expression = re.compile(r"""
    juju-gui-  # Juju GUI prefix.
    (
Esempio n. 31
0
def relation_ids(relation_name):
    cmd = command('relation-ids')
    args = [relation_name]
    return cmd(*args).split()
Esempio n. 32
0
    'wait_for_unit',          # client-side, NOT IMPLEMENTED
]

import operator
from shelltoolbox import (
    command,
)
import tempfile
import time
import urllib2
import yaml

SLEEP_AMOUNT = 0.1
# We create a juju_status Command here because it makes testing much,
# much easier.
juju_status = lambda: command('juju')('status')

# re-implemented as charmhelpers.fetch.configure_sources()
#def configure_source(update=False):
#    source = config_get('source')
#    if ((source.startswith('ppa:') or
#         source.startswith('cloud:') or
#         source.startswith('http:'))):
#        run('add-apt-repository', source)
#    if source.startswith("http:"):
#        run('apt-key', 'import', config_get('key'))
#    if update:
#        run('apt-get', 'update')


# DEPRECATED: client-side only
from shelltoolbox import (
    command,
    run,
)
import sys
import time
import tempfile
import yaml
import subprocess
import os
import os.path
import re

from retry import retry

juju_command = command('juju', '-v')

DEFAULT_ORIGIN = 'lp:juju-gui'
DEFAULT_CHARM = 'cs:~juju-gui/precise/juju-gui'


def juju(s):
    try:
        return juju_command(*s.split())
    except subprocess.CalledProcessError as err:
        print("Error running", repr(s))
        print(err.output)
        raise


# We found that the juju status call fails intermittently in
Esempio n. 34
0
)
from selenium.webdriver.support import ui
import shelltoolbox

# Utility function to print to stderr.
printerr = partial(print, file=sys.stderr)

# Add ../lib to sys.path to get the retry module.
root_path = os.path.dirname(os.path.dirname(os.path.normpath(__file__)))
lib_path = os.path.join(root_path, 'lib')
if lib_path not in sys.path:
    sys.path.append(lib_path)

from retry import retry

juju = shelltoolbox.command('juju')
ssh = shelltoolbox.command('ssh')

# Given the limited capabilities that the credentials impart (primarily the
# ability to run a web browser via Sauce Labs) and that anyone can sign up for
# their own credentials at no cost, it seems like an appropriate handling of
# the credentials to just include them here.
config = {
    'username': '******',
    'access-key': '0a3b7821-93ed-4a2d-abdb-f34854eeaba3',
}

credentials = ':'.join([config['username'], config['access-key']])
encoded_credentials = base64.encodestring(credentials)[:-1]
# This is saucelabs.com credentials and API endpoint rolled into a URL.
command_executor = 'http://%[email protected]:80/wd/hub' % credentials
Esempio n. 35
0
def config_get(attribute):
    cmd = command('config-get')
    args = [attribute]
    return cmd(*args).strip()
Esempio n. 36
0
def get_config():
    config_get = command('config-get', '--format=json')
    return json.loads(config_get())
Esempio n. 37
0
def unit_get(attribute):
    cmd = command('unit-get')
    args = [attribute]
    return cmd(*args).strip()
Esempio n. 38
0
def relation_set(**kwargs):
    cmd = command('relation-set')
    args = ['{}={}'.format(k, v) for k, v in kwargs.items()]
    return cmd(*args)
Esempio n. 39
0
from contextlib import contextmanager
import json
import operator
from shelltoolbox import (
    command,
    run,
    script_name,
)
import os
import tempfile
import time
import urllib2
import yaml

log = command('juju-log')


def log_entry():
    log("--> Entering {}".format(script_name()))


def log_exit():
    log("<-- Exiting {}".format(script_name()))


def get_config():
    config_get = command('config-get', '--format=json')
    return json.loads(config_get())