Esempio n. 1
0
def test_subtract_operators():
    d1 = MeldDict({
        'a': 'a',
        'b': 'b',
        'c': {
            'a': 'c.a',
            'b': 'c.b'
        },
        'd': ['d.0', 'd.1']
    })
    d2 = {
        'b': 'B',
        'c': {
            'b': 'c.B',
            'c': 'c.c'
        },
        'd': ['d.1', 'd.2'],
        'f': 'f'
    }
    dr = {'a': 'a', 'c': {'a': 'c.a'}, 'd': ['d.0']}
    drr = {'c': {'c': 'c.c'}, 'd': ['d.2'], 'f': 'f'}
    assert d1 - d2 == dr
    assert d2 - d1 == drr
    d3 = MeldDict(deepcopy(d1))
    d3 -= d2
    assert d3 == dr
    d4 = deepcopy(d2)
    d4 -= d1
    assert d4 == drr
Esempio n. 2
0
def test_add():
    d1 = MeldDict({
        'a': 'a',
        'b': 'b',
        'c': {
            'a': 'c.a',
            'b': 'c.b'
        },
        'd': ['d.0'],
        'e': 'e',
        'f': 'f'
    })
    d2 = {
        'b': 'B',
        'c': {
            'b': 'c.B',
            'c': 'c.c'
        },
        'd': ['d.1'],
        'e': ['e.0'],
        'f': {
            'f': 'f.f'
        },
        'g': 'g'
    }
    with pytest.raises(TypeError):
        d1.add('foo')
    res = d1.add(d2)
    assert d1 == {
        'a': 'a',
        'b': 'B',
        'c': {
            'a': 'c.a',
            'b': 'c.B',
            'c': 'c.c'
        },
        'd': ['d.0', 'd.1'],
        'e': ['e.0'],
        'f': {
            'f': 'f.f'
        },
        'g': 'g'
    }
    assert res is d1

    d3 = MeldDict({'a': ['a.0']})
    d3.meld_iters = False
    d3.add({'a': ['a.1']})
    assert d3 == {'a': ['a.1']}
Esempio n. 3
0
async def bootstrap(controller,
                    cloud,
                    model='conjure-up',
                    series="xenial",
                    credential=None):
    """ Performs juju bootstrap

    If not LXD pass along the newly defined credentials

    Arguments:
    controller: name of your controller
    cloud: name of local or public cloud to deploy to
    model: name of default model to create
    series: define the bootstrap series defaults to xenial
    credential: credentials key
    """
    if app.provider.region is not None:
        app.log.debug("Bootstrapping to set region: {}")
        cloud = "{}/{}".format(app.provider.cloud, app.provider.region)

    cmd = [
        app.juju.bin_path, "bootstrap", cloud, controller, "--default-model",
        model
    ]

    def add_config(k, v):
        cmd.extend(["--config", "{}={}".format(k, v)])

    app.provider.model_defaults = MeldDict(app.provider.model_defaults or {})
    app.provider.model_defaults.add(app.conjurefile.get('model-config', {}))
    if app.provider.model_defaults:
        for k, v in app.provider.model_defaults.items():
            if v is not None:
                add_config(k, v)

    add_config("image-stream", "daily")
    if app.conjurefile['http-proxy']:
        add_config("http-proxy", app.conjurefile['http-proxy'])
    if app.conjurefile['https-proxy']:
        add_config("https-proxy", app.conjurefile['https-proxy'])
    if app.conjurefile['apt-http-proxy']:
        add_config("apt-http-proxy", app.conjurefile['apt-http-proxy'])
    if app.conjurefile['apt-https-proxy']:
        add_config("apt-https-proxy", app.conjurefile['apt-https-proxy'])
    if app.conjurefile['no-proxy']:
        add_config("no-proxy", app.conjurefile['no-proxy'])
    if app.conjurefile['bootstrap-timeout']:
        add_config("bootstrap-timeout", app.conjurefile['bootstrap-timeout'])
    if app.conjurefile['bootstrap-to']:
        cmd.extend(["--to", app.conjurefile['bootstrap-to']])

    cmd.extend(["--bootstrap-series", series])
    if credential is not None:
        cmd.extend(["--credential", credential])

    if app.conjurefile['debug']:
        cmd.append("--debug")
    app.log.debug("bootstrap cmd: {}".format(cmd))

    log_file = '{}-bootstrap'.format(app.provider.controller)
    path_base = str(Path(app.config['spell-dir']) / log_file)
    out_path = path_base + '.out'
    err_path = path_base + '.err'
    rc, _, _ = await utils.arun(cmd, stdout=out_path, stderr=err_path)
    if rc < 0:
        raise errors.BootstrapInterrupt('Bootstrap killed by user')
    elif rc > 0:
        return False
    events.ModelAvailable.set()
    return True
Esempio n. 4
0
""" application state module
"""
import os
from types import SimpleNamespace

from melddict import MeldDict

from . import log
from .collect import Collector

app = SimpleNamespace(
    # spec object
    spec=None,
    # debug
    debug=None,
    # environment variables, these are accessible throughout all plugins
    env=MeldDict(os.environ.copy()),
    # list of all plugins, across all phases
    plugins=[],
    # logger
    log=log,
    # collector
    collect=Collector(),
    # jobs
    jobs=[],
)
Esempio n. 5
0
def test_add_operators():
    d1 = MeldDict({
        'a': 'a',
        'b': 'b',
        'c': {
            'a': 'c.a',
            'b': 'c.b'
        },
        'd': ['d.0'],
        'e': 'e',
        'f': 'f'
    })
    d2 = {
        'b': 'B',
        'c': {
            'b': 'c.B',
            'c': 'c.c'
        },
        'd': ['d.1'],
        'e': ['e.0'],
        'f': {
            'f': 'f.f'
        },
        'g': 'g'
    }
    dr = {
        'a': 'a',
        'b': 'B',
        'c': {
            'a': 'c.a',
            'b': 'c.B',
            'c': 'c.c'
        },
        'd': ['d.0', 'd.1'],
        'e': ['e.0'],
        'f': {
            'f': 'f.f'
        },
        'g': 'g'
    }
    drr = {
        'a': 'a',
        'b': 'b',
        'c': {
            'a': 'c.a',
            'b': 'c.b',
            'c': 'c.c'
        },
        'd': ['d.1', 'd.0'],
        'e': 'e',
        'f': 'f',
        'g': 'g'
    }
    assert d1 + d2 == dr
    assert d2 + d1 == drr
    d3 = MeldDict(deepcopy(d1))
    d3 += d2
    assert d3 == dr
    d4 = deepcopy(d2)
    d4 += d1
    assert d4 == drr
Esempio n. 6
0
def test_subtract():
    d1 = MeldDict({
        'a': 'a',
        'b': 'b',
        'c': {
            'a': 'c.a',
            'b': 'c.b'
        },
        'd': ['d.0', 'd.1']
    })
    d2 = {
        'b': 'B',
        'c': {
            'b': 'c.B',
            'c': 'c.c'
        },
        'd': ['d.1', 'd.2'],
        'f': 'f'
    }
    with pytest.raises(TypeError):
        d1.subtract('foo')
    res = d1.subtract(d2)
    assert d1 == {'a': 'a', 'c': {'a': 'c.a'}, 'd': ['d.0']}
    assert res is d1

    d3 = MeldDict({'a': ['a.0', 'a.1'], 'b': 'b'})
    d3.meld_iters = False
    d3.subtract({'a': ['a.1']})
    assert d3 == {'b': 'b'}

    d4 = MeldDict({'a': ['a.0'], 'b': {'a': 'b.a'}})
    d4.remove_emptied = True
    d4.subtract(d4)
    assert d4 == {}