Exemplo n.º 1
0
def test_003_health_status_update(foreach_test):
    """ Update service health data"""
    conn = sqlite3.connect(Config.getDbPath())
    service_instances = conn.execute(
        """SELECT * from SERVICE_RD WHERE SERVICE_NAME = ?""",
        (TEST_PARAMS["health_object_2"]["service_name"], )).fetchall()
    conn.close()
    assert service_instances[0][3] == 41.2
    Health.health(TEST_PARAMS["health_object_2_updated"])
    conn = sqlite3.connect(Config.getDbPath())
    service_instances = conn.execute(
        """SELECT * from SERVICE_RD WHERE SERVICE_NAME = ?""",
        (TEST_PARAMS["health_object_2"]["service_name"], )).fetchall()
    conn.close()
    assert service_instances[0][3] == 61.2
Exemplo n.º 2
0
def test_002_health_status_deregister(foreach_test):
    """ Deregister service """
    conn = sqlite3.connect(Config.getDbPath())
    service_instances = conn.execute(
        """SELECT * from SERVICE_RD WHERE SERVICE_NAME = ?""",
        (TEST_PARAMS["health_object_2"]["service_name"], )).fetchall()
    conn.close()
    assert len(service_instances) > 0
    Health.health(TEST_PARAMS["health_object_2_down"])
    conn = sqlite3.connect(Config.getDbPath())
    service_instances = conn.execute(
        """SELECT * from SERVICE_RD WHERE SERVICE_NAME = ?""",
        (TEST_PARAMS["health_object_2"]["service_name"], )).fetchall()
    conn.close()
    assert len(service_instances) == 0
def foreach_test():
    print("Setup before test")
    """ Test Environment Setup for each test case """
    Config.setDbPath(os.path.join(basedir, "src/sharkradar/Util"))
    Config.setAlgorithm("wpmc")
    sharkradarDbutils.createTableIfNotExists()
    Health.health(TEST_PARAMS["health_object_1"])
    Health.health(TEST_PARAMS["health_object_2"])
    Health.health(TEST_PARAMS["health_object_3"])
    app.testing = True
    client = app.test_client()
    yield client
    print("Teardown after test")
    """ Test Environment Clean up for each test case """
    sharkradarDbutils.deleteServiceByNameAndIpAndPort(
        TEST_PARAMS["health_object_1"]["service_name"],
        TEST_PARAMS["health_object_1"]["ip"],
        TEST_PARAMS["health_object_1"]["port"])
    sharkradarDbutils.deleteServiceByNameAndIpAndPort(
        TEST_PARAMS["health_object_2"]["service_name"],
        TEST_PARAMS["health_object_2"]["ip"],
        TEST_PARAMS["health_object_2"]["port"])
    sharkradarDbutils.deleteServiceByNameAndIpAndPort(
        TEST_PARAMS["health_object_3"]["service_name"],
        TEST_PARAMS["health_object_3"]["ip"],
        TEST_PARAMS["health_object_3"]["port"])
    sharkradarDbutils.deleteServiceByNameAndIpAndPort(
        TEST_PARAMS["health_object_4"]["service_name"],
        TEST_PARAMS["health_object_4"]["ip"],
        TEST_PARAMS["health_object_4"]["port"])
    conn = sqlite3.connect(Config.getDbPath())
    conn.execute("""DELETE FROM SERVICE_LOGS WHERE 1 = 1""")
    conn.execute("""DELETE FROM DISCOVERY_LOGS WHERE 1 = 1""")
    conn.commit()
    conn.close()
Exemplo n.º 4
0
def test_009_health_status_register_check_logs(foreach_test):
    """ Register service and check service logs"""
    Health.health(TEST_PARAMS["health_object_1"])
    time.sleep(2)
    Health.health(TEST_PARAMS["health_object_1"])
    time.sleep(2)
    Health.health(TEST_PARAMS["health_object_1"])
    conn = sqlite3.connect(Config.getDbPath())
    service_instance = conn.execute(
        """SELECT * from SERVICE_LOGS""").fetchall()
    conn.close()
    assert len(service_instance) == 3
Exemplo n.º 5
0
def health():
    """
        API Endpoint to send health report of micro-services to Service R/D
        @method: PUT
        @params: A json body containing the following key-value pairs about a micro-service.
                     KEYS:                  VALUES:
               ---------            -------------
              i) ip                 ip address associated with micro-service
             ii) port               port associated with micro-service
            iii) service_name       unique name of the micro-service (But same for all instances of same microservice)
             iv) status             status (up/down) sent from the micro-service
              v) mem_usage          Current memory usage in %
             vi) cpu_usage          Current CPU usage in %
            vii) nw_tput_bw_ratio   Current network throughput in %
            viii) req_active_ratio  No. of requests currently being processed / Max.
                                    no. of request can be processed in %
             ix) success_rate       Fraction of requests successfully served in %
              x) health_interval    The time interval in seconds specified by the micro-service
                                    at which it will send health report to service
                                    R/D continuously
        @return: {"status" : "<BOOL>"} <BOOL>=True|False
    """
    response_objects = {"status": "False"}
    try:
        json_object = {}
        json_object['ip'] = request.form['ip']
        json_object['port'] = request.form['port']
        json_object['service_name'] = request.form['service_name']
        json_object['status'] = request.form['status']
        json_object['mem_usage'] = request.form['mem_usage']
        json_object['cpu_usage'] = request.form['cpu_usage']
        json_object['nw_tput_bw_ratio'] = request.form['nw_tput_bw_ratio']
        json_object['req_active_ratio'] = request.form['req_active_ratio']
        json_object['success_rate'] = request.form['success_rate']
        json_object['health_interval'] = request.form['health_interval']
        json_object['current_timestamp'] = time.time()
        respBool = Health.health(json_object)
        if respBool:
            response_objects["status"] = "True"
            return json.dumps(response_objects)
        return json.dumps(response_objects)
    except Exception as e:
        return json.dumps(response_objects)
Exemplo n.º 6
0
def test_008_health_status_register_improper_data(foreach_test):
    """ Register service with improper data """
    assert Health.health(TEST_PARAMS["health_object_6"]) == False
Exemplo n.º 7
0
def test_001_health_status_register(foreach_test):
    """ Register service """
    assert Health.health(TEST_PARAMS["health_object_1"]) == True