ft:test launch configuration

This commit is contained in:
hxy7yx
2024-05-08 18:28:04 +08:00
parent 3e1e6d0269
commit c3309a5a29
6 changed files with 147 additions and 1 deletions
+1 -1
View File
@@ -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);
+7
View File
@@ -0,0 +1,7 @@
{
"ip": "0.0.0.0",
"port": 7000,
"disable_auth": 1,
"syslog_host": "",
"syslog_port": 541
}
+111
View File
@@ -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']
+4
View File
@@ -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)
+3
View File
@@ -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})
+21
View File
@@ -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(