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

Proposed by Javier Collado
Status: Merged
Approved by: Max Brustkern
Approved revision: 856
Merged at revision: 853
Proposed branch: lp:~javier.collado/utah/bug1160247
Merge into: lp:utah
Diff against target: 127 lines (+14/-10)
8 files modified
debian/changelog (+1/-0)
examples/run_install_test.py (+1/-1)
examples/run_test_bamboo_feeder.py (+1/-1)
examples/run_test_cobbler.py (+1/-1)
examples/run_test_vm.py (+1/-1)
examples/run_utah_tests.py (+1/-1)
utah/cleanup.py (+1/-1)
utah/run.py (+7/-4)
To merge this branch: bzr merge lp:~javier.collado/utah/bug1160247
Reviewer Review Type Date Requested Status
Max Brustkern (community) Approve
Andy Doan (community) Approve
Review via email: mp+156878@code.launchpad.net

Description of the change

I haven't been able to reproduce the problem, but I've seen that the SIGTERM
handler was raising a UTAHException and that there are lots of places in which
`UTAHException`s might be caught. Hence, the handler has been updated to call
`sys.exit` which raises `SystemExit`.

In addition to this, to make sure that `SystemExit` isn't caught anywhere in
the code, the catch all except clauses like this:
except:

have been replaced with:
except Exception:

this ensures that all exception except `SystemExit` are caught, that is, when
SIGTERM is received the server process exits as soon as possible running any
cleanup code in the `finally` clauses that might be around.

To post a comment you must log in.
Revision history for this message
Andy Doan (doanac) :
review: Approve
Revision history for this message
Max Brustkern (nuclearbob) 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 'debian/changelog'
2--- debian/changelog 2013-04-03 09:45:19 +0000
3+++ debian/changelog 2013-04-03 15:00:38 +0000
4@@ -5,6 +5,7 @@
5 * Stop server on installation failure (LP: #1161855)
6 * Check group after command line argument parsing (LP: #1126219)
7 * Added INVALID_USER return code (LP: #1160032)
8+ * Use sys.exit when SIGTERM is received (LP: #1160247)
9
10 -- Javier Collado <javier.collado@canonical.com> Wed, 27 Mar 2013 13:00:47 +0100
11
12
13=== modified file 'examples/run_install_test.py'
14--- examples/run_install_test.py 2013-04-01 11:56:16 +0000
15+++ examples/run_install_test.py 2013-04-03 15:00:38 +0000
16@@ -82,7 +82,7 @@
17 except UTAHException as error:
18 sys.stderr.write('Exception: ' + str(error))
19 exitstatus = ReturnCodes.UTAH_EXCEPTION_ERROR
20- except:
21+ except Exception:
22 logging.exception('Unhandled error in UTAH')
23 exitstatus = ReturnCodes.UNHANDLED_ERROR
24 finally:
25
26=== modified file 'examples/run_test_bamboo_feeder.py'
27--- examples/run_test_bamboo_feeder.py 2013-04-01 11:56:16 +0000
28+++ examples/run_test_bamboo_feeder.py 2013-04-03 15:00:38 +0000
29@@ -89,7 +89,7 @@
30 except (AttributeError, NameError):
31 sys.stderr.write(mesg)
32 exitstatus = ReturnCodes.UTAH_EXCEPTION_ERROR
33- except:
34+ except Exception:
35 logging.exception('Unhandled error in UTAH')
36 exitstatus = ReturnCodes.UNHANDLED_ERROR
37 finally:
38
39=== modified file 'examples/run_test_cobbler.py'
40--- examples/run_test_cobbler.py 2013-04-01 11:56:16 +0000
41+++ examples/run_test_cobbler.py 2013-04-03 15:00:38 +0000
42@@ -94,7 +94,7 @@
43 except (AttributeError, NameError):
44 sys.stderr.write(mesg)
45 exitstatus = ReturnCodes.UTAH_EXCEPTION_ERROR
46- except:
47+ except Exception:
48 logging.exception('Unhandled error in UTAH')
49 exitstatus = ReturnCodes.UNHANDLED_ERROR
50 finally:
51
52=== modified file 'examples/run_test_vm.py'
53--- examples/run_test_vm.py 2013-04-01 11:56:16 +0000
54+++ examples/run_test_vm.py 2013-04-03 15:00:38 +0000
55@@ -76,7 +76,7 @@
56 except UTAHException as error:
57 sys.stderr.write('Exception: ' + str(error))
58 exitstatus = ReturnCodes.UTAH_EXCEPTION_ERROR
59- except:
60+ except Exception:
61 logging.exception('Unhandled error in UTAH')
62 exitstatus = ReturnCodes.UNHANDLED_ERROR
63 finally:
64
65=== modified file 'examples/run_utah_tests.py'
66--- examples/run_utah_tests.py 2013-04-01 11:56:16 +0000
67+++ examples/run_utah_tests.py 2013-04-03 15:00:38 +0000
68@@ -98,7 +98,7 @@
69 except UTAHException as error:
70 sys.stderr.write('Exception: ' + str(error))
71 exitstatus = ReturnCodes.UTAH_EXCEPTION_ERROR
72- except:
73+ except Exception:
74 logging.exception('Unhandled error in UTAH')
75 exitstatus = ReturnCodes.UNHANDLED_ERROR
76 finally:
77
78=== modified file 'utah/cleanup.py'
79--- utah/cleanup.py 2013-03-29 09:01:21 +0000
80+++ utah/cleanup.py 2013-04-03 15:00:38 +0000
81@@ -88,7 +88,7 @@
82 # process is completed as much as possible
83 try:
84 ProcessRunner(command)
85- except:
86+ except Exception:
87 self.logger.error('Cleanup error: {}'
88 .format(traceback.format_exc()))
89 finally:
90
91=== modified file 'utah/run.py'
92--- utah/run.py 2013-03-27 11:55:17 +0000
93+++ utah/run.py 2013-04-03 15:00:38 +0000
94@@ -18,12 +18,13 @@
95 """
96 import logging
97 import os
98-import time
99-import urllib
100-import traceback
101 import shutil
102 import signal
103 import socket
104+import sys
105+import time
106+import traceback
107+import urllib
108
109 from utah import config
110 from utah.exceptions import UTAHException
111@@ -41,6 +42,7 @@
112 TIMEOUT_ERROR = 2 # Unable to complete before config.jobtimeout seconds
113 GROUP_ERROR = 3 # User isn't in UTAH group
114 UNHANDLED_ERROR = 4 # Non UTAH exception caught
115+ SIGTERM_RECEIVED = 5 # SIGTERM signal received
116
117 @staticmethod
118 def client_error(returncode):
119@@ -372,7 +374,8 @@
120 """
121 def handler(signum, frame):
122 """Raise exception when signal is received."""
123- raise UTAHException('Signal received: {}'.format(signum))
124+ logging.warning('Signal received: %d', signum)
125+ sys.exit(ReturnCodes.SIGTERM_RECEIVED)
126
127 signal.signal(signal.SIGTERM, handler)
128

Subscribers

People subscribed via source and target branches