From 520f1582b590f52bbb9452db573ba07109c955a2 Mon Sep 17 00:00:00 2001 From: George Shuklin Date: Tue, 10 Nov 2020 15:31:23 +0200 Subject: [PATCH 1/2] Switch testinfra inventory from file to dir (should respect linked hosts and allow to use `hostvars[linked_host]`). --- lib/molecule/driver/base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/molecule/driver/base.py b/lib/molecule/driver/base.py index 5342c5963b..ff53e61722 100644 --- a/lib/molecule/driver/base.py +++ b/lib/molecule/driver/base.py @@ -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 From 376df42d3fb8e55e58794e242d9264e1cdf10b62 Mon Sep 17 00:00:00 2001 From: George Shuklin Date: Tue, 10 Nov 2020 16:00:59 +0200 Subject: [PATCH 2/2] Fix few tests. --- .../test/unit/driver/test_delegated.py | 2 +- .../test/unit/verifier/test_testinfra.py | 29 +++++++++++-------- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/lib/molecule/test/unit/driver/test_delegated.py b/lib/molecule/test/unit/driver/test_delegated.py index 8c52c47bb4..510fc9a720 100644 --- a/lib/molecule/test/unit/driver/test_delegated.py +++ b/lib/molecule/test/unit/driver/test_delegated.py @@ -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 diff --git a/lib/molecule/test/unit/verifier/test_testinfra.py b/lib/molecule/test/unit/verifier/test_testinfra.py index 0f479d69d6..99b3f2fb6d 100644 --- a/lib/molecule/test/unit/verifier/test_testinfra.py +++ b/lib/molecule/test/unit/verifier/test_testinfra.py @@ -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", @@ -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", } @@ -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, @@ -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, @@ -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") @@ -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",