diff --git a/src/core/manager.c b/src/core/manager.c index d99b834d..fab4d28e 100644 --- a/src/core/manager.c +++ b/src/core/manager.c @@ -97,7 +97,7 @@ neu_manager_t *neu_manager_create() manager->plugin_manager = neu_plugin_manager_create(); manager->node_manager = neu_node_manager_create(); manager->subscribe_manager = neu_subscribe_manager_create(); - manager->log_level = ZLOG_LEVEL_NOTICE; + manager->log_level = default_log_level; manager->server_fd = socket(AF_UNIX, SOCK_DGRAM, 0); assert(manager->server_fd > 0); diff --git a/tests/ft/login/neuron.json b/tests/ft/login/neuron.json new file mode 100644 index 00000000..bf1c72b4 --- /dev/null +++ b/tests/ft/login/neuron.json @@ -0,0 +1,7 @@ +{ + "ip": "0.0.0.0", + "port": 7000, + "disable_auth": 1, + "syslog_host": "", + "syslog_port": 541 +} diff --git a/tests/ft/login/test_launch.py b/tests/ft/login/test_launch.py new file mode 100644 index 00000000..1e42211e --- /dev/null +++ b/tests/ft/login/test_launch.py @@ -0,0 +1,111 @@ +import neuron.api as api +from neuron.config import * +from neuron.common import description +import neuron.process as process +from neuron.error import * +import shutil +import os + + +class TestLaunch: + + @description(given="encironment variables 0, configuration file 0 , command line 1", + when="start neuron", + then="command line has the highest priority") + def test_priority_command_line(self): + process.remove_persistence() + + os.environ['NEURON_DISABLE_AUTH'] = '0' + + p = process.NeuronProcess() + p.start_disable_auth() + + response = api.get_nodes_disable_auth(NEU_NODE_DRIVER) + assert 200 == response.status_code + + p.stop() + + del os.environ['NEURON_DISABLE_AUTH'] + + @description(given="encironment variables 1, configuration file 0 , command line 0", + when="start neuron", + then="encironment variables has the second priority") + def test_priority_environment_variable(self): + process.remove_persistence() + + os.environ['NEURON_DISABLE_AUTH'] = '1' + + p = process.NeuronProcess() + p.start() + + response = api.get_nodes_disable_auth(NEU_NODE_DRIVER) + assert 200 == response.status_code + + p.stop() + + del os.environ['NEURON_DISABLE_AUTH'] + + @description(given="encironment variables 0, configuration file 1 , command line 0", + when="start neuron", + then="configuration file has the third priority") + def test_priority_configuration_file(self): + process.remove_persistence() + + dst_file = './build/config/neuron.json' + dst_backup = dst_file + '_backup' + os.rename(dst_file, dst_backup) + try: + shutil.copy2('./tests/ft/login/neuron.json', dst_file) + except Exception as e: + if os.path.exists(dst_backup): + os.rename(dst_backup, dst_file) + return + + p = process.NeuronProcess() + p.start() + + response = api.get_nodes_disable_auth(NEU_NODE_DRIVER) + assert 200 == response.status_code + + p.stop() + + os.remove(dst_file) + os.rename(dst_backup, dst_file) + + @description(given="encironment variables 1, command line 0", + when="start neuron", + then="log level set right") + def test_log_level_environment(self): + process.remove_persistence() + + os.environ['NEURON_LOG_LEVEL'] = 'DEBUG' + + p = process.NeuronProcess() + p.start() + + response = api.get_nodes_state(node="") + assert 200 == response.status_code + assert "debug" == response.json()["neuron_core"] + + p.stop() + + del os.environ['NEURON_LOG_LEVEL'] + + @description(given="encironment variables 1, command line 1", + when="start neuron", + then="log level set right") + def test_log_level_environment_command_line(self): + process.remove_persistence() + + os.environ['NEURON_LOG_LEVEL'] = 'NOTICE' + + p = process.NeuronProcess() + p.start_debug() + + response = api.get_nodes_state(node="") + assert 200 == response.status_code + assert "debug" == response.json()["neuron_core"] + + p.stop() + + del os.environ['NEURON_LOG_LEVEL'] \ No newline at end of file diff --git a/tests/ft/metrics/test_metrics.py b/tests/ft/metrics/test_metrics.py index 6c950467..b4793257 100644 --- a/tests/ft/metrics/test_metrics.py +++ b/tests/ft/metrics/test_metrics.py @@ -151,4 +151,8 @@ class TestMetrics: "group_last_timer_ms": (0, {"group": "group", "node": "modbus"}) } + assert_metrics(resp.content.decode('utf-8'), expected_metrics) + + resp = api.get_metrics(category="driver") + assert 200 == resp.status_code assert_metrics(resp.content.decode('utf-8'), expected_metrics) \ No newline at end of file diff --git a/tests/ft/neuron/api.py b/tests/ft/neuron/api.py index fc250ab1..c7a4366b 100644 --- a/tests/ft/neuron/api.py +++ b/tests/ft/neuron/api.py @@ -347,3 +347,6 @@ def mqtt_node_setting(node): return node_setting(node, json={"client-id": "neuron_aBcDeF", "qos": 0, "format": 0, "write-req-topic": f"/neuron/{node}/write/req", "write-resp-topic": f"/neuron/{node}/write/resp", "offline-cache": False, "cache-sync-interval": 100, "host": "broker.emqx.io", "port": 1883, "username": "", "password": "", "ssl": False}) + +def get_nodes_disable_auth(type): + return requests.get(url=config.BASE_URL + '/api/v2/node', params={"type": type}) \ No newline at end of file diff --git a/tests/ft/neuron/process.py b/tests/ft/neuron/process.py index bd708ce7..98b603a4 100644 --- a/tests/ft/neuron/process.py +++ b/tests/ft/neuron/process.py @@ -24,6 +24,27 @@ class NeuronProcess: stop_neuron(self.p) self.p = None + def start_disable_auth(self): + self.p = start_neuron_disable_auth(self.dir) + + def start_debug(self): + self.p = start_neuron_debug(self.dir) + +def start_neuron_disable_auth(dir='build/'): + command = ['./neuron', '--disable_auth'] + process = subprocess.Popen( + command, stderr=subprocess.PIPE, cwd=dir) + time.sleep(1) + assert process.poll() is None + return process + +def start_neuron_debug(dir='build/'): + command = ['./neuron', '--log_level', 'DEBUG'] + process = subprocess.Popen( + command, stderr=subprocess.PIPE, cwd=dir) + time.sleep(1) + assert process.poll() is None + return process def start_neuron(dir='build/'): process = subprocess.Popen(