def test_run_mscm_command_returns_command_output(self): driver = MSCMPowerDriver() command = factory.make_name("command") context = make_context() SSHClient = self.patch(mscm_module, "SSHClient") AutoAddPolicy = self.patch(mscm_module, "AutoAddPolicy") ssh_client = SSHClient.return_value expected = factory.make_name("output").encode("utf-8") stdout = BytesIO(expected) streams = factory.make_streams(stdout=stdout) ssh_client.exec_command = Mock(return_value=streams) output = driver.run_mscm_command(command, **context) self.expectThat(expected.decode("utf-8"), Equals(output)) self.expectThat(SSHClient, MockCalledOnceWith()) self.expectThat( ssh_client.set_missing_host_key_policy, MockCalledOnceWith(AutoAddPolicy.return_value), ) self.expectThat( ssh_client.connect, MockCalledOnceWith( context["power_address"], username=context["power_user"], password=context["power_pass"], ), ) self.expectThat(ssh_client.exec_command, MockCalledOnceWith(command))
def test_power_query_returns_power_state_on(self): driver = MSCMPowerDriver() system_id = factory.make_name("system_id") context = make_context() run_mscm_command = self.patch(driver, "run_mscm_command") run_mscm_command.return_value = ( "show node power c1n1\r\r\n\r\nCartridge #1\r\n Node #1\r\n" " Power State: On\r\n") output = driver.power_query(system_id, context) self.assertThat(output, Equals("on"))
def test_power_query_returns_power_state(self, power_state): states = {"Off": "off", "Unavailable": "off", "On": "on"} driver = MSCMPowerDriver() system_id = factory.make_name("system_id") context = make_context() run_mscm_command = self.patch(driver, "run_mscm_command") run_mscm_command.return_value = ( "show node power c1n1\r\r\n\r\nCartridge #1\r\n Node #1\r\n" " Power State: %s\r\n" % power_state) output = driver.power_query(system_id, context) self.assertThat(output, Equals(states[power_state]))
def test_power_off_calls_run_mscm_command(self): driver = MSCMPowerDriver() system_id = factory.make_name('system_id') context = make_context() run_mscm_command = self.patch(driver, "run_mscm_command") driver.power_off(system_id, context) self.assertThat( run_mscm_command, MockCalledOnceWith( "set node power off force %s" % context['node_id'], **context))
def test_power_query_crashes_when_unable_to_find_match(self): driver = MSCMPowerDriver() system_id = factory.make_name("system_id") context = make_context() run_mscm_command = self.patch(driver, "run_mscm_command") run_mscm_command.return_value = "Rubbish" self.assertRaises(PowerFatalError, driver.power_query, system_id, context)
def test_power_query_crashes_for_connection_error(self): driver = MSCMPowerDriver() system_id = factory.make_name("system_id") context = make_context() run_mscm_command = self.patch(driver, "run_mscm_command") run_mscm_command.side_effect = PowerConnError("Connection Error") self.assertRaises(PowerActionError, driver.power_query, system_id, context)
def test_power_on_calls_run_mscm_command(self): driver = MSCMPowerDriver() system_id = factory.make_name('system_id') context = make_context() power_query = self.patch(driver, "power_query") power_query.return_value = 'on' self.patch(driver, "power_off") self.patch(driver, "configure_node_bootonce_pxe") run_mscm_command = self.patch(driver, "run_mscm_command") driver.power_on(system_id, context) self.assertThat( run_mscm_command, MockCallsMatch( call("set node bootonce pxe %s" % context['node_id'], **context), call("set node power on %s" % context['node_id'], **context)))
def test_run_mscm_command_crashes_for_ssh_connection_error(self, error): driver = MSCMPowerDriver() command = factory.make_name("command") context = make_context() self.patch(mscm_module, "AutoAddPolicy") SSHClient = self.patch(mscm_module, "SSHClient") ssh_client = SSHClient.return_value ssh_client.connect.side_effect = error self.assertRaises(PowerConnError, driver.run_mscm_command, command, **context)
def test_power_on_crashes_for_connection_error(self): driver = MSCMPowerDriver() system_id = factory.make_name("system_id") context = make_context() power_query = self.patch(driver, "power_query") power_query.return_value = "off" self.patch(driver, "configure_node_bootonce_pxe") run_mscm_command = self.patch(driver, "run_mscm_command") run_mscm_command.side_effect = PowerConnError("Connection Error") self.assertRaises(PowerActionError, driver.power_on, system_id, context)
] validate(schemas, JSON_POWER_DRIVERS_SCHEMA) return schemas # Register all the power drivers. power_drivers = [ AMTPowerDriver(), APCPowerDriver(), DLIPowerDriver(), HMCPowerDriver(), IPMIPowerDriver(), LXDPowerDriver(), ManualPowerDriver(), MoonshotIPMIPowerDriver(), MSCMPowerDriver(), MicrosoftOCSPowerDriver(), NovaPowerDriver(), OpenBMCPowerDriver(), RECSPowerDriver(), RedfishPowerDriver(), SeaMicroPowerDriver(), UCSMPowerDriver(), VirshPowerDriver(), VMwarePowerDriver(), WedgePowerDriver(), ] for driver in power_drivers: PowerDriverRegistry.register_item(driver.name, driver)