From f374d6df0400513b1f19caba1f7a9582bc7e2ee2 Mon Sep 17 00:00:00 2001 From: Zack Cerza Date: Tue, 23 Aug 2016 14:57:50 -0600 Subject: [PATCH] Add _console_command() This provides a way to generate a command that establishes a SOL console session that, depending on whether conserver settings are present, will use that or fall back to ipmitool. Signed-off-by: Zack Cerza --- teuthology/orchestra/console.py | 10 +++++ teuthology/orchestra/test/test_console.py | 45 ++++++++++++++++++++--- 2 files changed, 49 insertions(+), 6 deletions(-) diff --git a/teuthology/orchestra/console.py b/teuthology/orchestra/console.py index 4ebce301e0..e2dcd0096d 100644 --- a/teuthology/orchestra/console.py +++ b/teuthology/orchestra/console.py @@ -68,6 +68,16 @@ class PhysicalConsole(): ) return child + def _console_command(self): + if self.has_conserver: + return 'console -M {master} -p {port} {host}'.format( + master=self.conserver_master, + port=self.conserver_port, + host=self.shortname, + ) + else: + return self._build_command('sol activate') + def _build_command(self, subcommand): template = \ 'ipmitool -H {s}.{dn} -I lanplus -U {ipmiuser} -P {ipmipass} {cmd}' diff --git a/teuthology/orchestra/test/test_console.py b/teuthology/orchestra/test/test_console.py index 297f347fa7..0782d13391 100644 --- a/teuthology/orchestra/test/test_console.py +++ b/teuthology/orchestra/test/test_console.py @@ -9,29 +9,62 @@ class TestConsole(object): class TestPhysicalConsole(TestConsole): klass = console.PhysicalConsole + ipmi_cmd_templ = 'ipmitool -H {h}.{d} -I lanplus -U {u} -P {p} {c}' + conserver_cmd_templ = 'console -M {m} -p {p} {h}' def setup(self): + self.hostname = 'host' teuth_config.ipmi_domain = 'ipmi_domain' teuth_config.ipmi_user = 'ipmi_user' teuth_config.ipmi_password = 'ipmi_pass' - self.hostname = 'host' + teuth_config.conserver_master = 'conserver_master' + teuth_config.conserver_port = 3109 + + def test_console_command_conserver(self): + cons = self.klass( + self.hostname, + teuth_config.ipmi_user, + teuth_config.ipmi_password, + teuth_config.ipmi_domain, + ) + cons.has_conserver = True + console_cmd = cons._console_command() + assert console_cmd == self.conserver_cmd_templ.format( + m=teuth_config.conserver_master, + p=teuth_config.conserver_port, + h=self.hostname, + ) - def test_build_command(self): - cmd_templ = 'ipmitool -H {h}.{d} -I lanplus -U {u} -P {p} {c}' + def test_console_command_ipmi(self): + teuth_config.conserver_master = None cons = self.klass( self.hostname, teuth_config.ipmi_user, teuth_config.ipmi_password, teuth_config.ipmi_domain, ) - sol_cmd = cons._build_command('sol activate') - assert sol_cmd == cmd_templ.format( + sol_cmd = cons._console_command() + assert sol_cmd == self.ipmi_cmd_templ.format( h=self.hostname, d=teuth_config.ipmi_domain, u=teuth_config.ipmi_user, p=teuth_config.ipmi_password, c='sol activate', ) + + def test_build_command_ipmi(self): + cons = self.klass( + self.hostname, + teuth_config.ipmi_user, + teuth_config.ipmi_password, + teuth_config.ipmi_domain, + ) pc_cmd = cons._build_command('power cycle') - assert pc_cmd == sol_cmd.replace('sol activate', 'power cycle') + assert pc_cmd == self.ipmi_cmd_templ.format( + h=self.hostname, + d=teuth_config.ipmi_domain, + u=teuth_config.ipmi_user, + p=teuth_config.ipmi_password, + c='power cycle', + ) -- 2.39.5