def test_setup_bot(self): self.mock(bot_main, 'get_remote', lambda: self.server) setup_bots = [] def setup_bot(_bot): setup_bots.append(1) return False from config import bot_config self.mock(bot_config, 'setup_bot', setup_bot) restarts = [] post_event = [] self.mock(os_utilities, 'restart', lambda *a, **kw: restarts.append( (a, kw))) self.mock(bot.Bot, 'post_event', lambda *a, **kw: post_event.append( (a, kw))) self.expected_requests([]) bot_main.setup_bot(False) expected = [ (('Starting new swarming bot: %s' % bot_main.THIS_FILE, ), { 'timeout': 900 }), ] self.assertEqual(expected, restarts) # It is called twice, one as part of setup_bot(False), another as part of # on_shutdown_hook(). self.assertEqual([1, 1], setup_bots) expected = [ 'Starting new swarming bot: %s' % bot_main.THIS_FILE, 'Bot is stuck restarting for: Starting new swarming bot: %s' % bot_main.THIS_FILE, ] self.assertEqual(expected, [i[0][2] for i in post_event])
def test_setup_bot(self): self.mock(bot_main, "get_remote", lambda: self.server) setup_bots = [] def setup_bot(_bot): setup_bots.append(1) return False from config import bot_config self.mock(bot_config, "setup_bot", setup_bot) restarts = [] post_event = [] self.mock(os_utilities, "restart", lambda *a, **kw: restarts.append((a, kw))) self.mock(bot.Bot, "post_event", lambda *a, **kw: post_event.append((a, kw))) self.expected_requests([]) bot_main.setup_bot(False) expected = [(("Starting new swarming bot: %s" % bot_main.THIS_FILE,), {"timeout": 900})] self.assertEqual(expected, restarts) # It is called twice, one as part of setup_bot(False), another as part of # on_shutdown_hook(). self.assertEqual([1, 1], setup_bots) expected = [ "Starting new swarming bot: %s" % bot_main.THIS_FILE, "Bot is stuck restarting for: Starting new swarming bot: %s" % bot_main.THIS_FILE, ] self.assertEqual(expected, [i[0][2] for i in post_event])
def CMDstart_slave(args): """Ill named command that actually sets up the bot then start it.""" # TODO(maruel): Rename function. logging_utils.prepare_logging('bot_config.log') logging_utils.set_console_level(logging.DEBUG) parser = optparse.OptionParser() parser.add_option( '--survive', action='store_true', help='Do not reboot the host even if bot_config.setup_bot() asked to') options, args = parser.parse_args(args) # User provided bot_config.py logging.info('importing bot_config: %s, %s', THIS_FILE, zip_package.generate_version()) try: import bot_main bot_main.setup_bot(options.survive) except Exception: logging.exception('bot_config.py is invalid.') logging.info('Starting the bot: %s', THIS_FILE) cmd = [sys.executable, THIS_FILE, 'start_bot'] if sys.platform in ('cygwin', 'win32'): try: subprocess.Popen(cmd) return 0 except Exception as e: logging.exception('failed to start: %s', e) return 1 else: os.execv(cmd[0], cmd)
def test_setup_bot(self): setup_bots = [] def setup_bot(_bot): setup_bots.append(1) return False from config import bot_config self.mock(bot_config, 'setup_bot', setup_bot) restarts = [] post_event = [] self.mock( os_utilities, 'restart', lambda *a, **kw: restarts.append((a, kw))) self.mock( bot.Bot, 'post_event', lambda *a, **kw: post_event.append((a, kw))) self.expected_requests([]) bot_main.setup_bot(False) expected = [ (('Starting new swarming bot: %s' % bot_main.THIS_FILE,), {'timeout': 900}), ] self.assertEqual(expected, restarts) # It is called twice, one as part of setup_bot(False), another as part of # on_shutdown_hook(). self.assertEqual([1, 1], setup_bots) expected = [ 'Starting new swarming bot: %s' % bot_main.THIS_FILE, 'Bot is stuck restarting for: Starting new swarming bot: %s' % bot_main.THIS_FILE, ] self.assertEqual(expected, [i[0][2] for i in post_event])
def test_setup_bot(self): self.mock(bot_main, 'get_remote', lambda: self.server) setup_bots = [] def setup_bot(_bot): setup_bots.append(1) return False self.mock(bot_config, 'setup_bot', setup_bot) restarts = [] post_event = [] self.mock(os_utilities, 'restart', lambda *a, **kw: restarts.append( (a, kw))) self.mock(bot.Bot, 'post_event', lambda *a, **kw: post_event.append( (a, kw))) self.expected_requests([]) bot_main.setup_bot(False) self.assertEqual([(('Starting new swarming bot: %s' % THIS_FILE, ), { 'timeout': 900 })], restarts) self.assertEqual([1], setup_bots) expected = [ 'Starting new swarming bot: %s' % THIS_FILE, 'Bot is stuck restarting for: Starting new swarming bot: %s' % THIS_FILE, ] self.assertEqual(expected, [i[0][2] for i in post_event])
def CMDstart_slave(args): """Ill named command that actually sets up the bot then start it.""" # TODO(maruel): Rename function. logging_utils.prepare_logging('bot_config.log') logging_utils.set_console_level(logging.DEBUG) parser = optparse.OptionParser() parser.add_option( '--survive', action='store_true', help='Do not reboot the host even if bot_config.setup_bot() asked to') options, args = parser.parse_args(args) # User provided bot_config.py logging.info( 'importing bot_config: %s, %s', THIS_FILE, zip_package.generate_version()) try: import bot_main bot_main.setup_bot(options.survive) except Exception: logging.exception('bot_config.py is invalid.') logging.info('Starting the bot: %s', THIS_FILE) cmd = [sys.executable, THIS_FILE, 'start_bot'] if sys.platform in ('cygwin', 'win32'): try: subprocess.Popen(cmd) return 0 except Exception as e: logging.exception('failed to start: %s', e) return 1 else: os.execv(cmd[0], cmd)
def test_setup_bot(self): self.mock(bot_main, 'get_remote', lambda: self.server) setup_bots = [] def setup_bot(_bot): setup_bots.append(1) return False self.mock(bot_config, 'setup_bot', setup_bot) restarts = [] post_event = [] self.mock( os_utilities, 'restart', lambda *a, **kw: restarts.append((a, kw))) self.mock( bot.Bot, 'post_event', lambda *a, **kw: post_event.append((a, kw))) self.expected_requests([]) bot_main.setup_bot(False) self.assertEqual( [(('Starting new swarming bot: %s' % THIS_FILE,), {'timeout': 900})], restarts) self.assertEqual([1], setup_bots) expected = [ 'Starting new swarming bot: %s' % THIS_FILE, 'Bot is stuck restarting for: Starting new swarming bot: %s' % THIS_FILE, ] self.assertEqual(expected, [i[0][2] for i in post_event])