#52 standard-inventory-qcow2 hangs when `/dev/tty` cannot be openend
Closed: SOLVED Opened by larsu.

Ansible runs its inventory scripts with pipes attached to standard inputs and outputs. standard-inventory-qcow2 redirects qemu's stdout to /dev/null, but doesn't touch stderr, so it inherits the pipe, which gets closed in the call to dup2() later. However, if that call (or opening /dev/tty) fails, the pipe never gets closed and ansible hangs.

I've worked around this by redirecting qemu's stderr to /dev/null as well. In that case, we probably don't need to open /dev/tty at all, which seems to me to be a bit fragile anyway.

diff --git a/inventory/standard-inventory-qcow2 b/inventory/standard-inventory-qcow2
index bc202ee..b52f7bc 100755
--- a/inventory/standard-inventory-qcow2
+++ b/inventory/standard-inventory-qcow2
@@ -108,7 +108,7 @@ def start_qemu(image, cloudinit, log, portrange=(2222, 5555)):
         "-enable-kvm", "-snapshot", "-cdrom", cloudinit,
         "-net", "nic,model=virtio", "-net", "user,hostfwd=tcp:127.0.0.3:{0}-:22".format(port),
         "-device", "isa-serial,chardev=pts2", "-chardev", "file,id=pts2,path=" + log,
-        "-display", "none"], stdout=open(os.devnull, 'w')), port
+        "-display", "none"], stdout=open(os.devnull, 'w'), stderr=subprocess.STDOUT), port

This is exactly the reason for the change (and exactly the same fix) implemented by PR#47.

/dev/tty is opened so the inventory script can get diagnostic messages back to the interactive user if necessary--such as when TEST_DEBUG is enabled.

This is exactly the reason for the change (and exactly the same fix) implemented by PR#47.

Ah sorry, I missed that. Thanks for pointing it out.

/dev/tty is opened so the inventory script can get diagnostic messages back to the interactive user if necessary--such as when TEST_DEBUG is enabled.

But the fix in #47 suppresses diagnostic messages in every case, doesn't it?

PR#47 will cause stderr from just the invocation of qemu-system-x86_64 to be dropped. I actually have plans to make a future enhancement to the script to redirect that output to a logfile (along with other diagnostic/trace information), but I'm waiting until after the PR#39 work is completed to avoid extensive dependencies.

I've got the stderr=subprocess.STDOUT) in #39 BTW, just can't push b/c repo-problems :confounded:

Another thing I added to #39 is opening up a qemu-monitor port. There's a TON you can do with one of those, like retrieving status info, redirecting logs, and taking screen-shots. it's just a simple telnet interface, so almost trivial to hook into.

Fixed with: https://pagure.io/standard-test-roles/pull-request/47

Metadata Update from @astepano:
- Issue assigned to astepano

Metadata Update from @astepano:
- Issue close_status updated to: SOLVED
- Issue status updated to: Closed (was: Open)

Metadata