From 3a53b78063f0eb88bbbe966650e9a332b61247e0 Mon Sep 17 00:00:00 2001 From: Stef Walter Date: Mon, 21 Aug 2017 16:59:40 +0200 Subject: [PATCH] tests: Make sure the log directory exists In the qemu_provision module, make sure the log directory exists before trying to write to it. --- tests/library/qemu_provision.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/library/qemu_provision.py b/tests/library/qemu_provision.py index 1e776a1..049557c 100644 --- a/tests/library/qemu_provision.py +++ b/tests/library/qemu_provision.py @@ -109,6 +109,14 @@ def main(argv): "-output", cloudinit, userdata, metadata], stdout=null) log = module.params.get("log") or os.devnull + artifacts = os.path.dirname(log) + + # Make sure the log directory exists + try: + os.makedirs(artifacts) + except OSError as exc: + if exc.errno != errno.EEXIST or not os.path.isdir(artifacts): + raise inventory = os.path.join(directory, "inventory") with open(inventory, 'w') as f: