Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
# 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)
# 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'
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
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'