'Ensure excpetions in reply header are raised by the RPC client.
Coho cluster\'s RPC server packs errors into the reply header.
This test ensures that the RPC client parses the reply header
correctly and raises exceptions on various errors that can be
included in the reply header.'

def test_rpc_client_error_in_reply_header(self):

    mock_socket = self.mock_object(socket, 'socket')
    mock_recvrecord = self.mock_object(coho.Client, '_recvrecord')
    rpc_client = coho.CohoRPCClient(ADDR, RPC_PORT)
    mock_recvrecord.return_value = NO_REPLY_BIN
    with self.assertRaisesRegex(exception.CohoException, 'no    REPLY.*'):
        rpc_client.create_snapshot('src', 'dest', 0)
    mock_recvrecord.return_value = MSG_DENIED_BIN
    with self.assertRaisesRegex(exception.CohoException, '.*MSG_DENIED.*'):
        rpc_client.delete_snapshot('snapshot')
    mock_recvrecord.return_value = PROG_UNAVAIL_BIN
    with self.assertRaisesRegex(exception.CohoException, '.*PROG_UNAVAIL'):
        rpc_client.delete_snapshot('snapshot')
    mock_recvrecord.return_value = PROG_MISMATCH_BIN
    with self.assertRaisesRegex(exception.CohoException, '.*PROG_MISMATCH.*'):
        rpc_client.delete_snapshot('snapshot')
    mock_recvrecord.return_value = GARBAGE_ARGS_BIN
    with self.assertRaisesRegex(exception.CohoException, '.*GARBAGE_ARGS'):
        rpc_client.delete_snapshot('snapshot')
    mock_recvrecord.return_value = PROC_UNAVAIL_BIN
    with self.assertRaisesRegex(exception.CohoException, '.*PROC_UNAVAIL'):
        rpc_client.delete_snapshot('snapshot')
    self.assertTrue(mock_recvrecord.called)
    mock_socket.assert_has_calls([mock.call(socket.AF_INET, socket.SOCK_STREAM), mock.call().connect((ADDR, RPC_PORT))])
