=== modified file 'lava-dispatch'
@@ -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 <json job file>')
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'
@@ -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'
@@ -4,5 +4,3 @@
python-openid
lockfile
python-daemon
-
-
=== modified file 'setup.py'
@@ -22,6 +22,7 @@
},
install_requires=[
"pexpect >= 2.3",
+ "json-schema-validator",
],
setup_requires=[
'versiontools >= 1.8',