diff options
author | Tony Asleson <tasleson@redhat.com> | 2023-03-09 11:27:19 -0600 |
---|---|---|
committer | Tony Asleson <tasleson@redhat.com> | 2023-03-10 12:51:53 -0600 |
commit | 9c3b91a513b70e74f21ca40e73f9ad7e3578ac48 (patch) | |
tree | 103512af7686e574e32013071b537acee855803a /test | |
parent | 9714f3ec4f3d4526a33781baf706c24930b6f26c (diff) | |
download | lvm2-9c3b91a513b70e74f21ca40e73f9ad7e3578ac48.tar.gz |
lvmdbustest: Shutdown cleanly with "exit"
Make the error injection wrapper handle the exit case, so that we can
clean up gracefully when instructed to do so.
Diffstat (limited to 'test')
-rwxr-xr-x | test/dbus/lvm_error_inject.py | 25 |
1 files changed, 20 insertions, 5 deletions
diff --git a/test/dbus/lvm_error_inject.py b/test/dbus/lvm_error_inject.py index 98520845c..d00b79b05 100755 --- a/test/dbus/lvm_error_inject.py +++ b/test/dbus/lvm_error_inject.py @@ -13,10 +13,12 @@ # systemctl restart lvm2-lvmdbusd import copy import json +import multiprocessing import os import pty import random import select +import signal import string import subprocess import sys @@ -29,6 +31,10 @@ from subprocess import Popen CS = string.ascii_letters + "\n\t " + string.digits +run = multiprocessing.Value('i', 1) + +SH = None + def rs(length, character_set=CS): return ''.join(random.choice(character_set) for _ in range(length)) @@ -253,10 +259,16 @@ class LvmShellHandler: self.report_text_in_progress = "" def _handle_command(self): + global run stdin_text = sys.stdin.readline() self.last_request = stdin_text debug("stdin: %s..." % stdin_text[:min(10, len(stdin_text) - 1)]) + + if "exit\n" in stdin_text: + debug("asking to exit ...") + run.value = 0 + self.parent_stdin.writelines(stdin_text) self.parent_stdin.flush() @@ -267,8 +279,9 @@ class LvmShellHandler: queue.extend(line) def run(self): + global run select_tmo = 0.2 - while True: + while run.value == 1: try: rd_fd = [sys.stdin.fileno(), self.parent_stdout_fd, self.parent_stderr_fd, self.child_report_fd] ready = select.select(rd_fd, [], [], select_tmo) @@ -305,9 +318,11 @@ class LvmShellHandler: break except IOError as ioe: debug("run_cmd:" + str(ioe)) - pass - debug("exiting %d " % self.process.returncode) + if self.process.poll() is not None: + debug("exiting %d " % self.process.returncode) + else: + debug("lvm process still running, be we are exiting ...") return self.process.returncode @@ -321,8 +336,8 @@ if __name__ == "__main__": cmdline.extend(args) ec = run_one(cmdline) else: - sh = LvmShellHandler(cmdline) - ec = sh.run() + SH = LvmShellHandler(cmdline) + ec = SH.run() sys.exit(ec) except Exception: traceback.print_exc(file=d_out) |