Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_same_website_root():
tree = {}
for name in ("default", "production"):
conn = testinfra.get_backend(
name, connection="paramiko", ssh_config=".vagrant-ssh-config")
Command = conn.get_module("Command")
tree[name] = Command.check_output("tree /srv/website")
assert tree["default"] == tree["production"]
''' This file starts with 000 to make it run first '''
import pytest
import testinfra
run_local = testinfra.get_backend(
"local://"
).get_module("Command").run
@pytest.mark.parametrize("upstream,image,tag", [
( 'alpine:edge', 'alpine.docker', 'diginc/pi-hole:alpine' ),
( 'debian:jessie', 'debian.docker', 'diginc/pi-hole:debian' ),
#( 'jsurf/rpi-raspbian', 'debian-armhf.docker', 'diginc/pi-hole:arm' ),
])
def test_build_pihole_image(upstream, image, tag):
run_local('docker pull {}'.format(upstream))
build_cmd = run_local('docker build -f {} -t {} .'.format(image, tag))
if build_cmd.rc != 0:
print build_cmd.stdout
print build_cmd.stderr
assert build_cmd.rc == 0
def _get_module(module_name, backend=default_backend):
"""Retrieve the correct module implementation determined by the backend
being used.
:param module_name: TestInfra module to retrieve
:param backend: string representing backend for TestInfra
:returns: desired TestInfra module object
:rtype: object
"""
backend_instance = testinfra.get_backend(backend)
return backend_instance.get_module(_to_pascal_case(module_name))
# 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')
assert command == f.content_string.rstrip()