mirror of
https://github.com/systemd/systemd-stable.git
synced 2025-01-20 14:03:39 +03:00
0239991775
as it may take a bit longer on slower machines: ``` [ OK ] Reached target System Reboot. Found cgroup2 on /sys/fs/cgroup/, full unified hierarchy Failed to open watchdog device /dev/watchdog0, ignoring: No such file or directory binfmt_misc is not mounted, not detaching entries. Sending SIGTERM to remaining processes... ERROR:test-shutdown:Timeout exceeded. <pexpect.pty_spawn.spawn object at 0x7f3d4bcd20b0> command: /systemd-meson-build/systemd-nspawn <...snip...> buffer (last 100 chars): 'mbinfmt_misc is not mounted, not detaching entries.\x1b[0m\r\nSending SIGTERM to remaining processes...\r\n' before (last 100 chars): 'mbinfmt_misc is not mounted, not detaching entries.\x1b[0m\r\nSending SIGTERM to remaining processes...\r\n' after: <class 'pexpect.exceptions.TIMEOUT'> match: None match_index: None exitstatus: None flag_eof: False pid: 572528 child_fd: 5 closed: False timeout: 30 delimiter: <class 'pexpect.exceptions.EOF'> logfile: <_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'> logfile_read: None logfile_send: None maxread: 2000 ignorecase: False searchwindowsize: None delaybeforesend: 0.05 delayafterclose: 0.1 delayafterterminate: 0.1 searcher: searcher_re: 0: re.compile('H login: ') INFO:test-shutdown:killing child pid 572528 E: nspawn failed with exit code 1 ``` (cherry picked from commit 3e624bb13b18b241d00c8d375d5774acde25aa3f)
115 lines
3.1 KiB
Python
Executable File
115 lines
3.1 KiB
Python
Executable File
#!/usr/bin/python3
|
|
# SPDX-License-Identifier: LGPL-2.1-or-later
|
|
#
|
|
|
|
import argparse
|
|
import logging
|
|
import pexpect
|
|
import sys
|
|
|
|
|
|
def run(args):
|
|
|
|
ret = 1
|
|
logger = logging.getLogger("test-shutdown")
|
|
|
|
logger.info("spawning test")
|
|
console = pexpect.spawn(args.command, args.arg, env={
|
|
"TERM": "linux",
|
|
}, encoding='utf-8', timeout=30)
|
|
|
|
if args.verbose:
|
|
console.logfile = sys.stdout
|
|
|
|
logger.debug("child pid %d" % console.pid)
|
|
|
|
try:
|
|
logger.info("waiting for login prompt")
|
|
console.expect('H login: ', 10)
|
|
|
|
logger.info("log in and start screen")
|
|
console.sendline('root')
|
|
console.expect('bash.*# ', 10)
|
|
console.sendline('screen')
|
|
console.expect('screen0 ', 10)
|
|
console.sendcontrol('a')
|
|
console.send('c')
|
|
console.expect('screen1 ', 10)
|
|
|
|
# console.interact()
|
|
|
|
console.sendline('tty')
|
|
console.expect(r'/dev/(pts/\d+)')
|
|
pty = console.match.group(1)
|
|
logger.info("window 1 at line %s", pty)
|
|
|
|
logger.info("schedule reboot")
|
|
console.sendline('shutdown -r')
|
|
console.expect("Reboot scheduled for (?P<date>.*), use 'shutdown -c' to cancel", 2)
|
|
date = console.match.group('date')
|
|
logger.info("reboot scheduled for %s", date)
|
|
|
|
console.sendcontrol('a')
|
|
console.send('0')
|
|
logger.info("verify broadcast message")
|
|
console.expect('Broadcast message from root@H on %s' % pty, 2)
|
|
console.expect('The system is going down for reboot at %s' % date, 2)
|
|
|
|
logger.info("check show output")
|
|
console.sendline('shutdown --show')
|
|
console.expect("Reboot scheduled for %s, use 'shutdown -c' to cancel" % date, 2)
|
|
|
|
logger.info("cancel shutdown")
|
|
console.sendline('shutdown -c')
|
|
console.sendcontrol('a')
|
|
console.send('1')
|
|
console.expect('The system shutdown has been cancelled', 2)
|
|
|
|
logger.info("call for reboot")
|
|
console.sendline('sleep 10; shutdown -r now')
|
|
console.sendcontrol('a')
|
|
console.send('0')
|
|
console.expect("The system is going down for reboot NOW!", 12)
|
|
|
|
logger.info("waiting for reboot")
|
|
|
|
console.expect('H login: ', 30)
|
|
console.sendline('root')
|
|
console.expect('bash.*# ', 10)
|
|
|
|
console.sendline('> /testok')
|
|
|
|
logger.info("power off")
|
|
console.sendline('poweroff')
|
|
|
|
logger.info("expect termination now")
|
|
console.expect(pexpect.EOF)
|
|
|
|
ret = 0
|
|
except Exception as e:
|
|
logger.error(e)
|
|
logger.info("killing child pid %d" % console.pid)
|
|
console.terminate()
|
|
|
|
return ret
|
|
|
|
|
|
if __name__ == '__main__':
|
|
parser = argparse.ArgumentParser(description='test logind shutdown feature')
|
|
parser.add_argument("-v", "--verbose", action="store_true", help="verbose")
|
|
parser.add_argument("command", help="command to run")
|
|
parser.add_argument("arg", nargs='*', help="args for command")
|
|
|
|
args = parser.parse_args()
|
|
|
|
if args.verbose:
|
|
level = logging.DEBUG
|
|
else:
|
|
level = logging.INFO
|
|
|
|
logging.basicConfig(level=level)
|
|
|
|
sys.exit(run(args))
|
|
|
|
# vim: sw=4 et
|