Skip to content

Commit e629c7b

Browse files
committed
handle recent debian, tweak tests a bit
1 parent 8bdac71 commit e629c7b

File tree

11 files changed

+128
-37
lines changed

11 files changed

+128
-37
lines changed

.github/workflows/github-workflow-molecule.yml

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,15 @@ jobs:
4141
fail-fast: false
4242
matrix:
4343
config:
44-
- 2204
45-
- 2404
44+
- os: ubuntu
45+
version: 2204
46+
image: geerlingguy/docker-ubuntu2204-ansible:latest
47+
- os: ubuntu
48+
version: 2404
49+
image: geerlingguy/docker-ubuntu2404-ansible:latest
50+
- os: debian
51+
version: 13
52+
image: geerlingguy/docker-debian13-ansible:latest
4653

4754
steps:
4855
- name: Checkout code
@@ -64,5 +71,6 @@ jobs:
6471
- name: Run molecule test
6572
run: molecule test
6673
env:
67-
MOLECULE_UBUNTU_VERSION: ${{ matrix.config }}
68-
74+
MOLECULE_OS: ${{ matrix.config.os }}
75+
MOLECULE_VERSION: ${{ matrix.config.version }}
76+
MOLECULE_IMAGE: ${{ matrix.config.image }}

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,6 @@ Icon
99
.ansible
1010
__pycache__
1111
molecule*.log
12-
.act/
12+
.act/
13+
.#*
14+
*.*#

Makefile

Lines changed: 33 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
2-
.PHONY: help clean lint test format act act-download distclean
1+
.PHONY: help clean lint test format act act-download distclean test_workflow
32

43
ACT_VERSION ?= 0.2.82
54
ACT_BINARY := $(shell pwd)/.act/act
@@ -25,20 +24,39 @@ format: ## Format code with black and other formatters
2524
black tests/ --line-length 88 --target-version py39
2625
@echo "Code formatting completed!"
2726

27+
# Convenience molecule targets (Ubuntu)
2828
molecule-2204-no-uv:
29-
@echo "molecule: ubuntu-22.04 (no uv)"
30-
LOG=molecule-2204-no-uv.log; \
31-
( MOLECULE_UBUNTU_VERSION=2204 PYTHON_UV_INSTALL=false $(molecule) test -s default 2>&1 | tee $$LOG ) || ( echo "FAILED: see $$LOG"; cat $$LOG; false )
29+
@echo "molecule: ubuntu-22.04 (no uv)"
30+
LOG=molecule-2204-no-uv.log; \
31+
( MOLECULE_OS=ubuntu MOLECULE_VERSION=2204 PYTHON_UV_INSTALL=false $(molecule) test -s default 2>&1 | tee $$LOG ) || ( echo "FAILED: see $$LOG"; cat $$LOG; false )
3232

3333
molecule-2404-no-uv:
34-
@echo "molecule: ubuntu-24.04 (no uv)"
35-
LOG=molecule-2404-no-uv.log; \
36-
( MOLECULE_UBUNTU_VERSION=2404 PYTHON_UV_INSTALL=false $(molecule) test -s default 2>&1 | tee $$LOG ) || ( echo "FAILED: see $$LOG"; cat $$LOG; false )
34+
@echo "molecule: ubuntu-24.04 (no uv)"
35+
LOG=molecule-2404-no-uv.log; \
36+
( MOLECULE_OS=ubuntu MOLECULE_VERSION=2404 PYTHON_UV_INSTALL=false $(molecule) test -s default 2>&1 | tee $$LOG ) || ( echo "FAILED: see $$LOG"; cat $$LOG; false )
3737

3838
molecule-2404-uv:
39-
@echo "molecule: ubuntu-24.04 (with uv)"
40-
LOG=molecule-2404-uv.log; \
41-
( MOLECULE_UBUNTU_VERSION=2404 PYTHON_UV_INSTALL=true PYTHON_UV_SUFFIX="-alt" $(molecule) test -s default 2>&1 | tee $$LOG ) || ( echo "FAILED: see $$LOG"; cat $$LOG; false )
39+
@echo "molecule: ubuntu-24.04 (with uv)"
40+
LOG=molecule-2404-uv.log; \
41+
( MOLECULE_OS=ubuntu MOLECULE_VERSION=2404 PYTHON_UV_INSTALL=true PYTHON_UV_SUFFIX="-alt" $(molecule) test -s default 2>&1 | tee $$LOG ) || ( echo "FAILED: see $$LOG"; cat $$LOG; false )
42+
43+
# Convenience molecule targets (Debian 13)
44+
molecule-debian-13-no-uv:
45+
@echo "molecule: debian-13 (no uv)"
46+
LOG=molecule-debian-13-no-uv.log; \
47+
( MOLECULE_OS=debian MOLECULE_VERSION=13 MOLECULE_IMAGE=${MOLECULE_IMAGE:-geerlingguy/docker-debian13-ansible:latest} PYTHON_UV_INSTALL=false $(molecule) test -s default 2>&1 | tee $$LOG ) || ( echo "FAILED: see $$LOG"; cat $$LOG; false )
48+
49+
molecule-debian-13-uv:
50+
@echo "molecule: debian-13 (with uv)"
51+
LOG=molecule-debian-13-uv.log; \
52+
( MOLECULE_OS=debian MOLECULE_VERSION=13 MOLECULE_IMAGE=${MOLECULE_IMAGE:-geerlingguy/docker-debian13-ansible:latest} PYTHON_UV_INSTALL=true PYTHON_UV_SUFFIX="-alt" $(molecule) test -s default 2>&1 | tee $$LOG ) || ( echo "FAILED: see $$LOG"; cat $$LOG; false )
53+
54+
# Generic runner: allows invocation like:
55+
# make molecule-run MOLECULE_OS=debian MOLECULE_VERSION=13 MOLECULE_IMAGE=... PYTHON_UV_INSTALL=false
56+
molecule-run:
57+
@echo "molecule: ${MOLECULE_OS:-ubuntu}-${MOLECULE_VERSION:-2404} (uv=${PYTHON_UV_INSTALL:-true})"
58+
LOG=molecule-${MOLECULE_OS:-ubuntu}-${MOLECULE_VERSION:-2404}-$$( [ "${PYTHON_UV_INSTALL:-true}" = "true" ] && echo uv || echo no-uv ).log; \
59+
( MOLECULE_OS="${MOLECULE_OS:-ubuntu}" MOLECULE_VERSION="${MOLECULE_VERSION:-2404}" MOLECULE_IMAGE="${MOLECULE_IMAGE:-geerlingguy/docker-${MOLECULE_OS:-ubuntu}${MOLECULE_VERSION:-2404}-ansible:latest}" PYTHON_UV_INSTALL="${PYTHON_UV_INSTALL:-true}" PYTHON_UV_SUFFIX="${PYTHON_UV_SUFFIX}" $(molecule) test -s default 2>&1 | tee $$LOG ) || ( echo "FAILED: see $$LOG"; cat $$LOG; false )
4260

4361
act-download: ## download act
4462
@if [ ! -f "$(ACT_BINARY)" ]; then \
@@ -47,12 +65,14 @@ act-download: ## download act
4765
curl -L https://github.com/nektos/act/releases/download/v$(ACT_VERSION)/act_Linux_x86_64.tar.gz | tar -xz -C $(shell pwd)/.act act ; \
4866
fi
4967

50-
molecule: molecule-2404-uv molecule-2404-no-uv molecule-2204-no-uv
68+
molecule: molecule-2404-uv molecule-2404-no-uv molecule-2204-no-uv molecule-debian-13-uv molecule-debian-13-no-uv
5169

52-
test: act-download ## Run GitHub workflows, but locally
70+
test_workflow: act-download ## Run GitHub workflows, but locally
5371
@echo "Running Tests!"
5472
$(ACT_BINARY)
5573

74+
test: molecule
75+
5676
clean: molecule-destroy ## Clean up molecule instances and temporary files
5777
@echo "Cleaning up..."
5878
find . -name "*.pyc" -delete

molecule/default/molecule.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ driver:
66
name: docker
77

88
platforms:
9-
- name: "anxs-python-ubuntu-${MOLECULE_UBUNTU_VERSION:-2404}${PYTHON_UV_SUFFIX}"
10-
image: "geerlingguy/docker-ubuntu${MOLECULE_UBUNTU_VERSION:-2404}-ansible:latest"
9+
- name: "anxs-python-${MOLECULE_OS:-ubuntu}-${MOLECULE_VERSION:-2404}${PYTHON_UV_SUFFIX}"
10+
image: "${MOLECULE_IMAGE:-geerlingguy/docker-ubuntu2404-ansible:latest}"
1111
volumes:
1212
- /sys/fs/cgroup:/sys/fs/cgroup:rw
1313
privileged: true

molecule/default/tests/test_python_installation.py

Lines changed: 56 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,65 @@ def test_pip_is_installed(self, host):
3535
assert cmd.rc == 0
3636
assert "pip" in cmd.stdout
3737

38+
def _detect_os_release(self, host):
39+
"""Return a dict of /etc/os-release values"""
40+
os_release = {}
41+
f = host.file('/etc/os-release')
42+
if not f.exists:
43+
return os_release
44+
for line in f.content_string.splitlines():
45+
if '=' in line:
46+
k, v = line.split('=', 1)
47+
os_release[k.strip()] = v.strip().strip('"')
48+
return os_release
49+
3850
def test_python_packages_can_be_installed(self, host):
39-
"""Test that pip can install packages"""
40-
# Test installing a simple package
41-
cmd = host.run("pip3 install --user requests")
51+
"""Test that pip can install packages system-wide on supported distros
52+
53+
This test runs only on distributions which support system-level pip
54+
installs (Ubuntu, or Debian older than 13). On Debian 13+ we skip this
55+
because some packaging changes make system-level pip installs unreliable
56+
in CI images.
57+
"""
58+
osr = self._detect_os_release(host)
59+
distro = osr.get('ID', '').lower()
60+
version = osr.get('VERSION_ID', '')
61+
62+
# Skip system-level pip install test on Debian 13 and newer
63+
if distro == 'debian' and version:
64+
try:
65+
major = int(version.split('.')[0])
66+
except Exception:
67+
major = None
68+
if major and major >= 13:
69+
pytest.skip("System-level pip installs are skipped on Debian 13+")
70+
71+
# Attempt a system-level install (CI runs as root inside molecule by
72+
# default). We install a small package and assert success.
73+
cmd = host.run("pip3 install requests")
4274
assert cmd.rc == 0
4375

76+
def test_python_packages_in_virtualenv(self, host):
77+
"""Create a virtualenv and install a package inside it"""
78+
venv_dir = "/tmp/test-venv"
79+
80+
# Create the virtualenv
81+
cmd = host.run(f"python3 -m venv {venv_dir}")
82+
assert cmd.rc == 0
83+
84+
# Install a package inside the virtualenv
85+
pip_bin = f"{venv_dir}/bin/pip"
86+
cmd = host.run(f"{pip_bin} install requests")
87+
assert cmd.rc == 0
88+
89+
# Verify the package can be imported using the virtualenv's python
90+
py_bin = f"{venv_dir}/bin/python"
91+
cmd = host.run(f"{py_bin} -c \"import requests; print(requests.__version__)\"")
92+
assert cmd.rc == 0
93+
94+
# Cleanup the virtualenv
95+
host.run(f"rm -rf {venv_dir}")
96+
4497

4598
class TestUVInstallation:
4699
"""Test UV installation functionality"""

tasks/main.yml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
---
22
- name: "Get the distribution specific variables"
3-
include_vars: "{{ ansible_distribution | lower }}-{{ ansible_distribution_version }}.yml"
3+
include_vars: "{{ lookup('ansible.builtin.first_found', params) }}"
4+
vars:
5+
params:
6+
files:
7+
- "{{ ansible_distribution | lower }}-{{ ansible_distribution_version }}.yml"
8+
- "{{ ansible_distribution | lower }}-{{ (ansible_distribution_version.split('.') | first) }}.yml"
9+
paths:
10+
- "{{ role_path }}/vars"
411

512
- name: "Install python and accesory packages"
613
include_tasks: "package.yml"

tests/prepare.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,24 @@
44
become: true
55
gather_facts: true
66
tasks:
7+
78
- name: Update apt cache
89
apt:
910
update_cache: true
1011
cache_valid_time: 86400
1112
when: ansible_os_family == "Debian"
1213

1314
- name: Install essential packages
14-
package:
15+
apt:
1516
name:
1617
- curl
1718
- ca-certificates
1819
- gnupg
19-
- software-properties-common
20+
- "{{ 'software-properties-common' if (ansible_distribution != 'Debian' or (ansible_distribution == 'Debian' and (ansible_distribution_major_version | int) < 13)) else omit }}"
21+
- "lsb-release"
2022
state: present
23+
update_cache: yes
24+
when: ansible_os_family == "Debian"
2125

2226
- name: Create test user for permission tests
2327
user:

vars/debian-10.yml

Lines changed: 0 additions & 11 deletions
This file was deleted.

vars/debian-13.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
python_packages_add:
3+
- "python3"
4+
- "python3-dev"
5+
- "python3-venv"
6+
- "python3-virtualenv"

vars/main.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ python_uv_arch_map:
33
x86_64: "x86_64-unknown-linux-gnu"
44
aarch64: "aarch64-unknown-linux-gnu"
55
armv7l: "armv7-unknown-linux-gnu"
6+
armv6l: "arm-unknown-linux-musleabihf"

0 commit comments

Comments
 (0)