From patchwork Thu Nov 17 17:34:15 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Larson X-Patchwork-Id: 5185 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id 45D0523E0E for ; Thu, 17 Nov 2011 17:34:18 +0000 (UTC) Received: from mail-fx0-f52.google.com (mail-fx0-f52.google.com [209.85.161.52]) by fiordland.canonical.com (Postfix) with ESMTP id 2C3FEA18608 for ; Thu, 17 Nov 2011 17:34:18 +0000 (UTC) Received: by faaa26 with SMTP id a26so5694008faa.11 for ; Thu, 17 Nov 2011 09:34:18 -0800 (PST) Received: by 10.152.135.179 with SMTP id pt19mr23762570lab.47.1321551257825; Thu, 17 Nov 2011 09:34:17 -0800 (PST) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.152.41.198 with SMTP id h6cs145710lal; Thu, 17 Nov 2011 09:34:17 -0800 (PST) Received: by 10.227.209.71 with SMTP id gf7mr16570848wbb.11.1321551255876; Thu, 17 Nov 2011 09:34:15 -0800 (PST) Received: from indium.canonical.com (indium.canonical.com. [91.189.90.7]) by mx.google.com with ESMTPS id x5si17310263wiw.49.2011.11.17.09.34.15 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 17 Nov 2011 09:34:15 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of bounces@canonical.com designates 91.189.90.7 as permitted sender) client-ip=91.189.90.7; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of bounces@canonical.com designates 91.189.90.7 as permitted sender) smtp.mail=bounces@canonical.com Received: from ackee.canonical.com ([91.189.89.26]) by indium.canonical.com with esmtp (Exim 4.71 #1 (Debian)) id 1RR5qp-000368-AX for ; Thu, 17 Nov 2011 17:34:15 +0000 Received: from ackee.canonical.com (localhost [127.0.0.1]) by ackee.canonical.com (Postfix) with ESMTP id 43E12E002F for ; Thu, 17 Nov 2011 17:34:15 +0000 (UTC) MIME-Version: 1.0 X-Launchpad-Project: lava-dispatcher X-Launchpad-Branch: ~linaro-validation/lava-dispatcher/trunk X-Launchpad-Message-Rationale: Subscriber X-Launchpad-Branch-Revision-Number: 160 X-Launchpad-Notification-Type: branch-revision To: Linaro Patch Tracker From: noreply@launchpad.net Subject: [Branch ~linaro-validation/lava-dispatcher/trunk] Rev 160: Add a --validate switch for using the dispatcher to validate the schema Message-Id: <20111117173415.29183.45215.launchpad@ackee.canonical.com> Date: Thu, 17 Nov 2011 17:34:15 -0000 Reply-To: noreply@launchpad.net Sender: bounces@canonical.com Errors-To: bounces@canonical.com Precedence: bulk X-Generated-By: Launchpad (canonical.com); Revision="14291"; Instance="launchpad-lazr.conf" X-Launchpad-Hash: 4d5edc8544e040e6f9abc8a52ffbdc26747be4c3 Merge authors: Michael Hudson-Doyle (mwhudson) Related merge proposals: https://code.launchpad.net/~mwhudson/lava-dispatcher/validate-job-files/+merge/82237 proposed by: Michael Hudson-Doyle (mwhudson) ------------------------------------------------------------ revno: 160 [merge] committer: Paul Larson branch nick: lava-dispatcher timestamp: Thu 2011-11-17 11:29:55 -0600 message: Add a --validate switch for using the dispatcher to validate the schema before running a job. modified: lava-dispatch lava_dispatcher/job.py requirements.txt setup.py --- lp:lava-dispatcher https://code.launchpad.net/~linaro-validation/lava-dispatcher/trunk You are subscribed to branch lp:lava-dispatcher. To unsubscribe from this branch go to https://code.launchpad.net/~linaro-validation/lava-dispatcher/trunk/+edit-subscription === modified file 'lava-dispatch' --- lava-dispatch 2011-11-14 00:52:45 +0000 +++ lava-dispatch 2011-11-14 04:45:54 +0000 @@ -24,12 +24,17 @@ import sys import logging.config +from linaro_json.schema import ValidationError + from lava_dispatcher.job import LavaTestJob from lava_dispatcher.config import get_config parser = optparse.OptionParser('%prog: lava-dispatch ') parser.add_option( "--oob-fd", default=None, type=int, help="Write OOB data to this fd.") +parser.add_option( + "--validate", action='store_true', + help="Just validate the job file, do not execute any steps.") (options, args) = parser.parse_args() @@ -59,4 +64,10 @@ job = LavaTestJob(jobdata, oob_file) #FIXME Return status -job.run() +if options.validate: + try: + job.validate() + except ValidationError as e: + print e +else: + job.run() === modified file 'lava_dispatcher/job.py' --- lava_dispatcher/job.py 2011-11-11 14:47:22 +0000 +++ lava_dispatcher/job.py 2011-11-15 01:44:45 +0000 @@ -23,12 +23,53 @@ import pexpect import traceback +from linaro_json.schema import Schema, Validator + from lava_dispatcher.actions import get_all_cmds from lava_dispatcher.client import CriticalError, GeneralError from lava_dispatcher.config import get_config from lava_dispatcher.context import LavaContext +job_schema = { + 'type': 'object', + 'additionalProperties': False, + 'properties': { + 'actions': { + 'items': { + 'properties': { + 'command': { + 'optional': False, + }, + 'parameters': { + 'optional': True, + }, + 'metadata': { + 'optional': True, + }, + }, + 'additionalProperties': False, + }, + }, + 'device_type': { + 'optional': True, + }, + 'job_name': { + 'optional': True, + }, + 'image_type': { + 'optional': True, + }, + 'target': { + 'optional': True, + }, + 'timeout': { + 'type': 'integer', + 'optional': False, + }, + }, + } + class LavaTestJob(object): def __init__(self, job_json, oob_file): self.job_status = 'pass' @@ -49,7 +90,19 @@ def image_type(self): return self.job_data.get('image_type') + def validate(self): + schema = Schema(job_schema) + validator = Validator() + validator.validate(schema, self.job_data) + + lava_commands = get_all_cmds() + for action in self.job_data['actions']: + command_name = action['command'] + if command_name not in lava_commands: + raise CriticalError("action %r not known" % command_name) + def run(self): + self.validate() lava_commands = get_all_cmds() if self.job_data['actions'][-1]['command'].startswith("submit_results"): === modified file 'requirements.txt' --- requirements.txt 2011-04-20 22:45:21 +0000 +++ requirements.txt 2011-11-14 04:24:37 +0000 @@ -4,5 +4,3 @@ python-openid lockfile python-daemon - - === modified file 'setup.py' --- setup.py 2011-11-11 14:38:21 +0000 +++ setup.py 2011-11-14 04:24:37 +0000 @@ -22,6 +22,7 @@ }, install_requires=[ "pexpect >= 2.3", + "json-schema-validator", ], setup_requires=[ 'versiontools >= 1.8',