From c05bb59350b291042f523aac32f086814f401646 Mon Sep 17 00:00:00 2001 From: Sorin Sbarnea Date: Tue, 1 Sep 2020 14:05:57 +0100 Subject: [PATCH] Removed support for gilt As gilt project is not actively maintained, we remove support for installing dependencies with it. --- docs/configuration.rst | 6 - molecule/config.py | 4 +- molecule/dependency/gilt.py | 118 ------------ molecule/model/schema_v3.py | 2 +- molecule/test/functional/test_command.py | 18 -- .../dependency/molecule/gilt/converge.yml | 6 - .../dependency/molecule/gilt/gilt.yml | 4 - .../dependency/molecule/gilt/molecule.yml | 16 -- .../plugins/molecule/default/molecule.yml | 2 +- molecule/test/unit/dependency/test_gilt.py | 179 ------------------ .../unit/model/v2/test_dependency_section.py | 6 - molecule/test/unit/test_config.py | 14 +- setup.cfg | 1 - 13 files changed, 4 insertions(+), 372 deletions(-) delete mode 100644 molecule/dependency/gilt.py delete mode 100644 molecule/test/scenarios/dependency/molecule/gilt/converge.yml delete mode 100644 molecule/test/scenarios/dependency/molecule/gilt/gilt.yml delete mode 100644 molecule/test/scenarios/dependency/molecule/gilt/molecule.yml delete mode 100644 molecule/test/unit/dependency/test_gilt.py diff --git a/docs/configuration.rst b/docs/configuration.rst index 897d19a9f4..4504b8e080 100644 --- a/docs/configuration.rst +++ b/docs/configuration.rst @@ -26,12 +26,6 @@ Ansible Galaxy .. autoclass:: molecule.dependency.ansible_galaxy.AnsibleGalaxy() :undoc-members: -Gilt -^^^^ - -.. autoclass:: molecule.dependency.gilt.Gilt() - :undoc-members: - Shell ^^^^^ diff --git a/molecule/config.py b/molecule/config.py index 39e211b455..52f32c1cb0 100644 --- a/molecule/config.py +++ b/molecule/config.py @@ -25,7 +25,7 @@ import pkg_resources from molecule import api, interpolation, logger, platforms, scenario, state, util -from molecule.dependency import ansible_galaxy, gilt, shell +from molecule.dependency import ansible_galaxy, shell from molecule.model import schema_v3 from molecule.provisioner import ansible from molecule.util import boolean @@ -160,8 +160,6 @@ def dependency(self): dependency_name = self.config["dependency"]["name"] if dependency_name == "galaxy": return ansible_galaxy.AnsibleGalaxy(self) - elif dependency_name == "gilt": - return gilt.Gilt(self) elif dependency_name == "shell": return shell.Shell(self) diff --git a/molecule/dependency/gilt.py b/molecule/dependency/gilt.py deleted file mode 100644 index 92ebb4ccd6..0000000000 --- a/molecule/dependency/gilt.py +++ /dev/null @@ -1,118 +0,0 @@ -# Copyright (c) 2015-2018 Cisco Systems, Inc. -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to -# deal in the Software without restriction, including without limitation the -# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or -# sell copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in -# all copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -# DEALINGS IN THE SOFTWARE. -"""Gilt Dependency Module.""" - -import os - -import sh - -from molecule import logger, util -from molecule.dependency import base - -LOG = logger.get_logger(__name__) - - -class Gilt(base.Base): - """ - `Gilt`_ is an alternate dependency manager. - - Additional options can be passed to ``gilt overlay`` through the options - dict. Any option set in this section will override the defaults. - - .. code-block:: yaml - - dependency: - name: gilt - options: - debug: True - - - The dependency manager can be disabled by setting ``enabled`` to False. - - .. code-block:: yaml - - dependency: - name: gilt - enabled: False - - Environment variables can be passed to the dependency. - - .. code-block:: yaml - - dependency: - name: gilt - env: - FOO: bar - - .. _`Gilt`: https://gilt.readthedocs.io - """ - - def __init__(self, config): - """Construct Gilt.""" - super(Gilt, self).__init__(config) - self._sh_command = None - - self.command = "gilt" - - @property - def default_options(self): - config = os.path.join(self._config.scenario.directory, "gilt.yml") - d = {"config": config} - if self._config.debug: - d["debug"] = True - - return d - - @property - def default_env(self): - return util.merge_dicts(os.environ, self._config.env) - - def bake(self): - """ - Bake a ``gilt`` command so it's ready to execute and returns None. - - :return: None - """ - self._sh_command = getattr(sh, self.command) - self._sh_command = self._sh_command.bake( - self.options, "overlay", _env=self.env, _out=LOG.out, _err=LOG.error - ) - - def execute(self): - if not self.enabled: - msg = "Skipping, dependency is disabled." - LOG.warning(msg) - return - - if not self._has_requirements_file(): - msg = "Skipping, missing the requirements file." - LOG.warning(msg) - return - - if self._sh_command is None: - self.bake() - - self.execute_with_retries() - - def _config_file(self): - return self.options.get("config") - - def _has_requirements_file(self): - return os.path.isfile(self._config_file()) diff --git a/molecule/model/schema_v3.py b/molecule/model/schema_v3.py index 1a5362ee02..2039d53ff4 100644 --- a/molecule/model/schema_v3.py +++ b/molecule/model/schema_v3.py @@ -45,7 +45,7 @@ def pre_validate_base_schema(env, keep_string): "name": { "type": "string", "molecule_env_var": True, - "allowed": ["galaxy", "gilt", "shell"], + "allowed": ["galaxy", "shell"], } }, }, diff --git a/molecule/test/functional/test_command.py b/molecule/test/functional/test_command.py index 42fc363af6..987703e484 100644 --- a/molecule/test/functional/test_command.py +++ b/molecule/test/functional/test_command.py @@ -126,24 +126,6 @@ def test_command_dependency_ansible_galaxy( # assert os.path.isdir(dependency_role) -@pytest.mark.parametrize( - "scenario_to_test, driver_name, scenario_name", - [("dependency", "delegated", "gilt")], - indirect=["scenario_to_test", "driver_name", "scenario_name"], -) -def test_command_dependency_gilt( - request, scenario_to_test, with_scenario, scenario_name -): - options = {"scenario_name": scenario_name} - cmd = sh.molecule.bake("dependency", **options) - pytest.helpers.run_command(cmd) - - dependency_role = os.path.join( - ephemeral_directory("molecule"), "dependency", "gilt", "roles", "timezone" - ) - assert os.path.isdir(dependency_role) - - @pytest.mark.parametrize( "scenario_to_test, driver_name, scenario_name", [("dependency", "delegated", "shell")], diff --git a/molecule/test/scenarios/dependency/molecule/gilt/converge.yml b/molecule/test/scenarios/dependency/molecule/gilt/converge.yml deleted file mode 100644 index 01223e7e8b..0000000000 --- a/molecule/test/scenarios/dependency/molecule/gilt/converge.yml +++ /dev/null @@ -1,6 +0,0 @@ ---- -- name: Converge - hosts: all - gather_facts: false - roles: - - molecule diff --git a/molecule/test/scenarios/dependency/molecule/gilt/gilt.yml b/molecule/test/scenarios/dependency/molecule/gilt/gilt.yml deleted file mode 100644 index 00b837ace6..0000000000 --- a/molecule/test/scenarios/dependency/molecule/gilt/gilt.yml +++ /dev/null @@ -1,4 +0,0 @@ ---- -- git: https://github.com/yatesr/ansible-timezone.git - version: master - dst: $MOLECULE_EPHEMERAL_DIRECTORY/roles/timezone/ diff --git a/molecule/test/scenarios/dependency/molecule/gilt/molecule.yml b/molecule/test/scenarios/dependency/molecule/gilt/molecule.yml deleted file mode 100644 index 6286503b41..0000000000 --- a/molecule/test/scenarios/dependency/molecule/gilt/molecule.yml +++ /dev/null @@ -1,16 +0,0 @@ ---- -dependency: - name: gilt -driver: - name: delegated -platforms: - - name: instance - image: ${TEST_BASE_IMAGE} -provisioner: - name: ansible - env: - ANSIBLE_ROLES_PATH: ../../../../../resources/roles/ -scenario: - name: gilt -verifier: - name: ansible diff --git a/molecule/test/scenarios/plugins/molecule/default/molecule.yml b/molecule/test/scenarios/plugins/molecule/default/molecule.yml index ca65cea0b8..9f9101cc2a 100644 --- a/molecule/test/scenarios/plugins/molecule/default/molecule.yml +++ b/molecule/test/scenarios/plugins/molecule/default/molecule.yml @@ -1,6 +1,6 @@ --- dependency: - name: gilt + name: galaxy driver: name: delegated platforms: diff --git a/molecule/test/unit/dependency/test_gilt.py b/molecule/test/unit/dependency/test_gilt.py deleted file mode 100644 index df465582f3..0000000000 --- a/molecule/test/unit/dependency/test_gilt.py +++ /dev/null @@ -1,179 +0,0 @@ -# Copyright (c) 2015-2018 Cisco Systems, Inc. -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to -# deal in the Software without restriction, including without limitation the -# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or -# sell copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in -# all copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -# DEALINGS IN THE SOFTWARE. - -import os - -import pytest -import sh - -from molecule import config -from molecule.dependency import gilt - - -@pytest.fixture -def _patched_gilt_has_requirements_file(mocker): - m = mocker.patch("molecule.dependency.gilt.Gilt._has_requirements_file") - m.return_value = True - - return m - - -@pytest.fixture -def _dependency_section_data(): - return { - "dependency": {"name": "gilt", "options": {"foo": "bar"}, "env": {"FOO": "bar"}} - } - - -# NOTE(retr0h): The use of the `patched_config_validate` fixture, disables -# config.Config._validate from executing. Thus preventing odd side-effects -# throughout patched.assert_called unit tests. -@pytest.fixture -def _instance(_dependency_section_data, patched_config_validate, config_instance): - return gilt.Gilt(config_instance) - - -@pytest.fixture -def gilt_config(_instance): - return os.path.join(_instance._config.scenario.directory, "gilt.yml") - - -def test_config_private_member(_instance): - assert isinstance(_instance._config, config.Config) - - -def test_default_options_property(gilt_config, _instance): - x = {"config": gilt_config} - - assert x == _instance.default_options - - -def test_default_env_property(_instance): - assert "MOLECULE_FILE" in _instance.default_env - assert "MOLECULE_INVENTORY_FILE" in _instance.default_env - assert "MOLECULE_SCENARIO_DIRECTORY" in _instance.default_env - assert "MOLECULE_INSTANCE_CONFIG" in _instance.default_env - - -@pytest.mark.parametrize("config_instance", ["_dependency_section_data"], indirect=True) -def test_name_property(_instance): - assert "gilt" == _instance.name - - -def test_enabled_property(_instance): - assert _instance.enabled - - -@pytest.mark.parametrize("config_instance", ["_dependency_section_data"], indirect=True) -def test_options_property(gilt_config, _instance): - x = {"config": gilt_config, "foo": "bar"} - - assert x == _instance.options - - -@pytest.mark.parametrize("config_instance", ["_dependency_section_data"], indirect=True) -def test_options_property_handles_cli_args(gilt_config, _instance): - _instance._config.args = {"debug": True} - x = {"config": gilt_config, "foo": "bar", "debug": True} - - assert x == _instance.options - - -@pytest.mark.parametrize("config_instance", ["_dependency_section_data"], indirect=True) -def test_env_property(_instance): - assert "bar" == _instance.env["FOO"] - - -@pytest.mark.parametrize("config_instance", ["_dependency_section_data"], indirect=True) -def test_bake(gilt_config, _instance): - _instance.bake() - x = [str(sh.gilt), "--foo=bar", "--config={}".format(gilt_config), "overlay"] - result = str(_instance._sh_command).split() - - assert sorted(x) == sorted(result) - - -def test_execute( - patched_run_command, - _patched_gilt_has_requirements_file, - patched_logger_success, - _instance, -): - _instance._sh_command = "patched-command" - _instance.execute() - - patched_run_command.assert_called_once_with("patched-command", debug=False) - - msg = "Dependency completed successfully." - patched_logger_success.assert_called_once_with(msg) - - -def test_execute_does_not_execute_when_disabled( - patched_run_command, patched_logger_warning, _instance -): - _instance._config.config["dependency"]["enabled"] = False - _instance.execute() - - assert not patched_run_command.called - - msg = "Skipping, dependency is disabled." - patched_logger_warning.assert_called_once_with(msg) - - -def test_execute_does_not_execute_when_no_requirements_file( - patched_run_command, - _patched_gilt_has_requirements_file, - patched_logger_warning, - _instance, -): - _patched_gilt_has_requirements_file.return_value = False - _instance.execute() - - assert not patched_run_command.called - - msg = "Skipping, missing the requirements file." - patched_logger_warning.assert_called_once_with(msg) - - -def test_execute_bakes( - patched_run_command, gilt_config, _patched_gilt_has_requirements_file, _instance -): - _instance.execute() - assert _instance._sh_command is not None - - assert 1 == patched_run_command.call_count - - -def test_executes_catches_and_exits_return_code( - patched_run_command, _patched_gilt_has_requirements_file, _instance -): - patched_run_command.side_effect = sh.ErrorReturnCode_1(sh.gilt, b"", b"") - with pytest.raises(SystemExit) as e: - _instance.execute() - - assert 1 == e.value.code - - -def test_config_file(_instance, gilt_config): - assert gilt_config == _instance._config_file() - - -def test_has_requirements_file(_instance): - assert not _instance._has_requirements_file() diff --git a/molecule/test/unit/model/v2/test_dependency_section.py b/molecule/test/unit/model/v2/test_dependency_section.py index bdb269cb4c..d4b541d89d 100644 --- a/molecule/test/unit/model/v2/test_dependency_section.py +++ b/molecule/test/unit/model/v2/test_dependency_section.py @@ -81,11 +81,6 @@ def _model_dependency_allows_galaxy_section_data(): return {"dependency": {"name": "galaxy"}} -@pytest.fixture -def _model_dependency_allows_gilt_section_data(): - return {"dependency": {"name": "gilt"}} - - @pytest.fixture def _model_dependency_allows_shell_section_data(): return {"dependency": {"name": "shell"}} @@ -95,7 +90,6 @@ def _model_dependency_allows_shell_section_data(): "_config", [ ("_model_dependency_allows_galaxy_section_data"), - ("_model_dependency_allows_gilt_section_data"), ("_model_dependency_allows_shell_section_data"), ], indirect=True, diff --git a/molecule/test/unit/test_config.py b/molecule/test/unit/test_config.py index 90c4835217..ee91ca8a8e 100644 --- a/molecule/test/unit/test_config.py +++ b/molecule/test/unit/test_config.py @@ -23,7 +23,7 @@ import pytest from molecule import config, platforms, scenario, state, util -from molecule.dependency import ansible_galaxy, gilt, shell +from molecule.dependency import ansible_galaxy, shell from molecule.provisioner import ansible from molecule.verifier.ansible import Ansible as AnsibleVerifier @@ -85,18 +85,6 @@ def test_dependency_property(config_instance): assert isinstance(config_instance.dependency, ansible_galaxy.AnsibleGalaxy) -@pytest.fixture -def _config_dependency_gilt_section_data(): - return {"dependency": {"name": "gilt"}} - - -@pytest.mark.parametrize( - "config_instance", ["_config_dependency_gilt_section_data"], indirect=True -) -def test_dependency_property_is_gilt(config_instance): - assert isinstance(config_instance.dependency, gilt.Gilt) - - @pytest.fixture def _config_dependency_shell_section_data(): return {"dependency": {"name": "shell", "command": "bin/command"}} diff --git a/setup.cfg b/setup.cfg index 11bb9f0cb7..f3e8e9294c 100644 --- a/setup.cfg +++ b/setup.cfg @@ -69,7 +69,6 @@ install_requires = click-help-colors >= 0.6 colorama >= 0.3.9 cookiecutter >= 1.6.0, != 1.7.1 - python-gilt >= 1.2.1, < 2 Jinja2 >= 2.10.1 paramiko >= 2.5.0, < 3 pexpect >= 4.6.0, < 5