Exemplo n.º 1
0
def test_overlay(mocker, temp_dir):
    name = "lorin.openstack-ansible-modules"
    repo = "https://github.com/lorin/openstack-ansible-modules.git"
    branch = "master"
    clone_dir = os.path.join(temp_dir.strpath, name)
    dst_dir = os.path.join(temp_dir.strpath, "dst", "")

    os.mkdir(clone_dir)
    os.mkdir(dst_dir)

    files = [
        mocker.Mock(src=os.path.join(clone_dir, "*_manage"), dst=dst_dir),
        mocker.Mock(src=os.path.join(clone_dir, "nova_quota"), dst=dst_dir),
        mocker.Mock(
            src=os.path.join(clone_dir, "neutron_router"),
            dst=os.path.join(dst_dir, "neutron_router.py"),
        ),
        mocker.Mock(
            src=os.path.join(clone_dir, "tests"),
            dst=os.path.join(dst_dir, "tests"),
        ),
    ]
    git.clone(name, repo, clone_dir)
    git.overlay(clone_dir, files, branch)

    assert 5 == len(glob.glob("{}/*_manage".format(dst_dir)))
    assert 1 == len(glob.glob("{}/nova_quota".format(dst_dir)))
    assert 1 == len(glob.glob("{}/neutron_router.py".format(dst_dir)))
    assert 2 == len(glob.glob("{}/*".format(os.path.join(dst_dir, "tests"))))
Exemplo n.º 2
0
def test_overlay(mocker, temp_dir):
    name = 'lorin.openstack-ansible-modules'
    repo = 'https://github.com/lorin/openstack-ansible-modules.git'
    branch = 'master'
    clone_dir = os.path.join(temp_dir.strpath, name)
    dst_dir = os.path.join(temp_dir.strpath, 'dst', '')

    os.mkdir(clone_dir)
    os.mkdir(dst_dir)

    # yapf: disable
    files = [
        mocker.Mock(src=os.path.join(clone_dir, '*_manage'), dst=dst_dir),
        mocker.Mock(src=os.path.join(clone_dir, 'nova_quota'), dst=dst_dir),
        mocker.Mock(src=os.path.join(clone_dir, 'neutron_router'),
                    dst=os.path.join(dst_dir, 'neutron_router.py')),
        mocker.Mock(
            src=os.path.join(clone_dir, 'tests'),
            dst=os.path.join(dst_dir, 'tests'))
    ]
    # yapf: enable
    git.clone(name, repo, clone_dir)
    git.overlay(clone_dir, files, branch)

    assert 5 == len(glob.glob('{}/*_manage'.format(dst_dir)))
    assert 1 == len(glob.glob('{}/nova_quota'.format(dst_dir)))
    assert 1 == len(glob.glob('{}/neutron_router.py'.format(dst_dir)))
    assert 2 == len(glob.glob('{}/*'.format(os.path.join(dst_dir, 'tests'))))
Exemplo n.º 3
0
def overlay(ctx):  # pragma: no cover
    """Install gilt dependencies """
    args = ctx.obj.get("args")
    filename = args.get("config")
    debug = args.get("debug")
    _setup(filename)

    for c in config.config(filename):
        with fasteners.InterProcessLock(c.lock_file):
            util.print_info("{}:".format(c.name))
            if not os.path.exists(c.src):
                git.clone(c.name, c.git, c.src, debug=debug)
            if c.dst:
                git.extract(c.src, c.dst, c.version, debug=debug)
                post_commands = {c.dst: c.post_commands}
            else:
                git.overlay(c.src, c.files, c.version, debug=debug)
                post_commands = {
                    conf.dst: conf.post_commands
                    for conf in c.files
                }
            # Run post commands if any.
            for dst, commands in post_commands.items():
                for command in commands:
                    msg = "  - running `{}` in {}".format(command, dst)
                    util.print_info(msg)
                    cmd = util.build_sh_cmd(command, cwd=dst)
                    util.run_command(cmd, debug=debug)
Exemplo n.º 4
0
def test_clone(temp_dir):
    name = 'retr0h.ansible-etcd'
    repo = 'https://github.com/retr0h/ansible-etcd.git'
    destination = os.path.join(temp_dir.strpath, name)

    git.clone(name, repo, destination)

    assert os.path.exists(destination)
Exemplo n.º 5
0
def test_is_branch(temp_dir):
    name = 'retr0h.ansible-etcd'
    repo = 'https://github.com/retr0h/ansible-etcd.git'
    destination = os.path.join(temp_dir.strpath, name)
    git.clone(name, repo, destination)
    os.chdir(destination)
    assert git._is_branch('master')
    assert not git._is_branch('1.1')
    assert not git._is_branch('888ef7b')
Exemplo n.º 6
0
def overlay(ctx):  # pragma: no cover
    """ Install gilt dependencies """
    args = ctx.obj.get('args')
    filename = args.get('config')
    debug = args.get('debug')
    _setup(filename)

    for c in config.config(filename):
        with fasteners.InterProcessLock(c.lock_file):
            util.print_info('{}:'.format(c.name))
            if not os.path.exists(c.src):
                git.clone(c.name, c.git, c.src, debug=debug)
            if c.dst:
                git.extract(c.src, c.dst, c.version, debug=debug)
            else:
                git.overlay(c.src, c.files, c.version, debug=debug)
Exemplo n.º 7
0
def test_overlay_existing_directory(mocker, temp_dir):
    name = 'lorin.openstack-ansible-modules'
    repo = 'https://github.com/lorin/openstack-ansible-modules.git'
    branch = 'master'
    clone_dir = os.path.join(temp_dir.strpath, name)
    dst_dir = os.path.join(temp_dir.strpath, 'dst', '')

    os.mkdir(clone_dir)
    os.mkdir(dst_dir)
    os.mkdir(os.path.join(dst_dir, 'tests'))

    files = [
        mocker.Mock(src=os.path.join(clone_dir, 'tests'),
                    dst=os.path.join(dst_dir, 'tests'))
    ]
    git.clone(name, repo, clone_dir)
    git.overlay(clone_dir, files, branch)

    assert 2 == len(glob.glob('{}/*'.format(os.path.join(dst_dir, 'tests'))))
Exemplo n.º 8
0
def test_has_version(temp_dir):
    name = "retr0h.ansible-etcd"
    repo = "https://github.com/retr0h/ansible-etcd.git"
    destination = os.path.join(temp_dir.strpath, name)
    git.clone(name, repo, destination)
    os.chdir(destination)
    # _has_branch tests
    assert git._has_branch("master")
    assert not git._has_branch("1.1")
    assert not git._has_branch("888ef7b")

    # _has_tag tests
    assert not git._has_tag("master")
    assert git._has_tag("1.1")
    assert not git._has_tag("888ef7b")

    # _has_commit tests
    assert not git._has_commit("master")
    assert not git._has_commit("1.1")
    assert git._has_commit("888ef7b")
Exemplo n.º 9
0
def test_extract(temp_dir):
    name = 'retr0h.ansible-etcd'
    repo = 'https://github.com/retr0h/ansible-etcd.git'
    branch = 'gilt'
    clone_dir = os.path.join(temp_dir.strpath, 'clone_dir')
    extract_dir = os.path.join(temp_dir.strpath, 'extract_dir')

    os.mkdir(clone_dir)
    os.mkdir(extract_dir)

    clone_destination = os.path.join(clone_dir, name)
    extract_destination = os.path.join(extract_dir, name, '')

    git.clone(name, repo, clone_destination)
    git.extract(clone_destination, extract_destination, branch)

    assert os.path.exists(extract_destination)
    git_dir = os.path.join(extract_destination, os.extsep.join(('', 'git')))
    assert not os.path.exists(git_dir)
    giltfile = os.path.join(extract_destination, 'giltfile')
    assert os.path.exists(giltfile)
Exemplo n.º 10
0
def test_overlay_existing_directory(mocker, temp_dir):
    name = "lorin.openstack-ansible-modules"
    repo = "https://github.com/lorin/openstack-ansible-modules.git"
    branch = "master"
    clone_dir = os.path.join(temp_dir.strpath, name)
    dst_dir = os.path.join(temp_dir.strpath, "dst", "")

    os.mkdir(clone_dir)
    os.mkdir(dst_dir)
    os.mkdir(os.path.join(dst_dir, "tests"))

    files = [
        mocker.Mock(
            src=os.path.join(clone_dir, "tests"),
            dst=os.path.join(dst_dir, "tests"),
        )
    ]
    git.clone(name, repo, clone_dir)
    git.overlay(clone_dir, files, branch)

    assert 2 == len(glob.glob("{}/*".format(os.path.join(dst_dir, "tests"))))
Exemplo n.º 11
0
def test_extract(temp_dir):
    name = "retr0h.ansible-etcd"
    repo = "https://github.com/retr0h/ansible-etcd.git"
    branch = "gilt"
    clone_dir = os.path.join(temp_dir.strpath, "clone_dir")
    extract_dir = os.path.join(temp_dir.strpath, "extract_dir")

    os.mkdir(clone_dir)
    os.mkdir(extract_dir)

    clone_destination = os.path.join(clone_dir, name)
    extract_destination = os.path.join(extract_dir, name, "")

    git.clone(name, repo, clone_destination)
    git.extract(clone_destination, extract_destination, branch)

    assert os.path.exists(extract_destination)
    git_dir = os.path.join(extract_destination, os.extsep.join(("", "git")))
    assert not os.path.exists(git_dir)
    giltfile = os.path.join(extract_destination, "giltfile")
    assert os.path.exists(giltfile)