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(
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(
: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(
+from mock import patch
+
from teuthology.config import config as teuth_config
from .. import console
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]