def test__power_control_seamicro15k_ipmi_calls_call_and_check(self): ip, username, password, server_id, _ = self.make_context() power_change = choice(["on", "off"]) seamicro_power_driver = SeaMicroPowerDriver() call_and_check_mock = self.patch(seamicro_module, "call_and_check") seamicro_power_driver._power_control_seamicro15k_ipmi( ip, username, password, server_id, power_change) power_mode = 1 if power_change == "on" else 6 self.assertThat( call_and_check_mock, MockCalledOnceWith([ "ipmitool", "-I", "lanplus", "-H", ip, "-U", username, "-P", password, "raw", "0x2E", "1", "0x00", "0x7d", "0xab", power_mode, "0", server_id, ]), )
def test_power_off_calls_power(self): _, _, _, _, context = self.make_context() context["power_control"] = factory.make_name("power_control") seamicro_power_driver = SeaMicroPowerDriver() power_mock = self.patch(seamicro_power_driver, "_power") seamicro_power_driver.power_off(context["system_id"], context) self.assertThat(power_mock, MockCalledOnceWith("off", context))
def test_power_query_returns_unknown_if_not_restapi2(self): ip, username, password, server_id, context = self.make_context() context["power_control"] = factory.make_name("power_control") seamicro_power_driver = SeaMicroPowerDriver() power_state = seamicro_power_driver.power_query( context["system_id"], context) self.assertThat(power_state, Equals("unknown"))
def test_power_off_calls_power(self): _, _, _, _, context = self.make_context() context['power_control'] = factory.make_name('power_control') seamicro_power_driver = SeaMicroPowerDriver() power_mock = self.patch(seamicro_power_driver, '_power') seamicro_power_driver.power_off(context['system_id'], context) self.assertThat( power_mock, MockCalledOnceWith('off', context))
def test__power_calls__power_control_seamicro15k_ipmi(self): ip, username, password, server_id, context = self.make_context() context['power_control'] = 'ipmi' power_change = choice(['on', 'off']) seamicro_power_driver = SeaMicroPowerDriver() _power_control_seamicro15k_ipmi_mock = self.patch( seamicro_power_driver, '_power_control_seamicro15k_ipmi') seamicro_power_driver._power(power_change, context) self.assertThat( _power_control_seamicro15k_ipmi_mock, MockCalledOnceWith( ip, username, password, server_id, power_change=power_change))
def test__power_control_seamicro15k_ipmi_raises_PowerFatalError(self): ip, username, password, server_id, _ = self.make_context() power_change = choice(['on', 'off']) seamicro_power_driver = SeaMicroPowerDriver() call_and_check_mock = self.patch(seamicro_module, 'call_and_check') call_and_check_mock.side_effect = ( ExternalProcessError(1, "ipmitool something")) self.assertRaises( PowerActionError, seamicro_power_driver._power_control_seamicro15k_ipmi, ip, username, password, server_id, power_change)
def test_power_query_calls_power_query_seamicro15k_v2(self): ip, username, password, server_id, context = self.make_context() context['power_control'] = 'restapi2' seamicro_power_driver = SeaMicroPowerDriver() power_query_seamicro15k_v2_mock = self.patch( seamicro_module, 'power_query_seamicro15k_v2') power_query_seamicro15k_v2_mock.return_value = 'on' power_state = seamicro_power_driver.power_query( context['system_id'], context) self.expectThat( power_query_seamicro15k_v2_mock, MockCalledOnceWith( ip, username, password, server_id)) self.expectThat(power_state, Equals('on'))
def test_power_query_calls_power_query_seamicro15k_v2(self): ip, username, password, server_id, context = self.make_context() context["power_control"] = "restapi2" seamicro_power_driver = SeaMicroPowerDriver() power_query_seamicro15k_v2_mock = self.patch( seamicro_module, "power_query_seamicro15k_v2") power_query_seamicro15k_v2_mock.return_value = "on" power_state = seamicro_power_driver.power_query( context["system_id"], context) self.expectThat( power_query_seamicro15k_v2_mock, MockCalledOnceWith(ip, username, password, server_id), ) self.expectThat(power_state, Equals("on"))
def test__power_control_seamicro15k_ipmi_calls_call_and_check(self): ip, username, password, server_id, _ = self.make_context() power_change = choice(['on', 'off']) seamicro_power_driver = SeaMicroPowerDriver() call_and_check_mock = self.patch(seamicro_module, 'call_and_check') seamicro_power_driver._power_control_seamicro15k_ipmi( ip, username, password, server_id, power_change) power_mode = 1 if power_change == 'on' else 6 self.assertThat( call_and_check_mock, MockCalledOnceWith([ 'ipmitool', '-I', 'lanplus', '-H', ip, '-U', username, '-P', password, 'raw', '0x2E', '1', '0x00', '0x7d', '0xab', power_mode, '0', server_id, ]))
def test__power_calls_power_control_seamicro15k_v2(self): ip, username, password, server_id, context = self.make_context() context["power_control"] = "restapi2" power_change = choice(["on", "off"]) seamicro_power_driver = SeaMicroPowerDriver() power_control_seamicro15k_v2_mock = self.patch( seamicro_module, "power_control_seamicro15k_v2") seamicro_power_driver._power(power_change, context) self.assertThat( power_control_seamicro15k_v2_mock, MockCalledOnceWith(ip, username, password, server_id, power_change=power_change), )
def test_power_calls__power_control_seamicro15k_ipmi(self): ip, username, password, server_id, context = self.make_context() context["power_control"] = "ipmi" power_change = choice(["on", "off"]) seamicro_power_driver = SeaMicroPowerDriver() _power_control_seamicro15k_ipmi_mock = self.patch( seamicro_power_driver, "_power_control_seamicro15k_ipmi") seamicro_power_driver._power(power_change, context) self.assertThat( _power_control_seamicro15k_ipmi_mock, MockCalledOnceWith(ip, username, password, server_id, power_change=power_change), )
# 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) # Pod drivers are also power drivers. for driver_name, driver in PodDriverRegistry: PowerDriverRegistry.register_item(driver_name, driver)