Skip to content

Commit

Permalink
Adapt smoke testing to test both molecule and ansible-lint
Browse files Browse the repository at this point in the history
  • Loading branch information
ssbarnea committed Jan 20, 2025
1 parent b5c3067 commit 63be515
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 18 deletions.
47 changes: 47 additions & 0 deletions tools/smoke.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
from tempfile import TemporaryDirectory
from pathlib import Path
import hashlib
import logging
from subprocess import run
import os

logging.basicConfig(level=logging.DEBUG,
format= '%(levelname)s: %(message)s',

)
parent_project_dir = Path(__file__).parent.parent.resolve().as_posix()
with TemporaryDirectory(delete=False) as tmp_dir:
checksum = hashlib.sha256(parent_project_dir.encode("utf-8")).hexdigest()[:4]
tmp_path = Path(tmp_dir) / f"ansible-compat-smoke-{checksum}"

logging.info(f"Using {tmp_path} temporary directory...")

# set -eu
# SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )

for project in ("ansible-lint", "molecule"):

logging.info(f"Running tests for {project}")
project_dir = tmp_path / project
if (project_dir / ".git").exists():
run(["git", "-C", project_dir, "pull"], check=True)
else:
project_dir.mkdir(parents=True, exist_ok=True)
run(["git", "clone", "--recursive", f"https://github.com/ansible/{project}", project_dir], check=True)

os.chdir(project_dir)
venv_dir = (project_dir / ".venv").as_posix()
os.environ["VIRTUAL_ENV"] = venv_dir
run(["uv", "venv", "--seed", venv_dir], check=True) # creates .venv (implicit for next commands)
run(["uv", "pip", "install", "-e", f"{parent_project_dir}[test]", "-e", ".[test]"], check=True)
run(["uv", "pip", "freeze"], check=True)
run(["uv", "run", "pytest", "-n", "auto"], check=True)

# tox devenv
# source venv/bin/activate
# uv pip install -e "$SCRIPT_DIR/.."
# uv pip freeze | grep "file:"
# pytest -n auto
# deactivate
# popd
# do
27 changes: 9 additions & 18 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ deps =
ansible217: ansible-core>=2.17,<2.18
ansible218: ansible-core>=2.18,<2.19

devel: ansible-core @ git+https://github.com/ansible/ansible.git@c5d18c39d81e2b3b10856b2fb76747230e4fac4a # GPLv3+
devel: ansible-core @ git+https://github.com/ansible/ansible.git@devel # GPLv3+
# avoid installing ansible-core on -devel envs:
!devel: ansible-core
extras =
Expand Down Expand Up @@ -89,6 +89,7 @@ allowlist_externals =
sh
# https://tox.wiki/en/latest/upgrading.html#editable-mode
package = editable
uv_seed = true

[testenv:lint]
description = Run all linters
Expand Down Expand Up @@ -174,21 +175,11 @@ extras = docs
passenv = *

[testenv:smoke]
description = Run ansible-lint own testing with current code from compat library
commands_pre =
ansible localhost -m ansible.builtin.git -a 'repo=https://github.com/ansible/ansible-lint dest={envdir}/tmp/ansible-lint'
pip install -e "{envdir}/tmp/ansible-lint[test]"
description = Run ansible-lint and molecule own testing with current code from compat library
commands =
bash -c "pip freeze|grep ansible"
pytest -k role
deps =
ansible-core
setenv =
{[testenv]setenv}
PIP_CONSTRAINT = /dev/null
UV_CONSTRAINT = /dev/null
PYTEST_REQPASS = 0
changedir = {envdir}/tmp/ansible-lint
allowlist_externals =
pwd
bash
python3 tools/smoke.py
del_env =
PIP_CONSTRAINT
UV_CONSTRAINT
editable = true
skip_install = true

0 comments on commit 63be515

Please sign in to comment.