コード例 #1
0
ファイル: main.py プロジェクト: nicko96/Chrome-Infra
def create_html_app():
  """Returns WSGI app that serves HTML pages."""
  routes = []
  routes.extend(ereporter2.get_frontend_routes())
  routes.extend(ereporter2.get_backend_routes())
  routes.append((r'.*', MainPage))
  return webapp2.WSGIApplication(routes, debug=utils.is_local_dev_server())
コード例 #2
0
def create_html_app():
    """Returns WSGI app that serves HTML pages."""
    routes = []
    routes.extend(ereporter2.get_frontend_routes())
    routes.extend(ereporter2.get_backend_routes())
    routes.append((r'.*', MainPage))
    return webapp2.WSGIApplication(routes, debug=utils.is_local_dev_server())
コード例 #3
0
    def test_bot_ereporter2_error(self):
        # ereporter2's //client/utils/on_error.py traps unhandled exceptions
        # automatically.
        self.mock(random, 'getrandbits', lambda _: 0x88)
        errors = []
        self.mock(ereporter2, 'log_request',
                  lambda *args, **kwargs: errors.append((args, kwargs)))
        token, params = self.get_bot_token()
        response = self.post_with_token('/swarming/api/v1/bot/poll', params,
                                        token)
        self.assertTrue(response.pop(u'duration'))
        expected = {
            u'cmd': u'sleep',
            u'quarantined': False,
        }
        self.assertEqual(expected, response)

        # The bot fails somehow.
        error_params = {
            'v': 1,
            'r': {
                'args': ['a', 'b'],
                'category': 'junk',
                'cwd': '/root',
                'duration': 0.1,
                'endpoint': '/root',
                'env': {
                    'a': 'b'
                },
                'exception_type': 'FooError',
                'hostname': 'localhost',
                'message': 'Something happened',
                'method': 'GET',
                'os': 'Amiga',
                'params': {
                    'a': 123
                },
                'python_version': '2.7',
                'request_id': '123',
                'source': params['dimensions']['id'][0],
                'source_ip': '127.0.0.1',
                'stack': 'stack trace...',
                'user': '******',
                'version': '12',
            },
        }
        ereporter2_app = webtest.TestApp(webapp2.WSGIApplication(
            ereporter2.get_frontend_routes(), debug=True),
                                         extra_environ={
                                             'REMOTE_ADDR':
                                             self.source_ip,
                                             'SERVER_SOFTWARE':
                                             os.environ['SERVER_SOFTWARE'],
                                         })
        response = ereporter2_app.post_json('/ereporter2/api/v1/on_error',
                                            error_params)
        expected = {
            u'id': 1,
            u'url': u'http://localhost/restricted/ereporter2/errors/1',
        }
        self.assertEqual(expected, response.json)

        # A bot error currently does not result in permanent quarantine. It will
        # eventually.
        response = self.post_with_token('/swarming/api/v1/bot/poll', params,
                                        token)
        self.assertTrue(response.pop(u'duration'))
        expected = {
            u'cmd': u'sleep',
            u'quarantined': False,
        }
        self.assertEqual(expected, response)
        self.assertEqual([], errors)
コード例 #4
0
  def test_bot_ereporter2_error(self):
    # ereporter2's //client/utils/on_error.py traps unhandled exceptions
    # automatically.
    self.mock(random, 'getrandbits', lambda _: 0x88)
    errors = []
    self.mock(
        ereporter2, 'log_request',
        lambda *args, **kwargs: errors.append((args, kwargs)))
    token, params = self.get_bot_token()
    response = self.post_with_token('/swarming/api/v1/bot/poll', params, token)
    self.assertTrue(response.pop(u'duration'))
    expected = {
      u'cmd': u'sleep',
      u'quarantined': False,
    }
    self.assertEqual(expected, response)

    # The bot fails somehow.
    error_params = {
      'v': 1,
      'r': {
        'args': ['a', 'b'],
        'category': 'junk',
        'cwd': '/root',
        'duration': 0.1,
        'endpoint': '/root',
        'env': {'a': 'b'},
        'exception_type': 'FooError',
        'hostname': 'localhost',
        'message': 'Something happened',
        'method': 'GET',
        'os': 'Amiga',
        'params': {'a': 123},
        'python_version': '2.7',
        'request_id': '123',
        'source': params['dimensions']['id'][0],
        'source_ip': '127.0.0.1',
        'stack': 'stack trace...',
        'user': '******',
        'version': '12',
      },
    }
    ereporter2_app = webtest.TestApp(
        webapp2.WSGIApplication(ereporter2.get_frontend_routes(), debug=True),
        extra_environ={
          'REMOTE_ADDR': self.source_ip,
          'SERVER_SOFTWARE': os.environ['SERVER_SOFTWARE'],
        })
    response = ereporter2_app.post_json(
        '/ereporter2/api/v1/on_error', error_params)
    expected = {
      u'id': 1,
      u'url': u'http://localhost/restricted/ereporter2/errors/1',
    }
    self.assertEqual(expected, response.json)

    # A bot error currently does not result in permanent quarantine. It will
    # eventually.
    response = self.post_with_token('/swarming/api/v1/bot/poll', params, token)
    self.assertTrue(response.pop(u'duration'))
    expected = {
      u'cmd': u'sleep',
      u'quarantined': False,
    }
    self.assertEqual(expected, response)
    self.assertEqual([], errors)