Skip to content

Commit

Permalink
Remove ability to configure collections-path and roles-path for depen…
Browse files Browse the repository at this point in the history
…dency (#3956)
  • Loading branch information
ssbarnea authored Jul 4, 2023
1 parent e2acbf1 commit 5012292
Show file tree
Hide file tree
Showing 10 changed files with 24 additions and 157 deletions.
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: 452
PYTEST_REQPASS: 450
steps:
- uses: actions/checkout@v3
with:
Expand Down
9 changes: 9 additions & 0 deletions docs/next.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Molecule Next

Molecule "next" is the future major version of molecule, one that is currently
available from the main branch. This page documents all notable changes
implemented so far.

- `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.
1 change: 1 addition & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ nav:
- Using:
- getting-started.md
- usage.md
- next.md
- configuration.md
- ci.md
- examples.md
Expand Down
7 changes: 0 additions & 7 deletions src/molecule/dependency/ansible_galaxy/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,6 @@ def __init__(self, config) -> None:

self.command = "ansible-galaxy"

@property
@abc.abstractmethod
def install_path(self): # cover
pass

@property
@abc.abstractmethod
def requirements_file(self): # cover
Expand Down Expand Up @@ -133,8 +128,6 @@ def _setup(self):
:return: None
"""
if not os.path.isdir(self.install_path):
os.makedirs(self.install_path, exist_ok=True)

def _has_requirements_file(self):
return os.path.isfile(self.requirements_file)
16 changes: 2 additions & 14 deletions src/molecule/dependency/ansible_galaxy/collections.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
class Collections(AnsibleGalaxyBase):
"""Collection-specific Ansible Galaxy dependency handling."""

FILTER_OPTS = ("role-file", "roles-path") # type: ignore
FILTER_OPTS = ("role-file",) # type: ignore
COMMANDS = ("collection", "install")

@property
Expand All @@ -24,26 +24,14 @@ def default_options(self):
self._config.scenario.directory,
"collections.yml",
),
"collections-path": os.path.join(
self._config.scenario.ephemeral_directory,
"collections",
),
},
)

return specific

@property
def default_env(self):
general = super().default_env
return util.merge_dicts(
general,
{self._config.ansible_collections_path: self.install_path},
)

@property
def install_path(self):
return self.options["collections-path"]
return super().default_env

@property
def requirements_file(self):
Expand Down
10 changes: 1 addition & 9 deletions src/molecule/dependency/ansible_galaxy/roles.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
class Roles(AnsibleGalaxyBase):
"""Role-specific Ansible Galaxy dependency handling."""

FILTER_OPTS = ("requirements-file", "collections-path") # type: ignore
FILTER_OPTS = ("requirements-file",) # type: ignore
COMMANDS = ("install",)

@property
Expand All @@ -24,18 +24,10 @@ def default_options(self):
self._config.scenario.directory,
"requirements.yml",
),
"roles-path": os.path.join(
self._config.scenario.ephemeral_directory,
"roles",
),
},
)
return specific

@property
def install_path(self):
return os.path.join(self._config.scenario.directory, self.options["roles-path"])

@property
def requirements_file(self):
return self.options["role-file"]
9 changes: 0 additions & 9 deletions src/molecule/provisioner/ansible.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,6 @@ class Ansible(base.Base):
name: ansible
config_options:
defaults:
roles_path: /path/to/roles_path
library: /path/to/library
filter_plugins: /path/to/filter_plugins
privilege_escalation: {}
Expand Down Expand Up @@ -593,16 +592,9 @@ def env(self):
# ensure that all keys and values are strings
env = {str(k): str(v) for k, v in env.items()}

roles_path = default_env["ANSIBLE_ROLES_PATH"]
library_path = default_env["ANSIBLE_LIBRARY"]
filter_plugins_path = default_env["ANSIBLE_FILTER_PLUGINS"]

try:
path = self._absolute_path_for(env, "ANSIBLE_ROLES_PATH")
roles_path = f"{roles_path}:{path}"
except KeyError:
pass

try:
path = self._absolute_path_for(env, "ANSIBLE_LIBRARY")
library_path = f"{library_path}:{path}"
Expand All @@ -615,7 +607,6 @@ def env(self):
except KeyError:
pass

env["ANSIBLE_ROLES_PATH"] = roles_path
env["ANSIBLE_LIBRARY"] = library_path
env["ANSIBLE_FILTER_PLUGINS"] = filter_plugins_path

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,17 +65,12 @@ def role_file(_instance):
return os.path.join(_instance._config.scenario.directory, "collections.yml")


@pytest.fixture()
def roles_path(_instance):
return os.path.join(_instance._config.scenario.ephemeral_directory, "collections")


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


def test_default_options_property(_instance, role_file, roles_path):
x = {"requirements-file": role_file, "collections-path": roles_path, "force": True}
def test_default_options_property(_instance, role_file):
x = {"requirements-file": role_file, "force": True}

assert x == _instance.default_options

Expand All @@ -98,11 +93,10 @@ def test_enabled_property(_instance):


@pytest.mark.parametrize("config_instance", ["_dependency_section_data"], indirect=True)
def test_options_property(_instance, role_file, roles_path):
def test_options_property(_instance, role_file):
x = {
"force": True,
"requirements-file": role_file,
"collections-path": roles_path,
"foo": "bar",
"v": True,
}
Expand All @@ -111,12 +105,11 @@ def test_options_property(_instance, role_file, roles_path):


@pytest.mark.parametrize("config_instance", ["_dependency_section_data"], indirect=True)
def test_options_property_handles_cli_args(role_file, roles_path, _instance):
def test_options_property_handles_cli_args(role_file, _instance):
_instance._config.args = {"debug": True}
x = {
"force": True,
"requirements-file": role_file,
"collections-path": roles_path,
"foo": "bar",
"vvv": True,
}
Expand All @@ -130,14 +123,12 @@ def test_env_property(_instance):


@pytest.mark.parametrize("config_instance", ["_dependency_section_data"], indirect=True)
def test_collections_bake(_instance, role_file, roles_path):
def test_collections_bake(_instance, role_file):
_instance.bake()
args = [
"ansible-galaxy",
"collection",
"install",
"--collections-path",
roles_path,
"--foo",
"bar",
"--force",
Expand All @@ -157,12 +148,6 @@ def test_execute(
_instance._sh_command = "patched-command"
_instance.execute()

role_directory = os.path.join(
_instance._config.scenario.directory,
_instance.options["collections-path"],
)
assert os.path.isdir(role_directory)

patched_run_command.assert_called_once_with(
"patched-command",
debug=False,
Expand Down Expand Up @@ -207,7 +192,6 @@ def test_execute_bakes(
_instance,
role_file,
_patched_ansible_galaxy_has_requirements_file,
roles_path,
):
_instance.execute()
assert _instance._sh_command is not None
Expand All @@ -228,16 +212,8 @@ def test_collections_executes_catches_and_exits_return_code(


def test_setup(_instance):
role_directory = os.path.join(
_instance._config.scenario.directory,
_instance.options["collections-path"],
)
assert not os.path.isdir(role_directory)

_instance._setup()

assert os.path.isdir(role_directory)


def test_role_file(role_file, _instance):
assert role_file == _instance.requirements_file
Expand Down
38 changes: 5 additions & 33 deletions src/molecule/test/a_unit/dependency/ansible_galaxy/test_roles.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,17 +64,12 @@ def role_file(_instance):
return os.path.join(_instance._config.scenario.directory, "requirements.yml")


@pytest.fixture()
def roles_path(_instance):
return os.path.join(_instance._config.scenario.ephemeral_directory, "roles")


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


def test_default_options_property(_instance, role_file, roles_path):
x = {"role-file": role_file, "roles-path": roles_path, "force": True}
def test_default_options_property(_instance, role_file):
x = {"role-file": role_file, "force": True}

assert x == _instance.default_options

Expand All @@ -97,11 +92,10 @@ def test_enabled_property(_instance):


@pytest.mark.parametrize("config_instance", ["_dependency_section_data"], indirect=True)
def test_options_property(_instance, role_file, roles_path):
def test_options_property(_instance, role_file):
x = {
"force": True,
"role-file": role_file,
"roles-path": roles_path,
"foo": "bar",
"v": True,
}
Expand All @@ -110,12 +104,11 @@ def test_options_property(_instance, role_file, roles_path):


@pytest.mark.parametrize("config_instance", ["_dependency_section_data"], indirect=True)
def test_options_property_handles_cli_args(role_file, roles_path, _instance):
def test_options_property_handles_cli_args(role_file, _instance):
_instance._config.args = {"debug": True}
x = {
"force": True,
"role-file": role_file,
"roles-path": roles_path,
"foo": "bar",
"vvv": True,
}
Expand All @@ -129,7 +122,7 @@ def test_env_property(_instance):


@pytest.mark.parametrize("config_instance", ["_dependency_section_data"], indirect=True)
def test_galaxy_bake(_instance, role_file, roles_path):
def test_galaxy_bake(_instance, role_file):
_instance.bake()
args = [
"ansible-galaxy",
Expand All @@ -139,8 +132,6 @@ def test_galaxy_bake(_instance, role_file, roles_path):
"--force",
"--role-file",
role_file,
"--roles-path",
roles_path,
"-v",
]
assert _instance._sh_command.cmd == args
Expand All @@ -155,12 +146,6 @@ def test_execute(
_instance._sh_command = "patched-command"
_instance.execute()

role_directory = os.path.join(
_instance._config.scenario.directory,
_instance.options["roles-path"],
)
assert os.path.isdir(role_directory)

patched_run_command.assert_called_once_with(
"patched-command",
debug=False,
Expand Down Expand Up @@ -205,7 +190,6 @@ def test_execute_bakes(
_instance,
role_file,
_patched_ansible_galaxy_has_requirements_file,
roles_path,
):
_instance.execute()
assert _instance._sh_command is not None
Expand All @@ -225,18 +209,6 @@ def test_galaxy_executes_catches_and_exits_return_code(
assert e.value.code == 1


def test_setup(_instance):
role_directory = os.path.join(
_instance._config.scenario.directory,
_instance.options["roles-path"],
)
assert not os.path.isdir(role_directory)

_instance._setup()

assert os.path.isdir(role_directory)


def test_role_file(role_file, _instance):
assert role_file == _instance.requirements_file

Expand Down
Loading

0 comments on commit 5012292

Please sign in to comment.