From c9a5915432a6941369d35a9fa7b953c3adcb997b Mon Sep 17 00:00:00 2001 From: Stef Walter Date: Jul 19 2017 15:57:27 +0000 Subject: inventory: Place qcow2 and docker logs in artifacts directory The $TEST_ARTIFACTS directory is a place to put logs resulting from the tests. Have the inventory scripts place their logs there too. --- diff --git a/inventory/standard-inventory-docker b/inventory/standard-inventory-docker index b8854f2..aca3aec 100755 --- a/inventory/standard-inventory-docker +++ b/inventory/standard-inventory-docker @@ -1,6 +1,7 @@ #!/usr/bin/env python import argparse +import errno import json import os import shutil @@ -91,6 +92,9 @@ def host(image): except subprocess.CalledProcessError, ex: raise RuntimeError("Could not install Ansible dependencies in launched container") + # Directory to place artifacts + artifacts = os.environ.get("TEST_ARTIFACTS", os.path.join(os.getcwd(), "artifacts")) + # The variables variables = { "ansible_connection": "docker", @@ -125,12 +129,19 @@ def host(image): except OSError: break # Either of the processes no longer exist - # Kill the container + # Dump the container logs try: - subprocess.call(["/usr/bin/docker", "kill", name ], stdout=null) - subprocess.call(["/usr/bin/docker", "rm", "-f", name ], stdout=null) - except OSError: - pass + os.makedirs(artifacts) + except OSError as exc: + if exc.errno != errno.EEXIST or not os.path.isdir(artifacts): + raise + log = os.path.join(artifacts, "{0}.log".format(os.path.basename(image))) + + # Kill the container + with open(log, "w") as f: + subprocess.call(["/usr/bin/docker", "logs", name ], stdout=f.fileno()) + subprocess.call(["/usr/bin/docker", "kill", name ], stdout=null.fileno()) + subprocess.call(["/usr/bin/docker", "rm", "-f", name ], stdout=null) shutil.rmtree(directory) sys.exit(0) diff --git a/inventory/standard-inventory-qcow2 b/inventory/standard-inventory-qcow2 index 07cd277..9ac7def 100755 --- a/inventory/standard-inventory-qcow2 +++ b/inventory/standard-inventory-qcow2 @@ -1,6 +1,7 @@ #!/usr/bin/env python import argparse +import errno import json import os import shutil @@ -133,7 +134,13 @@ def host(image): sys.stderr.write("Launching virtual machine for {0}\n".format(image)) # And launch the actual VM - log = os.path.join(os.getcwd(), "{0}.log".format(os.path.basename(image))) + artifacts = os.environ.get("TEST_ARTIFACTS", os.path.join(os.getcwd(), "artifacts")) + try: + os.makedirs(artifacts) + except OSError as exc: + if exc.errno != errno.EEXIST or not os.path.isdir(artifacts): + raise + log = os.path.join(artifacts, "{0}.log".format(os.path.basename(image))) proc = subprocess.Popen(["/usr/bin/qemu-system-x86_64", "-m", "1024", image, "-enable-kvm", "-snapshot", "-cdrom", cloudinit, "-net", "nic,model=virtio", "-net", "user,hostfwd=tcp:127.0.0.3:{0}-:22".format(port),