summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndy Doan <andy.doan@linaro.org>2016-02-25 14:49:29 -0600
committerStephen Finucane <stephen.finucane@intel.com>2016-02-26 19:16:54 +0000
commit602bffd75d123215bb4d1a8643943b739e762c36 (patch)
tree3eb8aafb1f4914f32cc375a722e5f930291f3881
parent5a31ec6e577bd36d50a2787832915ab51f062168 (diff)
downloadpatchwork-602bffd75d123215bb4d1a8643943b739e762c36.tar
patchwork-602bffd75d123215bb4d1a8643943b739e762c36.tar.gz
xmlrpc: Add a check_create function
This changes adds the ability to create Check objects via the XMLRPC interface. It includes a corresponding helper to the pwclient script. The command can be used like: pwclient check_create -c context1 -s success -u http://f.com \ -d "desc of check" PATCH_ID Signed-off-by: Andy Doan <andy.doan@linaro.org> Acked-by: Stephen Finucane <stephen.finucane@intel.com>
-rwxr-xr-xpatchwork/bin/pwclient28
-rw-r--r--patchwork/views/xmlrpc.py31
2 files changed, 57 insertions, 2 deletions
diff --git a/patchwork/bin/pwclient b/patchwork/bin/pwclient
index a271132..fdd9035 100755
--- a/patchwork/bin/pwclient
+++ b/patchwork/bin/pwclient
@@ -242,6 +242,13 @@ def action_checks(rpc):
print("%d (for '%s')" % (check['id'], check['patch']))
+def action_check_create(rpc, patch_id, context, state, url, description):
+ try:
+ rpc.check_create(patch_id, context, state, url, description)
+ except xmlrpclib.Fault as f:
+ sys.stderr.write("Error creating check: %s\n" % f.faultString)
+
+
def action_states(rpc):
states = rpc.state_list("", 0)
print("%-5s %s" % ("ID", "Name"))
@@ -366,7 +373,7 @@ def patch_id_from_hash(rpc, project, hash):
sys.exit(1)
return patch_id
-auth_actions = ['update']
+auth_actions = ['check_create', 'update']
def main():
@@ -473,6 +480,18 @@ def main():
help='''Show list of patch checks'''
)
checks_parser.set_defaults(subcmd='checks')
+ check_create_parser = subparsers.add_parser(
+ 'check-create', parents=[hash_parser], conflict_handler='resolve',
+ help='Add a check to a patch')
+ check_create_parser.set_defaults(subcmd='check_create')
+ check_create_parser.add_argument(
+ '-c', metavar='CONTEXT')
+ check_create_parser.add_argument(
+ '-s', choices=('pending', 'success', 'warning', 'fail'))
+ check_create_parser.add_argument(
+ '-u', metavar='TARGET_URL', default="")
+ check_create_parser.add_argument(
+ '-d', metavar='DESCRIPTION', default="")
states_parser = subparsers.add_parser(
'states',
help='''Show list of potential patch states'''
@@ -689,7 +708,7 @@ def main():
elif action.startswith('project'):
action_projects(rpc)
- elif action.startswith('check'):
+ elif action.startswith('checks'):
action_checks(rpc)
elif action.startswith('state'):
@@ -747,6 +766,11 @@ def main():
archived=archived_str, commit=commit_str
)
+ elif action == 'check_create':
+ for patch_id in non_empty(h, patch_ids):
+ action_check_create(
+ rpc, patch_id, args['c'], args['s'], args['u'], args['d'])
+
else:
sys.stderr.write("Unknown action '%s'\n" % action)
action_parser.print_help()
diff --git a/patchwork/views/xmlrpc.py b/patchwork/views/xmlrpc.py
index 2881afb..7ad34d8 100644
--- a/patchwork/views/xmlrpc.py
+++ b/patchwork/views/xmlrpc.py
@@ -959,6 +959,37 @@ def check_get(check_id):
return {}
+@xmlrpc_method(login_required=True)
+def check_create(user, patch_id, context, state, target_url="",
+ description=""):
+ """Add a Check to a patch.
+
+ **NOTE:** Authentication is required for this method.
+
+ Args:
+ patch_id (id): The ID of the patch to create the check against.
+ context: Type of test or system that generated this check.
+ state: "pending", "success", "warning", or "fail"
+ target_url: Link to artifact(s) relating to this check.
+ description: A brief description of the check.
+
+ Returns:
+ True, if successful else raise exception.
+ """
+ patch = Patch.objects.get(id=patch_id)
+ if not patch.is_editable(user):
+ raise Exception('No permissions to edit this patch')
+ for state_val, state_str in Check.STATE_CHOICES:
+ if state == state_str:
+ state = state_val
+ break
+ else:
+ raise Exception("Invalid check state: %s" % state)
+ Check.objects.create(patch=patch, context=context, state=state, user=user,
+ target_url=target_url, description=description)
+ return True
+
+
@xmlrpc_method()
def patch_check_get(patch_id):
"""Get a patch's combined checks by its ID.