def test_reboot_fail(self): info = ssh._parse_driver_info(self.node) info['macs'] = ["11:11:11:11:11:11", "52:54:00:cf:2d:31"] self.mox.StubOutWithMock(ssh, '_parse_driver_info') self.mox.StubOutWithMock(ssh, '_get_nodes_mac_addresses') self.mox.StubOutWithMock(ssh, '_get_connection') self.mox.StubOutWithMock(ssh, '_get_power_status') self.mox.StubOutWithMock(ssh, '_power_off') self.mox.StubOutWithMock(ssh, '_power_on') ssh._parse_driver_info(self.node).\ AndReturn(info) ssh._get_nodes_mac_addresses(mox.IgnoreArg(), self.node).\ AndReturn(info['macs']) ssh._get_connection(self.node).AndReturn(self.sshclient) ssh._get_power_status(self.sshclient, info).\ AndReturn(states.POWER_ON) ssh._power_off(self.sshclient, info).\ AndReturn(None) ssh._power_on(self.sshclient, info).\ AndReturn(states.POWER_OFF) self.mox.ReplayAll() with task_manager.acquire([info['uuid']], shared=False) as task: self.assertRaises(exception.PowerStateFailure, task.resources[0].driver.power.reboot, task, self.node) self.mox.VerifyAll()
def test__power_off_fail(self): info = ssh._parse_driver_info(self.node) info["macs"] = ["11:11:11:11:11:11", "52:54:00:cf:2d:31"] self.mox.StubOutWithMock(ssh, "_get_power_status") self.mox.StubOutWithMock(ssh, "_get_hosts_name_for_node") self.mox.StubOutWithMock(ssh, "_exec_ssh_command") ssh._get_power_status(self.sshclient, info).AndReturn(states.POWER_ON) ssh._get_hosts_name_for_node(self.sshclient, info).AndReturn("NodeName") cmd_to_exec = info["cmd_set"]["stop_cmd"] cmd_to_exec = cmd_to_exec.replace("{_NodeName_}", "NodeName") ssh._exec_ssh_command(self.sshclient, cmd_to_exec).AndReturn(None) ssh._get_power_status(self.sshclient, info).AndReturn(states.POWER_ON) self.mox.ReplayAll() current_state = ssh._power_off(self.sshclient, info) self.assertEqual(current_state, states.ERROR) self.mox.VerifyAll()
def test__get_power_status_correct_node(self, get_hosts_name_mock, exec_ssh_mock): # Bug: #1397834 test that get_power_status return status of # baremeta_1 (off) and not baremetal_11 (on) info = ssh._parse_driver_info(self.node) exec_ssh_mock.return_value = ('"baremetal_11"\n"seed"\n', "") get_hosts_name_mock.return_value = "baremetal_1" pstate = ssh._get_power_status(self.sshclient, info) self.assertEqual(states.POWER_OFF, pstate)
def test__get_power_status_correct_node(self, get_hosts_name_mock, exec_ssh_mock): # Bug: #1397834 test that get_power_status return status of # baremeta_1 (off) and not baremetal_11 (on) info = ssh._parse_driver_info(self.node) exec_ssh_mock.return_value = ('"baremetal_11"\n"seed"\n', '') get_hosts_name_mock.return_value = "baremetal_1" pstate = ssh._get_power_status(self.sshclient, info) self.assertEqual(states.POWER_OFF, pstate)
def test__get_power_status_off(self, get_hosts_name_mock, exec_ssh_mock): info = ssh._parse_driver_info(self.node) exec_ssh_mock.return_value = ('"NodeName" {b43c4982-110c-4c29-9325-d5f41b053513}', "") get_hosts_name_mock.return_value = "NotNodeName" pstate = ssh._get_power_status(self.sshclient, info) ssh_cmd = "%s %s" % (info["cmd_set"]["base_cmd"], info["cmd_set"]["list_running"]) self.assertEqual(states.POWER_OFF, pstate) exec_ssh_mock.assert_called_once_with(self.sshclient, ssh_cmd) get_hosts_name_mock.assert_called_once_with(self.sshclient, info)
def test_reboot_good(self): info = ssh._parse_driver_info(self.node) info["macs"] = ["11:11:11:11:11:11", "52:54:00:cf:2d:31"] self.mox.StubOutWithMock(ssh, "_parse_driver_info") self.mox.StubOutWithMock(ssh, "_get_nodes_mac_addresses") self.mox.StubOutWithMock(ssh, "_get_connection") self.mox.StubOutWithMock(ssh, "_get_power_status") self.mox.StubOutWithMock(ssh, "_power_off") self.mox.StubOutWithMock(ssh, "_power_on") ssh._parse_driver_info(self.node).AndReturn(info) ssh._get_nodes_mac_addresses(mox.IgnoreArg(), self.node).AndReturn(info["macs"]) ssh._get_connection(self.node).AndReturn(self.sshclient) ssh._get_power_status(self.sshclient, info).AndReturn(states.POWER_ON) ssh._power_off(self.sshclient, info).AndReturn(None) ssh._power_on(self.sshclient, info).AndReturn(states.POWER_ON) self.mox.ReplayAll() with task_manager.acquire([info["uuid"]], shared=False) as task: task.resources[0].driver.power.reboot(task, self.node) self.mox.VerifyAll()
def test__power_off_fail(self): info = ssh._parse_driver_info(self.node) info['macs'] = ["11:11:11:11:11:11", "52:54:00:cf:2d:31"] self.mox.StubOutWithMock(ssh, '_get_power_status') self.mox.StubOutWithMock(ssh, '_get_hosts_name_for_node') self.mox.StubOutWithMock(ssh, '_exec_ssh_command') ssh._get_power_status(self.sshclient, info).\ AndReturn(states.POWER_ON) ssh._get_hosts_name_for_node(self.sshclient, info).\ AndReturn("NodeName") cmd_to_exec = info['cmd_set']['stop_cmd'] cmd_to_exec = cmd_to_exec.replace('{_NodeName_}', 'NodeName') ssh._exec_ssh_command(self.sshclient, cmd_to_exec).\ AndReturn(None) ssh._get_power_status(self.sshclient, info).\ AndReturn(states.POWER_ON) self.mox.ReplayAll() current_state = ssh._power_off(self.sshclient, info) self.assertEqual(current_state, states.ERROR) self.mox.VerifyAll()
def test__power_off_good(self): info = ssh._parse_driver_info(self.node) info['macs'] = ["11:11:11:11:11:11", "52:54:00:cf:2d:31"] self.mox.StubOutWithMock(ssh, '_get_power_status') self.mox.StubOutWithMock(ssh, '_get_hosts_name_for_node') self.mox.StubOutWithMock(ssh, '_exec_ssh_command') ssh._get_power_status(self.sshclient, info).\ AndReturn(states.POWER_ON) ssh._get_hosts_name_for_node(self.sshclient, info).\ AndReturn("NodeName") cmd_to_exec = info['cmd_set']['stop_cmd'] cmd_to_exec = cmd_to_exec.replace('{_NodeName_}', 'NodeName') ssh._exec_ssh_command(self.sshclient, cmd_to_exec).\ AndReturn(None) ssh._get_power_status(self.sshclient, info).\ AndReturn(states.POWER_OFF) self.mox.ReplayAll() current_state = ssh._power_off(self.sshclient, info) self.assertEqual(current_state, states.POWER_OFF) self.mox.VerifyAll()
def test__get_power_status_off(self, get_hosts_name_mock, exec_ssh_mock): info = ssh._parse_driver_info(self.node) exec_ssh_mock.return_value = ( '"NodeName" {b43c4982-110c-4c29-9325-d5f41b053513}', '') get_hosts_name_mock.return_value = "NotNodeName" pstate = ssh._get_power_status(self.sshclient, info) ssh_cmd = "%s %s" % (info['cmd_set']['base_cmd'], info['cmd_set']['list_running']) self.assertEqual(states.POWER_OFF, pstate) exec_ssh_mock.assert_called_once_with(self.sshclient, ssh_cmd) get_hosts_name_mock.assert_called_once_with(self.sshclient, info)
def test__get_power_status_on_unquoted(self, get_hosts_name_mock, exec_ssh_mock): info = ssh._parse_driver_info(self.node) exec_ssh_mock.return_value = ('ExactNodeName', '') get_hosts_name_mock.return_value = "ExactNodeName" pstate = ssh._get_power_status(self.sshclient, info) ssh_cmd = "%s %s" % (info['cmd_set']['base_cmd'], info['cmd_set']['list_running']) self.assertEqual(states.POWER_ON, pstate) exec_ssh_mock.assert_called_once_with(self.sshclient, ssh_cmd) get_hosts_name_mock.assert_called_once_with(self.sshclient, info)
def test__get_power_status_on_unquoted(self, get_hosts_name_mock, exec_ssh_mock): info = ssh._parse_driver_info(self.node) exec_ssh_mock.return_value = ( 'ExactNodeName', '') get_hosts_name_mock.return_value = "ExactNodeName" pstate = ssh._get_power_status(self.sshclient, info) ssh_cmd = "%s %s" % (info['cmd_set']['base_cmd'], info['cmd_set']['list_running']) self.assertEqual(states.POWER_ON, pstate) exec_ssh_mock.assert_called_once_with(self.sshclient, ssh_cmd) get_hosts_name_mock.assert_called_once_with(self.sshclient, info)
def test__get_power_status_error(self): info = ssh._parse_driver_info(self.node) self.mox.StubOutWithMock(ssh, "_exec_ssh_command") self.mox.StubOutWithMock(ssh, "_get_hosts_name_for_node") ssh._exec_ssh_command(self.sshclient, info["cmd_set"]["list_running"]).AndReturn( ['"NodeName" {b43c4982-110c-4c29-9325-d5f41b053513}'] ) ssh._get_hosts_name_for_node(self.sshclient, info).AndReturn(None) self.mox.ReplayAll() pstate = ssh._get_power_status(self.sshclient, info) self.assertEqual(pstate, states.ERROR) self.mox.VerifyAll()
def test__get_power_status_error(self): info = ssh._parse_driver_info(self.node) self.mox.StubOutWithMock(ssh, '_exec_ssh_command') self.mox.StubOutWithMock(ssh, '_get_hosts_name_for_node') ssh._exec_ssh_command( self.sshclient, info['cmd_set']['list_running']).AndReturn( ['"NodeName" {b43c4982-110c-4c29-9325-d5f41b053513}']) ssh._get_hosts_name_for_node(self.sshclient, info).\ AndReturn(None) self.mox.ReplayAll() pstate = ssh._get_power_status(self.sshclient, info) self.assertEqual(pstate, states.ERROR) self.mox.VerifyAll()
def test__get_power_status_off(self): info = ssh._parse_driver_info(self.node) self.mox.StubOutWithMock(ssh, '_exec_ssh_command') self.mox.StubOutWithMock(ssh, '_get_hosts_name_for_node') ssh._exec_ssh_command( self.sshclient, info['cmd_set']['list_running']).AndReturn( ['"NodeName" {b43c4982-110c-4c29-9325-d5f41b053513}']) ssh._get_hosts_name_for_node(self.sshclient, info).\ AndReturn("NotNodeName") self.mox.ReplayAll() pstate = ssh._get_power_status(self.sshclient, info) self.assertEqual(pstate, states.POWER_OFF) self.mox.VerifyAll()
def test__get_power_status_on(self): info = ssh._parse_driver_info(self.node) with mock.patch.object(ssh, '_get_hosts_name_for_node') \ as get_hosts_name_mock: self.exec_ssh_mock.return_value = ( '"NodeName" {b43c4982-110c-4c29-9325-d5f41b053513}', '') get_hosts_name_mock.return_value = "NodeName" pstate = ssh._get_power_status(self.sshclient, info) ssh_cmd = "%s %s" % (info['cmd_set']['base_cmd'], info['cmd_set']['list_running']) self.assertEqual(pstate, states.POWER_ON) self.exec_ssh_mock.assert_called_once_with(self.sshclient, ssh_cmd) get_hosts_name_mock.assert_called_once_with(self.sshclient, info)
def test__get_power_status_off(self): info = ssh._parse_driver_info(self.node) with mock.patch.object(ssh, '_get_hosts_name_for_node') \ as get_hosts_name_mock: self.exec_ssh_mock.return_value = ( '"NodeName" {b43c4982-110c-4c29-9325-d5f41b053513}', '') get_hosts_name_mock.return_value = "NotNodeName" pstate = ssh._get_power_status(self.sshclient, info) ssh_cmd = "%s %s" % (info['cmd_set']['base_cmd'], info['cmd_set']['list_running']) self.assertEqual(states.POWER_OFF, pstate) self.exec_ssh_mock.assert_called_once_with(self.sshclient, ssh_cmd) get_hosts_name_mock.assert_called_once_with(self.sshclient, info)