def test_power_off_nodes_soft_clears_shutdown_token_shutdown_fails(self): cluster = AcropolisCluster(self.cluster_metadata) cluster._prism_client = mock.Mock(spec=NutanixRestApiClient) cluster._prism_client.genesis_prepare_node_for_shutdown.return_value = True cluster._prism_client.genesis_shutdown_hypervisor.side_effect = \ [True, True, False, False] nodes = [mock.Mock() for _ in xrange(4)] for index, node in enumerate(nodes): node.node_id.return_value = str(index) with mock.patch.object(cluster, "get_power_state_for_nodes") as m_gpsfn: m_gpsfn.return_value = {"0": "kNormalConnected", "1": "kNormalConnected", "2": "kNormalConnected", "3": "kNormalConnected"} with self.assertRaises(CurieTestException) as ar: cluster.power_off_nodes_soft(nodes) self.assertEqual(str(ar.exception), "Failed to power off nodes") cluster._prism_client.genesis_prepare_node_for_shutdown.assert_has_calls( [mock.call("0"), mock.call("1")] ) cluster._prism_client.genesis_shutdown_hypervisor.assert_has_calls( [mock.call("0"), mock.call("1")] ) cluster._prism_client.genesis_clear_shutdown_token.assert_called_once_with()
def test_power_off_nodes_soft(self): cluster = AcropolisCluster(self.cluster_metadata) cluster._prism_client = mock.Mock(spec=NutanixRestApiClient) cluster._prism_client.genesis_prepare_node_for_shutdown.return_value = True cluster._prism_client.genesis_shutdown_hypervisor.return_value = True nodes = [mock.Mock() for _ in xrange(4)] for index, node in enumerate(nodes): node.node_id.return_value = str(index) with mock.patch.object(cluster, "get_power_state_for_nodes") as m_gpsfn: m_gpsfn.return_value = {"0": "kNormalConnected", "1": "kNormalConnected", "2": "kNormalConnected", "3": "kNormalConnected"} cluster.power_off_nodes_soft(nodes) cluster._prism_client.genesis_prepare_node_for_shutdown.assert_has_calls( [mock.call("0"), mock.call("1"), mock.call("2"), mock.call("3")] ) cluster._prism_client.genesis_shutdown_hypervisor.assert_has_calls( [mock.call("0"), mock.call("1"), mock.call("2"), mock.call("3")] ) cluster._prism_client.genesis_clear_shutdown_token.assert_called_once_with()