<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:

def grant_permission(username, resource=None, resource_type='keyspace', permission=None, contact_points=None, port=None,
                     cql_user=None, cql_pass=None):
    '''
    Grant permissions to a user.

    :param username:       The name of the user to grant permissions to.
    :type  username:       str
    :param resource:       The resource (keyspace or table), if None, permissions for all resources are granted.
    :type  resource:       str
    :param resource_type:  The resource_type (keyspace or table), defaults to 'keyspace'.
    :type  resource_type:  str
    :param permission:     A permission name (e.g. select), if None, all permissions are granted.
    :type  permission:     str
    :param contact_points: The Cassandra cluster addresses, can either be a string or a list of IPs.
    :type  contact_points: str | list[str]
    :param cql_user:       The Cassandra user if authentication is turned on.
    :type  cql_user:       str
    :param cql_pass:       The Cassandra user password if authentication is turned on.
    :type  cql_pass:       str
    :param port:           The Cassandra cluster port, defaults to None.
    :type  port:           int
    :return:
    :rtype:

    CLI Example:

    .. code-block:: bash

        salt 'minion1' cassandra_cql.grant_permission

        salt 'minion1' cassandra_cql.grant_permission username=joe resource=test_keyspace permission=select

        salt 'minion1' cassandra_cql.grant_permission username=joe resource=test_table resource_type=table \
        permission=select contact_points=minion1
    '''
    permission_cql = "grant {0}".format(permission) if permission else "grant all permissions"
    resource_cql = "on {0} {1}".format(resource_type, resource) if resource else "on all keyspaces"
    query = "{0} {1} to {2}".format(permission_cql, resource_cql, username)
    log.debug("Attempting to grant permissions with query '%s'", query)

    try:
        cql_query(query, contact_points, port, cql_user, cql_pass)
    except CommandExecutionError:
        log.critical('Could not grant permissions.')
        raise
    except BaseException as e:
        log.critical('Unexpected error while granting permissions: %s', e)
        raise

    return True