Skip to content

Commit

Permalink
Switch from inventory file to directory for testinfra call (#2962)
Browse files Browse the repository at this point in the history
* Switch testinfra inventory from file to dir
(should respect linked hosts and allow to use `hostvars[linked_host]`).

* Fix few tests.
  • Loading branch information
amarao authored Nov 15, 2020
1 parent d65ea4f commit 94624bc
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 14 deletions.
2 changes: 1 addition & 1 deletion lib/molecule/driver/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def testinfra_options(self):
"""
return {
"connection": "ansible",
"ansible-inventory": self._config.provisioner.inventory_file,
"ansible-inventory": self._config.provisioner.inventory_directory,
}

@abc.abstractproperty
Expand Down
2 changes: 1 addition & 1 deletion lib/molecule/test/unit/driver/test_delegated.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def test_config_private_member(_instance):
def test_testinfra_options_property(_instance):
assert {
"connection": "ansible",
"ansible-inventory": _instance._config.provisioner.inventory_file,
"ansible-inventory": _instance._config.provisioner.inventory_directory,
} == _instance.testinfra_options


Expand Down
29 changes: 17 additions & 12 deletions lib/molecule/test/unit/verifier/test_testinfra.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,25 +59,30 @@ def inventory_file(_instance):
return _instance._config.provisioner.inventory_file


@pytest.fixture
def inventory_directory(_instance):
return _instance._config.provisioner.inventory_directory


def test_config_private_member(_instance):
assert isinstance(_instance._config, config.Config)


def test_default_options_property(inventory_file, _instance):
def test_default_options_property(inventory_directory, _instance):
x = {
"connection": "ansible",
"ansible-inventory": inventory_file,
"ansible-inventory": inventory_directory,
"p": "no:cacheprovider",
}

assert x == _instance.default_options


def test_default_options_property_updates_debug(inventory_file, _instance):
def test_default_options_property_updates_debug(inventory_directory, _instance):
_instance._config.args = {"debug": True}
x = {
"connection": "ansible",
"ansible-inventory": inventory_file,
"ansible-inventory": inventory_directory,
"debug": True,
"vvv": True,
"p": "no:cacheprovider",
Expand All @@ -87,12 +92,12 @@ def test_default_options_property_updates_debug(inventory_file, _instance):


def test_default_options_property_updates_sudo(
inventory_file, _instance, _patched_testinfra_get_tests
inventory_directory, _instance, _patched_testinfra_get_tests
):
_instance._config.args = {"sudo": True}
x = {
"connection": "ansible",
"ansible-inventory": inventory_file,
"ansible-inventory": inventory_directory,
"sudo": True,
"p": "no:cacheprovider",
}
Expand Down Expand Up @@ -162,10 +167,10 @@ def test_directory_property_overridden(_instance):


@pytest.mark.parametrize("config_instance", ["_verifier_section_data"], indirect=True)
def test_options_property(inventory_file, _instance):
def test_options_property(inventory_directory, _instance):
x = {
"connection": "ansible",
"ansible-inventory": inventory_file,
"ansible-inventory": inventory_directory,
"foo": "bar",
"v": True,
"verbose": True,
Expand All @@ -176,11 +181,11 @@ def test_options_property(inventory_file, _instance):


@pytest.mark.parametrize("config_instance", ["_verifier_section_data"], indirect=True)
def test_options_property_handles_cli_args(inventory_file, _instance):
def test_options_property_handles_cli_args(inventory_directory, _instance):
_instance._config.args = {"debug": True}
x = {
"connection": "ansible",
"ansible-inventory": inventory_file,
"ansible-inventory": inventory_directory,
"foo": "bar",
"debug": True,
"vvv": True,
Expand All @@ -192,7 +197,7 @@ def test_options_property_handles_cli_args(inventory_file, _instance):


@pytest.mark.parametrize("config_instance", ["_verifier_section_data"], indirect=True)
def test_bake(_patched_testinfra_get_tests, inventory_file, _instance):
def test_bake(_patched_testinfra_get_tests, inventory_directory, _instance):
tests_directory = _instance._config.verifier.directory
file1_file = os.path.join(tests_directory, "file1.py")

Expand All @@ -203,7 +208,7 @@ def test_bake(_patched_testinfra_get_tests, inventory_file, _instance):
args = [
"pytest",
"--ansible-inventory",
inventory_file,
inventory_directory,
"--connection",
"ansible",
"--foo",
Expand Down

0 comments on commit 94624bc

Please sign in to comment.