|
| 1 | +"""Every flag compose2pod emits for a long-form mount, run once against the floor podman. |
| 2 | +
|
| 3 | +`refusals.py` measures one direction: that podman will not make a mount we refuse. |
| 4 | +Nothing measured the other, and that is the direction #104 and #114 both failed in -- |
| 5 | +a document passes the gate, emits a flag, and the script dies at `podman run`. Unit |
| 6 | +coverage cannot catch it, because `test_emit.py` asserts the string compose2pod |
| 7 | +produces, which is a fact about compose2pod, not about podman. |
| 8 | +
|
| 9 | +A row is the inverse of a `Refusal`, and its `expected_argv` is checked against what |
| 10 | +`emit` really produces before it is run. That check is deliberately the opposite of |
| 11 | +`refusals.py`'s rule, where the argv is hand-written so an emit bug cannot hide behind |
| 12 | +a parity claim: here the emitted flag is the thing under test, so the row has to be |
| 13 | +pinned to it or it measures a flag nobody ships. |
| 14 | +
|
| 15 | +A row goes red when a podman in the supported range drops or renames an option -- |
| 16 | +the same maintenance trigger the `subpath` refusals carry, pointing the other way. |
| 17 | +""" |
| 18 | + |
| 19 | +from dataclasses import dataclass |
| 20 | +from typing import Any |
| 21 | + |
| 22 | + |
| 23 | +@dataclass(frozen=True) |
| 24 | +class Acceptance: |
| 25 | + """A form the gate accepts, the flag it compiles to, and podman's verdict on that flag. |
| 26 | +
|
| 27 | + `{host}` in `expected_argv` is substituted with the test's project directory, which is |
| 28 | + also what `emit` resolves a relative bind source against. `host_dir` is created under it |
| 29 | + first, because a bind whose source does not exist fails for that reason instead of |
| 30 | + proving anything about the option being measured. |
| 31 | + """ |
| 32 | + |
| 33 | + id: str |
| 34 | + service: dict[str, Any] |
| 35 | + expected_argv: list[str] |
| 36 | + host_dir: str = "" |
| 37 | + |
| 38 | + |
| 39 | +def _bind(nested: dict[str, Any]) -> dict[str, Any]: |
| 40 | + return { |
| 41 | + "image": "busybox:1.36", |
| 42 | + "volumes": [{"type": "bind", "source": "./d", "target": "/data", "bind": nested}], |
| 43 | + } |
| 44 | + |
| 45 | + |
| 46 | +def _tmpfs(nested: dict[str, Any]) -> dict[str, Any]: |
| 47 | + return {"image": "busybox:1.36", "volumes": [{"type": "tmpfs", "target": "/data", "tmpfs": nested}]} |
| 48 | + |
| 49 | + |
| 50 | +def _mount(value: str) -> list[str]: |
| 51 | + return ["--mount", value] |
| 52 | + |
| 53 | + |
| 54 | +ACCEPTANCES: list[Acceptance] = [ |
| 55 | + Acceptance( |
| 56 | + id=f"bind-propagation-{propagation}", |
| 57 | + service=_bind({"propagation": propagation}), |
| 58 | + expected_argv=_mount(f"type=bind,source={{host}}/d,target=/data,bind-propagation={propagation}"), |
| 59 | + host_dir="d", |
| 60 | + ) |
| 61 | + # Every value `_PROPAGATION_VALUES` admits. Only `rprivate` had ever run. |
| 62 | + for propagation in ("private", "rprivate", "shared", "rshared", "slave", "rslave") |
| 63 | +] + [ |
| 64 | + Acceptance( |
| 65 | + id="bind-relabel-shared", |
| 66 | + service=_bind({"selinux": "z"}), |
| 67 | + expected_argv=_mount("type=bind,source={host}/d,target=/data,relabel=shared"), |
| 68 | + host_dir="d", |
| 69 | + ), |
| 70 | + Acceptance( |
| 71 | + id="bind-relabel-private", |
| 72 | + service=_bind({"selinux": "Z"}), |
| 73 | + expected_argv=_mount("type=bind,source={host}/d,target=/data,relabel=private"), |
| 74 | + host_dir="d", |
| 75 | + ), |
| 76 | + Acceptance( |
| 77 | + id="tmpfs-size", |
| 78 | + service=_tmpfs({"size": "1m"}), |
| 79 | + expected_argv=_mount("type=tmpfs,target=/data,tmpfs-size=1m"), |
| 80 | + ), |
| 81 | + Acceptance( |
| 82 | + id="tmpfs-mode", |
| 83 | + service=_tmpfs({"mode": 1777}), |
| 84 | + expected_argv=_mount("type=tmpfs,target=/data,tmpfs-mode=1777"), |
| 85 | + ), |
| 86 | + Acceptance( |
| 87 | + id="tmpfs-size-and-mode", |
| 88 | + service=_tmpfs({"size": "1m", "mode": 1777}), |
| 89 | + expected_argv=_mount("type=tmpfs,target=/data,tmpfs-size=1m,tmpfs-mode=1777"), |
| 90 | + ), |
| 91 | + Acceptance( |
| 92 | + id="bind-read-only", |
| 93 | + service={ |
| 94 | + "image": "busybox:1.36", |
| 95 | + "volumes": [{"type": "bind", "source": "./d", "target": "/data", "read_only": True}], |
| 96 | + }, |
| 97 | + expected_argv=_mount("type=bind,source={host}/d,target=/data,ro"), |
| 98 | + host_dir="d", |
| 99 | + ), |
| 100 | + Acceptance( |
| 101 | + id="volume-read-only", |
| 102 | + service={"image": "busybox:1.36", "volumes": [{"type": "volume", "target": "/data", "read_only": True}]}, |
| 103 | + expected_argv=_mount("type=volume,target=/data,ro"), |
| 104 | + ), |
| 105 | + Acceptance( |
| 106 | + id="service-tmpfs", |
| 107 | + service={"image": "busybox:1.36", "tmpfs": "/data"}, |
| 108 | + expected_argv=["--tmpfs", "/data"], |
| 109 | + ), |
| 110 | +] |
0 commit comments