Skip to content

Commit

Permalink
Fix prepare_environment call for role installs (#3409)
Browse files Browse the repository at this point in the history
* Fix prepare_environment call for role installs

* Add test for prepare_environment call

Co-authored-by: Macklan Weinstein <[email protected]>
Co-authored-by: Sorin Sbarnea <[email protected]>
  • Loading branch information
3 people authored Feb 9, 2022
1 parent 990a6bf commit 4912d69
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/molecule/command/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def execute_cmdline_scenarios(scenario_name, args, command_args, ansible_args=()

if scenario.config.config["prerun"]:
LOG.info("Performing prerun...")
scenario.config.runtime.prepare_environment()
scenario.config.runtime.prepare_environment(install_local=True)

if command_args.get("subcommand") == "reset":
LOG.info("Removing %s", scenario.ephemeral_directory)
Expand Down
10 changes: 8 additions & 2 deletions src/molecule/test/functional/test_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.

import os
from typing import Optional

import pytest
Expand Down Expand Up @@ -106,9 +107,14 @@ def test_command_converge(scenario_to_test, with_scenario, scenario_name):
indirect=["scenario_to_test", "driver_name", "scenario_name"],
)
@pytest.mark.serial
def test_command_create(scenario_to_test, with_scenario, scenario_name):
def test_command_create(scenario_to_test, with_scenario, scenario_name, tmp_path):
os.environ["ANSIBLE_ROLES_PATH"] = str(tmp_path)
cmd = ["molecule", "create", "--scenario-name", scenario_name]
assert run_command(cmd).returncode == 0
assert run_command(cmd, env=os.environ).returncode == 0

# Validate that ansible-compat created a symlink in the roles path
role_path = tmp_path / "molecule.delegated_test"
assert role_path.is_symlink()


@pytest.mark.parametrize(
Expand Down
8 changes: 8 additions & 0 deletions src/molecule/test/scenarios/driver/delegated/meta/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
dependencies: []

galaxy_info:
author: Molecule Developer
description: Role to test ansible_compat installation of role
namespace: molecule
role_name: delegated_test

0 comments on commit 4912d69

Please sign in to comment.