Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change current directory to scenario before running playbooks #3966

Merged
merged 7 commits into from
Aug 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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: 446
PYTEST_REQPASS: 447
steps:
- uses: actions/checkout@v3
with:
Expand Down
10 changes: 10 additions & 0 deletions molecule/smoke/converge.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
- name: Converge
hosts: localhost
tasks:
- name: Assert CWD is the same as playbook_dir
ansible.builtin.assert:
that:
- playbook_dir == lookup('env', 'PWD')
msg: >
Molecule should automatically chdir to scenario directory {{ playbook_dir }}
but we found that it runs from {{ lookup('env', 'PWD') }} instead."
2 changes: 2 additions & 0 deletions molecule/smoke/molecule.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
platforms:
- name: localhost
2 changes: 2 additions & 0 deletions src/molecule/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import os
import warnings
from collections.abc import MutableMapping
from pathlib import Path
from uuid import uuid4

from ansible_compat.ports import cache, cached_property
Expand Down Expand Up @@ -114,6 +115,7 @@ def __init__(
self._run_uuid = str(uuid4())
self.project_directory = os.getenv("MOLECULE_PROJECT_DIRECTORY", os.getcwd())
self.runtime = app.runtime
self.scenario_path = Path(molecule_file).parent

def after_init(self):
self.config = self._reget_config()
Expand Down
2 changes: 2 additions & 0 deletions src/molecule/provisioner/ansible_playbook.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,12 @@ def execute(self, action_args=None):
with warnings.catch_warnings(record=True) as warns:
warnings.filterwarnings("default", category=MoleculeRuntimeWarning)
self._config.driver.sanity_checks()
cwd = self._config.scenario_path
result = util.run_command(
cmd=self._ansible_command,
env=self._env,
debug=self._config.debug,
cwd=cwd,
)

if result.returncode != 0:
Expand Down
7 changes: 7 additions & 0 deletions src/molecule/test/b_functional/test_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,3 +352,10 @@ def test_docker() -> None:
).returncode
== 0
)


def test_smoke() -> None:
"""Execute smoke-test scenario that should spot potentially breaking changes."""
assert run_command(
["molecule", "test", "--scenario-name", "smoke"],
)