From fe720087c4bab1addea9dd29ea1dfe5ce06a5ff9 Mon Sep 17 00:00:00 2001 From: Zack Cerza Date: Wed, 24 Aug 2016 08:48:37 -0600 Subject: [PATCH] Get console sessions using _get_console() Signed-off-by: Zack Cerza --- teuthology/orchestra/console.py | 11 +++++-- teuthology/orchestra/test/test_console.py | 35 +++++++++++++++++++++++ 2 files changed, 43 insertions(+), 3 deletions(-) diff --git a/teuthology/orchestra/console.py b/teuthology/orchestra/console.py index 5244579681..f3a82a2110 100644 --- a/teuthology/orchestra/console.py +++ b/teuthology/orchestra/console.py @@ -65,6 +65,11 @@ class PhysicalConsole(): logfile=self.logfile, ) + def _get_console(self): + cmd = self._console_command() + child = self._pexpect_spawn(cmd) + return child + def _console_command(self): if self.has_conserver: return 'console -M {master} -p {port} {host}'.format( @@ -112,7 +117,7 @@ class PhysicalConsole(): for i in range(0, attempts): start = time.time() while time.time() - start < t: - child = self._pexpect_spawn_ipmi('sol activate') + child = self._get_console() child.send('\n') log.debug('expect: {s} login'.format(s=self.shortname)) r = child.expect( @@ -251,12 +256,12 @@ class PhysicalConsole(): :returns: a subprocess.Popen object """ - ipmi_cmd = self._ipmi_command('sol activate') + console_cmd = self._console_command() pexpect_templ = \ "import pexpect; " \ "pexpect.run('{cmd}', logfile=file('{log}', 'w'), timeout=None)" python_cmd = 'python -c "%s"' % pexpect_templ.format( - cmd=ipmi_cmd, + cmd=console_cmd, log=dest_path, ) proc = subprocess.Popen( diff --git a/teuthology/orchestra/test/test_console.py b/teuthology/orchestra/test/test_console.py index 3e24e07852..c7c12a5062 100644 --- a/teuthology/orchestra/test/test_console.py +++ b/teuthology/orchestra/test/test_console.py @@ -1,3 +1,5 @@ +from mock import patch + from teuthology.config import config as teuth_config from .. import console @@ -68,3 +70,36 @@ class TestPhysicalConsole(TestConsole): c='power cycle', ) + def test_get_console_conserver(self): + with patch( + 'teuthology.orchestra.console.subprocess.Popen', + autospec=True, + ) as m_popen: + m_popen.return_value.wait.return_value = 0 + cons = self.klass(self.hostname) + assert cons.has_conserver is True + with patch( + 'teuthology.orchestra.console.pexpect.spawn', + autospec=True, + ) as m_spawn: + cons._get_console() + assert m_spawn.call_count == 1 + assert teuth_config.conserver_master in \ + m_spawn.call_args_list[0][0][0] + + def test_get_console_ipmitool(self): + with patch( + 'teuthology.orchestra.console.subprocess.Popen', + autospec=True, + ) as m_popen: + m_popen.return_value.wait.return_value = 0 + cons = self.klass(self.hostname) + assert cons.has_conserver is True + with patch( + 'teuthology.orchestra.console.pexpect.spawn', + autospec=True, + ) as m_spawn: + cons.has_conserver = False + cons._get_console() + assert m_spawn.call_count == 1 + assert 'ipmitool' in m_spawn.call_args_list[0][0][0] -- 2.39.5