Ejemplo n.º 1
0
def copy_file(tpl_file, charm_dir, is_bundle=False, debug=False):
    c = Charm(charm_dir)

    if not c.is_charm():
        raise Exception('%s is not a charm' % charm_dir)

    shutil.copy(os.path.join(CHARM_TPL, tpl_file), charm_dir)
Ejemplo n.º 2
0
def copy_file(tpl_file, charm_dir, is_bundle=False, debug=False):
    c = Charm(charm_dir)

    if not c.is_charm():
        raise Exception('%s is not a charm' % charm_dir)

    shutil.copy(os.path.join(CHARM_TPL, tpl_file), charm_dir)
Ejemplo n.º 3
0
def proof(path, is_bundle, debug):
    path = os.path.abspath(path)
    home_path = utils.get_home()
    if not home_path:  # expansion failed
        return ['Could not determine home directory'], 200
    if not path.startswith(home_path):
        return [
            'For security reasons, only paths under '
            'your home directory can be accessed'
        ], 200
    if not is_bundle:
        try:
            c = Charm(path)
        except:
            try:
                c = Bundle(path, debug)
            except Exception as e:
                return [
                    "FATAL: No bundle.yaml (Bundle) or metadata.yaml "
                    "(Charm) found, cannot proof"
                ], 200
    else:
        try:
            c = Bundle(path, debug)
        except Exception as e:
            return ["FATAL: %s" % e.message], 200

    lint, err_code = c.proof()
    return lint, err_code
Ejemplo n.º 4
0
def readme(charm_dir, is_bundle=False, debug=False):
    c = Charm(charm_dir)

    if not c.is_charm():
        raise Exception('%s is not a charm' % charm_dir)

    shutil.copy(os.path.join(CHARM_TPL, 'README.ex'), charm_dir)
Ejemplo n.º 5
0
def tests(charm_dir, is_bundle=False, debug=False, series='trusty'):
    c = Charm(charm_dir)

    if not c.is_charm():
        raise Exception('Not a Charm')

    mdata = c.metadata()

    interfaces = {}
    deploy = [mdata['name']]
    relations = []

    for rel_type in ['provides', 'requires']:
        if rel_type in mdata:
            interfaces[rel_type] = {}
            for rel, data in mdata[rel_type].iteritems():
                iface = data['interface']
                if iface and iface not in interfaces[rel_type]:
                    r = graph(iface, rel_type, series=series)
                    # If we dont find an interface, do nothing
                    if r is None:
                        continue
                    interfaces[rel_type][iface] = r
                    deploy.append(r.name)

                relations.append(['%s:%s' % (mdata['name'], rel), r.name])

    t = Template(file=os.path.join(TPL_DIR, 'tests', '99-autogen.tpl'),
                 searchList=[{
                     'deploy': deploy,
                     'relate': relations,
                     'series': series
                 }])

    if not os.path.exists(os.path.join(charm_dir, 'tests')):
        os.mkdir(os.path.join(charm_dir, 'tests'))

    with open(os.path.join(charm_dir, 'tests', '99-autogen'), 'w') as f:
        f.write(str(t))

    if not os.path.exists(os.path.join(charm_dir, 'tests', '00-setup')):
        with open(os.path.join(charm_dir, 'tests', '00-setup'), 'w') as f:
            f.write("""#!/bin/bash

sudo add-apt-repository ppa:juju/stable -y
sudo apt-get update
sudo apt-get install amulet python3-requests -y
""")

    os.chmod(os.path.join(charm_dir, 'tests', '99-autogen'), 0755)
    os.chmod(os.path.join(charm_dir, 'tests', '00-setup'), 0755)
Ejemplo n.º 6
0
def tests(charm_dir, is_bundle=False, debug=False, series='trusty'):
    c = Charm(charm_dir)

    if not c.is_charm():
        raise Exception('Not a Charm')

    mdata = c.metadata()

    interfaces = {}
    deploy = [mdata['name']]
    relations = []

    for rel_type in ['provides', 'requires']:
        if rel_type in mdata:
            interfaces[rel_type] = {}
            for rel, data in mdata[rel_type].iteritems():
                iface = data['interface']
                if iface and iface not in interfaces[rel_type]:
                    r = graph(iface, rel_type, series=series)
                    # If we dont find an interface, do nothing
                    if r is None:
                        continue
                    interfaces[rel_type][iface] = r
                    deploy.append(r.name)

                relations.append(['%s:%s' % (mdata['name'], rel), r.name])

    t = Template(file=os.path.join(TPL_DIR, 'tests', '99-autogen.tpl'),
                 searchList=[{'deploy': deploy, 'relate': relations,
                              'series': series}])

    if not os.path.exists(os.path.join(charm_dir, 'tests')):
        os.mkdir(os.path.join(charm_dir, 'tests'))

    with open(os.path.join(charm_dir, 'tests', '99-autogen'), 'w') as f:
        f.write(str(t))

    if not os.path.exists(os.path.join(charm_dir, 'tests', '00-setup')):
        with open(os.path.join(charm_dir, 'tests', '00-setup'), 'w') as f:
            f.write("""#!/bin/bash

sudo add-apt-repository ppa:juju/stable -y
sudo apt-get update
sudo apt-get install amulet python3-requests -y
""")

    os.chmod(os.path.join(charm_dir, 'tests', '99-autogen'), 0755)
    os.chmod(os.path.join(charm_dir, 'tests', '00-setup'), 0755)
Ejemplo n.º 7
0
def tests(charm_dir, is_bundle=False, debug=False):
    c = Charm(charm_dir)

    interfaces = {}
    deploy = []
    relations = []

    if not c.is_charm():
        raise Exception('Not a Charm')

    mdata = c.metadata()

    for rel_type in ['provides', 'requires']:
        if rel_type in mdata:
            interfaces[rel_type] = {}
            for rel, data in mdata[rel_type].iteritems():
                iface = data['interface']
                if iface and iface not in interfaces[rel_type]:
                    r = graph(iface, rel_type)
                    interfaces[rel_type][iface] = r
                    deploy.append(r.url)

                relations.append(['%s:%s' % (mdata['name'], rel), r.name])

    d = Template(file=ATPL['deploy'], searchList=[{'services': deploy}])
    s = Template(file=ATPL['relate'], searchList=[{'relations': relations}])

    t = Template(file=ATPL['body'], searchList=[{'deploy': d, 'relate': s}])

    if not os.path.exists(os.path.join(charm_dir, 'tests')):
        os.mkdir(os.path.join(charm_dir, 'tests'))

    with open(os.path.join(charm_dir, 'tests', '00-autogen'), 'w') as f:
        f.write(str(t))

    if not os.path.exists(os.path.join(charm_dir, 'tests', '00-setup')):
        with open(os.path.join(charm_dir, 'tests', '00-setup'), 'w') as f:
            f.write("""#!/bin/bash

add-apt-repository ppa:juju/stable
apt-get update
apt-get install amulet
""")

    os.chmod(os.path.join(charm_dir, 'tests', '00-autogen'), 0755)
    os.chmod(os.path.join(charm_dir, 'tests', '00-setup'), 0755)
Ejemplo n.º 8
0
def proof(path, is_bundle=False, with_remote=True, debug=False):
    path = os.path.abspath(path)
    if not is_bundle:
        try:
            c = Charm(path)
        except:
            try:
                c = Bundle(path, debug)
            except Exception as e:
                return ["FATAL: Not a Bundle or a Charm, can not proof"], 200
    else:
        try:
            c = Bundle(path, debug)
        except Exception as e:
            return ["FATAL: %s" % e.strerror], 200

    lint, err_code = c.proof(with_remote)
    return lint, err_code
Ejemplo n.º 9
0
def proof(path, is_bundle, debug):
    path = os.path.abspath(path)
    if not is_bundle:
        try:
            c = Charm(path)
        except:
            try:
                c = Bundle(path, debug)
            except Exception as e:
                return ["FATAL: Not a Bundle or a Charm, can not proof"], 200
    else:
        try:
            c = Bundle(path, debug)
        except Exception as e:
            return ["FATAL: %s" % e.message], 200

    lint, err_code = c.proof()
    return lint, err_code
Ejemplo n.º 10
0
def proof(path, is_bundle, debug):
    path = os.path.abspath(path)
    if not is_bundle:
        try:
            c = Charm(path)
        except:
            try:
                c = Bundle(path, debug)
            except Exception as e:
                return ["FATAL: No bundle.yaml (Bundle) or metadata.yaml "
                        "(Charm) found, cannot proof"], 200
    else:
        try:
            c = Bundle(path, debug)
        except Exception as e:
            return ["FATAL: %s" % e.message], 200

    lint, err_code = c.proof()
    return lint, err_code
Ejemplo n.º 11
0
def proof(path, is_bundle, with_remote, debug, server, port, secure):
    path = os.path.abspath(path)
    if not is_bundle:
        try:
            c = Charm(path)
        except:
            try:
                c = Bundle(path, debug)
            except Exception as e:
                return ["FATAL: Not a Bundle or a Charm, can not proof"], 200
    else:
        try:
            c = Bundle(path, debug)
        except Exception as e:
            return ["FATAL: %s" % e.message], 200

    lint, err_code = c.proof(
        remote=with_remote, server=server, port=port, secure=secure)
    return lint, err_code
Ejemplo n.º 12
0
def proof(path, is_bundle, debug):
    messages = []
    exit_code = 0
    path = os.path.abspath(path)
    home_path = utils.get_home()
    home_msg = ('For security reasons, only paths under '
                'your home directory can be accessed')
    if not home_path:  # expansion failed
        messages.append('Could not determine home directory')
        messages.append(home_msg)
    elif not path.startswith(home_path):
        messages.append('The path {} is not under your '
                        'home directory'.format(path))
        messages.append(home_msg)
    if not os.access(path, os.R_OK):
        messages.append('Unable to read from {}'.format(path))
        exit_code = 200
        return messages, exit_code
    if not is_bundle:
        try:
            c = Charm(path)
        except:
            try:
                c = Bundle(path, debug)
            except Exception as e:
                return [
                    "FATAL: No bundle.yaml (Bundle) or metadata.yaml "
                    "(Charm) found, cannot proof"
                ], 200
    else:
        try:
            c = Bundle(path, debug)
        except Exception as e:
            return ["FATAL: %s" % e.message], 200

    lint, err_code = c.proof()
    return lint, err_code