コード例 #1
0
ファイル: bot_main_test.py プロジェクト: stefb965/luci-py
    def test_poll_server_reboot(self):
        reboots = []
        bit = threading.Event()
        self.mock(bit, 'wait', self.fail)
        self.mock(bot_main, '_run_manifest', self.fail)
        self.mock(bot_main, '_update_bot', self.fail)
        self.mock(self.bot, 'host_reboot', lambda *args: reboots.append(args))

        self.expected_requests([
            (
                'https://localhost:1/swarming/api/v1/bot/poll',
                {
                    'data': self.attributes,
                    'follow_redirects': False,
                    'headers': {
                        'Cookie': 'GOOGAPPUID=42'
                    },
                    'timeout': remote_client.NET_CONNECTION_TIMEOUT_SEC,
                },
                {
                    'cmd': 'host_reboot',
                    'message': 'Please die now',
                },
            ),
        ])
        self.assertTrue(bot_main._poll_server(self.bot, bit, 0))
        self.assertEqual([('Please die now', )], reboots)
        self.assertEqual(None, self.bot.bot_restart_msg())
コード例 #2
0
ファイル: bot_main_test.py プロジェクト: stefb965/luci-py
    def test_poll_server_sleep_with_auth(self):
        slept = []
        bit = threading.Event()
        self.mock(bit, 'wait', slept.append)
        self.mock(bot_main, '_run_manifest', self.fail)
        self.mock(bot_main, '_update_bot', self.fail)

        self.bot = self.make_bot(lambda: ({'A': 'a'}, time.time() + 3600))

        self.expected_requests([
            (
                'https://localhost:1/swarming/api/v1/bot/poll',
                {
                    'data': self.attributes,
                    'follow_redirects': False,
                    'headers': {
                        'A': 'a',
                        'Cookie': 'GOOGAPPUID=42'
                    },
                    'timeout': remote_client.NET_CONNECTION_TIMEOUT_SEC,
                },
                {
                    'cmd': 'sleep',
                    'duration': 1.24,
                },
            ),
        ])
        self.assertFalse(bot_main._poll_server(self.bot, bit, 0))
        self.assertEqual([1.24], slept)
コード例 #3
0
ファイル: bot_main_test.py プロジェクト: stefb965/luci-py
    def test_poll_server_run(self):
        manifest = []
        clean = []
        bit = threading.Event()
        self.mock(bit, 'wait', self.fail)
        self.mock(bot_main, '_run_manifest',
                  lambda *args: manifest.append(args))
        self.mock(bot_main, '_clean_cache', lambda *args: clean.append(args))
        self.mock(bot_main, '_update_bot', self.fail)

        self.expected_requests([
            (
                'https://localhost:1/swarming/api/v1/bot/poll',
                {
                    'data': self.bot._attributes,
                    'follow_redirects': False,
                    'headers': {
                        'Cookie': 'GOOGAPPUID=42'
                    },
                    'timeout': remote_client.NET_CONNECTION_TIMEOUT_SEC,
                },
                {
                    'cmd': 'run',
                    'manifest': {
                        'foo': 'bar'
                    },
                },
            ),
        ])
        self.assertTrue(bot_main._poll_server(self.bot, bit, 0))
        expected = [(self.bot, {'foo': 'bar'}, time.time())]
        self.assertEqual(expected, manifest)
        expected = [(self.bot, )]
        self.assertEqual(expected, clean)
        self.assertEqual(None, self.bot.bot_restart_msg())
コード例 #4
0
ファイル: bot_main_test.py プロジェクト: stefb965/luci-py
    def test_poll_server_sleep(self):
        slept = []
        bit = threading.Event()
        self.mock(bit, 'wait', slept.append)
        self.mock(bot_main, '_run_manifest', self.fail)
        self.mock(bot_main, '_update_bot', self.fail)
        from config import bot_config
        called = []
        self.mock(bot_config, 'on_bot_idle', lambda _bot, _s: called.append(1))

        self.expected_requests([
            (
                'https://localhost:1/swarming/api/v1/bot/poll',
                {
                    'data': self.attributes,
                    'follow_redirects': False,
                    'headers': {
                        'Cookie': 'GOOGAPPUID=42'
                    },
                    'timeout': remote_client.NET_CONNECTION_TIMEOUT_SEC,
                },
                {
                    'cmd': 'sleep',
                    'duration': 1.24,
                },
            ),
        ])
        self.assertFalse(bot_main._poll_server(self.bot, bit, 2))
        self.assertEqual([1.24], slept)
        self.assertEqual([1], called)