From decd843cd73a22fda776098bd73fdd75f5b5332c Mon Sep 17 00:00:00 2001 From: Ralph Bean Date: Jun 04 2016 19:52:03 +0000 Subject: [PATCH 1/2] Add a test of the runroot hub plugin. --- diff --git a/Makefile b/Makefile index beea79c..09db069 100644 --- a/Makefile +++ b/Makefile @@ -64,7 +64,7 @@ git-clean: @git clean -d -q -x test: - PYTHONPATH=hub/. nosetests --with-coverage --cover-package . + PYTHONPATH=hub/.:plugins/hub/. nosetests --with-coverage --cover-package . subdirs: for d in $(SUBDIRS); do make -C $$d; [ $$? = 0 ] || exit 1; done diff --git a/tests/test_plugins/__init__.py b/tests/test_plugins/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/tests/test_plugins/__init__.py diff --git a/tests/test_plugins/test_runroot_hub.py b/tests/test_plugins/test_runroot_hub.py new file mode 100644 index 0000000..97fd1cf --- /dev/null +++ b/tests/test_plugins/test_runroot_hub.py @@ -0,0 +1,22 @@ +import unittest +import mock + +import runroot_hub + + +class TestRunrootHub(unittest.TestCase): + @mock.patch('kojihub.make_task') + @mock.patch('runroot_hub.context') + def test_basic_invocation(self, context, make_task): + runroot_hub.runroot( + tagInfo='some_tag', + arch='x86_64', + command='ls', + ) + make_task.assert_called_once_with( + 'runroot', + ('some_tag', 'x86_64', 'ls'), + priority=15, + arch='x86_64', + channel='runroot', + ) From e329e5b7ecc1daecea201ba69b77a893158897af Mon Sep 17 00:00:00 2001 From: Ralph Bean Date: Jun 04 2016 19:52:25 +0000 Subject: [PATCH 2/2] Remove mktask in favor of make_task (and fix all references). --- diff --git a/hub/kojihub.py b/hub/kojihub.py index c88946c..2ea1689 100644 --- a/hub/kojihub.py +++ b/hub/kojihub.py @@ -568,17 +568,6 @@ def make_task(method,arglist,**opts): koji.plugin.run_callbacks('postTaskStateChange', attribute='state', old=None, new='FREE', info=opts) return task_id -def mktask(__taskopts,__method,*args,**opts): - """A wrapper around make_task with alternate signature - - Parameters: - _taskopts: a dictionary of task options (e.g. priority, ...) - _method: the method to be invoked - - All remaining args (incl. optional ones) are passed on to the task. - """ - return make_task(__method,koji.encode_args(*args,**opts),**__taskopts) - def eventCondition(event, table=None): """return the proper WHERE condition to select data at the time specified by event. """ if not table: diff --git a/plugins/hub/runroot_hub.py b/plugins/hub/runroot_hub.py index a666919..3238739 100644 --- a/plugins/hub/runroot_hub.py +++ b/plugins/hub/runroot_hub.py @@ -9,9 +9,9 @@ import koji import random import sys -#XXX - have to import kojihub for mktask +#XXX - have to import kojihub for make_task sys.path.insert(0, '/usr/share/koji-hub/') -from kojihub import mktask, get_tag, get_all_arches +import kojihub __all__ = ('runroot',) @@ -38,12 +38,12 @@ def runroot(tagInfo, arch, command, channel=None, **opts): if arch == 'noarch': #not all arches can generate a proper buildroot for all tags - tag = get_tag(tagInfo) + tag = kojihub.get_tag(tagInfo) if not tag['arches']: raise koji.GenericError, 'no arches defined for tag %s' % tag['name'] #get all known arches for the system - fullarches = get_all_arches() + fullarches = kojihub.get_all_arches() tagarches = tag['arches'].split() @@ -57,5 +57,6 @@ def runroot(tagInfo, arch, command, channel=None, **opts): % (tagInfo, taskopts['channel']) taskopts['arch'] = koji.canonArch(random.choice(choices)) - return mktask(taskopts,'runroot', tagInfo, arch, command, **opts) + args = koji.encode_args(tagInfo, arch, command,**opts) + return kojihub.make_task('runroot', args, **taskopts)