mirror of
https://github.com/systemd/systemd.git
synced 2025-02-14 05:57:40 +03:00
In mkosi, we run the test inside the VM instead of outside. To simplify the implementation we drop the reboot part and only verify that we can schedule and cancel shutdowns and that the wall messages are sent as expected.
59 lines
1.7 KiB
Python
Executable File
59 lines
1.7 KiB
Python
Executable File
#!/usr/bin/python3
|
|
# SPDX-License-Identifier: LGPL-2.1-or-later
|
|
# pylint: disable=broad-except
|
|
|
|
import logging
|
|
import sys
|
|
|
|
import pexpect
|
|
|
|
|
|
def main():
|
|
logger = logging.getLogger("test-shutdown")
|
|
|
|
consoles = []
|
|
for _ in range(2):
|
|
# Use script to allocate a separate pseudo tty to run the login shell in.
|
|
console = pexpect.spawn(
|
|
"script", ["--quiet", "--return", "--flush", "--command", "login -f root", "/dev/null"],
|
|
logfile=sys.stdout,
|
|
env={"TERM": "dumb"},
|
|
encoding="utf-8",
|
|
timeout=60,
|
|
)
|
|
|
|
logger.info("waiting for login prompt")
|
|
console.expect(".*# ", 10)
|
|
|
|
consoles += [console]
|
|
|
|
consoles[1].sendline("tty")
|
|
consoles[1].expect(r"/dev/(pts/\d+)")
|
|
pty = console.match.group(1)
|
|
logger.info("window 1 at tty %s", pty)
|
|
|
|
logger.info("schedule reboot")
|
|
consoles[1].sendline("shutdown -r")
|
|
consoles[1].expect("Reboot scheduled for (?P<date>.*), use 'shutdown -c' to cancel", 2)
|
|
date = consoles[1].match.group("date")
|
|
logger.info("reboot scheduled for %s", date)
|
|
|
|
logger.info("verify broadcast message")
|
|
consoles[0].expect(f"Broadcast message from root@H on {pty}", 2)
|
|
consoles[0].expect(f"The system will reboot at {date}!", 2)
|
|
|
|
logger.info("check show output")
|
|
consoles[1].sendline("shutdown --show")
|
|
consoles[1].expect(f"Reboot scheduled for {date}, use 'shutdown -c' to cancel", 2)
|
|
|
|
logger.info("cancel shutdown")
|
|
consoles[1].sendline("shutdown -c")
|
|
consoles[0].expect("System shutdown has been cancelled", 2)
|
|
|
|
consoles[0].sendline("> /testok")
|
|
|
|
if __name__ == "__main__":
|
|
main()
|
|
|
|
# vim: sw=4 et
|