Merge lp:~javier.collado/utah/bug1040015 into lp:utah

Proposed by Javier Collado
Status: Merged
Merged at revision: 666
Proposed branch: lp:~javier.collado/utah/bug1040015
Merge into: lp:utah
Diff against target: 195 lines (+74/-30)
5 files modified
client.py (+2/-4)
utah/client/exceptions.py (+38/-16)
utah/client/runner.py (+8/-2)
utah/client/testcase.py (+10/-3)
utah/client/testsuite.py (+16/-5)
To merge this branch: bzr merge lp:~javier.collado/utah/bug1040015
Reviewer Review Type Date Requested Status
Joe Talbott (community) Approve
UTAH Dev Pending
Review via email: mp+121586@code.launchpad.net

Description of the change

Added customized error messages for each validation error. That means that when a file fails to validate, the output in the client will show the filename and the test suite/case name together with the information that is already part of the backtrace.

Some examples:
Master runlist failed to validate: '/home/javi/code/bzr/utah/bug1040015/utah/client/examples/master.run'
Detailed information: 'testsuites' is a required property

'utah_tests' test suite runlist invalid: 'utah_tests/tslist.run'
Detailed information: 'test' is a required property

'test_one' test case control file invalid: 'utah_tests/test_one/tc_control'
Detailed information: 'description' is a required property

To post a comment you must log in.
Revision history for this message
Max Brustkern (nuclearbob) wrote :

This looks reasonable to me, but I think it wouldn't hurt to have Joe take a look since he wrote the YAML stuff to begin with.

Revision history for this message
Joe Talbott (joetalbott) wrote :

Looks okay to me.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'client.py'
--- client.py 2012-08-09 21:39:20 +0000
+++ client.py 2012-08-28 11:46:19 +0000
@@ -11,7 +11,7 @@
11from utah.client.result import Result, ResultYAML, ResultJSON11from utah.client.result import Result, ResultYAML, ResultJSON
1212
13from utah.client.common import DEFAULT_STATE_FILE13from utah.client.common import DEFAULT_STATE_FILE
14from utah.client import exceptions14from utah.client.exceptions import UTAHClientError
1515
1616
17def process_cmdline_argparse():17def process_cmdline_argparse():
@@ -126,9 +126,7 @@
126126
127 returncode = runner.run()127 returncode = runner.run()
128128
129 except (exceptions.BadDir,129 except UTAHClientError as e:
130 exceptions.MissingFile,
131 exceptions.YAMLParsingError) as e:
132 errno = getattr(e, 'errno', 1)130 errno = getattr(e, 'errno', 1)
133 exit(errno, e)131 exit(errno, e)
134132
135133
=== modified file 'utah/client/exceptions.py'
--- utah/client/exceptions.py 2012-08-02 18:36:14 +0000
+++ utah/client/exceptions.py 2012-08-28 11:46:19 +0000
@@ -1,20 +1,42 @@
1#!/usr/bin/python1"""
22UTAH client exceptions
33"""
4class BadDir(Exception):4
5 pass5
66class UTAHClientError(Exception):
77 """
8class MissingFile(Exception):8 Base class of all exceptions in the client
9 pass9 """
1010
1111
12class BadMasterRunlist(Exception):12class BadDir(UTAHClientError):
13 pass13 """
1414 Raised when some test directory isn't found
1515 or and error happens when trying to change to it
16class YAMLParsingError(Exception):16 """
17
18
19class MissingFile(UTAHClientError):
20 """
21 Raised when yaml file with metadata about tests
22 cannot be found
23 """
24
25
26class BadMasterRunlist(UTAHClientError):
27 """
28 Raised when master runlist isn't in the expected format
29 """
30
31
32class YAMLParsingError(UTAHClientError):
17 """33 """
18 Used to provided the filename and the location34 Used to provided the filename and the location
19 in which the parsing error happened when calling yaml.load35 in which the parsing error happened when calling yaml.load
20 """36 """
37
38
39class ValidationError(UTAHClientError):
40 """
41 Used to provide additional information when schema validation fails
42 """
2143
=== modified file 'utah/client/runner.py'
--- utah/client/runner.py 2012-08-21 21:34:06 +0000
+++ utah/client/runner.py 2012-08-28 11:46:19 +0000
@@ -3,8 +3,8 @@
3from result import Result3from result import Result
4from testsuite import TestSuite4from testsuite import TestSuite
5from state_agent import StateAgentYAML5from state_agent import StateAgentYAML
6
7import exceptions6import exceptions
7
8import os8import os
9import shutil9import shutil
10import stat10import stat
@@ -343,7 +343,13 @@
343 raise exceptions.MissingFile(runlist)343 raise exceptions.MissingFile(runlist)
344344
345 data = parse_yaml_file(local_filename)345 data = parse_yaml_file(local_filename)
346 jsonschema.validate(data, self.MASTER_RUNLIST_SCHEMA)346 try:
347 jsonschema.validate(data, self.MASTER_RUNLIST_SCHEMA)
348 except jsonschema.ValidationError as exception:
349 raise exceptions.ValidationError(
350 'Master runlist failed to validate: {!r}\n'
351 'Detailed information: {}'
352 .format(local_filename, exception))
347353
348 if 'timeout' in data:354 if 'timeout' in data:
349 self.timeout = int(data['timeout'])355 self.timeout = int(data['timeout'])
350356
=== modified file 'utah/client/testcase.py'
--- utah/client/testcase.py 2012-08-08 13:11:52 +0000
+++ utah/client/testcase.py 2012-08-28 11:46:19 +0000
@@ -1,11 +1,12 @@
1"""1"""
2Testcase specific code.2Testcase specific code.
3"""3"""
4import jsonschema
45
5from common import run_cmd, parse_control_file6from common import run_cmd, parse_control_file
6from common import do_nothing7from common import do_nothing
7from common import CMD_TC_BUILD, CMD_TC_SETUP, CMD_TC_TEST, CMD_TC_CLEANUP8from common import CMD_TC_BUILD, CMD_TC_SETUP, CMD_TC_TEST, CMD_TC_CLEANUP
8from exceptions import MissingFile9from exceptions import MissingFile, ValidationError
910
1011
11class TestCase(object):12class TestCase(object):
@@ -75,8 +76,14 @@
75 import os76 import os
76 if _control_data is None:77 if _control_data is None:
77 if os.path.exists(self.filename):78 if os.path.exists(self.filename):
78 control_data = parse_control_file(self.filename,79 try:
79 self.CONTROL_SCHEMA)80 control_data = parse_control_file(self.filename,
81 self.CONTROL_SCHEMA)
82 except jsonschema.ValidationError as exception:
83 raise ValidationError(
84 '{!r} test case control file invalid: {!r}\n'
85 'Detailed information: {}'
86 .format(self.name, self.filename, exception))
80 else:87 else:
81 raise MissingFile(self.filename)88 raise MissingFile(self.filename)
82 else:89 else:
8390
=== modified file 'utah/client/testsuite.py'
--- utah/client/testsuite.py 2012-08-16 21:41:30 +0000
+++ utah/client/testsuite.py 2012-08-28 11:46:19 +0000
@@ -11,8 +11,7 @@
11from .common import CMD_TS_BUILD, CMD_TS_SETUP, CMD_TS_CLEANUP11from .common import CMD_TS_BUILD, CMD_TS_SETUP, CMD_TS_CLEANUP
12from .common import do_nothing12from .common import do_nothing
13from .testcase import TestCase13from .testcase import TestCase
14from .exceptions import MissingFile14from .exceptions import MissingFile, ValidationError
15
1615
1716
18def parse_runlist_file(runlist_file):17def parse_runlist_file(runlist_file):
@@ -109,8 +108,14 @@
109 if _control_data is not None:108 if _control_data is not None:
110 control_data = _control_data109 control_data = _control_data
111 elif self.control_file is not None:110 elif self.control_file is not None:
112 control_data = parse_control_file(self.control_file,111 try:
113 self.CONTROL_SCHEMA)112 control_data = parse_control_file(self.control_file,
113 self.CONTROL_SCHEMA)
114 except jsonschema.ValidationError as exception:
115 raise ValidationError(
116 '{!r} test suite control file invalid: {!r}\n'
117 'Detailed information: {}'
118 .format(self.name, self.control_file, exception))
114119
115 if control_data is not None:120 if control_data is not None:
116 # already initialized121 # already initialized
@@ -122,7 +127,13 @@
122 if _runlist_data is not None:127 if _runlist_data is not None:
123 runlist_data = _runlist_data128 runlist_data = _runlist_data
124 elif os.path.exists(self.runlist_file):129 elif os.path.exists(self.runlist_file):
125 runlist_data = parse_runlist_file(self.runlist_file)130 try:
131 runlist_data = parse_runlist_file(self.runlist_file)
132 except jsonschema.ValidationError as exception:
133 raise ValidationError(
134 '{!r} test suite runlist invalid: {!r}\n'
135 'Detailed information: {}'
136 .format(self.name, self.runlist_file, exception))
126 else:137 else:
127 raise MissingFile('File not found: {}'.format(self.runlist_file))138 raise MissingFile('File not found: {}'.format(self.runlist_file))
128139

Subscribers

People subscribed via source and target branches