103 lines
4.3 KiB
Python
103 lines
4.3 KiB
Python
"""PM system tests driven by bare workshop-baker prebake."""
|
|
|
|
import os
|
|
import pytest
|
|
from probes import binary_exists
|
|
|
|
PACMAN_MIRROR = "https://mirrors.tuna.tsinghua.edu.cn/archlinux/$repo/os/$arch"
|
|
|
|
|
|
def _yml(pm, pkgs, mirror="", repo=None):
|
|
"""Build prebake.yml. repo is a list of lines (without lead indent)."""
|
|
m = ""
|
|
if mirror:
|
|
m += ' mirror: "' + mirror + '"\n'
|
|
if repo:
|
|
m += " repositories:\n"
|
|
for line in repo:
|
|
m += " " + line + "\n"
|
|
return """\
|
|
version: "1.0"
|
|
environment:
|
|
builder: "baremetal"
|
|
bootstrap:
|
|
user: "vulcan"
|
|
dependencies:
|
|
system:
|
|
{pm}:
|
|
packages: [{pkgs}]
|
|
{m}""".format(pm=pm, pkgs=pkgs, m=m)
|
|
|
|
|
|
# ── install ──────────────────────────────────────────────────────────
|
|
|
|
@pytest.mark.parametrize("pm_name,pkgs", [
|
|
("pacman", '"curl", "git"'),
|
|
("apt", '"curl", "git"'),
|
|
("dnf", '"curl", "git"'),
|
|
("apk", '"curl", "git"'),
|
|
])
|
|
def test_install(run_cmd, work_dir, pm_name, pkgs):
|
|
cfg = os.path.join(work_dir, "pm.yml")
|
|
mirror = PACMAN_MIRROR if pm_name == "pacman" else ""
|
|
with open(cfg, "w") as f:
|
|
f.write(_yml(pm_name, pkgs, mirror=mirror))
|
|
r = run_cmd(["/baker", "-p", "t", "-b", "1", "-u", "testuser",
|
|
"bare", "prebake", cfg], timeout=120)
|
|
assert r["success"], "[{}] prebake: {}".format(pm_name, r["stderr"][:300])
|
|
for pkg in ["curl", "git"]:
|
|
assert binary_exists("/usr/bin/" + pkg), "[{}] {} missing".format(pm_name, pkg)
|
|
|
|
|
|
@pytest.mark.parametrize("pm_name", ["pacman", "apt", "dnf", "apk"])
|
|
def test_reinstall(run_cmd, work_dir, pm_name):
|
|
cfg = os.path.join(work_dir, "pm.yml")
|
|
mirror = PACMAN_MIRROR if pm_name == "pacman" else ""
|
|
with open(cfg, "w") as f:
|
|
f.write(_yml(pm_name, '"curl"', mirror=mirror))
|
|
cmd = ["/baker", "-p", "t", "-b", "1", "-u", "testuser", "bare", "prebake", cfg]
|
|
r1 = run_cmd(cmd, timeout=120)
|
|
assert r1["success"], "[{}] first install failed".format(pm_name)
|
|
r2 = run_cmd(cmd, timeout=120)
|
|
assert r2["success"], "[{}] reinstall failed".format(pm_name)
|
|
|
|
|
|
# ── change_mirror ────────────────────────────────────────────────────
|
|
|
|
@pytest.mark.parametrize("pm_name", ["pacman", "apt", "dnf", "apk"])
|
|
def test_mirror(run_cmd, work_dir, pm_name):
|
|
cfg = os.path.join(work_dir, "pm.yml")
|
|
mirror = PACMAN_MIRROR if pm_name == "pacman" else ""
|
|
with open(cfg, "w") as f:
|
|
f.write(_yml(pm_name, '"which"', mirror=mirror))
|
|
r = run_cmd(["/baker", "-p", "t", "-b", "1", "-u", "testuser",
|
|
"bare", "prebake", cfg], timeout=120)
|
|
assert r["success"], "[{}] mirror: {}".format(pm_name, r["stderr"][:300])
|
|
assert binary_exists("/usr/bin/which"), "[{}] which not installed".format(pm_name)
|
|
|
|
|
|
# ── add_repository ───────────────────────────────────────────────────
|
|
|
|
@pytest.mark.parametrize("pm_name,repo_lines,result_file", [
|
|
("pacman", ['- name: custom', ' server: "https://repo.example.com/$arch"'],
|
|
"/etc/pacman.conf"),
|
|
("apt", ['- url: "https://repo.example.com/debian"', ' distro: bookworm'],
|
|
"/etc/apt/sources.list.d/custom.list"),
|
|
("dnf", ['- name: custom', ' baseurl: "https://repo.example.com/fedora"'],
|
|
"/etc/yum.repos.d/custom.repo"),
|
|
("apk", ['- url: "https://repo.example.com/v3.19/main"'],
|
|
"/etc/apk/repositories"),
|
|
])
|
|
@pytest.mark.xfail(reason="fake repo URL, package install may fail", strict=False)
|
|
def test_add_repo(run_cmd, work_dir, pm_name, repo_lines, result_file):
|
|
cfg = os.path.join(work_dir, "pm.yml")
|
|
mirror = PACMAN_MIRROR if pm_name == "pacman" else ""
|
|
with open(cfg, "w") as f:
|
|
f.write(_yml(pm_name, '"curl"', mirror=mirror, repo=repo_lines))
|
|
r = run_cmd(["/baker", "-p", "t", "-b", "1", "-u", "testuser",
|
|
"bare", "prebake", cfg], timeout=120)
|
|
# Prebake may fail if repo URL is unreachable — check only the config file
|
|
# was written by add_repository before the (possibly failing) install step.
|
|
assert binary_exists(result_file), \
|
|
"[{}] repo file missing: {}".format(pm_name, result_file)
|