예제 #1
0
def test_multivm_config():
    '''
    Test methods retrieving configuration settings.
    '''
    v = vagrant.Vagrant(TD, quiet_stdout=False, quiet_stderr=False)
    v.up(vm_name=VM_1)
    command = "vagrant ssh-config " + VM_1
    ssh_config = compat.decode(
        subprocess.check_output(command, cwd=TD, shell=True))
    parsed_config = dict(line.strip().split(None, 1)
                         for line in ssh_config.splitlines()
                         if line.strip() and not line.strip().startswith('#'))

    user = v.user(vm_name=VM_1)
    expected_user = parsed_config["User"]
    eq_(user, expected_user)

    hostname = v.hostname(vm_name=VM_1)
    expected_hostname = parsed_config["HostName"]
    eq_(hostname, expected_hostname)

    port = v.port(vm_name=VM_1)
    expected_port = parsed_config["Port"]
    eq_(port, expected_port)

    user_hostname = v.user_hostname(vm_name=VM_1)
    eq_(user_hostname, "{}@{}".format(expected_user, expected_hostname))

    user_hostname_port = v.user_hostname_port(vm_name=VM_1)
    eq_(user_hostname_port, "{}@{}:{}".format(expected_user, expected_hostname,
                                              expected_port))

    keyfile = v.keyfile(vm_name=VM_1)
    eq_(keyfile, parsed_config["IdentityFile"])
예제 #2
0
def test_vm_config():
    '''
    Test methods retrieving ssh config settings, like user, hostname, and port.
    '''
    v = vagrant.Vagrant(TD)
    v.up()
    command = "vagrant ssh-config"
    ssh_config = compat.decode(
        subprocess.check_output(command, cwd=TD, shell=True))
    parsed_config = dict(line.strip().split(None, 1)
                         for line in ssh_config.splitlines()
                         if line.strip() and not line.strip().startswith('#'))

    user = v.user()
    expected_user = parsed_config["User"]
    eq_(user, expected_user)

    hostname = v.hostname()
    expected_hostname = parsed_config["HostName"]
    eq_(hostname, expected_hostname)

    port = v.port()
    expected_port = parsed_config["Port"]
    eq_(port, expected_port)

    user_hostname = v.user_hostname()
    eq_(user_hostname, "{}@{}".format(expected_user, expected_hostname))

    user_hostname_port = v.user_hostname_port()
    eq_(user_hostname_port, "{}@{}:{}".format(expected_user, expected_hostname,
                                              expected_port))

    keyfile = v.keyfile()
    eq_(keyfile, parsed_config["IdentityFile"])
예제 #3
0
def test_multivm_config():
    '''
    Test methods retrieving configuration settings.
    '''
    v = vagrant.Vagrant(TD, quiet_stdout=False, quiet_stderr=False)
    v.up(vm_name=VM_1)
    command = "vagrant ssh-config " + VM_1
    ssh_config = compat.decode(subprocess.check_output(command, cwd=TD, shell=True))
    parsed_config = dict(line.strip().split(None, 1) for line in
                            ssh_config.splitlines() if line.strip() and not
                            line.strip().startswith('#'))

    user = v.user(vm_name=VM_1)
    expected_user = parsed_config["User"]
    eq_(user, expected_user)

    hostname = v.hostname(vm_name=VM_1)
    expected_hostname = parsed_config["HostName"]
    eq_(hostname, expected_hostname)

    port = v.port(vm_name=VM_1)
    expected_port = parsed_config["Port"]
    eq_(port, expected_port)

    user_hostname = v.user_hostname(vm_name=VM_1)
    eq_(user_hostname, "{}@{}".format(expected_user, expected_hostname))

    user_hostname_port = v.user_hostname_port(vm_name=VM_1)
    eq_(user_hostname_port,
        "{}@{}:{}".format(expected_user, expected_hostname, expected_port))

    keyfile = v.keyfile(vm_name=VM_1)
    eq_(keyfile, parsed_config["IdentityFile"])
예제 #4
0
def test_vm_config():
    '''
    Test methods retrieving ssh config settings, like user, hostname, and port.
    '''
    v = vagrant.Vagrant(TD)
    v.up()
    command = "vagrant ssh-config"
    ssh_config = compat.decode(subprocess.check_output(command, cwd=TD, shell=True))
    parsed_config = dict(line.strip().split(None, 1) for line in
                            ssh_config.splitlines() if line.strip() and not
                            line.strip().startswith('#'))

    user = v.user()
    expected_user = parsed_config["User"]
    eq_(user, expected_user)

    hostname = v.hostname()
    expected_hostname = parsed_config["HostName"]
    eq_(hostname, expected_hostname)

    port = v.port()
    expected_port = parsed_config["Port"]
    eq_(port, expected_port)

    user_hostname = v.user_hostname()
    eq_(user_hostname, "{}@{}".format(expected_user, expected_hostname))

    user_hostname_port = v.user_hostname_port()
    eq_(user_hostname_port,
        "{}@{}:{}".format(expected_user, expected_hostname, expected_port))

    keyfile = v.keyfile()
    eq_(keyfile, parsed_config["IdentityFile"])
예제 #5
0
def _execute_command_in_vm(v, command):
    """
    Run command via ssh on the test vagrant box.  Returns a tuple of the
    return code and output of the command.
    """
    # ignore the fact that this host is not in our known hosts
    ssh_command = [VAGRANT_EXE, "ssh", "-c", command]
    return compat.decode(subprocess.check_output(ssh_command, cwd=v.root))
예제 #6
0
def _execute_command_in_vm(v, command):
    '''
    Run command via ssh on the test vagrant box.  Returns a tuple of the
    return code and output of the command.
    '''
    vagrant_exe = vagrant.get_vagrant_executable()

    if not vagrant_exe:
        raise RuntimeError(vagrant.VAGRANT_NOT_FOUND_WARNING)

    # ignore the fact that this host is not in our known hosts
    ssh_command = [vagrant_exe, 'ssh', '-c', command]
    return compat.decode(subprocess.check_output(ssh_command, cwd=v.root))
예제 #7
0
def _execute_command_in_vm(v, command):
    '''
    Run command via ssh on the test vagrant box.  Returns a tuple of the
    return code and output of the command.
    '''
    vagrant_exe = vagrant.get_vagrant_executable()

    if not vagrant_exe:
        raise RuntimeError(vagrant.VAGRANT_NOT_FOUND_WARNING)

    # ignore the fact that this host is not in our known hosts
    ssh_command = [vagrant_exe, 'ssh', '-c', command]
    return compat.decode(subprocess.check_output(ssh_command, cwd=v.root))
예제 #8
0
def list_box_names():
    '''
    Return a list of the currently installed vagrant box names.  This is 
    implemented outside of `vagrant.Vagrant`, so that it will still work
    even if the `Vagrant.box_list()` implementation is broken.
    '''
    listing = compat.decode(subprocess.check_output('vagrant box list --machine-readable', shell=True))
    box_names = []
    for line in listing.splitlines():
        timestamp, _, kind, data = line.split(',')
        if kind == 'box-name':
            box_names.append(data.strip())
    return box_names
예제 #9
0
def list_box_names():
    '''
    Return a list of the currently installed vagrant box names.  This is 
    implemented outside of `vagrant.Vagrant`, so that it will still work
    even if the `Vagrant.box_list()` implementation is broken.
    '''
    listing = compat.decode(
        subprocess.check_output('vagrant box list --machine-readable',
                                shell=True))
    box_names = []
    for line in listing.splitlines():
        timestamp, _, kind, data = line.split(',')
        if kind == 'box-name':
            box_names.append(data.strip())
    return box_names
예제 #10
0
def list_box_names():
    '''
    Return a list of the currently installed vagrant box names.  This is 
    implemented outside of `vagrant.Vagrant`, so that it will still work
    even if the `Vagrant.box_list()` implementation is broken.
    '''
    listing = compat.decode(subprocess.check_output('vagrant box list --machine-readable', shell=True))
    box_names = []
    for line in listing.splitlines():
        # Vagrant 1.8 added additional fields to the --machine-readable output,
        # so unpack the fields according to the number of separators found.
        if line.count(',') == 3:
            timestamp, _, kind, data = line.split(',')
        else:
            timestamp, _, kind, data, extra_data = line.split(',')
        if kind == 'box-name':
            box_names.append(data.strip())
    return box_names
예제 #11
0
def list_box_names():
    '''
    Return a list of the currently installed vagrant box names.  This is 
    implemented outside of `vagrant.Vagrant`, so that it will still work
    even if the `Vagrant.box_list()` implementation is broken.
    '''
    listing = compat.decode(
        subprocess.check_output('vagrant box list --machine-readable',
                                shell=True))
    box_names = []
    for line in listing.splitlines():
        # Vagrant 1.8 added additional fields to the --machine-readable output,
        # so unpack the fields according to the number of separators found.
        if line.count(',') == 3:
            timestamp, _, kind, data = line.split(',')
        else:
            timestamp, _, kind, data, extra_data = line.split(',')
        if kind == 'box-name':
            box_names.append(data.strip())
    return box_names
예제 #12
0
def test_multivm_config(vm_dir):
    """
    Test methods retrieving configuration settings.
    """
    v = vagrant.Vagrant(vm_dir, quiet_stdout=False, quiet_stderr=False)
    v.up(vm_name=VM_1)
    command = [VAGRANT_EXE, "ssh-config", VM_1]
    ssh_config = compat.decode(subprocess.check_output(command, cwd=vm_dir))
    parsed_config = dict(line.strip().split(None, 1)
                         for line in ssh_config.splitlines()
                         if line.strip() and not line.strip().startswith("#"))

    user = v.user(vm_name=VM_1)
    expected_user = parsed_config["User"]
    assert user == expected_user

    hostname = v.hostname(vm_name=VM_1)
    expected_hostname = parsed_config["HostName"]
    assert hostname == expected_hostname

    port = v.port(vm_name=VM_1)
    expected_port = parsed_config["Port"]
    assert port == expected_port

    user_hostname = v.user_hostname(vm_name=VM_1)
    assert user_hostname == "{}@{}".format(expected_user, expected_hostname)

    user_hostname_port = v.user_hostname_port(vm_name=VM_1)
    assert user_hostname_port == "{}@{}:{}".format(expected_user,
                                                   expected_hostname,
                                                   expected_port)

    keyfile = v.keyfile(vm_name=VM_1)
    try:
        assert keyfile == parsed_config["IdentityFile"]
    except AssertionError:
        # Vagrant 1.8 adds quotes around the filepath for the private key.
        assert keyfile == parsed_config["IdentityFile"].lstrip('"').rstrip('"')
예제 #13
0
nodeList = nodes["nodes"]

hosts = {'nodes': ''}

hostinfos = {}

print(
    "++++++++++++++++++++++++++ Preparing Configurations Files +++++++++++++++++++++++++++++"
)

for key, value in nodeList.iteritems():

    command = "vagrant ssh-config " + value.get(":node_name")

    ssh_config = compat.decode(
        subprocess.check_output(command, cwd=TD, shell=True))

    hostinfo = ssh_config.splitlines(True)[1]

    hostinfos[key] = hostinfo.strip().split(" ")[1]

hosts['nodes'] = hostinfos

with open('hosts.yml', 'w') as outfile:
    outfile.write(yaml.dump(hosts, default_flow_style=False))

print(
    "++++++++++++++++++++++++++++++++++++++ Finished +++++++++++++++++++++++++++++++++++++++"
)