fix(testing): fix containerized packaging tests for #45
- Copy packages to /pkg/ instead of /tmp/ to avoid tmpfs masking in docker run --tmpfs /tmp, which hid packages needed at runtime by the migration guard and upgrade tests - Add version faking for deb upgrade test: sed the dpkg status to show version 0.2.0 so dpkg -i treats the reinstall as an upgrade and postinst receives the old-version argument - For RPM upgrade test: extract and manually invoke the post scriptlet with $1=2 (upgrade arguments), since faking a different version in the binary RPM database is not practical - Parameterize migration guard and upgrade assertions with pkg_name (and version) instead of hardcoding filenames All 16 packaging tests now pass across debian:bookworm, ubuntu:22.04, ubuntu:24.04, and fedora:40. Co-authored-by: CommandCodeBot <noreply@commandcode.ai>
This commit is contained in:
co-authored by
CommandCodeBot
parent
8fa86c3bf8
commit
f1e1c0eebc
+25
-15
@@ -97,8 +97,8 @@ def _build_deb_dockerfile(image: str, pkg_name: str) -> str:
|
|||||||
RUN apt-get update && apt-get install -y --no-install-recommends \\
|
RUN apt-get update && apt-get install -y --no-install-recommends \\
|
||||||
python3 smartmontools systemd systemd-sysv dbus && \\
|
python3 smartmontools systemd systemd-sysv dbus && \\
|
||||||
rm -rf /var/lib/apt/lists/*
|
rm -rf /var/lib/apt/lists/*
|
||||||
COPY dist/{pkg_name} /tmp/{pkg_name}
|
COPY dist/{pkg_name} /pkg/{pkg_name}
|
||||||
RUN dpkg -i /tmp/{pkg_name} || apt-get install -f -y
|
RUN dpkg -i /pkg/{pkg_name} || apt-get install -f -y
|
||||||
""")
|
""")
|
||||||
|
|
||||||
|
|
||||||
@@ -109,8 +109,8 @@ def _build_rpm_dockerfile(image: str, pkg_name: str) -> str:
|
|||||||
RUN dnf install -y --setopt=install_weak_deps=False \
|
RUN dnf install -y --setopt=install_weak_deps=False \
|
||||||
python3 smartmontools systemd dbus && \
|
python3 smartmontools systemd dbus && \
|
||||||
dnf clean all
|
dnf clean all
|
||||||
COPY dist/{pkg_name} /tmp/{pkg_name}
|
COPY dist/{pkg_name} /pkg/{pkg_name}
|
||||||
RUN rpm -ivh /tmp/{pkg_name}
|
RUN rpm -ivh /pkg/{pkg_name}
|
||||||
""")
|
""")
|
||||||
|
|
||||||
|
|
||||||
@@ -219,7 +219,7 @@ def _assert_dormant_layout(container: str, fmt: str, version: str) -> None:
|
|||||||
assert rc != 0, "Legacy manifest.txt should not exist in package install"
|
assert rc != 0, "Legacy manifest.txt should not exist in package install"
|
||||||
|
|
||||||
|
|
||||||
def _assert_migration_guard(container: str, fmt: str) -> None:
|
def _assert_migration_guard(container: str, fmt: str, pkg_name: str) -> None:
|
||||||
"""Assert that install aborts on make-install remnants (spec §7, §9)."""
|
"""Assert that install aborts on make-install remnants (spec §7, §9)."""
|
||||||
if fmt == "deb":
|
if fmt == "deb":
|
||||||
# Plant the legacy manifest marker
|
# Plant the legacy manifest marker
|
||||||
@@ -228,7 +228,7 @@ def _assert_migration_guard(container: str, fmt: str) -> None:
|
|||||||
# Attempt install — should fail with migration pointer
|
# Attempt install — should fail with migration pointer
|
||||||
rc, out = _container_exec(
|
rc, out = _container_exec(
|
||||||
container,
|
container,
|
||||||
"dpkg -i /tmp/fenris_0.3.0_amd64.deb 2>&1 || true",
|
f"dpkg -i /pkg/{pkg_name} 2>&1 || true",
|
||||||
)
|
)
|
||||||
assert "remnants" in out.lower() or "migrat" in out.lower() or rc != 0, \
|
assert "remnants" in out.lower() or "migrat" in out.lower() or rc != 0, \
|
||||||
f"Migration guard did not trigger: {out}"
|
f"Migration guard did not trigger: {out}"
|
||||||
@@ -243,7 +243,7 @@ def _assert_migration_guard(container: str, fmt: str) -> None:
|
|||||||
)
|
)
|
||||||
rc, out = _container_exec(
|
rc, out = _container_exec(
|
||||||
container,
|
container,
|
||||||
"rpm -ivh /tmp/fenris-0.3.0-1.x86_64.rpm 2>&1 || true",
|
f"rpm -ivh /pkg/{pkg_name} 2>&1 || true",
|
||||||
)
|
)
|
||||||
assert "remnants" in out.lower() or "migrat" in out.lower() or rc != 0, \
|
assert "remnants" in out.lower() or "migrat" in out.lower() or rc != 0, \
|
||||||
f"Migration guard did not trigger: {out}"
|
f"Migration guard did not trigger: {out}"
|
||||||
@@ -253,7 +253,7 @@ def _assert_migration_guard(container: str, fmt: str) -> None:
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def _assert_upgrade_semantics(container: str, fmt: str) -> None:
|
def _assert_upgrade_semantics(container: str, fmt: str, pkg_name: str, version: str) -> None:
|
||||||
"""Assert upgrade behavior (spec §7, ADR 0007 §6)."""
|
"""Assert upgrade behavior (spec §7, ADR 0007 §6)."""
|
||||||
# Create a fake observation store using system Python
|
# Create a fake observation store using system Python
|
||||||
# (venv Python may not execute if host shared libs differ)
|
# (venv Python may not execute if host shared libs differ)
|
||||||
@@ -268,16 +268,26 @@ def _assert_upgrade_semantics(container: str, fmt: str) -> None:
|
|||||||
)
|
)
|
||||||
|
|
||||||
if fmt == "deb":
|
if fmt == "deb":
|
||||||
|
# Fake older version so dpkg treats reinstall as upgrade
|
||||||
|
_container_exec(
|
||||||
|
container,
|
||||||
|
f"sed -i 's/^Version: {version}$/Version: 0.2.0/' /var/lib/dpkg/status",
|
||||||
|
)
|
||||||
# Re-install triggers upgrade path
|
# Re-install triggers upgrade path
|
||||||
rc, out = _container_exec(
|
rc, out = _container_exec(
|
||||||
container,
|
container,
|
||||||
"dpkg --force-confnew -i /tmp/fenris_*.deb 2>&1 || "
|
f"dpkg --force-confnew -i /pkg/{pkg_name} 2>&1 || "
|
||||||
"apt-get install -f -y 2>&1 || true",
|
"apt-get install -f -y 2>&1 || true",
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
rc, out = _container_exec(
|
# RPM: manually invoke the post scriptlet with upgrade arguments ($1=2)
|
||||||
|
# because faking a different version in the binary RPM database is not
|
||||||
|
# practical — we only need to verify the scriptlet's upgrade behaviour.
|
||||||
|
_container_exec(
|
||||||
container,
|
container,
|
||||||
"rpm -Uvh /tmp/fenris-*.rpm 2>&1 || true",
|
f"rpm -q --scripts -p /pkg/{pkg_name} "
|
||||||
|
"| sed -n '/^postinstall scriptlet/,/^preuninstall/"
|
||||||
|
"{/^preuninstall/d;/^postinstall scriptlet/d;p}' | sh -s 2 2",
|
||||||
)
|
)
|
||||||
|
|
||||||
# Snapshot should exist
|
# Snapshot should exist
|
||||||
@@ -408,7 +418,7 @@ def test_migration_guard(skip_no_docker, image, fmt, version):
|
|||||||
RUN apt-get update && apt-get install -y --no-install-recommends \
|
RUN apt-get update && apt-get install -y --no-install-recommends \
|
||||||
python3 python3-minimal smartmontools systemd systemd-sysv dbus && \
|
python3 python3-minimal smartmontools systemd systemd-sysv dbus && \
|
||||||
rm -rf /var/lib/apt/lists/*
|
rm -rf /var/lib/apt/lists/*
|
||||||
COPY dist/{pkg_name} /tmp/{pkg_name}
|
COPY dist/{pkg_name} /pkg/{pkg_name}
|
||||||
# Plant make-install remnant BEFORE installing
|
# Plant make-install remnant BEFORE installing
|
||||||
RUN mkdir -p /var/lib/fenris && echo '# manifest' > /var/lib/fenris/manifest.txt
|
RUN mkdir -p /var/lib/fenris && echo '# manifest' > /var/lib/fenris/manifest.txt
|
||||||
""")
|
""")
|
||||||
@@ -418,7 +428,7 @@ def test_migration_guard(skip_no_docker, image, fmt, version):
|
|||||||
RUN dnf install -y --setopt=install_weak_deps=False \
|
RUN dnf install -y --setopt=install_weak_deps=False \
|
||||||
python3 smartmontools systemd dbus && \
|
python3 smartmontools systemd dbus && \
|
||||||
dnf clean all
|
dnf clean all
|
||||||
COPY dist/{pkg_name} /tmp/{pkg_name}
|
COPY dist/{pkg_name} /pkg/{pkg_name}
|
||||||
RUN mkdir -p /etc/systemd/system && \\
|
RUN mkdir -p /etc/systemd/system && \\
|
||||||
echo '[Unit]' > /etc/systemd/system/fenris-collect.timer
|
echo '[Unit]' > /etc/systemd/system/fenris-collect.timer
|
||||||
""")
|
""")
|
||||||
@@ -444,7 +454,7 @@ def test_migration_guard(skip_no_docker, image, fmt, version):
|
|||||||
)
|
)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
_assert_migration_guard(container, fmt)
|
_assert_migration_guard(container, fmt, pkg_name)
|
||||||
finally:
|
finally:
|
||||||
subprocess.run(
|
subprocess.run(
|
||||||
["docker", "rm", "-f", container],
|
["docker", "rm", "-f", container],
|
||||||
@@ -497,7 +507,7 @@ def test_upgrade_semantics(skip_no_docker, image, fmt, version):
|
|||||||
)
|
)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
_assert_upgrade_semantics(container, fmt)
|
_assert_upgrade_semantics(container, fmt, pkg_name, version)
|
||||||
finally:
|
finally:
|
||||||
subprocess.run(
|
subprocess.run(
|
||||||
["docker", "rm", "-f", container],
|
["docker", "rm", "-f", container],
|
||||||
|
|||||||
Reference in New Issue
Block a user