]> git.apps.os.sepia.ceph.com Git - teuthology.git/commitdiff
Get console sessions using _get_console()
authorZack Cerza <zack@redhat.com>
Wed, 24 Aug 2016 14:48:37 +0000 (08:48 -0600)
committerZack Cerza <zack@redhat.com>
Wed, 31 Aug 2016 21:16:39 +0000 (15:16 -0600)
Signed-off-by: Zack Cerza <zack@redhat.com>
teuthology/orchestra/console.py
teuthology/orchestra/test/test_console.py

index 5244579681768e6126df07dde8ec9488f50288c9..f3a82a2110e69bb151830005ebaf01decf5b291d 100644 (file)
@@ -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(
index 3e24e07852ead18818b51102748c4531f06bd2e6..c7c12a5062bcf84977ae510a2620e4d9b5e55aa1 100644 (file)
@@ -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]