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

Proposed by Javier Collado
Status: Merged
Approved by: Javier Collado
Approved revision: 707
Merged at revision: 718
Proposed branch: lp:~javier.collado/utah/bug1055802
Merge into: lp:utah
Diff against target: 89 lines (+24/-4)
4 files modified
utah/client/common.py (+6/-1)
utah/client/exceptions.py (+8/-1)
utah/client/runner.py (+5/-1)
utah/client/testsuite.py (+5/-1)
To merge this branch: bzr merge lp:~javier.collado/utah/bug1055802
Reviewer Review Type Date Requested Status
Joe Talbott (community) Approve
Review via email: mp+128999@code.launchpad.net

Description of the change

This branch adds a new exception to detect when a yaml file is empty.

This exception is caught when parsing the ts_control file, to allow empty files.

The case for the file not being there at all was already covered.

I think that the testsuite module needs some refactoring. In particular, I found confusing what's
the _control data variable used for and why None is used as default value when an empty dictionary
could be more appropriate since that would remove the need to handle special cases.

To post a comment you must log in.
Revision history for this message
Joe Talbott (joetalbott) wrote :

Looks good to me.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'utah/client/common.py'
2--- utah/client/common.py 2012-10-10 14:44:00 +0000
3+++ utah/client/common.py 2012-10-10 17:25:23 +0000
4@@ -15,7 +15,10 @@
5 import yaml
6 import jsonschema
7
8-from utah.client.exceptions import YAMLParsingError
9+from utah.client.exceptions import (
10+ YAMLParsingError,
11+ YAMLEmptyFile,
12+ )
13
14
15 PASS = 0
16@@ -167,6 +170,8 @@
17 try:
18 with open(filename, 'r') as fp:
19 data = yaml.load(fp)
20+ if data is None:
21+ raise YAMLEmptyFile('Empty YAML file: {}'.format(filename))
22 except yaml.YAMLError as exception:
23 if hasattr(exception, 'problem_mark'):
24 mark = exception.problem_mark
25
26=== modified file 'utah/client/exceptions.py'
27--- utah/client/exceptions.py 2012-10-04 15:39:50 +0000
28+++ utah/client/exceptions.py 2012-10-10 17:25:23 +0000
29@@ -31,11 +31,18 @@
30
31 class YAMLParsingError(UTAHClientError):
32 """
33- Used to provided the filename and the location
34+ Used to provide the filename and the location
35 in which the parsing error happened when calling yaml.load
36 """
37
38
39+class YAMLEmptyFile(UTAHClientError):
40+ """
41+ Used to signal that a file that was supposed to contain yaml data
42+ is actually empty
43+ """
44+
45+
46 class ValidationError(UTAHClientError):
47 """
48 Used to provide additional information when schema validation fails
49
50=== modified file 'utah/client/runner.py'
51--- utah/client/runner.py 2012-10-10 14:44:00 +0000
52+++ utah/client/runner.py 2012-10-10 17:25:23 +0000
53@@ -424,7 +424,11 @@
54 # Fetch the testsuite. On resume don't remove the testsuite
55 # directory.
56 if not resume and os.path.exists(name):
57- shutil.rmtree(name)
58+ # Using absolute name makes no difference
59+ # except on failures where it's easier
60+ # to find troubleshoot permission problems
61+ absolute_name = os.path.abspath(name)
62+ shutil.rmtree(absolute_name)
63 if not os.path.exists(name):
64 os.mkdir(name)
65
66
67=== modified file 'utah/client/testsuite.py'
68--- utah/client/testsuite.py 2012-08-28 11:22:41 +0000
69+++ utah/client/testsuite.py 2012-10-10 17:25:23 +0000
70@@ -11,7 +11,7 @@
71 from .common import CMD_TS_BUILD, CMD_TS_SETUP, CMD_TS_CLEANUP
72 from .common import do_nothing
73 from .testcase import TestCase
74-from .exceptions import MissingFile, ValidationError
75+from .exceptions import MissingFile, ValidationError, YAMLEmptyFile
76
77
78 def parse_runlist_file(runlist_file):
79@@ -111,6 +111,10 @@
80 try:
81 control_data = parse_control_file(self.control_file,
82 self.CONTROL_SCHEMA)
83+ except YAMLEmptyFile:
84+ # Skip schema validation for empty file
85+ # Schema allows an empty dictionary, but not None
86+ control_data = None
87 except jsonschema.ValidationError as exception:
88 raise ValidationError(
89 '{!r} test suite control file invalid: {!r}\n'

Subscribers

People subscribed via source and target branches