Exemplo n.º 1
0
 def test_post_error_task(self):
   self.mock(time, 'time', lambda: 126.0)
   self.mock(logging, 'error', lambda *_, **_kw: None)
   self.mock(bot_main, 'get_remote', lambda: self.server)
   # get_state() return value changes over time. Hardcode its value for the
   # duration of this test.
   self.mock(os_utilities, 'get_state', lambda: {'foo': 'bar'})
   expected_attribs = bot_main.get_attributes()
   self.expected_requests(
       [
         (
           'https://localhost:1/auth/api/v1/accounts/self/xsrf_token',
           {
             'data': expected_attribs,
             'headers': {'X-XSRF-Token-Request': '1'},
           },
           {'xsrf_token': 'token'},
         ),
         (
           'https://localhost:1/swarming/api/v1/bot/task_error/23',
           {
             'data': {
               'id': expected_attribs['dimensions']['id'][0],
               'message': 'error',
               'task_id': 23,
             },
             'headers': {'X-XSRF-Token': 'token'},
           },
           {},
         ),
       ])
   botobj = bot_main.get_bot()
   bot_main.post_error_task(botobj, 'error', 23)
Exemplo n.º 2
0
 def test_post_error_task(self):
     self.mock(time, "time", lambda: 126.0)
     self.mock(logging, "error", lambda *_, **_kw: None)
     self.mock(bot_main, "get_remote", lambda: self.server)
     # get_state() return value changes over time. Hardcode its value for the
     # duration of this test.
     self.mock(os_utilities, "get_state", lambda: {"foo": "bar"})
     expected_attribs = bot_main.get_attributes(None)
     self.expected_requests(
         [
             (
                 "https://localhost:1/auth/api/v1/accounts/self/xsrf_token",
                 {"data": expected_attribs, "headers": {"X-XSRF-Token-Request": "1"}},
                 {"xsrf_token": "token"},
             ),
             (
                 "https://localhost:1/swarming/api/v1/bot/task_error/23",
                 {
                     "data": {"id": expected_attribs["dimensions"]["id"][0], "message": "error", "task_id": 23},
                     "headers": {"X-XSRF-Token": "token"},
                 },
                 {},
             ),
         ]
     )
     botobj = bot_main.get_bot()
     bot_main.post_error_task(botobj, "error", 23)
Exemplo n.º 3
0
 def test_post_error_task(self):
   self.mock(time, 'time', lambda: 126.0)
   self.mock(logging, 'error', lambda *_: None)
   self.mock(bot_main, 'get_remote', lambda: self.server)
   expected_attribs = bot_main.get_attributes()
   self.expected_requests(
       [
         (
           'https://localhost:1/auth/api/v1/accounts/self/xsrf_token',
           {
             'data': expected_attribs,
             'headers': {'X-XSRF-Token-Request': '1'},
           },
           {'xsrf_token': 'token'},
         ),
         (
           'https://localhost:1/swarming/api/v1/bot/task_error/23',
           {
             'data': {
               'id': expected_attribs['dimensions']['id'][0],
               'message': 'error',
               'task_id': 23,
             },
             'headers': {'X-XSRF-Token': 'token'},
           },
           {},
         ),
       ])
   botobj = bot_main.get_bot()
   bot_main.post_error_task(botobj, 'error', 23)
Exemplo n.º 4
0
 def test_post_error_task(self):
     self.mock(time, 'time', lambda: 126.0)
     self.mock(logging, 'error', lambda *_, **_kw: None)
     self.mock(bot_main, 'get_config', lambda: {
         'server': self.url,
         'server_version': '1'
     })
     expected_attribs = bot_main.get_attributes(None)
     self.expected_requests([
         (
             'https://localhost:1/swarming/api/v1/bot/task_error/23',
             {
                 'data': {
                     'id': expected_attribs['dimensions']['id'][0],
                     'message': 'error',
                     'task_id': 23,
                 },
                 'follow_redirects': False,
                 'headers': {
                     'Cookie': 'GOOGAPPUID=42'
                 },
                 'timeout': remote_client.NET_CONNECTION_TIMEOUT_SEC,
             },
             {
                 'resp': 1
             },
         ),
     ])
     botobj = bot_main.get_bot(bot_main.get_config())
     self.assertEqual(True, bot_main._post_error_task(botobj, 'error', 23))
Exemplo n.º 5
0
 def test_post_error_task(self):
     self.mock(time, 'time', lambda: 126.0)
     self.mock(logging, 'error', lambda *_: None)
     self.mock(bot_main, 'get_remote', lambda: self.server)
     expected_attribs = bot_main.get_attributes()
     self.expected_requests([
         (
             'https://localhost:1/auth/api/v1/accounts/self/xsrf_token',
             {
                 'data': expected_attribs,
                 'headers': {
                     'X-XSRF-Token-Request': '1'
                 },
             },
             {
                 'xsrf_token': 'token'
             },
         ),
         (
             'https://localhost:1/swarming/api/v1/bot/task_error/23',
             {
                 'data': {
                     'id': expected_attribs['dimensions']['id'][0],
                     'message': 'error',
                     'task_id': 23,
                 },
                 'headers': {
                     'X-XSRF-Token': 'token'
                 },
             },
             {},
         ),
     ])
     botobj = bot_main.get_bot()
     bot_main.post_error_task(botobj, 'error', 23)
Exemplo n.º 6
0
 def test_post_error_task(self):
     self.mock(time, 'time', lambda: 126.0)
     self.mock(logging, 'error', lambda *_, **_kw: None)
     self.mock(bot_main, 'get_config', lambda: {
         'server': self.url,
         'server_version': '1'
     })
     expected_attribs = bot_main.get_attributes(None)
     self.expected_requests([
         (
             'https://localhost:1/swarming/api/v1/bot/task_error/23',
             {
                 'data': {
                     'id': expected_attribs['dimensions']['id'][0],
                     'message': 'error',
                     'task_id': 23,
                 },
             },
             {
                 'resp': 1
             },
         ),
     ])
     botobj = bot_main.get_bot()
     self.assertEqual({'resp': 1},
                      bot_main.post_error_task(botobj, 'error', 23))
Exemplo n.º 7
0
    def test_get_state_quarantine(self):
        botobj = bot_main.get_bot(bot_main.get_config())
        root = u'c:\\' if sys.platform == 'win32' else u'/'

        def get_state(_):
            return {
                u'disks': {
                    root: {
                        u'free_mb': 0.1,
                        u'size_mb': 1000,
                    },
                    botobj.base_dir: {
                        u'free_mb': 0.1,
                        u'size_mb': 1000,
                    },
                },
            }

        # This uses the default get_settings() values. The threshold used is
        # dependent on these values. This affects the error message below.
        # 'size' == 4096Mb
        # 'max_percent' == 15% * 1000Mb = 150Mb
        # 'min_percent' == 5% of 1000Mb == 50Mb
        # 'max_percent' is chosen.
        from config import bot_config
        self.mock(bot_config, 'get_state', get_state)
        expected = {
            u'disks': {
                u'c:\\' if sys.platform == 'win32' else u'/': {
                    u'free_mb': 0.1,
                    u'size_mb': 1000,
                },
                botobj.base_dir: {
                    u'free_mb': 0.1,
                    u'size_mb': 1000,
                },
            },
            u'quarantined':
            (u'Not enough free disk space on %s. 0.1mib < 100.0mib\n'
             u'Not enough free disk space on %s. 0.1mib < 150.0mib') %
            (root, botobj.base_dir),
            u'sleep_streak':
            1,
        }
        self.assertEqual(expected, bot_main._get_state(botobj, 1))
Exemplo n.º 8
0
 def test_post_error_task(self):
     self.mock(time, 'time', lambda: 126.0)
     self.mock(logging, 'error', lambda *_, **_kw: None)
     self.mock(bot_main, 'get_remote', lambda: self.server)
     # get_state() return value changes over time. Hardcode its value for the
     # duration of this test.
     self.mock(os_utilities, 'get_state', lambda: {'foo': 'bar'})
     expected_attribs = bot_main.get_attributes()
     self.expected_requests([
         (
             'https://localhost:1/auth/api/v1/accounts/self/xsrf_token',
             {
                 'data': expected_attribs,
                 'headers': {
                     'X-XSRF-Token-Request': '1'
                 },
             },
             {
                 'xsrf_token': 'token'
             },
         ),
         (
             'https://localhost:1/swarming/api/v1/bot/task_error/23',
             {
                 'data': {
                     'id': expected_attribs['dimensions']['id'][0],
                     'message': 'error',
                     'task_id': 23,
                 },
                 'headers': {
                     'X-XSRF-Token': 'token'
                 },
             },
             {},
         ),
     ])
     botobj = bot_main.get_bot()
     bot_main.post_error_task(botobj, 'error', 23)
Exemplo n.º 9
0
 def test_post_error_task(self):
   self.mock(time, 'time', lambda: 126.0)
   self.mock(logging, 'error', lambda *_, **_kw: None)
   self.mock(
       bot_main, 'get_config',
       lambda: {'server': self.url, 'server_version': '1'})
   expected_attribs = bot_main.get_attributes(None)
   self.expected_requests(
       [
         (
           'https://localhost:1/swarming/api/v1/bot/task_error/23',
           {
             'data': {
               'id': expected_attribs['dimensions']['id'][0],
               'message': 'error',
               'task_id': 23,
             },
           },
           {'resp': 1},
         ),
       ])
   botobj = bot_main.get_bot()
   self.assertEqual({'resp': 1}, bot_main.post_error_task(botobj, 'error', 23))