Skip to content

Commit

Permalink
Remove testinfra verifier (#3964)
Browse files Browse the repository at this point in the history
Starting with v6, there will be no testinfra plugin. Instead those
wanting to use testinfra, will be able to call it using
`ansible.builtin.shell` from `converge.yml` playbook.

Closes: #3920
  • Loading branch information
ssbarnea committed Jul 12, 2023
1 parent 99a95f8 commit 10714ef
Show file tree
Hide file tree
Showing 35 changed files with 7 additions and 853 deletions.
1 change: 0 additions & 1 deletion .config/requirements-test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ filelock >= 3.9.0
pexpect >= 4.8.0, < 5
pytest-mock >= 3.10.0
pytest-plus >= 0.4.0
pytest-testinfra >= 7.0.0
pytest-xdist >= 3.1.0
pytest >= 7.2.0
check-jsonschema
1 change: 0 additions & 1 deletion .config/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ pymdown-extensions==10.0.1
pytest==7.4.0
pytest-mock==3.11.1
pytest-plus==0.4.0
pytest-testinfra==8.1.0
pytest-xdist==3.3.1
python-dateutil==2.8.2
python-slugify==8.0.1
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/tox.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ jobs:
matrix: ${{ fromJson(needs.pre.outputs.matrix) }}

env:
PYTEST_REQPASS: 445
PYTEST_REQPASS: 424
steps:
- uses: actions/checkout@v3
with:
Expand Down
1 change: 0 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ repos:
- jsonschema
- pexpect
- pytest-mock
- pytest-testinfra
- repo: https://github.com/jazzband/pip-tools
rev: 6.14.0
hooks:
Expand Down
4 changes: 0 additions & 4 deletions docs/ci.md
Original file line number Diff line number Diff line change
Expand Up @@ -401,8 +401,6 @@ won't create any conflict.
---
dependency:
name: galaxy
driver:
name: docker
platforms:
- name: instance1-$TOX_ENVNAME
image: mariadb
Expand All @@ -412,6 +410,4 @@ platforms:
command: /usr/sbin/init
provisioner:
name: ansible
verifier:
name: testinfra
```
4 changes: 0 additions & 4 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,3 @@ Molecule handles role testing by invoking configurable verifiers.
### Ansible

::: molecule.verifier.ansible.Ansible

### Testinfra

::: molecule.verifier.testinfra.Testinfra
9 changes: 0 additions & 9 deletions docs/examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -359,15 +359,6 @@ shared-tests

Tests and playbooks can be shared across scenarios.

In this example the `tests` directory lives in a shared
location and `molecule.yml` points to the shared tests.

```yaml
verifier:
name: testinfra
directory: ../resources/tests/
```

In this second example the actions `create`,
`destroy`, `converge` and `prepare`
are loaded from a shared directory.
Expand Down
3 changes: 1 addition & 2 deletions docs/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ INSTALL.rst molecule.yml converge.yml verify.yml
- `verify.yml` is the Ansible file used for testing as Ansible is the
default [verifier](configuration.md#verifier). This allows you to
write specific tests against the state of the container after your
role has finished executing. Other verifier tools are available
Note that [testinfra](https://testinfra.readthedocs.io/en/latest/) was the default verifier prior to molecule version 3.
role has finished executing.

!!! note

Expand Down
4 changes: 3 additions & 1 deletion docs/next.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ reduce the amount of magic and just rely on ansible core features.
- `roles-path` and `collections-paths` are no longer configurable for
dependencies. Users are expected to make use of `ansible.cfg` file to
alter them when needed.
- testinfra verifier driver was removed but current users should be able to
keep calling their testinfra tests by using `command` or `shell` ansible
modules from within `verify.yml` playbook.

# Planned changes

- Removal of provisioning drivers support and documenting, with examples, how to easily migrate to a self-provisioning approach.
- Removal of testinfra verifier driver and documenting how to call testinfra from inside the converge playbook to keep using the tool.
- Refactoring how dependencies are installed
- Bringing ephemeral directory under scenario folder instead of the current
inconvenient location under `~/.cache/molecule/...`
Expand Down
2 changes: 0 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ molecule = "molecule.__main__:main"
default = "molecule.driver.delegated:Delegated"

[project.entry-points."molecule.verifier.next"]
testinfra = "molecule.verifier.testinfra:Testinfra"
ansible = "molecule.verifier.ansible:Ansible"

[tool.coverage.run]
Expand Down Expand Up @@ -97,7 +96,6 @@ module = [
"click_help_colors", # https://github.com/click-contrib/click-help-colors/issues/20
"pexpect", # https://github.com/pexpect/pexpect/issues/759
"pluggy", # https://github.com/pytest-dev/pluggy/pull/414
"testinfra.*", # https://github.com/pytest-dev/pytest-testinfra/issues/619
"pytest_mock",
]
ignore_missing_imports = true
Expand Down
11 changes: 0 additions & 11 deletions src/molecule/driver/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,17 +58,6 @@ def name(self, value): # pragma: no cover
:returns: None
"""

@property
def testinfra_options(self):
"""Testinfra specific options and returns a dict.
:returns: dict
"""
return {
"connection": "ansible",
"ansible-inventory": self._config.provisioner.inventory_directory,
}

@property
@abstractmethod
def login_cmd_template(self): # pragma: no cover
Expand Down
2 changes: 0 additions & 2 deletions src/molecule/driver/delegated.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +227,6 @@ def ansible_connection_options(self, instance_name):
)
if d.get("password", None):
conn_dict["ansible_password"] = d.get("password")
# Based on testinfra documentation, ansible password must be passed via ansible_ssh_pass
# issue to fix this can be found https://github.com/pytest-dev/pytest-testinfra/issues/580
conn_dict["ansible_ssh_pass"] = d.get("password")

return conn_dict
Expand Down
16 changes: 0 additions & 16 deletions src/molecule/interpolation.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,6 @@ def __init__(self, string: str, place: Exception) -> None:
class Interpolator:
"""Configuration options may contain environment variables.
For example, suppose the shell contains ``VERIFIER_NAME=testinfra`` and
the following molecule.yml is supplied.
```yaml
verifier:
- name: ${VERIFIER_NAME}
```
Molecule will substitute ``$VERIFIER_NAME`` with the value of the
``VERIFIER_NAME`` environment variable.
!!! warning
If an environment variable is not set, Molecule substitutes with an
empty string.
Both ``$VARIABLE`` and ``${VARIABLE}`` syntax are supported. Extended
shell-style features, such as ``${VARIABLE-default}`` and
``${VARIABLE:-default}`` are also supported. Even the default as another
Expand Down
Empty file.
67 changes: 0 additions & 67 deletions src/molecule/test/a_unit/cookiecutter/test_molecule.py

This file was deleted.

7 changes: 0 additions & 7 deletions src/molecule/test/a_unit/driver/test_delegated.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,6 @@ def test_config_private_member(_instance):
assert isinstance(_instance._config, config.Config)


def test_testinfra_options_property(_instance):
assert {
"connection": "ansible",
"ansible-inventory": _instance._config.provisioner.inventory_directory,
} == _instance.testinfra_options


def test_name_property(_instance):
assert _instance.name == "default"

Expand Down
21 changes: 0 additions & 21 deletions src/molecule/test/a_unit/model/v2/test_verifier_section.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,6 @@
from molecule.model import schema_v3


@pytest.fixture()
def _model_verifier_section_data():
return {
"verifier": {
"name": "testinfra",
"enabled": True,
"directory": "foo",
"options": {"foo": "bar"},
"env": {"FOO": "foo", "FOO_BAR": "foo_bar"},
"additional_files_or_dirs": ["foo"],
},
}


@pytest.mark.parametrize("_config", ["_model_verifier_section_data"], indirect=True)
def test_verifier(_config):
assert not schema_v3.validate(_config)

Expand All @@ -62,11 +47,6 @@ def test_verifier_has_errors(_config):
assert x == schema_v3.validate(_config)


@pytest.fixture()
def _model_verifier_allows_testinfra_section_data():
return {"verifier": {"name": "testinfra"}}


@pytest.fixture()
def _model_verifier_allows_ansible_section_data():
return {"verifier": {"name": "ansible"}}
Expand All @@ -75,7 +55,6 @@ def _model_verifier_allows_ansible_section_data():
@pytest.mark.parametrize(
"_config",
[
("_model_verifier_allows_testinfra_section_data"),
("_model_verifier_allows_ansible_section_data"),
],
indirect=True,
Expand Down
2 changes: 1 addition & 1 deletion src/molecule/test/a_unit/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,6 @@ def test_api_drivers():


def test_api_verifiers():
x = ["testinfra", "ansible"]
x = ["ansible"]

assert all(elem in api.verifiers() for elem in x)

0 comments on commit 10714ef

Please sign in to comment.