def _power(self, power_change, context): """Power SeaMicro node.""" ( ip, username, password, server_id, power_control, ) = extract_seamicro_parameters(context) if power_control == "ipmi": self._power_control_seamicro15k_ipmi(ip, username, password, server_id, power_change=power_change) elif power_control == "restapi": power_control_seamicro15k_v09(ip, username, password, server_id, power_change=power_change) elif power_control == "restapi2": power_control_seamicro15k_v2(ip, username, password, server_id, power_change=power_change)
def test_power_control_seamicro15k_v09(self): self.configure_api_v09_login() ip = factory.make_ipv4_address() username = factory.make_string() password = factory.make_string() mock = self.patch(SeaMicroAPIV09, "power_server") power_control_seamicro15k_v09(ip, username, password, "25", "on") self.assertThat( mock, MockCalledOnceWith("25/0", POWER_STATUS.ON, do_pxe=True))
def test_power_control_seamicro15k_v09_retry_failure(self): self.configure_api_v09_login() ip = factory.make_ipv4_address() username = factory.make_string() password = factory.make_string() mock = self.patch(SeaMicroAPIV09, "power_server") mock.side_effect = SeaMicroAPIV09Error("mock error", response_code=401) power_control_seamicro15k_v09( ip, username, password, "25", "on", retry_count=5, retry_wait=0 ) self.assertEqual(5, mock.call_count)