Beispiel #1
0
def simple_master_server():
    master = RedisServer(unix_socket=REDIS_SOCKET_PATH)

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

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

    sleep(1)

    with master.connect() as redis_connection:
        num_list_entries = redis_connection.llen(REDIS_LIST_NAME)

    if num_list_entries != 1:
        logging.error(
            "simple_master_server: wrong number of entries in the redis list {}: "
            + "expected 1 but got {}".format(REDIS_LIST_NAME,
                                             str(num_list_entries)))
        return False

    return True
Beispiel #2
0
def check_pid_file():
    filter = Filter(filter_name="logs")
    pid = -1

    filter.configure(FLOGS_CONFIG)
    filter.valgrind_start()

    try:
        with open(filter.pid) as f:
            pid = int(f.readline())
    except Exception as e:
        logging.error("check_pid: Unable to read pid file: {}".format(e))
        return False

    try:
        kill(pid, 0)
    except OSError as e:
        logging.error("check_pid: Process {} not running: {}".format(pid, e))
        return False

    filter.stop()

    if access(filter.pid, F_OK):
        logging.error("check_pid: PID file not deleted")
        return False

    return True
Beispiel #3
0
def check_socket_monitor_connection():
    filter = Filter(filter_name="logs")
    pid = -1

    filter.configure(FLOGS_CONFIG)
    filter.valgrind_start()

    try:
        with socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) as s:
            s.connect(filter.monitor)
            data = s.recv(4096).decode()
            s.close()
        if RESP_MON_STATUS_RUNNING not in data:
            logging.error(
                "check_socket_monitor_connection: Wrong response; got {}".
                format(data))
            return False
    except Exception as e:
        logging.error(
            "check_socket_monitor_connection: Error connecting to socket: {}".
            format(e))
        return False

    filter.stop()
    return True
Beispiel #4
0
def master_replica_transfer(function_name, healthcheck):
    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()

    try:
        # success
        filter.send_single(REDIS_LIST_TRIGGER)
    except Exception as e:
        logging.error("{}: Could not connect to test filter: {}".format(
            function_name, e))
        return False

    # master becomes replica
    with master.connect() as master_connection:
        master_connection.slaveof(replica.address, replica.port)
    #replica becomes master
    with replica.connect() as replica_connection:
        replica_connection.slaveof()
    sleep(1)

    if healthcheck:
        sleep(8)

    try:
        # success
        return_code = filter.send_single(REDIS_LIST_TRIGGER)
    except Exception as e:
        logging.error("{}: Could not connect to test filter: {}".format(
            function_name, e))
        return False

    if return_code != 0:
        logging.error(
            "{}: Filter didn't return correct code, " +
            "waited for 0 but got {}".format(function_name, return_code))
        return False

    with replica.connect() as new_master_connection:
        num_entries = new_master_connection.llen(REDIS_LIST_NAME)

    if num_entries != 2:
        logging.error("{}: Wrong number of entries in {}, " +
                      "expected 2 but got {}".format(
                          function_name, REDIS_LIST_NAME, num_entries))
        return False

    return True
Beispiel #5
0
def check_start_no_conf():
    filter = Filter(filter_name="logs")

    filter.valgrind_start()
    sleep(2)
    
    if not access(filter.pid, F_OK):
        return True

    logging.error("check_start_wrong_conf: Process running with wrong configuration")
    return False
Beispiel #6
0
def check_start_invalid_cache_num():
    filter = Filter(filter_name="logs", cache_size="General")

    filter.configure(FLOGS_CONFIG)
    filter.valgrind_start()
    sleep(0.5)
    if filter.check_start():
        logging.error(
            "check_start_invalid_cache_num: Process started when cache size was invalid"
        )
        filter.stop()
        return False

    return True
Beispiel #7
0
def check_start_invalid_threshold_num():
    filter = Filter(filter_name="logs", thresold="Kenobi")

    filter.configure(FLOGS_CONFIG)
    filter.valgrind_start()
    sleep(0.5)
    if filter.check_start():
        logging.error(
            "check_start_invalid_threshold_num: Process started when threshold was invalid"
        )
        filter.stop()
        return False

    return True
Beispiel #8
0
def check_start_invalid_thread_num():
    filter = Filter(filter_name="logs", nb_threads="HelloThere")

    filter.configure(FLOGS_CONFIG)
    filter.valgrind_start()
    sleep(0.5)
    if filter.check_start():
        logging.error(
            "check_start_invalid_thread_num: Process started when thread number was invalid"
        )
        filter.stop()
        return False

    return True
Beispiel #9
0
def check_start_outbound_threshold_num():
    filter = Filter(filter_name="logs",
                    thresold="459230781640628620899862803482")

    filter.configure(FLOGS_CONFIG)
    filter.valgrind_start()
    sleep(0.5)
    if filter.check_start():
        logging.error(
            "check_start_outbound_threshold_num: Process started when threshold was out of bounds"
        )
        filter.stop()
        return False

    return True
Beispiel #10
0
def check_start_outbound_cache_num():
    filter = Filter(filter_name="logs",
                    cache_size="950288419716939937510582097494")

    filter.configure(FLOGS_CONFIG)
    filter.valgrind_start()
    sleep(0.5)
    if filter.check_start():
        logging.error(
            "check_start_outbound_cache_num: Process started when cache size was out of bounds"
        )
        filter.stop()
        return False

    return True
Beispiel #11
0
def check_start_outbound_thread_num():
    filter = Filter(filter_name="logs",
                    nb_threads="314159265358979323846264338327")

    filter.configure(FLOGS_CONFIG)
    filter.valgrind_start()
    sleep(0.5)
    if filter.check_start():
        logging.error(
            "check_start_outbound_thread_num: Process started when thread number was out of bounds"
        )
        filter.stop()
        return False

    return True
Beispiel #12
0
def check_start_stop():
    filter = Filter(filter_name="logs")

    filter.configure(FLOGS_CONFIG)
    filter.valgrind_start()
    try:
        kill(filter.process.pid, 0)
    except OSError as e:
        logging.error("check_start_stop: Process {} not running: {}".format(filter.process.pid, e))
        return False

    if filter.stop() is not True:
        return False
    
    return True
Beispiel #13
0
def check_socket_connection():
    filter = Filter(filter_name="logs")
    pid = -1

    filter.configure(FLOGS_CONFIG)
    filter.valgrind_start()

    try:
        api = DarwinApi(socket_path=filter.socket, socket_type="unix")
        api.call("test\n", filter_code="logs", response_type="back")
        api.close()
    except Exception as e:
        logging.error("check_socket_connection_back: Error connecting to socket: {}".format(e))
        return False

    filter.stop()    
    return True
Beispiel #14
0
def check_socket_create_delete():
    filter = Filter(filter_name="logs")
    pid = -1

    filter.configure(FLOGS_CONFIG)
    filter.valgrind_start()

    if not access(filter.socket, F_OK):
        logging.error("check_socket_create_delete: Socket file not accesible")
        return False

    filter.stop()

    if access(filter.socket, F_OK):
        logging.error("check_socket_create_delete: Socket file not deleted")
        return False

    return True
Beispiel #15
0
def multi_thread_master():
    master = RedisServer(unix_socket=REDIS_SOCKET_PATH)

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

    thread_list = []

    def thread_brute(filter, count_log):
        for count in range(0, count_log):
            try:
                filter.send_single(REDIS_LIST_TRIGGER)
            except:
                return False
        return True

    for num in range(0, 5):
        thread_list.append(
            threading.Thread(target=thread_brute, args=(filter, 500)))

    for thread in thread_list:
        thread.start()

    for thread in thread_list:
        thread.join()

    sleep(1)

    number = master.get_number_of_connections()

    # 5 threads
    if number != 5:
        logging.error(
            "multi_thread_master: wrong number of active connections: expected 5 but got "
            + str(number))
        return False

    return True
Beispiel #16
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
Beispiel #17
0
def master_replica_master_temp_fail():
    master = RedisServer(address="127.0.0.1", port=1234)
    replica = RedisServer(address="127.0.0.1",
                          unix_socket=REDIS_SOCKET_PATH,
                          master=master)

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

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

    master.stop()
    sleep(1)

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

    sleep(1)

    if not filter.check_run():
        logging.error(
            "master_replica_master_temp_fail: filter seems to have crashed when master Redis got offline"
        )
        return False

    master.start()

    # rate limiting will prevent to reconnect immediately after failure, so there should have a wait
    # (rate limiting is not tested here)
    sleep(8)

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

    with master.connect() as master_connection:
        num_list_entries = master_connection.llen(REDIS_LIST_NAME)

    if num_list_entries != 1:
        logging.error(
            "master_replica_master_temp_fail: wrong number of entries in the redis list {}: "
            +
            "expected 1 but got {}".format(REDIS_LIST_NAME, num_list_entries))
        return False

    return True