#24 inventory: Place qcow2 and docker logs in artifacts directory
Merged 6 years ago by merlinm. Opened 6 years ago by stefw.
stefw/standard-test-roles artifacts-directory  into  master

@@ -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)

@@ -1,6 +1,7 @@ 

  #!/usr/bin/env python

  

  import argparse

+ import errno

  import json

  import os

  import shutil
@@ -133,7 +134,13 @@ 

      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),

The $TEST_ARTIFACTS directory is a place to put logs resulting
from the tests. Have the inventory scripts place their logs
there too.

Ugh. After merging PR #23, pagure is complaining about a merge conflict. @stefw, could you please rebase?

rebased

6 years ago

Thanks for the improvement. It works great for me.

Pull-Request has been merged by merlinm

6 years ago