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
=== modified file 'debian/changelog'
--- debian/changelog 2013-04-03 09:45:19 +0000
+++ debian/changelog 2013-04-03 15:00:38 +0000
@@ -5,6 +5,7 @@
5 * Stop server on installation failure (LP: #1161855)5 * Stop server on installation failure (LP: #1161855)
6 * Check group after command line argument parsing (LP: #1126219)6 * Check group after command line argument parsing (LP: #1126219)
7 * Added INVALID_USER return code (LP: #1160032)7 * Added INVALID_USER return code (LP: #1160032)
8 * Use sys.exit when SIGTERM is received (LP: #1160247)
89
9 -- Javier Collado <javier.collado@canonical.com> Wed, 27 Mar 2013 13:00:47 +010010 -- Javier Collado <javier.collado@canonical.com> Wed, 27 Mar 2013 13:00:47 +0100
1011
1112
=== modified file 'examples/run_install_test.py'
--- examples/run_install_test.py 2013-04-01 11:56:16 +0000
+++ examples/run_install_test.py 2013-04-03 15:00:38 +0000
@@ -82,7 +82,7 @@
82 except UTAHException as error:82 except UTAHException as error:
83 sys.stderr.write('Exception: ' + str(error))83 sys.stderr.write('Exception: ' + str(error))
84 exitstatus = ReturnCodes.UTAH_EXCEPTION_ERROR84 exitstatus = ReturnCodes.UTAH_EXCEPTION_ERROR
85 except:85 except Exception:
86 logging.exception('Unhandled error in UTAH')86 logging.exception('Unhandled error in UTAH')
87 exitstatus = ReturnCodes.UNHANDLED_ERROR87 exitstatus = ReturnCodes.UNHANDLED_ERROR
88 finally:88 finally:
8989
=== modified file 'examples/run_test_bamboo_feeder.py'
--- examples/run_test_bamboo_feeder.py 2013-04-01 11:56:16 +0000
+++ examples/run_test_bamboo_feeder.py 2013-04-03 15:00:38 +0000
@@ -89,7 +89,7 @@
89 except (AttributeError, NameError):89 except (AttributeError, NameError):
90 sys.stderr.write(mesg)90 sys.stderr.write(mesg)
91 exitstatus = ReturnCodes.UTAH_EXCEPTION_ERROR91 exitstatus = ReturnCodes.UTAH_EXCEPTION_ERROR
92 except:92 except Exception:
93 logging.exception('Unhandled error in UTAH')93 logging.exception('Unhandled error in UTAH')
94 exitstatus = ReturnCodes.UNHANDLED_ERROR94 exitstatus = ReturnCodes.UNHANDLED_ERROR
95 finally:95 finally:
9696
=== modified file 'examples/run_test_cobbler.py'
--- examples/run_test_cobbler.py 2013-04-01 11:56:16 +0000
+++ examples/run_test_cobbler.py 2013-04-03 15:00:38 +0000
@@ -94,7 +94,7 @@
94 except (AttributeError, NameError):94 except (AttributeError, NameError):
95 sys.stderr.write(mesg)95 sys.stderr.write(mesg)
96 exitstatus = ReturnCodes.UTAH_EXCEPTION_ERROR96 exitstatus = ReturnCodes.UTAH_EXCEPTION_ERROR
97 except:97 except Exception:
98 logging.exception('Unhandled error in UTAH')98 logging.exception('Unhandled error in UTAH')
99 exitstatus = ReturnCodes.UNHANDLED_ERROR99 exitstatus = ReturnCodes.UNHANDLED_ERROR
100 finally:100 finally:
101101
=== modified file 'examples/run_test_vm.py'
--- examples/run_test_vm.py 2013-04-01 11:56:16 +0000
+++ examples/run_test_vm.py 2013-04-03 15:00:38 +0000
@@ -76,7 +76,7 @@
76 except UTAHException as error:76 except UTAHException as error:
77 sys.stderr.write('Exception: ' + str(error))77 sys.stderr.write('Exception: ' + str(error))
78 exitstatus = ReturnCodes.UTAH_EXCEPTION_ERROR78 exitstatus = ReturnCodes.UTAH_EXCEPTION_ERROR
79 except:79 except Exception:
80 logging.exception('Unhandled error in UTAH')80 logging.exception('Unhandled error in UTAH')
81 exitstatus = ReturnCodes.UNHANDLED_ERROR81 exitstatus = ReturnCodes.UNHANDLED_ERROR
82 finally:82 finally:
8383
=== modified file 'examples/run_utah_tests.py'
--- examples/run_utah_tests.py 2013-04-01 11:56:16 +0000
+++ examples/run_utah_tests.py 2013-04-03 15:00:38 +0000
@@ -98,7 +98,7 @@
98 except UTAHException as error:98 except UTAHException as error:
99 sys.stderr.write('Exception: ' + str(error))99 sys.stderr.write('Exception: ' + str(error))
100 exitstatus = ReturnCodes.UTAH_EXCEPTION_ERROR100 exitstatus = ReturnCodes.UTAH_EXCEPTION_ERROR
101 except:101 except Exception:
102 logging.exception('Unhandled error in UTAH')102 logging.exception('Unhandled error in UTAH')
103 exitstatus = ReturnCodes.UNHANDLED_ERROR103 exitstatus = ReturnCodes.UNHANDLED_ERROR
104 finally:104 finally:
105105
=== modified file 'utah/cleanup.py'
--- utah/cleanup.py 2013-03-29 09:01:21 +0000
+++ utah/cleanup.py 2013-04-03 15:00:38 +0000
@@ -88,7 +88,7 @@
88 # process is completed as much as possible88 # process is completed as much as possible
89 try:89 try:
90 ProcessRunner(command)90 ProcessRunner(command)
91 except:91 except Exception:
92 self.logger.error('Cleanup error: {}'92 self.logger.error('Cleanup error: {}'
93 .format(traceback.format_exc()))93 .format(traceback.format_exc()))
94 finally:94 finally:
9595
=== modified file 'utah/run.py'
--- utah/run.py 2013-03-27 11:55:17 +0000
+++ utah/run.py 2013-04-03 15:00:38 +0000
@@ -18,12 +18,13 @@
18"""18"""
19import logging19import logging
20import os20import os
21import time
22import urllib
23import traceback
24import shutil21import shutil
25import signal22import signal
26import socket23import socket
24import sys
25import time
26import traceback
27import urllib
2728
28from utah import config29from utah import config
29from utah.exceptions import UTAHException30from utah.exceptions import UTAHException
@@ -41,6 +42,7 @@
41 TIMEOUT_ERROR = 2 # Unable to complete before config.jobtimeout seconds42 TIMEOUT_ERROR = 2 # Unable to complete before config.jobtimeout seconds
42 GROUP_ERROR = 3 # User isn't in UTAH group43 GROUP_ERROR = 3 # User isn't in UTAH group
43 UNHANDLED_ERROR = 4 # Non UTAH exception caught44 UNHANDLED_ERROR = 4 # Non UTAH exception caught
45 SIGTERM_RECEIVED = 5 # SIGTERM signal received
4446
45 @staticmethod47 @staticmethod
46 def client_error(returncode):48 def client_error(returncode):
@@ -372,7 +374,8 @@
372 """374 """
373 def handler(signum, frame):375 def handler(signum, frame):
374 """Raise exception when signal is received."""376 """Raise exception when signal is received."""
375 raise UTAHException('Signal received: {}'.format(signum))377 logging.warning('Signal received: %d', signum)
378 sys.exit(ReturnCodes.SIGTERM_RECEIVED)
376379
377 signal.signal(signal.SIGTERM, handler)380 signal.signal(signal.SIGTERM, handler)
378381

Subscribers

People subscribed via source and target branches