Skip to content

Commit

Permalink
Merge pull request #2571 from greg-hellings/molecule_limit_glob
Browse files Browse the repository at this point in the history
Avoid loading all scenarios if not needed

Reviewed-by: https://github.com/apps/ansible-zuul
  • Loading branch information
ansible-zuul[bot] authored Feb 23, 2020
2 parents 5511097 + 910f176 commit 888b2f3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
15 changes: 9 additions & 6 deletions molecule/command/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,11 @@ def execute_cmdline_scenarios(scenario_name, args, command_args, ansible_args=()
:returns: None
"""
glob_str = MOLECULE_GLOB
if scenario_name:
glob_str = glob_str.replace("*", scenario_name)
scenarios = molecule.scenarios.Scenarios(
get_configs(args, command_args, ansible_args), scenario_name
get_configs(args, command_args, ansible_args, glob_str), scenario_name
)
scenarios.print_matrix()
for scenario in scenarios:
Expand Down Expand Up @@ -157,7 +160,7 @@ def execute_scenario(scenario):
scenario._remove_scenario_state_directory()


def get_configs(args, command_args, ansible_args=()):
def get_configs(args, command_args, ansible_args=(), glob_str=MOLECULE_GLOB):
"""
Glob the current directory for Molecule config files, instantiate config \
objects, and returns a list.
Expand All @@ -176,14 +179,14 @@ def get_configs(args, command_args, ansible_args=()):
command_args=command_args,
ansible_args=ansible_args,
)
for c in glob.glob(MOLECULE_GLOB)
for c in glob.glob(glob_str)
]
_verify_configs(configs)
_verify_configs(configs, glob_str)

return configs


def _verify_configs(configs):
def _verify_configs(configs, glob_str=MOLECULE_GLOB):
"""
Verify a Molecule config was found and returns None.
Expand All @@ -200,7 +203,7 @@ def _verify_configs(configs):
util.sysexit_with_message(msg)

else:
msg = "'{}' glob failed. Exiting.".format(MOLECULE_GLOB)
msg = "'{}' glob failed. Exiting.".format(glob_str)
util.sysexit_with_message(msg)


Expand Down
2 changes: 1 addition & 1 deletion molecule/test/unit/command/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ def test_get_configs(config_instance):
def test_get_configs_calls_verify_configs(_patched_verify_configs):
base.get_configs({}, {})

_patched_verify_configs.assert_called_once_with([])
_patched_verify_configs.assert_called_once_with([], "molecule/*/molecule.yml")


def test_verify_configs(config_instance):
Expand Down

0 comments on commit 888b2f3

Please sign in to comment.