From 3a8df125c5fb964a84775f1295ae7245e2effc50 Mon Sep 17 00:00:00 2001 From: Kamil Páral Date: Mar 23 2017 08:55:23 +0000 Subject: koji_directive: always create target_dir Make sure target_dir is always created, even when no downloading is performed. That makes it simpler for subsequent scripts - they can just check whether a directory is empty, without also handling the case when the directory doesn't exist (which was not obvious before). Differential Revision: https://phab.qa.fedoraproject.org/D1175 --- diff --git a/libtaskotron/directives/koji_directive.py b/libtaskotron/directives/koji_directive.py index 848c6ae..edd7ca8 100644 --- a/libtaskotron/directives/koji_directive.py +++ b/libtaskotron/directives/koji_directive.py @@ -5,6 +5,13 @@ from __future__ import absolute_import +from libtaskotron.directives import BaseDirective +import libtaskotron.exceptions as exc +from libtaskotron.ext.fedora.koji_utils import KojiClient +from libtaskotron.ext.fedora import rpm_utils +from libtaskotron.logger import log +from libtaskotron import file_utils + DOCUMENTATION = """ module: koji_directive short_description: download builds and tags from Koji @@ -82,7 +89,7 @@ parameters: default: False target_dir: required: false - description: directory into which to download builds + description: directory into which to download builds. It gets created if it doesn't exist. type: str default: ${workdir} returns: | @@ -143,13 +150,6 @@ arches, but doesn't need ``noarch``:: """ -from libtaskotron.directives import BaseDirective -import libtaskotron.exceptions as exc -from libtaskotron.ext.fedora.koji_utils import KojiClient -from libtaskotron.ext.fedora import rpm_utils -from libtaskotron.logger import log - - directive_class = 'KojiDirective' @@ -170,11 +170,6 @@ class KojiDirective(BaseDirective): raise exc.TaskotronDirectiveError('%s is not a valid action for koji ' 'directive' % action) - if 'target_dir' not in params: - target_dir = arg_data['workdir'] - else: - target_dir = params['target_dir'] - if 'arch' not in params: detected_args = ', '.join(params.keys()) raise exc.TaskotronDirectiveError( @@ -195,6 +190,9 @@ class KojiDirective(BaseDirective): src = params.get('src', False) build_log = params.get('build_log', False) + target_dir = params.get('target_dir', arg_data['workdir']) + file_utils.makedirs(target_dir) + # download files output_data = {} diff --git a/testing/test_koji_directive.py b/testing/test_koji_directive.py index 1ca6eff..6fbddc0 100644 --- a/testing/test_koji_directive.py +++ b/testing/test_koji_directive.py @@ -6,6 +6,7 @@ from dingus import Dingus import pytest import mock +import os from libtaskotron.directives import koji_directive @@ -277,3 +278,17 @@ class TestKojiDirective(): assert retval['downloaded_logs'] == ref_get_bl_return['ok'] assert retval['log_errors'] == ref_get_bl_return['error'] + + def test_mkdir_targetdir(self, tmpdir): + rpmdir = tmpdir.join('rpmdir').strpath + self.ref_input = {'action': 'download', + 'arch': self.ref_arch, + 'koji_build': self.ref_nvr, + 'target_dir': rpmdir} + + stub_koji = Dingus(get_nvr_rpms__returns=self.ref_rpms) + test_helper = koji_directive.KojiDirective(stub_koji) + + assert not os.path.exists(rpmdir) + test_helper.process(self.ref_input, self.ref_arg_data) + assert os.path.isdir(rpmdir)