From 2a60748a9903069231f2136b03284669053756ed Mon Sep 17 00:00:00 2001 From: hxy7yx <1595670487@qq.com> Date: Tue, 21 Nov 2023 15:34:34 +0800 Subject: [PATCH] add http api ft --- .github/workflows/check.yml | 6 +-- plugins/restful/handle.c | 9 ----- plugins/restful/log_handle.c | 64 ------------------------------ plugins/restful/log_handle.h | 1 - tests/ft/http_api/test_http_api.py | 13 +++--- 5 files changed, 8 insertions(+), 85 deletions(-) diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index c5ec58e8e..6a867c99c 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -148,11 +148,11 @@ jobs: - name: function test run: | if [ "${{ matrix.plugin }}" = "core" ]; then - pytest -s -v tests/ft --ignore=tests/ft/test_modbus.py --ignore=tests/ft/test_metrics.py + pytest -s -v tests/ft --ignore=tests/ft/driver/test_modbus.py --ignore=tests/ft/metrics/test_metrics.py elif [ "${{ matrix.plugin }}" = "modbus" ]; then - pytest -s -v tests/ft/driver/"test_modbus.py" + pytest -s -v tests/ft/driver/test_modbus.py else - pytest -s -v tests/ft/metrics/"test_metrics.py" + pytest -s -v tests/ft/metrics/test_metrics.py fi - name: create cov report diff --git a/plugins/restful/handle.c b/plugins/restful/handle.c index c552aeebc..21c27e62a 100644 --- a/plugins/restful/handle.c +++ b/plugins/restful/handle.c @@ -107,9 +107,6 @@ static struct neu_http_handler cors_handler[] = { { .url = "/api/v2/password", }, - { - .url = "/api/v2/logs", - }, { .url = "/api/v2/log/level", }, @@ -366,12 +363,6 @@ static struct neu_http_handler rest_handlers[] = { .url = "/api/v2/node/state", .value.handler = handle_get_node_state, }, - { - .method = NEU_HTTP_METHOD_GET, - .type = NEU_HTTP_HANDLER_FUNCTION, - .url = "/api/v2/logs", - .value.handler = handle_logs_files, - }, { .method = NEU_HTTP_METHOD_PUT, .type = NEU_HTTP_HANDLER_FUNCTION, diff --git a/plugins/restful/log_handle.c b/plugins/restful/log_handle.c index 6b7c674e8..3f79ca164 100644 --- a/plugins/restful/log_handle.c +++ b/plugins/restful/log_handle.c @@ -42,70 +42,6 @@ #include "log_handle.h" #include "utils/utarray.h" -void handle_logs_files(nng_aio *aio) -{ - void * data = NULL; - size_t len = 0; - int rv = 0; - - NEU_VALIDATE_JWT(aio); - - /* check whether the neuron directory exists */ - rv = access("../neuron", F_OK); - if (0 != rv) { - nlog_error("The neuron directory does not exists"); - NEU_JSON_RESPONSE_ERROR(NEU_ERR_FILE_NOT_EXIST, { - neu_http_response(aio, error_code.error, result_error); - }); - return; - } - - rv = system("rm -rf /tmp/neuron_debug.tar.gz"); - nlog_warn("remove old neuron_debug.tar.gz, rv: %d", rv); - /* tar the neuron directory */ - rv = system("tar -zcvf /tmp/neuron_debug.tar.gz " - "--exclude='persistence/neuron.lic' ../neuron"); - if (rv == -1) { - nlog_error("failed to create neuron_debug.tar.gz, rv: %d", rv); - NEU_JSON_RESPONSE_ERROR(NEU_ERR_COMMAND_EXECUTION_FAILED, { - neu_http_response(aio, error_code.error, result_error); - }); - return; - } else { - if (WIFEXITED(rv)) { - if (WEXITSTATUS(rv) < 0) { - nlog_error("failed to create neuron_debug.tar.gz, rv: %d", - WEXITSTATUS(rv)); - NEU_JSON_RESPONSE_ERROR(NEU_ERR_COMMAND_EXECUTION_FAILED, { - neu_http_response(aio, error_code.error, result_error); - }); - return; - } - } else { - nlog_error("failed to create neuron_debug.tar.gz, rv: %d", - WEXITSTATUS(rv)); - NEU_JSON_RESPONSE_ERROR(NEU_ERR_COMMAND_EXECUTION_FAILED, { - neu_http_response(aio, error_code.error, result_error); - }); - return; - } - } - - rv = read_file("/tmp/neuron_debug.tar.gz", &data, &len); - if (0 != rv) { - NEU_JSON_RESPONSE_ERROR( - rv, { neu_http_response(aio, error_code.error, result_error); }); - return; - } - - /* handle http response */ - rv = neu_http_response_file(aio, data, len, - "attachment; filename=neuron_debug.tar.gz"); - - free(data); - nlog_notice("download neuron_debug.tar.gz, ret: %d", rv); -} - void handle_log_level(nng_aio *aio) { neu_plugin_t *plugin = neu_rest_get_plugin(); diff --git a/plugins/restful/log_handle.h b/plugins/restful/log_handle.h index cff2b9137..a5f2b06fb 100644 --- a/plugins/restful/log_handle.h +++ b/plugins/restful/log_handle.h @@ -23,7 +23,6 @@ #include // void handle_get_log(nng_aio *aio); -void handle_logs_files(nng_aio *aio); void handle_log_level(nng_aio *aio); int read_file(const char *file_name, void **datap, size_t *lenp); diff --git a/tests/ft/http_api/test_http_api.py b/tests/ft/http_api/test_http_api.py index dbb68f443..995d9c2a9 100644 --- a/tests/ft/http_api/test_http_api.py +++ b/tests/ft/http_api/test_http_api.py @@ -121,7 +121,7 @@ def test_get_global_config(self): assert len(config_data['settings']) == 2 assert config_data['settings'][0]['node'] == 'mqtt' - response = api.del_node_check(node='mqtt') + response = api.del_node_check(node='modbus') response = api.get_global_config() assert 200 == response.status_code @@ -130,20 +130,17 @@ def test_get_global_config(self): assert 'nodes' in config_data assert len(config_data['nodes']) == 1 - assert config_data['nodes'][0]['plugin'] == 'Modbus TCP' + assert config_data['nodes'][0]['plugin'] == 'MQTT' assert 'groups' in config_data - assert len(config_data['groups']) == 1 - assert config_data['groups'][0]['driver'] == 'modbus' + assert len(config_data['groups']) == 0 assert 'tags' in config_data - assert len(config_data['tags']) == 1 - assert config_data['tags'][0]['driver'] == 'modbus' - assert len(config_data['tags'][0]['tags']) == 1 + assert len(config_data['tags']) == 0 assert 'subscriptions' in config_data assert len(config_data['subscriptions']) == 0 assert 'settings' in config_data assert len(config_data['settings']) == 1 - assert config_data['settings'][0]['node'] == 'modbus' \ No newline at end of file + assert config_data['settings'][0]['node'] == 'mqtt' \ No newline at end of file