How to use the testinfra.utils function in testinfra

To help you get started, we’ve selected a few testinfra examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github philpep / testinfra / testinfra / backend / base.py View on Github external
# A literal IPv6 address might be like
        #  [fe80:0::a:b:c]:80
        # thus, below in words; if this starts with a '[' assume it
        # encloses an ipv6 address with a closing ']', with a possible
        # trailing port after a colon
        if name.startswith('['):
            name, port = name.split(']')
            name = name[1:]
            if port.startswith(':'):
                port = port[1:]
            else:
                port = None
        else:
            if ':' in name:
                name, port = name.split(':', 1)
        name = testinfra.utils.urlunquote(name)
        if user is not None:
            user = testinfra.utils.urlunquote(user)
        if password is not None:
            password = testinfra.utils.urlunquote(password)
        return HostSpec(name, port, user, password)
github vmware / ansible-role-ovftool / tests / test_default.py View on Github external
# Copyright 2015 VMware, Inc.  All rights reserved.
# SPDX-License-Identifier: Apache-2.0 OR GPL-3.0-only

import testinfra.utils.ansible_runner

testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
    '.molecule/ansible_inventory').get_hosts('all')


def test_hosts_file(File):
    f = File('/usr/bin/ovftool')

    assert f.exists
    assert f.user == 'root'
    assert f.group == 'root'
github hugoShaka / ansible-mailserver / test / suite / additional / replication.py View on Github external
def servers():
    import testinfra.utils.ansible_runner

    inventory = testinfra.utils.ansible_runner.AnsibleRunner(
        os.environ["MOLECULE_INVENTORY_FILE"]
    )
    mda_hosts = inventory.get_hosts("mda")
    if len(mda_hosts) != 2:
        raise ValuerError("Too many mda hosts")

    server_ips = []
    for mda_host in mda_hosts:
        mda_facts = inventory.run_module(mda_host, "setup", [])
        mda_ip = mda_facts["ansible_facts"]["ansible_default_ipv4"]["address"]
        server_ips.append(mda_ip)

    return server_ips
github ansible / molecule / molecule / cookiecutter / scenario / verifier / testinfra / {{cookiecutter.molecule_directory}} / {{cookiecutter.scenario_name}} / {{cookiecutter.verifier_directory}} / test_default.py View on Github external
import os

import testinfra.utils.ansible_runner

testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
    os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all')


def test_hosts_file(File):
    f = File('/etc/hosts')

    assert f.exists
    assert f.user == 'root'
    assert f.group == 'root'