Skip to content

Commit

Permalink
add http api ft
Browse files Browse the repository at this point in the history
  • Loading branch information
hxy7yx committed Nov 22, 2023
1 parent 693eb73 commit 2a60748
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 85 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 0 additions & 9 deletions plugins/restful/handle.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,6 @@ static struct neu_http_handler cors_handler[] = {
{
.url = "/api/v2/password",
},
{
.url = "/api/v2/logs",
},
{
.url = "/api/v2/log/level",
},
Expand Down Expand Up @@ -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,
Expand Down
64 changes: 0 additions & 64 deletions plugins/restful/log_handle.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
1 change: 0 additions & 1 deletion plugins/restful/log_handle.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
#include <nng/nng.h>

// 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);
Expand Down
13 changes: 5 additions & 8 deletions tests/ft/http_api/test_http_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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'
assert config_data['settings'][0]['node'] == 'mqtt'

0 comments on commit 2a60748

Please sign in to comment.