From 516e915bcc2f23dfb512d5e238e504cd09ca910a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Ferr=C3=A3o?= <2031761+viniciusferrao@users.noreply.github.com> Date: Wed, 14 Oct 2026 01:00:19 -0300 Subject: [PATCH 1/5] test(genesis): exercise the NetworkManager wait-online policy --- xCAT-test/native/genesis_metadata.py | 52 ++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/xCAT-test/native/genesis_metadata.py b/xCAT-test/native/genesis_metadata.py index ca12ba1743..b45e4bc2b9 100644 --- a/xCAT-test/native/genesis_metadata.py +++ b/xCAT-test/native/genesis_metadata.py @@ -308,6 +308,58 @@ class GenesisMetadata(unittest.TestCase): with self.assertRaises(bb.process.ExecutionError): bb.build.exec_func("do_kernel_metadata", data, dirs=[data.getVar("WORKDIR")]) + def test_networkmanager_does_not_enable_wait_online(self): + def entries(file): + result = [] + section = None + for line in file.read_text().splitlines(): + line = line.strip() + if not line or line.startswith(("#", ";")): + continue + if line.startswith("[") and line.endswith("]"): + section = line[1:-1] + else: + self.assertIsNotNone(section) + key, value = line.split("=", 1) + result.append((section, key.strip(), value.strip())) + return result + + data = self.task_data("networkmanager") + # Preserve the recipe appends while replacing the external Meson installation. + data.setVar("do_install", 'cp -a "${WORKDIR}/meson-install/." "${D}/"\n', parsing=True) + root = Path(data.getVar("D")) + fixture = Path(data.getVar("WORKDIR")) / "meson-install" + sources = Path(data.getVar("UNPACKDIR")) + (sources / "networkmanager.initd").write_text("#!/bin/sh\nexit 0\n") + units = fixture / data.getVar("systemd_system_unitdir").lstrip("/") + units.mkdir(parents=True) + unit = units / "NetworkManager.service" + installed_unit = root / unit.relative_to(fixture) + rule = fixture / data.getVar("nonarch_base_libdir").lstrip("/") / "udev/rules.d/84-nm-drivers.rules" + rule.parent.mkdir(parents=True) + rule.touch() + expected = ("[Unit]\nDescription=NetworkManager fixture\n" + "[Service]\nExecStart=/usr/sbin/NetworkManager --no-daemon\n" + "[Install]\nWantedBy=multi-user.target\n" + "Alias=dbus-org.freedesktop.NetworkManager.service\n" + "Also=fixture-auxiliary.service\nAlso=fixture-second.service\n") + unit.write_text(expected) + expected_entries = entries(unit) + directive = "Also=NetworkManager-wait-online.service\n" + fixtures = { + "absent": expected, + "first": expected.replace("[Install]\n", "[Install]\n" + directive), + "last": expected + directive, + "repeated": expected + directive * 2, + } + for name, fixture_text in fixtures.items(): + with self.subTest(directive=name): + unit.write_text(fixture_text) + for unused in range(2): + bb.build.exec_func("do_install", data, dirs=[data.getVar("WORKDIR")]) + self.assertEqual(entries(installed_unit), expected_entries) + unit.write_bytes(installed_unit.read_bytes()) + def test_installed_network(self): data, root = self.install("xcat-genesis-network") file = self.installed(data, root, "sysconfdir", "NetworkManager/conf.d/10-xcat-genesis.conf", 0o644) From 2281b14a1325988a6ef05a9555878781edb55a04 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Ferr=C3=A3o?= <2031761+viniciusferrao@users.noreply.github.com> Date: Wed, 14 Oct 2026 01:03:11 -0300 Subject: [PATCH 2/5] test(genesis): exercise live console status and diagnostics --- xCAT-test/native/genesis_console_dialogs.py | 70 ++++++++++++++++++--- 1 file changed, 63 insertions(+), 7 deletions(-) diff --git a/xCAT-test/native/genesis_console_dialogs.py b/xCAT-test/native/genesis_console_dialogs.py index 1108c39a24..7f76679c1d 100644 --- a/xCAT-test/native/genesis_console_dialogs.py +++ b/xCAT-test/native/genesis_console_dialogs.py @@ -88,9 +88,20 @@ class ConsoleTerminal(unittest.TestCase): self.assertIsNone(self.process.poll(), display) self.fail(f"Terminal did not show {description}:\n{display}") + def assert_screen_stays(self, predicate, description, duration): + deadline = time.monotonic() + duration + while time.monotonic() < deadline: + display = self.read_screen(0.1) + self.assertTrue(predicate(display), f"{description}:\n{display}") + self.assertIsNone(self.process.poll(), display) + def key(self, sequence): os.write(self.master, sequence) + def visible_text(self, display): + return " ".join("".join(character if character.isascii() else " " + for character in display).split()) + class ConsoleDialogs(ConsoleTerminal): def test_help_and_diagnostics_scroll_close_and_reopen(self): @@ -108,15 +119,63 @@ class ConsoleDialogs(ConsoleTerminal): self.wait_text(first) self.wait_text(help_line) self.key(other_key) - self.assertIn(title, self.read_screen(0.2)) self.key(b"\x1b[6~" * 20) - self.wait_text(last) + self.assertIn(title, self.wait_text(last)) self.key(close_key) self.wait_text("Genesis status") self.wait_text("F1 Help") self.process.send_signal(signal.SIGTERM) self.assertEqual(self.process.wait(timeout=5), 0) + def publish(self, name, text): + target = self.root / name + target.parent.mkdir(parents=True, exist_ok=True) + temporary = target.with_suffix(".tmp") + temporary.write_text(text) + temporary.replace(target) + + def test_status_refresh_and_diagnostic_snapshot(self): + self.publish("response_file", "XCAT_NODE_NAME=updated-node\n") + self.assertRegex(self.wait_text("updated-node"), r"Node +updated-node") + self.publish("status_dir/action.env", "SCHEMA=1\nSTATE=RUNNING\n" + "DETAIL=Preparing test action\nUPDATED_SECONDS=100\n") + self.assertIn("RUNNING", self.wait_text("Preparing test action")) + self.key(b"\x1bOQ") + self.wait_text("Node: updated-node") + self.publish("response_file", "XCAT_NODE_NAME=short-node\n") + self.publish("status_dir/action.env", "SCHEMA=1\nSTATE=FAILED\n" + "DETAIL=Test action failed\nRECOVERY=Check test input\nUPDATED_SECONDS=101\n") + self.key(b"\x1b[6~" * 20) + self.wait_text("Provider names:") + self.key(b"\x1b[5~" * 20) + display = self.wait_text("Node: updated-node") + self.assertNotIn("short-node", display) + self.assert_screen_stays(lambda display: "Node: updated-node" in display + and "short-node" not in display, + "Diagnostics changed before reopening", 2) + self.key(b"\x1bOQ") + display = self.wait_text("Check test input") + self.assertRegex(display, r"Node +short-node +") + self.assertIn("FAILED", display) + self.assertIn("Test action failed", display) + self.assertNotIn("updated-node", display) + self.key(b"\x1bOQ") + self.wait_text("Node: short-node") + + def test_rendered_help_explains_read_only_pages_logs_and_shell(self): + self.key(b"\x1bOP") + display = self.wait_text("Screen fields") + text = self.visible_text(display) + self.assertIn("Status pages are read-only.", text) + self.assertIn("confirmed root maintenance shell", text) + self.key(b"\x1b[6~" * 20) + display = self.wait_text("Up and Down scroll this page.") + text = self.visible_text(display) + self.assertIn("F3 opens recent Genesis logs", text) + self.assertIn("press End to resume.", text) + self.assertIn("F12 asks before opening", text) + self.assertIn("Exit returns here.", text) + class ConsoleJournal(ConsoleTerminal): """Read real journal files in a private machine and journal namespace. @@ -189,11 +248,8 @@ class ConsoleJournal(ConsoleTerminal): f"selected log entry {text!r}") def assert_selection_stays(self, text): - deadline = time.monotonic() + 3 - while time.monotonic() < deadline: - self.read_screen(0.1) - self.assertEqual(self.selected_text(), text) - self.assertIsNone(self.process.poll()) + self.assert_screen_stays(lambda display: self.selected_text() == text, + "Selected journal entry changed", 3) def test_paused_entry_survives_history_rollover(self): self.write_journal([(f"RECORD-{number:04d}", "other.service", "xcat-genesis-register") From 385f641e03793ba2726ad4da001cfaa544e8b262 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Ferr=C3=A3o?= <2031761+viniciusferrao@users.noreply.github.com> Date: Fri, 16 Oct 2026 21:44:24 -0300 Subject: [PATCH 3/5] test(genesis): exercise journal follow and navigation --- xCAT-test/native/genesis_console_dialogs.py | 82 ++++++++++++++++++++- 1 file changed, 78 insertions(+), 4 deletions(-) diff --git a/xCAT-test/native/genesis_console_dialogs.py b/xCAT-test/native/genesis_console_dialogs.py index 7f76679c1d..43f78cf1d5 100644 --- a/xCAT-test/native/genesis_console_dialogs.py +++ b/xCAT-test/native/genesis_console_dialogs.py @@ -237,11 +237,14 @@ class ConsoleJournal(ConsoleTerminal): self.wait_text("Genesis logs") self.wait_text("F3 Back") + def selected_rows(self): + return ["".join(self.screen.buffer[row][column].data + for column in range(self.screen.columns) + if self.screen.buffer[row][column].bg == "red").strip() + for row in range(self.screen.lines)] + def selected_text(self): - return "\n".join("".join(self.screen.buffer[row][column].data - for column in range(self.screen.columns) - if self.screen.buffer[row][column].bg == "red").strip() - for row in range(self.screen.lines)).strip() + return "\n".join(self.selected_rows()).strip() def wait_selected(self, text): return self.wait_screen(lambda display: self.selected_text().endswith(text), @@ -343,6 +346,77 @@ class ConsoleJournal(ConsoleTerminal): self.key(b"\x1b[B") self.wait_selected("RECORD-0003") + def visible_entries(self): + return [message for message, unit, identifier in self.entries + if any(message in line for line in self.screen.display)] + + def assert_paused(self, text): + before = self.selected_rows() + self.assertIn(text, self.selected_text()) + self.assert_screen_stays(lambda display: self.selected_rows() == before, + "Paused journal selection moved", 5) + + def test_logs_follow_pause_and_reopen(self): + self.write_journal([ + ("FIRST", "xcat-genesis-register.service", "unit-fixture"), + ("TAIL", "other.service", "xcat-genesis-discovery"), + ]) + self.open_logs() + self.wait_selected("TAIL") + self.write_journal([("FOLLOWED", "other.service", "xcat-genesis-register")]) + self.wait_selected("FOLLOWED") + self.key(b"\x1b[H") + self.wait_selected("FIRST") + self.write_journal([("PAUSED", "other.service", "xcat-genesis-register")]) + self.wait_text("PAUSED") + self.assert_paused("FIRST") + self.key(b"\x1b[F") + self.wait_selected("PAUSED") + self.write_journal([("END-FOLLOWED", "other.service", "xcat-genesis-register")]) + self.wait_selected("END-FOLLOWED") + for index, close_key in enumerate((b"\x1bOR", b"\x1b")): + with self.subTest(close_key=close_key): + self.key(b"\x1b[H") + self.wait_selected("FIRST") + self.key(close_key) + self.wait_text("Genesis status") + self.open_logs() + self.wait_selected("END-FOLLOWED" if index == 0 else "REOPENED-0") + message = f"REOPENED-{index}" + self.write_journal([(message, "other.service", "xcat-genesis-register")]) + self.wait_selected(message) + + def test_logs_arrow_and_page_keys_pause_and_resume(self): + self.write_journal([(f"HISTORY-{number:03d}", "other.service", "xcat-genesis-register") + for number in range(40)]) + self.open_logs() + self.wait_selected("HISTORY-039") + for up, down in ((b"\x1b[A", b"\x1b[B"), (b"\x1b[5~", b"\x1b[6~")): + with self.subTest(up=up): + previous_tail = f"HISTORY-{len(self.entries) - 1:03d}" + if up == b"\x1b[A": + paused = f"HISTORY-{len(self.entries) - 2:03d}" + else: + visible = self.visible_entries() + self.assertGreater(len(visible), 2) + paused = visible[0] + self.key(up) + self.wait_selected(paused) + message = f"HISTORY-{len(self.entries):03d}" + self.write_journal([(message, "other.service", "xcat-genesis-register")]) + self.assert_paused(paused) + self.key(down) + self.wait_selected(previous_tail) + message = f"HISTORY-{len(self.entries):03d}" + self.write_journal([(message, "other.service", "xcat-genesis-register")]) + self.assert_paused(previous_tail) + self.key(down) + self.key(down) + self.wait_selected(message) + following = f"HISTORY-{len(self.entries):03d}" + self.write_journal([(following, "other.service", "xcat-genesis-register")]) + self.wait_selected(following) + def test_empty_journal(self): self.open_logs() self.wait_text("No Genesis journal entries are available.") From 8dab5e49891dce98019452ea79b682fcd216b684 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Ferr=C3=A3o?= <2031761+viniciusferrao@users.noreply.github.com> Date: Fri, 16 Oct 2026 21:51:02 -0300 Subject: [PATCH 4/5] test(genesis): exercise maintenance shell confirmation and return --- .github/workflows/genesis_openembedded.yml | 2 +- xCAT-test/native/genesis_console_dialogs.py | 132 ++++++++++++++++++-- 2 files changed, 123 insertions(+), 11 deletions(-) diff --git a/.github/workflows/genesis_openembedded.yml b/.github/workflows/genesis_openembedded.yml index 54b71d9d12..e025a4d766 100644 --- a/.github/workflows/genesis_openembedded.yml +++ b/.github/workflows/genesis_openembedded.yml @@ -22,7 +22,7 @@ jobs: sudo env DEBIAN_FRONTEND=noninteractive apt-get install -y \ build-essential meson ninja-build pkg-config libnewt-dev \ libsystemd-dev python3-pyte bubblewrap systemd-journal-remote - - name: Enable isolated journal test namespaces + - name: Enable isolated console test namespaces run: sudo sysctl -w kernel.apparmor_restrict_unprivileged_userns=0 - name: Exercise the newt dialogs run: /usr/bin/python3 xCAT-test/native/genesis_console_dialogs.py diff --git a/xCAT-test/native/genesis_console_dialogs.py b/xCAT-test/native/genesis_console_dialogs.py index 43f78cf1d5..16e65e693d 100644 --- a/xCAT-test/native/genesis_console_dialogs.py +++ b/xCAT-test/native/genesis_console_dialogs.py @@ -7,6 +7,7 @@ import os from pathlib import Path import pty import select +import shlex import signal import struct import subprocess @@ -61,6 +62,16 @@ class ConsoleTerminal(unittest.TestCase): def console_command(self): return [str(self.binary)] + def isolated_prefix(self, mounts): + command = ["bwrap", "--unshare-all", "--die-with-parent", "--ro-bind", "/", "/", + "--dev", "/dev", "--proc", "/proc", "--tmpfs", "/run", "--tmpfs", "/var/log", + *mounts] + result = subprocess.run(command + ["/bin/true"], text=True, + capture_output=True, timeout=10) + self.assertEqual(result.returncode, 0, + "Console tests require working Bubblewrap namespaces: " + result.stderr) + return command + def stop(self): if self.process.poll() is None: self.process.terminate() @@ -196,19 +207,12 @@ class ConsoleJournal(ConsoleTerminal): self.entries = [] machine_id_file = self.root / "machine-id" machine_id_file.write_text(self.machine_id + "\n") - sandbox = [ - "bwrap", "--unshare-all", "--die-with-parent", "--ro-bind", "/", "/", - "--dev", "/dev", "--proc", "/proc", "--tmpfs", "/run", "--tmpfs", "/var/log", + self.sandbox = self.isolated_prefix([ "--bind", str(self.root), str(self.root), "--ro-bind", str(machine_id_file), "/etc/machine-id", "--ro-bind", str(journal_root), "/var/log/journal", - ] - result = subprocess.run(sandbox + ["/bin/true"], text=True, - capture_output=True, timeout=10) - self.assertEqual(result.returncode, 0, - "Journal tests require working Bubblewrap namespaces: " + result.stderr) - self.sandbox = sandbox - return sandbox + [str(self.binary)] + ]) + return self.sandbox + [str(self.binary)] def write_journal(self, entries, interval=1000000): records = [] @@ -474,5 +478,113 @@ class ConsoleJournal(ConsoleTerminal): self.wait_text("RECORD-0129") +class ConsoleShell(ConsoleTerminal): + """Mount a fixture libexec directory containing the external shell launcher. + + The linked console still owns confirmation, fork/exec, waiting and redraw. + The per-test temporary root is the only writable host-backed directory. + The libexec mount is read-only. + /run and /var/log are private tmpfs mounts. + """ + + def console_command(self): + directory = self.root / "libexec" + (directory / "xcat").mkdir(parents=True) + self.launcher = directory / "xcat/genesis-maintenance-shell" + self.calls = self.root / "shell-calls" + self.input = self.root / "shell-input" + self.write_launcher(0) + return self.isolated_prefix([ + "--bind", str(self.root), str(self.root), + "--ro-bind", str(directory), "/usr/libexec", + ]) + [str(self.binary)] + + def write_launcher(self, exit_status): + self.launcher.write_text( + "#!/bin/sh\n" + f"printf '%s\\n' started >> {shlex.quote(str(self.calls))}\n" + "printf 'SHELL-RUNNING\\n'\n" + "IFS= read -r answer\n" + f"printf '%s\\n' \"$answer\" > {shlex.quote(str(self.input))}\n" + f"exit {exit_status}\n") + self.launcher.chmod(0o755) + + def shell_dialog_text(self, display): + lines = display.splitlines() + for row, line in enumerate(lines): + if "Maintenance shell" not in line: + continue + left, right = line.rfind("┌"), line.find("┐") + if left < 0 or right <= left: + continue + content = [] + for line in lines[row + 1:]: + if line[left:right + 1].startswith("└") and line[right] == "┘": + return self.visible_text("\n".join(content)) + content.append(line[left + 1:right]) + return "" + + def confirm_shell(self): + self.key(b"\x1b[24~") + display = self.wait_screen( + lambda text: "Open a root maintenance shell?" in self.shell_dialog_text(text), + "maintenance shell confirmation") + self.assertIn("Provisioning services continue in the background.", + self.shell_dialog_text(display)) + + def wait_main(self): + def is_main(display): + return ("Maintenance shell" not in display + and "SHELL-RUNNING" not in display + and "Genesis diagnostics" not in display + and "Genesis status" in display) + + self.wait_screen(is_main, "the restored status console") + self.assert_screen_stays(is_main, "The restored status console changed", 1) + + def test_cancel_does_not_launch_shell(self): + self.confirm_shell() + self.assertFalse(self.calls.exists()) + self.key(b"\t\r") + self.wait_main() + self.assertFalse(self.calls.exists()) + self.key(b"\x1bOP") + self.wait_text("Genesis help") + + def test_confirmed_shell_accepts_input_and_returns_to_console(self): + for count, exit_status in enumerate((0, 7), 1): + with self.subTest(launch=count, exit_status=exit_status): + self.write_launcher(exit_status) + self.confirm_shell() + self.assertEqual(self.calls.read_text() if self.calls.exists() else "", + "started\n" * (count - 1)) + self.key(b"\r") + self.wait_text("SHELL-RUNNING") + self.assertEqual(self.calls.read_text(), "started\n" * count) + self.key(f"operator-input-{count}\r".encode()) + self.wait_main() + self.assertEqual(self.input.read_text(), f"operator-input-{count}\n") + self.assertIsNone(self.process.poll()) + self.key(b"\x1bOQ") + self.wait_text("Genesis diagnostics") + self.key(b"\x1bOQ") + self.wait_main() + + def test_shell_exec_error_is_reported_and_console_recovers(self): + self.launcher.unlink() + self.confirm_shell() + self.key(b"\r") + display = self.wait_screen( + lambda text: "No such file or directory" in self.shell_dialog_text(text), + "the maintenance shell executable error") + self.assertIn("The maintenance shell could not be opened: No such file or directory", + self.shell_dialog_text(display)) + self.assertFalse(self.calls.exists()) + self.key(b"\r") + self.wait_main() + self.key(b"\x1bOP") + self.wait_text("Genesis help") + + if __name__ == "__main__": unittest.main(verbosity=2) From 32a98d6d997dd645487f3c5e26d216f596f2080f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Ferr=C3=A3o?= <2031761+viniciusferrao@users.noreply.github.com> Date: Fri, 16 Oct 2026 21:51:03 -0300 Subject: [PATCH 5/5] docs(test): describe Genesis policy and terminal coverage --- xCAT-test/native/README.md | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/xCAT-test/native/README.md b/xCAT-test/native/README.md index 4af5c8d7e3..b300996e19 100644 --- a/xCAT-test/native/README.md +++ b/xCAT-test/native/README.md @@ -247,6 +247,9 @@ permissions and an init process that reaps orphaned children. evaluate machine and package policy, install local-file recipes into temporary directories, generate extension manifests and reject invalid extension metadata. It does not extract or evaluate recipe source fragments. +The NetworkManager case supplies an installed-unit fixture and runs the +recipe's install append to check the wait-online policy. It does not verify +the unit format produced by an upstream NetworkManager build. The POWER patch case keeps BitBake's machine prepends and replaces only the upstream kernel task body with a no-op. It applies the real patch to a small metadata fixture, checks repeat runs and verifies that patch errors propagate. @@ -277,18 +280,27 @@ Meson, Ninja, pkg-config, and development packages for Newt and systemd. dependencies plus the `pyte` Python package, bubblewrap, systemd-journal-remote and journalctl. It runs the linked console in a pseudo-terminal and checks help and diagnostics navigation, scrolling, -return to the main screen, and F3 journal filtering, order and history limits. -Rollover cases check paused selection, expired entries, duplicate messages, -wrapped lines and returning to follow mode. +live status updates, diagnostic snapshots, and return to the main screen. +The F3 cases check journal filtering, order, history limits, follow mode, +paused selection, navigation and reopening. Rollover cases check expired +entries, duplicate messages and wrapped lines. The F12 cases check cancellation, +confirmation, terminal input, successful and nonzero exits, repeated launches +and executable errors. It checks termination from the main screen, not from inside a dialog. -The journal cases need working Linux user and mount namespaces. On Ubuntu -24.04, the CI job enables them with +The journal and shell cases need working Linux user and mount namespaces. +On Ubuntu 24.04, the CI job enables them with `sudo sysctl -w kernel.apparmor_restrict_unprivileged_userns=0`. -They import private journal files, including appends while F3 is open, and -verify each import with journalctl. They do not start a journal service or -read the host journal. Missing tools or namespace support fail the tests; -they do not skip. +The journal cases import private journal files, including appends while F3 +is open, and verify each import with journalctl. They do not start a journal +service or read the host journal. Missing tools or namespace support fail +the tests; they do not skip. +The shell cases mount a fixture directory over `/usr/libexec` in a private +namespace to replace the external shell launcher. The real console handles +confirmation, child execution, waiting and terminal restoration. +The per-test temporary root is the only writable host-backed directory. +The libexec mount is read-only. Other writable mounts are private. +The real maintenance shell is not run. The Genesis runtime BATS cases need Bash, Perl, OpenSSL, coreutils, diffutils and bubblewrap. The credential-file cases use a private `/etc` in a Linux