Exemple #1
0
def empty_log_to_all():
    redis_server = RedisServer(unix_socket=REDIS_SOCKET)
    filter = Logs()
    filter.configure(FLOGS_CONFIG_ALL)
    if not filter.valgrind_start():
        return False

    redis_server.channel_subscribe(REDIS_CHANNEL_NAME)

    try:
        filter.log(b'')
        sleep(1)
    except Exception as e:
        logging.error("empty_log_to_all: Unable to connect to filter: {}".format(e))
        return False

    logs = filter.get_logs_from_file()
    if logs != []:
        logging.error("empty_log_to_all: Log line not matching: {}".format(logs))
        return False

    log = Logs.get_log_from_redis(redis_server, REDIS_LIST_NAME)
    if log is not None:
        logging.error("empty_log_to_all: Log line not matching: {}".format(log))
        return False

    channel_log = redis_server.channel_get_message()
    if channel_log is not None:
        logging.error("empty_log_to_all: channel log line not matching: {}".format(channel_log))
        return False

    return True
Exemple #2
0
def multiple_log_to_redis_channel():
    redis_server = RedisServer(unix_socket=REDIS_SOCKET)
    filter = Logs()
    filter.configure(FLOGS_CONFIG_REDIS_CHANNEL)
    if not filter.valgrind_start():
        return False

    redis_server.channel_subscribe(REDIS_CHANNEL_NAME)

    try:
        filter.log(b'Computers are good at following instructions, but not at reading your mind. Donald Knuth\n')
        filter.log(b'If we wish to count lines of code, we should not regard them as lines produced but as lines spent. Edsger Dijkstra\n')
        sleep(1)
    except Exception as e:
        logging.error("multiple_log_to_redis_channel: Unable to connect to filter: {}".format(e))
        return False

    log = redis_server.channel_get_message()
    if log != 'Computers are good at following instructions, but not at reading your mind. Donald Knuth\n':
        logging.error("multiple_log_to_redis_channel: Log line not matching: {}".format(log))
        return False

    log = redis_server.channel_get_message()
    if log != 'If we wish to count lines of code, we should not regard them as lines produced but as lines spent. Edsger Dijkstra\n':
        logging.error("multiple_log_to_redis_channel: Log line not matching: {}".format(log))
        return False

    log = redis_server.channel_get_message()
    if log is not None:
        logging.error("multiple_log_to_redis_channel: Log line not matching: waited '' but got '{}'".format(log))
        return False

    return True
Exemple #3
0
def single_log_to_all():
    redis_server = RedisServer(unix_socket=REDIS_SOCKET)
    filter = Logs()
    filter.configure(FLOGS_CONFIG_ALL)
    if not filter.valgrind_start():
        return False

    redis_server.channel_subscribe(REDIS_CHANNEL_NAME)

    try:
        filter.log(b'There are only two things wrong with C++:  The initial concept and the implementation. Bertrand Meyer\n')
        sleep(1)
    except Exception as e:
        logging.error("single_log_to_all: Unable to connect to filter: {}".format(e))
        return False

    logs = filter.get_logs_from_file()
    if logs != ['There are only two things wrong with C++:  The initial concept and the implementation. Bertrand Meyer\n']:
        logging.error("single_log_to_all: Log line not matching: {}".format(logs))
        return False

    redis_log = Logs.get_log_from_redis(redis_server, REDIS_LIST_NAME)
    if redis_log != 'There are only two things wrong with C++:  The initial concept and the implementation. Bertrand Meyer\n':
        logging.error("single_log_to_all: Log line not matching: {}".format(log))
        return False

    redis_channel_log = redis_server.channel_get_message()
    if redis_channel_log != 'There are only two things wrong with C++:  The initial concept and the implementation. Bertrand Meyer\n':
        logging.error("single_log_to_all: Log line not matching: {}".format(log))
        return False

    return True
Exemple #4
0
def multiple_log_to_all():
    redis_server = RedisServer(unix_socket=REDIS_SOCKET)
    filter = Logs()
    filter.configure(FLOGS_CONFIG_ALL)
    if not filter.valgrind_start():
        return False

    redis_server.channel_subscribe(REDIS_CHANNEL_NAME)

    try:
        filter.log(b'UNIX is simple.  It just takes a genius to understand its simplicity. Denis Ritchie\n')
        filter.log(b'A hacker is someone who enjoys playful cleverness, not necessarily with computers. Richard Stallman\n')
        sleep(1)
    except Exception as e:
        logging.error("multiple_log_to_all: Unable to connect to filter: {}".format(e))
        return False

    logs = filter.get_logs_from_file()
    if logs != [
        'UNIX is simple.  It just takes a genius to understand its simplicity. Denis Ritchie\n',
        'A hacker is someone who enjoys playful cleverness, not necessarily with computers. Richard Stallman\n'
        ]:
        logging.error("multiple_log_to_all: Log line not matching: {}".format(logs))
        return False

    log = Logs.get_log_from_redis(redis_server, REDIS_LIST_NAME)
    channel_log = redis_server.channel_get_message()
    if log != 'UNIX is simple.  It just takes a genius to understand its simplicity. Denis Ritchie\n':
        logging.error("multiple_log_to_all: Log line not matching: {}".format(log))
        return False
    if log != channel_log:
        logging.error("multiple_log_to_all: channel log line not matching: {}".format(channel_log))
        return False

    log = Logs.get_log_from_redis(redis_server, REDIS_LIST_NAME)
    channel_log = redis_server.channel_get_message()
    if log != 'A hacker is someone who enjoys playful cleverness, not necessarily with computers. Richard Stallman\n':
        logging.error("multiple_log_to_all: Log line not matching: {}".format(log))
        return False
    if log != channel_log:
        logging.error("multiple_log_to_all: channel log line not matching: {}".format(channel_log))
        return False

    return True
Exemple #5
0
def single_log_to_redis_channel():
    redis_server = RedisServer(unix_socket=REDIS_SOCKET)
    filter = Logs()
    filter.configure(FLOGS_CONFIG_REDIS_CHANNEL)
    if not filter.valgrind_start():
        return False

    redis_server.channel_subscribe(REDIS_CHANNEL_NAME)

    try:
        filter.log(b'Surveillance is the business model of the Internet. Bruce Schneier\n')
        sleep(1)
    except Exception as e:
        logging.error("single_log_to_redis_channel: Unable to connect to filter: {}".format(e))
        return False

    log = redis_server.channel_get_message()
    if log != 'Surveillance is the business model of the Internet. Bruce Schneier\n':
        logging.error("single_log_to_redis_channel: Log line not matching: {}".format(log))
        return False

    return True
Exemple #6
0
def master_replica():
    master = RedisServer(address="127.0.0.1", port=1234)
    replica = RedisServer(address="127.0.0.1",
                          port=1235,
                          unix_socket=REDIS_SOCKET_PATH,
                          master=master)

    filter = Filter(filter_name='test')
    filter.configure(FTEST_CONF_TEMPLATE)
    filter.valgrind_start()

    master.channel_subscribe(REDIS_CHANNEL_NAME)

    try:
        filter.send_single(REDIS_CHANNEL_TRIGGER)
    except Exception as e:
        logging.error(
            "master_replica: Could not connect to test filter: {}".format(e))
        return False

    sleep(1)

    message = master.channel_get_message()

    if message is '':
        logging.error(
            "master_replica: expected to get a message in channel {} " +
            "but got nothing".format(REDIS_CHANNEL_NAME))
        return False

    if message != REDIS_CHANNEL_TRIGGER:
        logging.error(
            "master_replica: expected to get a message in channel {} saying '{}' "
            + "but got '{}' instead".format(REDIS_CHANNEL_NAME,
                                            REDIS_CHANNEL_TRIGGER, message))
        return False

    return True