Exemplo n.º 1
0
def test_nested_combine(loader_setup):
    c = loader_setup
    data = loader.combine(configs=c)

    assert 'scenario-1' == data['suites'][0]['name']
    assert 'overriden-scenario-2' == data['suites'][1]['name']
    assert 'overriden-scenario-3' == data['suites'][2]['name']
Exemplo n.º 2
0
def test_default_run(maquina_config, mocker):
    mocked = mocker.patch('subprocess.Popen')
    mocked.return_value = mock.Mock(stdout=io.StringIO(u'mocked stdout'))

    data = loader.combine()
    c = config.Config(data)
    i = c.instances[0]
    i.provisioner.run()

    expected = ['ansible-playbook', '--become', '--connection=ssh',
                '--flag1=foo', '--flag2=bar', '--inventory-file=inventory',
                '--user=vagrant', 'playbook.yml'],
    assert expected == mocked.call_args[0]

    ca = mocked.call_args[1]
    env = ca.get('env')
    assert 'roles:../' == env.get('ANSIBLE_ROLES_PATH')
    assert 'true' == env.get('ANSIBLE_FORCE_COLOR')
    assert 'false' == env.get('ANSIBLE_HOST_KEY_CHECKING')
    assert ('-o UserKnownHostsFile=/dev/null '
            '-o IdentitiesOnly=yes '
            '-o ControlMaster=auto '
            '-o ControlPersist=60s') == env.get('ANSIBLE_SSH_ARGS')
    assert 'bar' == env.get('FOO')
    assert 1 == ca.get('bufsize')
    assert -1 == ca.get('stdout')
Exemplo n.º 3
0
def main():
    args = _parse_args()
    data = loader.combine()
    c = config.Config(data)

    if args.subcmd == 'create':
        c.driver.create()
    elif args.subcmd == 'destroy':
        c.driver.destroy()
    elif args.subcmd == 'converge':
        for instance in c.instances:
            instance.provisioner.run()
    elif args.subcmd == 'verify':
        for instance in c.instances:
            print instance.verifier._get_run_command()
    elif args.subcmd == 'test':
        for instance in c.instances:
            msg = (
                'Testing:\n'
                '  suite: {instance.provisioner.suite.name}\n'
                '  run_list: {instance.provisioner.suite.run_list}\n'
                '  platforms: {instance.platforms}\n'
                '  driver: {instance.driver.name}').format(instance=instance)
            print msg
            instance.driver.create()
            instance.provisioner.run()
            instance.driver.destroy()
Exemplo n.º 4
0
def test_default_get_run_command(maquina_config):
    data = loader.combine()
    c = config.Config(data)
    d = driver.Vagrant(c)
    s = suite.create({'name': 'suite', 'run_list': 'playbook.yml'})
    p = provisioner.Ansible(c, d, s)
    v = verifier.Testinfra(p)

    expected = ['testinfra', '--connection=ansible', '--sudo', 'tests']
    assert expected == v._get_run_command()
Exemplo n.º 5
0
def test_instances(maquina_config):
    data = loader.combine()
    c = config.Config(data)

    result = c.instances
    assert 1 == len(result)

    assert 'ubuntu-14.04' == result[0].platforms[0].name
    assert 'ubuntu-12.04' == result[0].platforms[1].name

    assert isinstance(result[0].driver, driver.Vagrant)

    assert isinstance(result[0].provisioner, provisioner.Ansible)

    assert isinstance(result[0].verifier, verifier.Testinfra)
Exemplo n.º 6
0
def test_maquina_dir_override(loader_setup):
    c = loader_setup
    data = loader.combine(configs=c)
    c = config.Config(data)

    assert '/maquina/overriden-path/.maquina' == c.maquina_dir
Exemplo n.º 7
0
def test_maquina_dir_default(maquina_root, maquina_config):
    data = loader.combine()
    c = config.Config(data)

    assert '/maquina/path/.maquina' == c.maquina_dir
Exemplo n.º 8
0
def test_default_user(maquina_config):
    data = loader.combine()
    c = config.Config(data)
    d = driver.Vagrant(c)

    assert 'vagrant' == d.user
Exemplo n.º 9
0
def test_default_inventory(maquina_config):
    data = loader.combine()
    c = config.Config(data)
    d = driver.Vagrant(c)

    assert 'inventory' == d.inventory
Exemplo n.º 10
0
def test_simple_combine(loader_setup):
    c = loader_setup
    data = loader.combine(configs=c)

    assert 'overriden-driver' == data['driver']['name']
Exemplo n.º 11
0
def test_single_config(loader_setup):
    c = loader_setup
    data = loader.combine(configs=c)

    assert 'vagrant' == data['driver']['name']