| |
@@ -13,6 +13,7 @@
|
| |
import tempfile
|
| |
import time
|
| |
import traceback
|
| |
+ import distutils.util
|
| |
|
| |
IDENTITY = """
|
| |
-----BEGIN RSA PRIVATE KEY-----
|
| |
@@ -131,6 +132,12 @@
|
| |
"-volid", "cidata", "-joliet", "-rock", "-quiet",
|
| |
"-output", cloudinit, userdata, metadata], stdout=null)
|
| |
|
| |
+ # Determine if virtual machine should be kept available for diagnosis after completion
|
| |
+ try:
|
| |
+ diagnose = distutils.util.strtobool(os.getenv("TEST_DEBUG", "0"))
|
| |
+ except ValueError:
|
| |
+ diagnose = 0
|
| |
+
|
| |
sys.stderr.write("Launching virtual machine for {0}\n".format(image))
|
| |
|
| |
# And launch the actual VM
|
| |
@@ -214,6 +221,17 @@
|
| |
except OSError:
|
| |
break # Either of the processes no longer exist
|
| |
|
| |
+ if diagnose:
|
| |
+ sys.stderr.write("\n")
|
| |
+ sys.stderr.write("DIAGNOSE: ssh -p {0} -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null root@{1} # password: {2}\n".format(port, "127.0.0.3", "foobar"))
|
| |
+ sys.stderr.write("DIAGNOSE: kill {0} # when finished\n".format(os.getpid()))
|
| |
+
|
| |
+ def _signal_handler(*args):
|
| |
+ sys.stderr.write("\nDIAGNOSE ending...\n")
|
| |
+
|
| |
+ signal.signal(signal.SIGTERM, _signal_handler)
|
| |
+ signal.pause()
|
| |
+
|
| |
# Kill the qemu process
|
| |
try:
|
| |
os.kill(proc.pid, signal.SIGTERM)
|
| |
The inventory scripts do a very good job of cleaning up the containers and VMs when finished. Too good, in fact--which made it impossible to diagnose things going wrong inside the containers/VMs. With this PR, when the playbook finishes, if environment variable TEST_DIAGNOSE_INVENTORY is set to a true value, the inventory scripts will send diagnostic information to stderr and wait for an explicit signal before cleaning up.
For example: