コード例 #1
0
    def testSubCommandTimeout(self):
        """Tests that we can nest SubCommandTimeout correctly."""
        self.assertFalse('mock' in str(time.sleep).lower())
        with cros_build_lib.SubCommandTimeout(30):
            with cros_build_lib.SubCommandTimeout(20):
                with cros_build_lib.SubCommandTimeout(1):
                    self.assertRaises(cros_build_lib.TimeoutError, time.sleep,
                                      10)

                # Should not raise a timeout exception as 20 > 2.
                time.sleep(1)
コード例 #2
0
  def testSubCommandTimeoutNested(self):
    """Tests that we still re-raise an alarm if both are reached."""
    with cros_build_lib.SubCommandTimeout(1):
      try:
        with cros_build_lib.SubCommandTimeout(2):
          self.assertRaises(cros_build_lib.TimeoutError, time.sleep, 1)

      # Craziness to catch nested timeouts.
      except cros_build_lib.TimeoutError:
        pass
      else:
        self.assertTrue(False, 'Should have thrown an exception')
コード例 #3
0
    def Upload(cls, stats, url=None, timeout=None):
        """Upload |stats| to |url|.

      Does nothing if upload conditions aren't met.

      Arguments:
        stats: A Stats object to upload.
        url: The url to send the request to.
        timeout: A timeout value to set, in seconds.
    """
        if url is None:
            url = cls.URL
        if timeout is None:
            timeout = cls.UPLOAD_TIMEOUT

        if not cls._UploadConditionsMet(stats):
            return

        with cros_build_lib.SubCommandTimeout(timeout):
            try:
                cls._Upload(stats, url)
            # Stats upload errors are silenced, for the sake of user experience.
            except cros_build_lib.TimeoutError:
                logging.debug(cls.TIMEOUT_ERROR, timeout)
            except EnvironmentError:
                logging.debug(cls.ENVIRONMENT_ERROR, exc_info=True)
コード例 #4
0
    def _KillProcsIfNeeded(self):
        if self._CheckUiJobStarted():
            logging.info('Shutting down Chrome...')
            self.host.RemoteSh('stop ui')

        # Developers sometimes run session_manager manually, in which case we'll
        # need to help shut the chrome processes down.
        try:
            with cros_build_lib.SubCommandTimeout(KILL_PROC_MAX_WAIT):
                while self._ChromeFileInUse():
                    logging.warning(
                        'The chrome binary on the device is in use.')
                    logging.warning(
                        'Killing chrome and session_manager processes...\n')

                    self.host.RemoteSh("pkill 'chrome|session_manager'",
                                       error_code_ok=True)
                    # Wait for processes to actually terminate
                    time.sleep(POST_KILL_WAIT)
                    logging.info('Rechecking the chrome binary...')
        except cros_build_lib.TimeoutError:
            msg = (
                'Could not kill processes after %s seconds.  Please exit any '
                'running chrome processes and try again.' % KILL_PROC_MAX_WAIT)
            raise DeployFailure(msg)
コード例 #5
0
    def Upload(cls, stats, url=None, timeout=None):
        """Upload |stats| to |url|.

      Does nothing if upload conditions aren't met.

      Arguments:
        stats: A Stats object to upload.
        url: The url to send the request to.
        timeout: A timeout value to set, in seconds.
    """
        if url is None:
            url = cls.URL
        if timeout is None:
            timeout = cls.UPLOAD_TIMEOUT

        if not cls._UploadConditionsMet(stats):
            return

        with cros_build_lib.SubCommandTimeout(timeout):
            try:
                cls._Upload(stats, url)
            # Stats upload errors are silenced, for the sake of user experience.
            except cros_build_lib.TimeoutError:
                logging.debug(cls.TIMEOUT_ERROR, timeout)
            except urllib2.HTTPError as e:
                # HTTPError has a geturl() method, but it relies on self.url, which
                # is not always set.  In looking at source, self.filename equals url.
                logging.debug(cls.HTTPURL_ERROR, e.filename, exc_info=True)
            except EnvironmentError:
                logging.debug(cls.ENVIRONMENT_ERROR, exc_info=True)
コード例 #6
0
def SymUpload(sym_file, upload_url):
    """Run breakpad sym_upload helper"""
    # TODO(vapier): Rewrite to use native python HTTP libraries.  This tool
    # reads the sym_file and does a HTTP post to URL with a few fields set.
    # See the tiny breakpad/tools/linux/symupload/sym_upload.cc for details.
    cmd = ['sym_upload', sym_file, upload_url]
    with cros_build_lib.SubCommandTimeout(UPLOAD_TIMEOUT):
        return cros_build_lib.RunCommandCaptureOutput(
            cmd, debug_level=logging.DEBUG)
コード例 #7
0
def main(argv):
    """Main function."""
    # This is not meant to be a user-friendly script.  It takes one and
    # only one argument, which is a build stats file to be uploaded
    usage = 'Usage: %prog [-h|--help] build_stats_file'
    epilog = ('This script is not intended to be run manually.  It is used as'
              ' part of the build command statistics project.')

    parser = optparse.OptionParser(usage=usage, epilog=epilog)
    (_options, args) = parser.parse_args(argv)

    logging.getLogger().setLevel(logging.INFO)

    if len(args) > 1:
        logging.error('Only one argument permitted.')
        sys.exit(1)
    if len(args) < 1:
        logging.error('Missing command stats file argument.')
        sys.exit(1)

    # Silently do nothing if the conditions for uploading are not met.
    if UploadConditionsMet():
        try:
            stats = Stats()
            stats.LoadFile(args[0])

            with cros_build_lib.SubCommandTimeout(UPLOAD_TIMEOUT):
                stats.Upload(URL)

        except cros_build_lib.TimeoutError:
            logging.error('Timed out during upload - waited %i seconds',
                          UPLOAD_TIMEOUT)
            sys.exit(1)

        except StatsError as ex:
            logging.error(ex)
            sys.exit(1)