def run(self, connection, args=None): # Prompts commonly include # - when logging such strings, # use lazy logging or the string will not be quoted correctly. def check_prompt_characters(prompt): if not any([True for c in DISTINCTIVE_PROMPT_CHARACTERS if c in prompt]): self.logger.warning(self.check_prompt_characters_warning, prompt) connection.prompt_str = LinuxKernelMessages.get_init_prompts() # Skip auto login if the configuration is not found params = self.parameters.get('auto_login', None) if params is None: self.logger.debug("Skipping of auto login") else: self.logger.debug("Waiting for the login prompt") connection.prompt_str.append(params['login_prompt']) self.logger.debug(connection.prompt_str) results = LinuxKernelMessages.parse_failures(connection) if len(results) > 1: self.results = {'fail': results} return connection else: connection.sendline(params['username'], delay=self.character_delay) if 'password_prompt' in params: self.logger.debug("Waiting for password prompt") connection.prompt_str = params['password_prompt'] self.wait(connection) connection.sendline(params['password'], delay=self.character_delay) # prompt_str can be a list or str if isinstance(connection.prompt_str, str): connection.prompt_str = [DEFAULT_SHELL_PROMPT] else: connection.prompt_str.extend([DEFAULT_SHELL_PROMPT]) prompts = self.parameters.get('prompts', None) if isinstance(prompts, list): for prompt in prompts: check_prompt_characters(prompt) connection.prompt_str.extend(prompts) else: check_prompt_characters(prompts) connection.prompt_str.append(prompts) self.logger.debug("Setting shell prompt(s) to %s" % connection.prompt_str) # pylint: disable=logging-not-lazy if params is None: self.logger.debug("Parsing kernel messages") parsed = LinuxKernelMessages.parse_failures(connection) if len(parsed) and 'success' in parsed[0]: self.results = {'success': parsed[0]} else: self.results = {'fail': parsed} connection.sendline('export PS1="%s"' % DEFAULT_SHELL_PROMPT, delay=self.character_delay) return connection
def test_kernel_2(self): logfile = os.path.join(os.path.dirname(__file__), "kernel-2.txt") self.assertTrue(os.path.exists(logfile)) child = pexpect.spawn("cat", [logfile]) message_list = LinuxKernelMessages.get_kernel_prompts() self.assertIsNotNone(message_list) connection = FakeConnection(child, message_list) results = LinuxKernelMessages.parse_failures(connection) # traces as far as da227214a82491bf occur before Freeing init memory: self.assertEqual(len(list(results)), 9) message_list = LinuxKernelMessages.get_init_prompts() connection.prompt_str = message_list results = LinuxKernelMessages.parse_failures(connection) # 5 more traces appear during init self.assertEqual(len(list(results)), 5)
def test_kernel_2(self): logfile = os.path.join(os.path.dirname(__file__), 'kernel-2.txt') self.assertTrue(os.path.exists(logfile)) child = pexpect.spawn('cat', [logfile]) message_list = LinuxKernelMessages.get_kernel_prompts() self.assertIsNotNone(message_list) connection = FakeConnection(child, message_list) results = LinuxKernelMessages.parse_failures(connection) # traces as far as da227214a82491bf occur before Freeing init memory: self.assertEqual(len(list(results)), 9) message_list = LinuxKernelMessages.get_init_prompts() connection.prompt_str = message_list results = LinuxKernelMessages.parse_failures(connection) # 5 more traces appear during init self.assertEqual(len(list(results)), 5)
def test_kernel_4(self): logfile = os.path.join(os.path.dirname(__file__), 'kernel-4.txt') self.assertTrue(os.path.exists(logfile)) child = pexpect.spawn('cat', [logfile]) message_list = LinuxKernelMessages.get_init_prompts() self.assertIsNotNone(message_list) connection = FakeConnection(child, message_list) results = LinuxKernelMessages.parse_failures( connection, max_end_time=self.max_end_time) self.assertIn('Stack', results[0]['message'].decode('utf-8')) self.assertIn('Kernel panic', results[1]['message'].decode('utf-8'))
def test_kernel_ramdisk_alert(self): logfile = os.path.join(os.path.dirname(__file__), "kernel-3.txt") self.assertTrue(os.path.exists(logfile)) child = pexpect.spawn("cat", [logfile]) message_list = LinuxKernelMessages.get_init_prompts() self.assertIsNotNone(message_list) connection = FakeConnection(child, message_list) results = LinuxKernelMessages.parse_failures(connection) self.assertEqual(len(list(results)), 1) self.assertIn("message", results[0]) self.assertIn("success", results[0]) self.assertNotIn("panic", results[0])
def test_kernel_ramdisk_alert(self): logfile = os.path.join(os.path.dirname(__file__), 'kernel-3.txt') self.assertTrue(os.path.exists(logfile)) child = pexpect.spawn('cat', [logfile]) message_list = LinuxKernelMessages.get_init_prompts() self.assertIsNotNone(message_list) connection = FakeConnection(child, message_list) results = LinuxKernelMessages.parse_failures(connection) self.assertEqual(len(list(results)), 1) self.assertIn('message', results[0]) self.assertIn('success', results[0]) self.assertNotIn('panic', results[0])
def test_kernel_txt(self): """ The same logfile passes kernel boot and fails to find init - so the panic needs to be caught by InitMessages """ logfile = os.path.join(os.path.dirname(__file__), 'kernel-panic.txt') self.assertTrue(os.path.exists(logfile)) child = pexpect.spawn('cat', [logfile]) message_list = LinuxKernelMessages.get_kernel_prompts() self.assertIsNotNone(message_list) self.assertIn(LinuxKernelMessages.MESSAGE_CHOICES[0][1], message_list) self.assertIn(LinuxKernelMessages.MESSAGE_CHOICES[1][1], message_list) self.assertIn(LinuxKernelMessages.MESSAGE_CHOICES[2][1], message_list) self.assertIn(LinuxKernelMessages.MESSAGE_CHOICES[3][1], message_list) self.assertIn(LinuxKernelMessages.MESSAGE_CHOICES[4][1], message_list) self.assertIn(LinuxKernelMessages.MESSAGE_CHOICES[5][1], message_list) connection = FakeConnection(child, message_list) result = LinuxKernelMessages.parse_failures( connection, max_end_time=self.max_end_time) self.assertEqual(len(result), 2) self.assertIn('success', result[0]) self.assertIn('panic', result[1]) self.assertEqual(result[0]['success'], KERNEL_FREE_UNUSED_MSG) self.assertEqual(result[1]['panic'], KERNEL_PANIC_MSG) self.assertEqual(len(result), 2) self.assertIn('panic', result[1]) self.assertIn('message', result[1]) self.assertTrue('Attempted to kill init' in str(result[1]['message'])) self.assertTrue('(unwind_backtrace) from' in str(result[1]['message'])) message_list = LinuxKernelMessages.get_init_prompts() child = pexpect.spawn('cat', [logfile]) connection = FakeConnection(child, message_list) results = LinuxKernelMessages.parse_failures( connection, max_end_time=self.max_end_time) self.assertEqual(len(results), 1) self.assertIn('panic', result[1]) self.assertIn('message', result[1]) self.assertTrue('Attempted to kill init' in str(result[1]['message'])) self.assertTrue('(unwind_backtrace) from' in str(result[1]['message']))
def test_kernel_2(self): logfile = os.path.join(os.path.dirname(__file__), 'kernel-2.txt') self.assertTrue(os.path.exists(logfile)) child = pexpect.spawn('cat', [logfile]) message_list = LinuxKernelMessages.get_kernel_prompts() self.assertIsNotNone(message_list) self.assertIn(LinuxKernelMessages.MESSAGE_CHOICES[0][1], message_list) self.assertIn(LinuxKernelMessages.MESSAGE_CHOICES[1][1], message_list) self.assertIn(LinuxKernelMessages.MESSAGE_CHOICES[2][1], message_list) self.assertIn(LinuxKernelMessages.MESSAGE_CHOICES[3][1], message_list) self.assertIn(LinuxKernelMessages.MESSAGE_CHOICES[4][1], message_list) self.assertIn(LinuxKernelMessages.MESSAGE_CHOICES[5][1], message_list) connection = FakeConnection(child, message_list) results = LinuxKernelMessages.parse_failures( connection, max_end_time=self.max_end_time) self.assertEqual(len(list(results)), 14) message_list = LinuxKernelMessages.get_init_prompts() child = pexpect.spawn('cat', [logfile]) connection = FakeConnection(child, message_list) results = LinuxKernelMessages.parse_failures( connection, max_end_time=self.max_end_time) self.assertEqual(len(list(results)), 13)
def test_kernel_1(self): logfile = os.path.join(os.path.dirname(__file__), 'kernel-1.txt') self.assertTrue(os.path.exists(logfile)) child = pexpect.spawn('cat', [logfile]) message_list = LinuxKernelMessages.get_kernel_prompts() connection = FakeConnection(child, message_list) results = LinuxKernelMessages.parse_failures( connection, max_end_time=self.max_end_time) self.assertEqual(len(results), 1) self.assertEqual( results[0], { 'message': 'kernel-messages', 'success': 'Freeing unused kernel memory' })
def test_kernel_txt(self): """ The same logfile passes kernel boot and fails to find init - so the panic needs to be caught by InitMessages """ logfile = os.path.join(os.path.dirname(__file__), "kernel.txt") self.assertTrue(os.path.exists(logfile)) child = pexpect.spawn("cat", [logfile]) message_list = LinuxKernelMessages.get_kernel_prompts() self.assertIsNotNone(message_list) connection = FakeConnection(child, message_list) result = LinuxKernelMessages.parse_failures(connection) self.assertIn("success", result[0]) self.assertEqual(result[0]["success"], KERNEL_FREE_UNUSED_MSG) message_list = LinuxKernelMessages.get_init_prompts() self.assertIn(KERNEL_PANIC_MSG, message_list) self.assertNotIn(KERNEL_FREE_UNUSED_MSG, message_list) connection.prompt_str = message_list result = LinuxKernelMessages.parse_failures(connection) self.assertEqual(len(result), 1) self.assertIn("panic", result[0]) self.assertIn("message", result[0]) self.assertTrue("Attempted to kill init" in str(result[0]["message"])) self.assertTrue("(unwind_backtrace) from" in str(result[0]["message"]))
def check_kernel_messages(self, connection, max_end_time): """ Use the additional pexpect expressions to detect warnings and errors during the kernel boot. Ensure all test jobs using auto-login-action have a result set so that the duration is always available when the action completes successfully. """ if isinstance(connection, SShSession): self.logger.debug("Skipping kernel messages") return self.logger.info("Parsing kernel messages") self.logger.debug(connection.prompt_str) parsed = LinuxKernelMessages.parse_failures(connection, self, max_end_time=max_end_time) if len(parsed) and 'success' in parsed[0]: self.results = {'success': parsed[0]} elif not parsed: self.results = { 'success': "No kernel warnings or errors detected." } else: self.results = {'fail': parsed} self.logger.warning("Kernel warnings or errors detected.")