def test_run_manifest_internal_failure(self): posted = [] self.mock(bot_main, '_post_error_task', lambda *args: posted.append(args)) def call_hook(_botobj, name, *args): if name == 'on_after_task': failure, internal_failure, dimensions, summary = args self.assertEqual(False, failure) self.assertEqual(True, internal_failure) self.assertEqual({'pool': 'default'}, dimensions) self.assertEqual(result, summary) self.mock(bot_main, '_call_hook', call_hook) result = self._mock_popen(returncode=1) manifest = { 'command': ['echo', 'hi'], 'dimensions': { 'pool': 'default' }, 'grace_period': 30, 'hard_timeout': 60, 'io_timeout': 60, 'task_id': '24', } bot_main._run_manifest(self.bot, manifest, time.time()) expected = [(self.bot, 'Execution failed: internal error (1).', '24')] self.assertEqual(expected, posted)
def test_run_manifest_task_failure(self): self.mock(bot_main, '_post_error_task', self.print_err_and_fail) def call_hook(_botobj, name, *args): if name == 'on_after_task': failure, internal_failure, dimensions, summary = args self.assertEqual(True, failure) self.assertEqual(False, internal_failure) self.assertEqual({'pool': 'default'}, dimensions) self.assertEqual(result, summary) self.mock(bot_main, '_call_hook', call_hook) result = self._mock_popen(exit_code=1) manifest = { 'command': ['echo', 'hi'], 'dimensions': { 'pool': 'default' }, 'grace_period': 30, 'hard_timeout': 60, 'io_timeout': 60, 'task_id': '24', } bot_main._run_manifest(self.bot, manifest, time.time())
def test_run_manifest(self): self.mock(bot_main, '_post_error_task', self.print_err_and_fail) def call_hook(botobj, name, *args): if name == 'on_after_task': failure, internal_failure, dimensions, summary = args self.assertEqual(self.attributes['dimensions'], botobj.dimensions) self.assertEqual(False, failure) self.assertEqual(False, internal_failure) self.assertEqual({ 'os': 'Amiga', 'pool': 'default' }, dimensions) self.assertEqual(result, summary) self.mock(bot_main, '_call_hook', call_hook) result = self._mock_popen(url='https://localhost:3') manifest = { 'command': ['echo', 'hi'], 'dimensions': { 'os': 'Amiga', 'pool': 'default' }, 'grace_period': 30, 'hard_timeout': 60, 'host': 'https://localhost:3', 'task_id': '24', } self.assertEqual(self.root_dir, self.bot.base_dir) bot_main._run_manifest(self.bot, manifest, time.time())
def test_run_manifest_exception(self): posted = [] def post_error_task(botobj, msg, task_id): posted.append((botobj, msg.splitlines()[0], task_id)) self.mock(bot_main, '_post_error_task', post_error_task) def call_hook(_botobj, name, *args): if name == 'on_after_task': failure, internal_failure, dimensions, summary = args self.assertEqual(False, failure) self.assertEqual(True, internal_failure) self.assertEqual({'pool': 'default'}, dimensions) self.assertEqual({}, summary) self.mock(bot_main, '_call_hook', call_hook) def raiseOSError(*_a, **_k): raise OSError('Dang') self.mock(subprocess42, 'Popen', raiseOSError) manifest = { 'command': ['echo', 'hi'], 'dimensions': { 'pool': 'default' }, 'grace_period': 30, 'hard_timeout': 60, 'task_id': '24', } bot_main._run_manifest(self.bot, manifest, time.time()) expected = [(self.bot, 'Internal exception occured: Dang', '24')] self.assertEqual(expected, posted)
def test_run_manifest_with_auth_headers(self): self.bot = self.make_bot(auth_headers_cb=lambda: ({ 'A': 'a' }, time.time() + 3600)) self.mock(bot_main, '_post_error_task', self.print_err_and_fail) def call_hook(botobj, name, *args): if name == 'on_after_task': failure, internal_failure, dimensions, summary = args self.assertEqual(self.attributes['dimensions'], botobj.dimensions) self.assertEqual(False, failure) self.assertEqual(False, internal_failure) self.assertEqual({ 'os': 'Amiga', 'pool': 'default' }, dimensions) self.assertEqual(result, summary) self.mock(bot_main, '_call_hook', call_hook) result = self._mock_popen( url='https://*****:*****@example.com', # as in task manifest 'task_service_account': 'bot', }) manifest = { 'command': ['echo', 'hi'], 'dimensions': { 'os': 'Amiga', 'pool': 'default' }, 'grace_period': 30, 'hard_timeout': 60, 'host': 'https://*****:*****@example.com' }, 'task': { 'service_account': 'bot' }, }, 'task_id': '24', } self.assertEqual(self.root_dir, self.bot.base_dir) bot_main._run_manifest(self.bot, manifest, time.time())