| |
@@ -1,6 +1,7 @@
|
| |
#!/usr/bin/env python
|
| |
|
| |
import argparse
|
| |
+ import errno
|
| |
import json
|
| |
import os
|
| |
import shutil
|
| |
@@ -91,6 +92,9 @@
|
| |
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 @@
|
| |
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)
|
| |
The $TEST_ARTIFACTS directory is a place to put logs resulting
from the tests. Have the inventory scripts place their logs
there too.