installer 1.38.0 on main (NOT tagged): an appliance install stops on a system disk below 200 GB; --accept-small-disk for the operator (D83, R-1370); R-1398 filed
Claude-Session: https://claude.ai/code/session_0159rPz1ZhFKsS53msqPYxtS
This commit is contained in:
1 parent
44715fb38b
commit
92853bed2c
6 files changed
+370
-5
No files matched your search
@@ -851,6 +851,179 @@ def test_pve_trust_is_wired_into_the_agent_config():
|
||||
assert '%s = "%s"' % (name, path) in wrapper and path in func("resolve_pve_trust"), "the installer and the agent's root step disagree on %s" % name
|
||||
|
||||
|
||||
# ── D83 (R-1370, `16` §14.5): the system disk below 200 GB ───────────────────────────────────────
|
||||
# The disk is the one under the `pve` volume group; its size is the kernel's sector count. The stubs
|
||||
# stand for pvs and lsblk, and SYS_BLOCK_DIR for /sys/block — no real disk is read.
|
||||
GB200_LABEL = 200049647616 # a disk sold as "200 GB"
|
||||
GIB200 = 200 * 1024 ** 3 # a virtual disk made as "200G"
|
||||
|
||||
|
||||
def _disk_sandbox(disks, pvs_lines=("/dev/sda3",), parent="sda", kind="disk"):
|
||||
"""disks: {name: bytes}. pvs prints pvs_lines; lsblk says the PV's parent and the parent's type."""
|
||||
sb = Sandbox()
|
||||
for name, size in disks.items():
|
||||
os.makedirs(sb.path("sys", name))
|
||||
with open(sb.path("sys", name, "size"), "w") as f:
|
||||
f.write("%d\n" % (size // 512))
|
||||
sb.stub("pvs", "\n".join('echo " %s"' % l for l in pvs_lines) if pvs_lines else "exit 0")
|
||||
sb.stub("lsblk", 'case "$*" in *PKNAME*) echo "%s";; *TYPE*) echo "%s";; esac' % (parent, kind))
|
||||
return sb
|
||||
|
||||
|
||||
def _min_bytes_line():
|
||||
"""The installer's OWN minimum, read from the script — a test that sets the number itself cannot see it change."""
|
||||
m = re.search(r"^SYSTEM_DISK_MIN_BYTES=\d+$", SRC, re.M)
|
||||
assert m, "SYSTEM_DISK_MIN_BYTES not found in the installer"
|
||||
return m.group(0)
|
||||
|
||||
|
||||
def _disk_run(sb, mode, accept=False):
|
||||
return sb.run("set -euo pipefail\n" + one_liners() + func("system_disk_bytes") + func("check_system_disk") +
|
||||
_min_bytes_line() + '; SYS_BLOCK_DIR="$SB/sys"\n'
|
||||
'MODE="%s"; ACCEPT_SMALL_DISK=%s\ncheck_system_disk\n'
|
||||
'echo "WENT-ON small=$SMALL_DISK bytes=$SYSTEM_DISK_BYTES"\n' % (mode, "true" if accept else "false"))
|
||||
|
||||
|
||||
def test_small_disk_appliance_is_refused_before_anything_changes():
|
||||
sb = _disk_sandbox({"sda": 128 * 10 ** 9})
|
||||
try:
|
||||
rc, out = _disk_run(sb, "appliance")
|
||||
assert rc == 1 and "WENT-ON" not in out, "a 128 GB appliance install went on: rc=%s %s" % (rc, out)
|
||||
assert "This machine's system disk is 128 GB. Felhom needs 200 GB." in out and "Nothing was changed" in out, out
|
||||
assert "--accept-small-disk" in out, "the refusal does not name the flag: %s" % out
|
||||
# the check only READS: pvs and lsblk, nothing else was called
|
||||
called = {l.split()[0] for l in sb.logged().splitlines() if l.strip()}
|
||||
assert called == {"pvs", "lsblk"}, "the disk check ran more than its two reads: %s" % sorted(called)
|
||||
finally:
|
||||
sb.close()
|
||||
|
||||
|
||||
def test_small_disk_the_line_is_200_times_ten_to_the_nine_bytes():
|
||||
for size, passes in ((GB200_LABEL, True), (200 * 10 ** 9, True), (GIB200, True),
|
||||
(200 * 10 ** 9 - 512, False), (180 * 10 ** 9, False)):
|
||||
sb = _disk_sandbox({"sda": size})
|
||||
try:
|
||||
rc, out = _disk_run(sb, "appliance")
|
||||
assert (rc == 0 and "WENT-ON small=false bytes=%d" % size in out) == passes, \
|
||||
"%d bytes: passes=%s wanted %s: %s" % (size, rc == 0, passes, out)
|
||||
finally:
|
||||
sb.close()
|
||||
|
||||
|
||||
def test_small_disk_flag_goes_on_prints_the_cost_and_marks_it():
|
||||
sb = _disk_sandbox({"sda": 128 * 10 ** 9})
|
||||
try:
|
||||
rc, out = _disk_run(sb, "appliance", accept=True)
|
||||
assert rc == 0 and "WENT-ON small=true bytes=128000000000" in out, out
|
||||
assert "128 GB" in out and "The cost:" in out and "local copies can stop" in out, "the cost is not printed: %s" % out
|
||||
finally:
|
||||
sb.close()
|
||||
# the flag on a disk that is large enough marks nothing
|
||||
sb = _disk_sandbox({"sda": GB200_LABEL})
|
||||
try:
|
||||
rc, out = _disk_run(sb, "appliance", accept=True)
|
||||
assert rc == 0 and "WENT-ON small=false" in out, out
|
||||
finally:
|
||||
sb.close()
|
||||
|
||||
|
||||
def test_small_disk_byo_host_is_warned_never_refused():
|
||||
sb = _disk_sandbox({"sda": 128 * 10 ** 9})
|
||||
try:
|
||||
rc, out = _disk_run(sb, "byo")
|
||||
assert rc == 0 and "WENT-ON small=false" in out, "a byo host was stopped: %s" % out
|
||||
assert "[WARN]" in out and "128 GB" in out and "200 GB" in out, out
|
||||
finally:
|
||||
sb.close()
|
||||
# no --mode (the mode-agnostic --preflight-only): a warning too
|
||||
sb = _disk_sandbox({"sda": 128 * 10 ** 9})
|
||||
try:
|
||||
rc, out = _disk_run(sb, "")
|
||||
assert rc == 0 and "[WARN]" in out, out
|
||||
finally:
|
||||
sb.close()
|
||||
|
||||
|
||||
def test_small_disk_size_that_cannot_be_read_refuses_and_names_the_flag():
|
||||
cases = {
|
||||
"no pve volume group": dict(disks={"sda": GB200_LABEL}, pvs_lines=()),
|
||||
"two physical volumes": dict(disks={"sda": GB200_LABEL, "sdb": GB200_LABEL}, pvs_lines=("/dev/sda3", "/dev/sdb1")),
|
||||
"a RAID under the group": dict(disks={"md0": GB200_LABEL}, parent="md0", kind="raid1"),
|
||||
"no parent disk": dict(disks={"sda": GB200_LABEL}, parent=""),
|
||||
"no size file": dict(disks={"sdb": GB200_LABEL}),
|
||||
}
|
||||
for name, kw in cases.items():
|
||||
sb = _disk_sandbox(**kw)
|
||||
try:
|
||||
rc, out = _disk_run(sb, "appliance")
|
||||
assert rc == 1 and "WENT-ON" not in out, "%s: the install went on: %s" % (name, out)
|
||||
assert "Cannot read the system disk's size" in out and "--accept-small-disk" in out and "Nothing was changed" in out, "%s: %s" % (name, out)
|
||||
assert "[ERROR] Cannot read" in out and "system disk is" not in out, "%s: the refusal is not the 'cannot read' one: %s" % (name, out)
|
||||
rc, out = _disk_run(sb, "appliance", accept=True)
|
||||
assert rc == 0 and "WENT-ON small=true bytes=unknown" in out, "%s with the flag: %s" % (name, out)
|
||||
rc, out = _disk_run(sb, "byo")
|
||||
assert rc == 0 and "[WARN]" in out, "%s on a byo host: %s" % (name, out)
|
||||
finally:
|
||||
sb.close()
|
||||
|
||||
|
||||
def test_small_disk_a_large_second_disk_does_not_help():
|
||||
# the rule reads the SYSTEM disk (the one under `pve`), not the largest disk in the machine
|
||||
sb = _disk_sandbox({"sda": 128 * 10 ** 9, "sdb": 2000 * 10 ** 9})
|
||||
try:
|
||||
rc, out = _disk_run(sb, "appliance")
|
||||
assert rc == 1 and "128 GB" in out, out
|
||||
finally:
|
||||
sb.close()
|
||||
# and the other way round: a small second disk does not refuse a large system disk
|
||||
sb = _disk_sandbox({"sda": 512 * 10 ** 9, "sdb": 16 * 10 ** 9})
|
||||
try:
|
||||
rc, out = _disk_run(sb, "appliance")
|
||||
assert rc == 0 and "WENT-ON small=false" in out, out
|
||||
finally:
|
||||
sb.close()
|
||||
|
||||
|
||||
def test_small_disk_check_is_wired_first_in_the_preflight_and_recorded():
|
||||
body = func("step_preflight")
|
||||
at = body.find("\n check_system_disk\n")
|
||||
assert at > 0, "step_preflight no longer calls check_system_disk"
|
||||
for later in ("pveversion | head", "_state_put", "_state_mark", "pvesh get", "systemctl cat", "apt-get", "_byo_disclosure_ack", "mkdir", "curl -"):
|
||||
first = body.find(later)
|
||||
assert first == -1 or at < first, "check_system_disk runs AFTER %r — a refused machine may already be changed" % later
|
||||
assert '_state_put small_disk "${SMALL_DISK:-false}"' in body and '_state_put system_disk_bytes' in body, \
|
||||
"the preflight does not record small_disk in the install state"
|
||||
# the flag reaches the variable, and the help names it
|
||||
assert re.search(r"--accept-small-disk\)\s+ACCEPT_SMALL_DISK=true; shift ;;", SRC), "the flag is not parsed"
|
||||
assert "# --accept-small-disk" in SRC, "the help does not name the flag"
|
||||
# the existing pool warning stays as the second check
|
||||
assert "RECOMMENDED_MIN_LVM_GIB" in body
|
||||
|
||||
|
||||
def _enroll_run(small_state, small_var):
|
||||
sb = Sandbox()
|
||||
sb.stub("curl", 'printf \'{"host_id":"h1","api_key":"k1"}\\n201\'')
|
||||
os.makedirs(sb.path("state"))
|
||||
with open(sb.path("state", "state.json"), "w") as f:
|
||||
json.dump({"completed": [], "small_disk": small_state}, f)
|
||||
rc, out = sb.run("set -euo pipefail\n" + prelude() + func("_state_mark") + func("_state_get") + func("step_enroll") +
|
||||
'die_live_box() { exit 9; }\nPREFLIGHT_ONLY=false\nSTATE_DIR="$SB/state"; STATE_FILE="$SB/state/state.json"\n'
|
||||
'HUB_URL=http://hub.invalid; PASSPHRASE=p; CUSTOMER_ID=c1\n%sstep_enroll\n' % small_var)
|
||||
logged = sb.logged()
|
||||
sb.close()
|
||||
return rc, out, logged
|
||||
|
||||
|
||||
def test_small_disk_is_told_to_the_hub_at_the_enrolment():
|
||||
rc, out, logged = _enroll_run("true", "") # a resume: the flag comes from the state record
|
||||
assert rc == 0, out
|
||||
assert '{"customer_id":"c1","small_disk":true}' in logged, "the enrolment does not tell the hub: %s" % logged
|
||||
rc, out, logged = _enroll_run("false", "SMALL_DISK=true\n") # this run's own check wins
|
||||
assert rc == 0 and '"small_disk":true' in logged, logged
|
||||
rc, out, logged = _enroll_run("false", "") # the control: an ordinary box says nothing
|
||||
assert rc == 0 and '{"customer_id":"c1"}' in logged and "small_disk" not in logged, logged
|
||||
|
||||
|
||||
def main():
|
||||
tests = [(n, f) for n, f in sorted(globals().items()) if n.startswith("test_") and callable(f)]
|
||||
fails = 0
|
||||
|
||||
Reference in new issue
Block a user