The hooks can now use their process_testdata method to check the
correctness of provided options and arguments and abort the program if
something is wrong. It also allows hooks to have some mandatory options
defined.
---
autoqa | 10 ++++------
hooks/post-bodhi-update/README | 10 +++++-----
hooks/post-bodhi-update/hook.py | 15 ++++++++++++---
hooks/post-koji-build/README | 6 ++++--
hooks/post-koji-build/hook.py | 22 +++++++++++++++++-----
hooks/post-koji-build/watch-koji-builds.py | 1 -
hooks/post-repo-update/README | 13 ++++++-------
hooks/post-repo-update/hook.py | 10 ++++++++--
hooks/post-tree-compose/README | 11 ++++++-----
hooks/post-tree-compose/hook.py | 10 ++++++++--
10 files changed, 70 insertions(+), 38 deletions(-)
diff --git a/autoqa b/autoqa
index a718e49..8fd7dee 100755
--- a/autoqa
+++ b/autoqa
@@ -228,10 +228,6 @@ hook.extend_parser(parser)
(opts, args) = parser.parse_args()
args.pop(0) # dump hookname
-# Bail out if we didn't get at least one argument
-if not args:
- parser.error('No test argument given - nothing to test!')
-
# Run the tests locally, or schedule them through autotest?
run_local = (opts.local or (conf['local'].lower() == 'true'))
@@ -248,8 +244,10 @@ if opts.autotest_server:
conf['autotest_server'] = opts.autotest_server
# Ask hook to determine all arguments needed for tests. These variables will
-# be then written into the control file as autoqa_args dictionary.
-autoqa_args = hook.process_testdata(opts, args)
+# be then written into the control file as autoqa_args dictionary. The hook can
+# also call parser.error if it find out that not all options are correctly
+# populated.
+autoqa_args = hook.process_testdata(parser, opts, args)
# The test may also need the very name of the hook that executes it
autoqa_args['hook'] = hookname
diff --git a/hooks/post-bodhi-update/README b/hooks/post-bodhi-update/README
index 449bc5b..5b596e0 100644
--- a/hooks/post-bodhi-update/README
+++ b/hooks/post-bodhi-update/README
@@ -6,14 +6,14 @@ previously released version, checking for dependency problems, and
the like.
The required arguments are:
- --targettag - the koji tag of the target repo (e.g. f13-updates-testing)
+ --targettag: the koji tag of the target repo (e.g. dist-f13-updates)
plus one of:
- --updateid - the bodhi-provided Update ID for this update, or
- --title - the title of the update
+ --updateid: the bodhi-provided Update ID for this update, or
+ --title: the title of the update
and finally a list of the ENVRs of the package builds in this update.
AutoQA tests can expect the following variables from post-bodhi-update hook:
- name: title of the update request
- id: Unique ID of the update request (may be empty)
+ name: title of the update request (one of 'name' or 'id' may be empty)
+ id: Unique ID of the update request (one of 'name' or 'id' may be
empty)
kojitag: target koji tag for this update
envrs: list of package envrs in this update request
diff --git a/hooks/post-bodhi-update/hook.py b/hooks/post-bodhi-update/hook.py
index c203739..f4dd355 100644
--- a/hooks/post-bodhi-update/hook.py
+++ b/hooks/post-bodhi-update/hook.py
@@ -33,14 +33,23 @@ def extend_parser(parser):
help='Unique update ID for this update')
group.add_option('--targettag', '--target-tag', default='',
help='Target Koji tag for this update')
- # TODO require one of --updateid or --targettag somehow
parser.add_option_group(group)
return parser
-def process_testdata(opts, args, **extra):
+def process_testdata(parser, opts, args, **extra):
'''Given an optparse.Values object and a list of args (as returned from
OptionParser.parse_args()), return a dict containing the appropriate key=val
- pairs required by test's control files and test object.'''
+ pairs required by test's control files and test object. The hook can also
+ call parser.error here if it find out that not all options are correctly
+ populated.'''
+
+ if not args:
+ parser.error('No ENVR was specified as a test argument!')
+ if not opts.title:
+ parser.error('--title is a mandatory option!')
+ if not opts.updateid and not opts.targettag:
+ parser.error('At least one of --updateid or --targettag must be
supplied!')
+
testdata = {'envrs': args,
'kojitag': opts.targettag,
'id': opts.updateid,
diff --git a/hooks/post-koji-build/README b/hooks/post-koji-build/README
index 5cc8844..2989bb9 100644
--- a/hooks/post-koji-build/README
+++ b/hooks/post-koji-build/README
@@ -3,9 +3,11 @@ This hook is for scripts that run after a package is built in koji.
These tests usually do things like comparing the new package to the old package
to ensure the changes are reasonable, simple functional tests, etc.
-The required argument for autoqa is ENVR of the package to be tested.
+The required arguments are:
+ --kojitag: the koji tag applied to the new build (e.g. dist-f14-updates-candidate)
+and finally the ENVR of the package build to be tested.
AutoQA tests can expect the following variables from post-koji-build hook:
- envr: package ENVR (required, epoch can be skipped if 0)
+ envr: package ENVR (epoch may be skipped if 0)
name: package name
kojitag: koji tag applied to this package
diff --git a/hooks/post-koji-build/hook.py b/hooks/post-koji-build/hook.py
index 87ced2e..af29b59 100644
--- a/hooks/post-koji-build/hook.py
+++ b/hooks/post-koji-build/hook.py
@@ -20,6 +20,7 @@
# Will Woods <wwoods(a)redhat.com>
import optparse
+import rpmUtils.miscutils
name = 'post-koji-build'
@@ -29,14 +30,25 @@ def extend_parser(parser):
group = optparse.OptionGroup(parser, '%s options' % name)
group.add_option('-k', '--kojitag', default='',
help='Koji tag that has just been applied to this new build')
- group.add_option('-n', '--name', default='',
- help='The name of the package, by itself')
parser.add_option_group(group)
return parser
-def process_testdata(opts, args, **extra):
+def process_testdata(parser, opts, args, **extra):
'''Given an optparse.Values object and a list of args (as returned from
OptionParser.parse_args()), return a dict containing the appropriate key=val
- pairs required by test's control files and test object.'''
- testdata = {'envr': args[0], 'kojitag': opts.kojitag, 'name':
opts.name}
+ pairs required by test's control files and test object. The hook can also
+ call parser.error here if it find out that not all options are correctly
+ populated.'''
+
+ if not args:
+ parser.error('No ENVR was specified as a test argument!')
+ if not opts.kojitag:
+ parser.error('--kojitag is a mandatory option!')
+
+ # parse name from ENVR
+ envr = args[0]
+ nvrea = rpmUtils.miscutils.splitFilename(envr + '.noarch')
+ name = nvrea[0]
+
+ testdata = {'envr': envr, 'kojitag': opts.kojitag, 'name':
name}
return testdata
diff --git a/hooks/post-koji-build/watch-koji-builds.py
b/hooks/post-koji-build/watch-koji-builds.py
index 43369f6..56a093f 100755
--- a/hooks/post-koji-build/watch-koji-builds.py
+++ b/hooks/post-koji-build/watch-koji-builds.py
@@ -140,7 +140,6 @@ tags for new builds and kick off tests when new builds/packages are
found.')
# Get a list of all package arches in this build
arches = [r['arch'] for r in
session.listRPMs(b['build_id'])]
harnesscall = ['autoqa', 'post-koji-build',
- '--name', b['name'],
'--kojitag', tag]
# Invoke autoqa with an --arch arg for each arch we care about
diff --git a/hooks/post-repo-update/README b/hooks/post-repo-update/README
index 9b4a0ce..1adb2ba 100644
--- a/hooks/post-repo-update/README
+++ b/hooks/post-repo-update/README
@@ -4,13 +4,12 @@ This hook is for tests that run after a repo has changed. A repo is
considered
The required argument for autoqa is a yum-compatible URL (probably http) that
points to the changed repo.
-Some tests (e.g. repoclosure) need a list of "parent" repos to run properly.
-You can specify these by doing '--parent URL1 --parent URL2 ...'
-
-Any instances of '%a' in the URLs will be replaced by one of the listed
-arches when the tests are actually run.
+Optional arguments:
+ --name: human readable name for the repo under test
+ --parent: a repo URL that is "parent" to the the repo under test; may be
+ specified multiple times
AutoQA tests can expect the following variables from post-repo-update hook:
baseurl: url of repo that changed
- parents: list of urls for 'parent' repos of the given repo
- name: name for repo that changed, may be empty
+ parents: list of urls for 'parent' repos of the given repo (may be empty)
+ name: name for repo that changed (may be empty)
diff --git a/hooks/post-repo-update/hook.py b/hooks/post-repo-update/hook.py
index cd63152..2cfb7fd 100644
--- a/hooks/post-repo-update/hook.py
+++ b/hooks/post-repo-update/hook.py
@@ -34,10 +34,16 @@ def extend_parser(parser):
parser.add_option_group(group)
return parser
-def process_testdata(opts, args, **extra):
+def process_testdata(parser, opts, args, **extra):
'''Given an optparse.Values object and a list of args (as returned from
OptionParser.parse_args()), return a dict containing the appropriate key=val
- pairs required by test's control files and test object.'''
+ pairs required by test's control files and test object. The hook can also
+ call parser.error here if it find out that not all options are correctly
+ populated.'''
+
+ if not args:
+ parser.error('No repo URL was specified as a test argument!')
+
testdata = {'baseurl': args[0],
'parents': opts.parent,
'name': opts.name or ''}
diff --git a/hooks/post-tree-compose/README b/hooks/post-tree-compose/README
index 8707b84..1189dab 100644
--- a/hooks/post-tree-compose/README
+++ b/hooks/post-tree-compose/README
@@ -3,13 +3,14 @@ case, means that the tree contains a usable package repo, boot/install
images,
and metadata (e.g. .treeinfo).
These tests usually do things like check integrity of the install images,
-attempt boot tests, etc.
+attempt boot tests, etc. For best results, the HTTP/FTP server should be
+connected to the test system by a very fast link.
-The required argument to autoqa is a HTTP OR FTP URL to the newly-built tree.
+The required argument to autoqa is a HTTP or FTP URL to the newly-built tree.
-For best results, the HTTP/FTP server should be connected to the test system by
-a very fast link.
+Optional arguments:
+ --name: human readable name for the tree under test
AutoQA tests can expect the following variables from post-tree-compose hook:
baseurl: url of the new tree
- name: name for the new tree, may be empty
+ name: name for the new tree (may be empty)
diff --git a/hooks/post-tree-compose/hook.py b/hooks/post-tree-compose/hook.py
index c71f594..0e6f12b 100644
--- a/hooks/post-tree-compose/hook.py
+++ b/hooks/post-tree-compose/hook.py
@@ -20,10 +20,16 @@ def extend_parser(parser):
parser.add_option_group(group)
return parser
-def process_testdata(opts, args, arch, **extra):
+def process_testdata(parser, opts, args, **extra):
'''Given an optparse.Values object and a list of args (as returned from
OptionParser.parse_args()), return a dict containing the appropriate key=val
- pairs required by test's control files and test object.'''
+ pairs required by test's control files and test object. The hook can also
+ call parser.error here if it find out that not all options are correctly
+ populated.'''
+
+ if not args:
+ parser.error('No tree URL was specified as a test argument!')
+
testdata = {'baseurl': args[0],
'name': opts.name or ''}
return testdata
--
1.7.2.1