Bug 1169661: log when return_code changes; r=armenzg
authorDustin J. Mitchell <dustin@mozilla.com>
Mon, 01 Jun 2015 13:28:59 -0400
changeset 4089 387cda6bb0097eda99e2c9039441f508cfe3e15f
parent 4087 874bb5dc8e7132a5598bb73c146e09dedd5194ec
child 4093 931a0fb8631db70c0e0e1187d8cb795471a789d9
push id3248
push userdmitchell@mozilla.com
push dateWed, 03 Jun 2015 12:39:58 +0000
reviewersarmenzg
bugs1169661
Bug 1169661: log when return_code changes; r=armenzg
mozharness/base/script.py
--- a/mozharness/base/script.py
+++ b/mozharness/base/script.py
@@ -1019,16 +1019,17 @@ def PostScriptAction(action=None):
 
     return _wrapped
 
 
 # BaseScript {{{1
 class BaseScript(ScriptMixin, LogMixin, object):
     def __init__(self, config_options=None, ConfigClass=BaseConfig,
                  default_log_level="info", **kwargs):
+        self._return_code = 0
         super(BaseScript, self).__init__()
 
         # Collect decorated methods. We simply iterate over the attributes of
         # the current class instance and look for signatures deposited by
         # the decorators.
         self._listeners = dict(
             pre_run=[],
             pre_action=[],
@@ -1053,17 +1054,16 @@ class BaseScript(ScriptMixin, LogMixin, 
             if hasattr(item, '_post_action_listener'):
                 self._listeners['post_action'].append((
                     k,
                     item._post_action_listener))
 
             if hasattr(item, '_post_run_listener'):
                 self._listeners['post_run'].append(k)
 
-        self.return_code = 0
         self.log_obj = None
         self.abs_dirs = None
         if config_options is None:
             config_options = []
         self.summary_list = []
         self.failures = []
         rw_config = ConfigClass(config_options=config_options, **kwargs)
         self.config = rw_config.get_read_only_config()
@@ -1304,17 +1304,20 @@ class BaseScript(ScriptMixin, LogMixin, 
                 self.fatal("Aborting due to failure in post-run listener.")
         if self.config.get("copy_logs_post_run", True):
             self.copy_logs_to_upload_dir()
 
         return self.return_code
 
     def run_and_exit(self):
         """Runs the script and exits the current interpreter."""
-        sys.exit(self.run())
+        rc = self.run()
+        if rc != 0:
+            self.warning("returning nonzero exit status %d" % rc)
+        sys.exit(rc)
 
     def clobber(self):
         """
         Delete the working directory
         """
         dirs = self.query_abs_dirs()
         self.rmtree(dirs['abs_work_dir'], error_level=FATAL)
 
@@ -1504,12 +1507,21 @@ class BaseScript(ScriptMixin, LogMixin, 
         hasher = hashlib.sha512()
         with open(file_path, 'rb') as fh:
             buf = fh.read(bs)
             while len(buf) > 0:
                 hasher.update(buf)
                 buf = fh.read(bs)
         return hasher.hexdigest()
 
+    @property
+    def return_code(self):
+        return self._return_code
+
+    @return_code.setter
+    def return_code(self, code):
+        old_return_code, self._return_code = self._return_code, code
+        if old_return_code != code:
+            self.warning("setting return code to %d" % code)
 
 # __main__ {{{1
 if __name__ == '__main__':
     pass