Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import testinfra.utils.ansible_runner
import json
runner = testinfra.utils.ansible_runner.AnsibleRunner(
'.molecule/ansible_inventory')
testinfra_hosts = runner.get_hosts('all')
def test_change_existing(Command):
stdout = Command("cat /tmp/0.json").stdout
data = json.loads(stdout)
assert data['a'] == 'e'
assert data['c'] == 'f'
def test_nested_change_existing(Command):
stdout = Command("cat /tmp/1.json").stdout
data = json.loads(stdout)
assert data['c'] == {'d': 'f'}
import nginx
import os
import testinfra.utils.ansible_runner
testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all')
def test_nginx_is_installed(host):
ngx = host.package("nginx")
assert ngx.is_installed
def test_nginx_running_and_enabled(host):
ngx = host.service("nginx")
assert ngx.is_running
assert ngx.is_enabled
def test_hosts_file(host):
ngx = host.file('/etc/hosts')
import os
import testinfra.utils.ansible_runner
testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
os.environ['MOLECULE_INVENTORY_FILE']
).get_hosts('all')
def test_ansible_hostname(host):
f = host.file('/tmp/molecule/instance-1')
assert not f.exists
def test_testaid_unit_boilerplate_hosts_molecule_inventory_file(
monkeypatch):
monkeypatch.setenv('MOLECULE_INVENTORY_FILE', 'localhost')
monkeypatch.setattr(testinfra.utils.ansible_runner.AnsibleRunner,
'get_hosts',
lambda x, y: ['testhost'])
hosts = testaid.boilerplate.hosts()
assert hosts == ['testhost']
# Copyright 2015 VMware, Inc. All rights reserved.
# SPDX-License-Identifier: Apache-2.0 OR GPL-3.0-only
from __future__ import print_function
import testinfra.utils.ansible_runner
testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
'.molecule/ansible_inventory').get_hosts('all')
# Use testinfra to get a handy function to run commands locally
check_output = testinfra.get_backend(
"local://"
).get_module("Command").check_output
def test_hosts_file(File):
f = File('/root/.ssh/authorized_keys')
assert f.exists
assert f.user == 'root'
assert f.group == 'root'
command = check_output(
'cat ~/.ssh/ansible_role_test_key.pub')
def database_address(request):
import testinfra.utils.ansible_runner
inventory = testinfra.utils.ansible_runner.AnsibleRunner(
os.environ["MOLECULE_INVENTORY_FILE"]
)
database_hosts = inventory.get_hosts("db")
if len(database_hosts) != 1:
raise ValueError("Multiple databases are not correctly suported")
database_facts = inventory.run_module(database_hosts[0], "setup", [])
database_ip = database_facts["ansible_facts"]["ansible_default_ipv4"]["address"]
return database_ip
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(host):
f = host.file('/etc/hosts')
assert f.exists
assert f.user == 'root'
assert f.group == 'root'
import testinfra.utils.ansible_runner
testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
'.molecule/inventory').get_hosts('all')
def get(e, nodeName):
arg = r"./property[name='{nodename}']".format(nodename=nodeName)
return e.find(arg)[1].text
def test_hosts_file(File):
f = File('/etc/hosts')
assert f.exists
assert f.user == 'root'
assert f.group == 'root'
import testinfra.utils.ansible_runner
testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
'.molecule/ansible_inventory').get_hosts('all')
def test_application_running(Service):
application = Service("spring-boot-sample")
assert application.is_enabled
def test_application_properties_exists(File):
propertyFile = File("/opt/spring-boot-sample/application.yml")
assert propertyFile.exists
def test_application_conf_exists(File):
configFile = File("/opt/spring-boot-sample/spring-boot-sample.conf")
assert configFile.exists
import os
import testinfra.utils.ansible_runner
testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all')
def test_nginx_is_installed(host):
ngx = host.package("nginx")
assert ngx.is_installed
def test_nginx_running_and_enabled(host):
ngx = host.service("nginx")
assert ngx.is_running
assert ngx.is_enabled
def test_hosts_file(host):
ngx = host.file('/etc/hosts')