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

Proposed by Javier Collado
Status: Merged
Approved by: Javier Collado
Approved revision: 851
Merged at revision: 850
Proposed branch: lp:~javier.collado/utah/bug1160032
Merge into: lp:utah
Diff against target: 90 lines (+13/-11)
3 files modified
client.py (+9/-11)
debian/changelog (+1/-0)
utah/client/common.py (+3/-0)
To merge this branch: bzr merge lp:~javier.collado/utah/bug1160032
Reviewer Review Type Date Requested Status
Javier Collado (community) Approve
Max Brustkern (community) Approve
Review via email: mp+156570@code.launchpad.net

Description of the change

A couple of return codes have been added to deal with the invalid user problem
described in the bug and also when an exception is caught.

I've found that argparse also returns its own return code when a parsing error
happens, but I'll create a separate bug for that since it affects both the
server and the client.

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

Looks good to me, as long as you've tested it.

review: Approve
Revision history for this message
Javier Collado (javier.collado) wrote :

Yes, I've tested it.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'client.py'
2--- client.py 2013-03-01 13:04:22 +0000
3+++ client.py 2013-04-02 14:03:31 +0000
4@@ -25,7 +25,10 @@
5 from utah.client.state_agent import StateAgentYAML
6 from utah.client.result import Result, ResultYAML, ResultJSON
7
8-from utah.client.common import DEFAULT_STATE_FILE
9+from utah.client.common import (
10+ DEFAULT_STATE_FILE,
11+ ReturnCodes,
12+)
13 from utah.client.exceptions import UTAHClientError
14
15
16@@ -73,11 +76,6 @@
17 return parser
18
19
20-def exit(returncode, msg):
21- print msg
22- sys.exit(returncode)
23-
24-
25 def setup_logging(debug=False):
26 if debug:
27 level = logging.DEBUG
28@@ -102,7 +100,7 @@
29 sys.stderr.write('{}: UTAH client is expected '
30 'to be executed as root user\n'
31 .format(parser.prog))
32- sys.exit(3)
33+ sys.exit(ReturnCodes.INVALID_USER)
34
35 setup_logging(args.debug)
36
37@@ -133,8 +131,8 @@
38 try:
39 sys.stdout = open(output, open_flags)
40 except IOError as e:
41- exit(e.errno, e)
42-
43+ sys.stderr.write(str(e))
44+ sys.exit(ReturnCodes.EXCEPTION_ERROR)
45 if args.format == 'text':
46 result_class = Result
47 elif args.format == 'json':
48@@ -154,8 +152,8 @@
49 returncode = runner.run()
50
51 except UTAHClientError as e:
52- errno = getattr(e, 'errno', 1)
53- exit(errno, e)
54+ sys.stderr.write(str(e))
55+ sys.exit(ReturnCodes.EXCEPTION_ERROR)
56
57 sys.exit(returncode)
58
59
60=== modified file 'debian/changelog'
61--- debian/changelog 2013-04-01 11:56:56 +0000
62+++ debian/changelog 2013-04-02 14:03:31 +0000
63@@ -4,6 +4,7 @@
64 * Remove temporary files downloaded based on URL (LP: #1101186)
65 * Stop server on installation failure (LP: #1161855)
66 * Check group after command line argument parsing (LP: #1126219)
67+ * Added INVALID_USER return code (LP: #1160032)
68
69 -- Javier Collado <javier.collado@canonical.com> Wed, 27 Mar 2013 13:00:47 +0100
70
71
72=== modified file 'utah/client/common.py'
73--- utah/client/common.py 2013-03-21 15:43:29 +0000
74+++ utah/client/common.py 2013-04-02 14:03:31 +0000
75@@ -63,12 +63,15 @@
76 # REBOOT: The system under test rebooted as required by a test case. To get
77 # final result the state file has to be checked.
78 # UNKNOWN: Unable to retrieve state file to check if client finished properly.
79+# INVALID_GROUP: The client was launched with a user other than root.
80 class ReturnCodes:
81 PASS = 0
82 FAIL = 1
83 ERROR = 2
84 REBOOT = 3
85 UNKNOWN = 4
86+ INVALID_USER = 5
87+ EXCEPTION_ERROR = 6
88
89 CMD_TC_BUILD = 'testcase_build'
90 CMD_TC_SETUP = 'testcase_setup'

Subscribers

People subscribed via source and target branches