Skip to content

Instantly share code, notes, and snippets.

@tonk
Created April 23, 2018 13:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tonk/50cd329b029cfb0d654f5afc54b451db to your computer and use it in GitHub Desktop.
Save tonk/50cd329b029cfb0d654f5afc54b451db to your computer and use it in GitHub Desktop.
--> Validating schema /home/tonk/molecule/moletest/molecule/default/molecule.yml.
Validation completed successfully.
--> Test matrix
└── default
└── verify
--> Scenario: 'default'
--> Action: 'verify'
--> Executing Testinfra tests found in /home/tonk/molecule/moletest/molecule/default/tests/...
============================= test session starts ==============================
platform linux2 -- Python 2.7.14, pytest-3.3.2, py-1.5.2, pluggy-0.6.0 -- /usr/bin/python2
rootdir: /home/tonk/molecule/moletest/molecule/default, inifile:
plugins: testinfra-1.7.1
^Mcollecting 0 items ^Mcollecting 0 items / 1 errors ^Mcollected 0 items / 1 errors
==================================== ERRORS ====================================
___________________ ERROR collecting tests/test_packages.py ____________________
/usr/lib/python2.7/site-packages/pluggy/__init__.py:617: in __call__
return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
/usr/lib/python2.7/site-packages/pluggy/__init__.py:222: in _hookexec
return self._inner_hookexec(hook, methods, kwargs)
/usr/lib/python2.7/site-packages/pluggy/__init__.py:216: in <lambda>
firstresult=hook.spec_opts.get('firstresult'),
/usr/lib/python2.7/site-packages/_pytest/python.py:192: in pytest_pycollect_makeitem
res = list(collector._genfunctions(name, obj))
/usr/lib/python2.7/site-packages/_pytest/python.py:370: in _genfunctions
self.ihook.pytest_generate_tests(metafunc=metafunc)
/usr/lib/python2.7/site-packages/pluggy/__init__.py:617: in __call__
return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
/usr/lib/python2.7/site-packages/pluggy/__init__.py:222: in _hookexec
return self._inner_hookexec(hook, methods, kwargs)
/usr/lib/python2.7/site-packages/pluggy/__init__.py:216: in <lambda>
firstresult=hook.spec_opts.get('firstresult'),
/usr/lib/python2.7/site-packages/testinfra/plugin.py:143: in pytest_generate_tests
ansible_inventory=metafunc.config.option.ansible_inventory,
/usr/lib/python2.7/site-packages/testinfra/host.py:125: in get_hosts
for backend in testinfra.backend.get_backends(hosts, **kwargs):
/usr/lib/python2.7/site-packages/testinfra/backend/__init__.py:89: in get_backends
for name in klass.get_hosts(host, **kw):
/usr/lib/python2.7/site-packages/testinfra/backend/ansible.py:72: in get_hosts
return AnsibleRunner(kwargs.get("ansible_inventory")).get_hosts(host)
/usr/lib/python2.7/site-packages/testinfra/utils/ansible_runner.py:171: in __init__
self.cli._play_prereqs(self.cli.options))
/usr/lib/python2.7/site-packages/ansible/cli/__init__.py:804: in _play_prereqs
inventory = InventoryManager(loader=loader, sources=options.inventory)
/usr/lib/python2.7/site-packages/ansible/inventory/manager.py:145: in __init__
self.parse_sources(cache=True)
/usr/lib/python2.7/site-packages/ansible/inventory/manager.py:206: in parse_sources
parse = self.parse_source(source, cache=cache)
/usr/lib/python2.7/site-packages/ansible/inventory/manager.py:261: in parse_source
if plugin.verify_file(source):
/usr/lib/python2.7/site-packages/ansible/plugins/inventory/yaml.py:84: in verify_file
if not ext or ext in self.get_option('yaml_extensions'):
/usr/lib/python2.7/site-packages/ansible/plugins/__init__.py:58: in get_option
option_value = C.config.get_config_value(option, plugin_type=get_plugin_class(self), plugin_name=self._load_name, variables=hostvars)
/usr/lib/python2.7/site-packages/ansible/config/manager.py:284: in get_config_value
value, _drop = self.get_config_value_and_origin(config, cfile=cfile, plugin_type=plugin_type, plugin_name=plugin_name, keys=keys, variables=variables)
/usr/lib/python2.7/site-packages/ansible/config/manager.py:304: in get_config_value_and_origin
defs = self._plugins[plugin_type][plugin_name]
E KeyError: 'inventory'
!!!!!!!!!!!!!!!!!!! Interrupted: 1 errors during collection !!!!!!!!!!!!!!!!!!!!
=========================== 1 error in 1.85 seconds ============================
---
# Set dependency manager
dependency:
name: galaxy
options:
ignore-certs: True
ignore-errors: True
#
# Use Docker
#
driver:
name: docker
#
# Use Linter
#
lint:
name: yamllint
options:
config-file: molecule/default/yamllint.cfg
#
# Ansible provisioner and variables
#
provisioner:
name: ansible
inventory:
group_vars:
all:
name: Wile E. Coyote
company: ACME
domain: acme.net
lint:
name: ansible-lint
#
# Which tests
#
scenario:
name: default
verifier:
name: testinfra
options:
verbose: True name: flake8
#
# Which platforms
#
platforms:
#
- name: centos7
hostname: centos7
image: couchbase/centos7-systemd
image_version: latest
privileged: True
groups:
- chrony
- centos
command: "/usr/sbin/init"
volumes:
- "/sys/fs/cgroup:/sys/fs/cgroup:rw"
debug: False
lint:
"""Test infra sctructure."""
import testinfra.utils.ansible_runner as ti
# Get all hosts from the Ansible inventory
# The inventory is generated from the molecule.yml file
inventory = '/tmp/molecule/chrony/default/ansible_inventory.yml'
hosts = ti.AnsibleRunner(inventory).get_hosts('all')
def test_packages(host):
"""Test if all packages are present."""
present = [
host.package('chrony'),
host.package('ca-certificates'),
host.package('libselinux-python')
]
if present:
for this in present:
assert this.is_installed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment