fix(volumes): render a tmpfs size as the byte count compose demands

f85996b43a turned the tmpfs options into a dict so a declaration could carry a
mode as well as a size, and coerced the mode to the int docker expects. The size
sitting next to it kept being copied through verbatim. The short form accepts
"512m" and so does a human writing the declaration; the long form this renders
takes an integer and refuses the string rather than parsing it:

  services.checkmk.volumes.1.tmpfs.size must be a integer

That is the whole of Checkmk#0 in run 33317483326, and it stops the deploy before
the role does anything.

The suffix is resolved the way the mode already was, in a helper beside it, and
a value that is neither an int nor a byte count is refused instead of passed on
-- passing it on is what let "512m" reach compose in the first place.

The existing test asserted {"size": "64m"}, so it pinned the defect: the suite
stayed green while CI failed on it. It now asserts the byte count, every unit a
declaration may write resolves, and three malformed sizes raise.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
kevinveenbirkenbachandClaude Opus 5 committed 2026-08-31 01:17:54 +02:00
1 parent 1f870b1e57
commit 19a8580728
2 files changed
+71 -3

No files matched your search

@@ -122,7 +122,8 @@ class TestContainerVolumesConfigSecret(unittest.TestCase):
class TestContainerVolumesTmpfs(unittest.TestCase):
def test_tmpfs_renders_long_form_dict(self) -> None:
def test_tmpfs_size_renders_as_the_byte_count_the_long_form_takes(self) -> None:
"""Compose rejects "64m" outright: the long form takes an integer."""
meta = {
"scratch": {
"type": "tmpfs",
@@ -138,12 +139,48 @@ class TestContainerVolumesTmpfs(unittest.TestCase):
{
"type": "tmpfs",
"target": "/scratch",
"tmpfs": {"size": "64m"},
"tmpfs": {"size": 64 * 1024**2},
}
]
},
)
def test_every_unit_a_declaration_may_use_resolves(self) -> None:
for written, expected in (
("512m", 512 * 1024**2),
("64k", 64 * 1024),
("2g", 2 * 1024**3),
("900b", 900),
("900", 900),
(1024, 1024),
):
with self.subTest(size=written):
meta = {
"scratch": {
"type": "tmpfs",
"mounts": [
{"service": "app", "target": "/scratch", "size": written}
],
}
}
data = _parse(container_volumes(_apps(meta), "my-app", "app"))
self.assertEqual(expected, data["volumes"][0]["tmpfs"]["size"])
def test_a_size_that_is_not_a_byte_count_is_refused(self) -> None:
"""Silently passing it on is what let "512m" reach compose."""
for written in ("", "abc", "12x"):
with self.subTest(size=written):
meta = {
"scratch": {
"type": "tmpfs",
"mounts": [
{"service": "app", "target": "/scratch", "size": written}
],
}
}
with self.assertRaises(Exception): # noqa: B017 - the plugin raises an Ansible error type
container_volumes(_apps(meta), "my-app", "app")
def test_tmpfs_mode_renders_as_decimal_of_the_octal_string(self) -> None:
meta = {
"scratch": {