Files
neuron/ft/persistence_test.robot
T
2022-03-03 06:27:00 +00:00

370 lines
16 KiB
Plaintext

*** Settings ***
Resource common.resource
Suite Setup Neuron Context Ready
Suite Teardown Neuron Context Stop
*** Variables ***
${test_gconfig1} test_gconfig1
${test_gconfig2} test_gconfig2
${test_gconfig3} test_gconfig3
${modbus-tcp-1} modbus-tcp-1
${modbus-tcp-2} modbus-tcp-2
${modbus-tcp-3} modbus-tcp-3
${modbus-tcp-4} modbus-tcp-4
${mqtt-1} mqtt-1
${tag1} {"name": "tag1", "address": "1!400001", "attribute": 1, "type": 4}
${tag2} {"name": "tag2", "address": "1!00001", "attribute": 3, "type": 14}
${tag3} {"name": "tag3", "address": "2!400003", "attribute": 1, "type": 5}
*** Test Cases ***
Get the newly added adapters after stopping and restarting Neuron, it should return success
Skip If Not Http API
${process} = Neuron Start Running
Add Node type=${${NODE_DRIVER}} name=${${modbus-tcp-1}} plugin_name=modbus-tcp-plugin
Add Node type=${${NODE_DRIVER}} name=${${modbus-tcp-2}} plugin_name=modbus-tcp-plugin
Add Node type=${${NODE_DRIVER}} name=${${modbus-tcp-3}} plugin_name=modbus-tcp-plugin
Add Node type=${${NODE_DRIVER}} name=${${modbus-tcp-4}} plugin_name=modbus-tcp-plugin
${res} = Add Node type=${${NODE_MQTT}} name=${${mqtt-1}} plugin_name=mqtt-plugin
Check Response Status ${res} 200
Check Error Code ${res} ${ERR_SUCCESS}
Neuron Stop Running ${process}
${process} = Neuron Start Running
${res} = Get Nodes ${NODE_DRIVER}
Check Response Status ${res} 200
Node With Name Should Exist ${res}[nodes] ${modbus-tcp-1}
Node With Name Should Exist ${res}[nodes] ${modbus-tcp-2}
Node With Name Should Exist ${res}[nodes] ${modbus-tcp-3}
Node With Name Should Exist ${res}[nodes] ${modbus-tcp-4}
${res} = Get Nodes ${NODE_MQTT}
Check Response Status ${res} 200
Node With Name Should Exist ${res}[nodes] ${mqtt-1}
[Teardown] Neuron Stop Running ${process}
Get the deleted adapter after stopping and restarting Neuron, it should return failure
Skip If Not Http API
${process} = Neuron Start Running
${modbus_tcp4_id} = Get Node ID ${NODE_DRIVER} ${modbus-tcp-4}
Del Node ${modbus_tcp4_id}
${res} = Get Nodes ${NODE_DRIVER}
${modbus_tcp4_id} = Get Node By Name ${res}[nodes] ${modbus-tcp-4}
Should Be Equal As Integers ${modbus_tcp4_id} 0
Neuron Stop Running ${process}
${process} = Neuron Start Running
${res} = Get Nodes ${NODE_DRIVER}
${modbus_tcp4_id} = Get Node By Name ${res}[nodes] ${modbus-tcp-4}
Should Be Equal As Integers ${modbus_tcp4_id} 0
Node With Name Should Exist ${res}[nodes] ${modbus-tcp-1}
Node With Name Should Exist ${res}[nodes] ${modbus-tcp-2}
Node With Name Should Exist ${res}[nodes] ${modbus-tcp-3}
Node With Name Should Not Exist ${res}[nodes] ${modbus-tcp-4}
${res} = Get Nodes ${NODE_MQTT}
Node With Name Should Exist ${res}[nodes] ${mqtt-1}
[Teardown] Neuron Stop Running ${process}
Get the setted adapters information after stopping and restarting Neuron, it should return the correct information
Skip If Not Http API
${process} = Neuron Start Running
${modbus_tcp1_id} = Get Node ID ${NODE_DRIVER} ${modbus-tcp-1}
Node Setting ${modbus_tcp1_id} {"host": "127.0.0.1", "port": 502, "connection_mode": 0}
${modbus_tcp2_id} = Get Node ID ${NODE_DRIVER} ${modbus-tcp-2}
Node Setting ${modbus_tcp2_id} {"host": "127.0.0.1", "port": 502, "connection_mode": 0}
${mqtt_id} = Get Node ID ${NODE_MQTT} mqtt-1
Node Setting ${mqtt_id} {"req-topic": "Neuron/req", "res-topic": "Neuron/resp", "ssl": "false", "host": "127.0.0.1", "port": 1883, "username": "admin", "password": "0000"}
Neuron Stop Running ${process}
${process} = Neuron Start Running
${res} = Get Node Setting ${modbus_tcp1_id}
${params} = Set Variable ${res}[params]
Check Response Status ${res} 200
Should Be Equal As Integers ${res}[node_id] ${modbus_tcp1_id}
Should Be Equal As Integers ${params}[port] 502
Should Be Equal As Integers ${params}[connection_mode] 0
Should Be Equal As Strings ${params}[host] 127.0.0.1
${res} = Get Node Setting ${modbus_tcp2_id}
${params} = Set Variable ${res}[params]
Check Response Status ${res} 200
Should Be Equal As Integers ${res}[node_id] ${modbus_tcp2_id}
Should Be Equal As Integers ${params}[port] 502
Should Be Equal As Integers ${params}[connection_mode] 0
Should Be Equal As Strings ${params}[host] 127.0.0.1
${res} = Get Node Setting ${mqtt_id}
${params} = Set Variable ${res}[params]
Check Response Status ${res} 200
Should Be Equal As Integers ${res}[node_id] ${mqtt_id}
Should Be Equal As Integers ${params}[port] 1883
Should Be Equal As Strings ${params}[req-topic] Neuron/req
Should Be Equal As Strings ${params}[res-topic] Neuron/resp
Should Be Equal As Strings ${params}[ssl] false
Should Be Equal As Strings ${params}[host] 127.0.0.1
Should Be Equal As Strings ${params}[username] admin
Should Be Equal As Strings ${params}[password] 0000
[Teardown] Neuron Stop Running ${process}
Get the updated adapters settings information after stopping and restarting Neuron, it should return the correct information
Skip If Not Http API
${process} = Neuron Start Running
${modbus_tcp2_id} = Get Node ID ${NODE_DRIVER} ${modbus-tcp-2}
Node Setting ${modbus_tcp2_id} {"host": "127.0.0.1", "port": 502, "connection_mode": 1}
Neuron Stop Running ${process}
${process} = Neuron Start Running
${res} = Get Node Setting ${modbus_tcp2_id}
${params} = Set Variable ${res}[params]
Check Response Status ${res} 200
Should Be Equal As Integers ${res}[node_id] ${modbus_tcp2_id}
Should Be Equal As Integers ${params}[port] 502
Should Be Equal As Integers ${params}[connection_mode] 1
Should Be Equal As Strings ${params}[host] 127.0.0.1
[Teardown] Neuron Stop Running ${process}
Get the newly add group_configs after stopping and restarting Neuron, it should return success
Skip If Not Http API
${process} = Neuron Start Running
${modbus_tcp1_id} = Get Node ID ${NODE_DRIVER} ${modbus-tcp-1}
Add Group Config ${modbus_tcp1_id} ${test_gconfig1} 1500
Add Group Config ${modbus_tcp1_id} ${test_gconfig2} 1500
Add Group Config ${modbus_tcp1_id} ${test_gconfig3} 1500
Neuron Stop Running ${process}
${process} = Neuron Start Running
${res} = Get Group Config ${modbus_tcp1_id}
Check Response Status ${res} 200
${ret} = Group Config Check ${res}[group_configs] ${test_gconfig1} 1500
Should Be Equal As Integers ${ret} 0
${ret} = Group Config Check ${res}[group_configs] ${test_gconfig2} 1500
Should Be Equal As Integers ${ret} 0
${ret} = Group Config Check ${res}[group_configs] ${test_gconfig3} 1500
Should Be Equal As Integers ${ret} 0
[Teardown] Neuron Stop Running ${process}
Get the deleted group_configs after stopping and restarting Neuron, it should return failure
Skip If Not Http API
${process} = Neuron Start Running
${modbus_tcp1_id} = Get Node ID ${NODE_DRIVER} ${modbus-tcp-1}
Del Group Config ${modbus_tcp1_id} ${test_gconfig3}
Neuron Stop Running ${process}
${process} = Neuron Start Running
${res} = Get Group Config ${modbus_tcp1_id}
Check Response Status ${res} 200
${ret} = Group Config Check ${res}[group_configs] ${test_gconfig1} 1500
Should Be Equal As Integers ${ret} 0
${ret} = Group Config Check ${res}[group_configs] ${test_gconfig2} 1500
Should Be Equal As Integers ${ret} 0
${ret} = Get Group Config By Name ${res}[group_configs] ${test_gconfig3}
Should Be Equal As Integers ${ret} 0
[Teardown] Neuron Stop Running ${process}
Get the updated group_configs after stopping and restarting Neuron, it should return the correct configurations
Skip If Not Http API
${process} = Neuron Start Running
${modbus_tcp1_id} = Get Node ID ${NODE_DRIVER} ${modbus-tcp-1}
Update Group Config ${modbus_tcp1_id} ${test_gconfig1} 1000
Neuron Stop Running ${process}
${process} = Neuron Start Running
${res} = Get Group Config ${modbus_tcp1_id}
${ret} = Group Config Check ${res}[group_configs] ${test_gconfig1} 1000
Should Be Equal As Integers ${ret} 0
${ret} = Group Config Check ${res}[group_configs] ${test_gconfig2} 1500
Should Be Equal As Integers ${ret} 0
[Teardown] Neuron Stop Running ${process}
Get the newly add tags after stopping and restarting Neuron, it should return success
Skip If Not Http API
${process} = Neuron Start Running
${modbus_tcp1_id} = Get Node ID ${NODE_DRIVER} ${modbus-tcp-1}
Add Tags ${modbus_tcp1_id} ${test_gconfig1} ${tag1},${tag2},${tag3}
Neuron Stop Running ${process}
${process} = Neuron Start Running
${res} = Get Tags ${modbus_tcp1_id} ${test_gconfig1}
Check Response Status ${res} 200
${ret} = Tag Check ${res}[tags] tag1 4 ${test_gconfig1} 1 1!400001
Should Be Equal As Integers ${ret} 0
${ret} = Tag Check ${res}[tags] tag2 14 ${test_gconfig1} 3 1!00001
Should Be Equal As Integers ${ret} 0
${ret} = Tag Check ${res}[tags] tag3 5 ${test_gconfig1} 1 2!400003
Should Be Equal As Integers ${ret} 0
[Teardown] Neuron Stop Running ${process}
Get the deleted tags after stopping and restarting Neuron, it should return success
Skip If Not Http API
${process} = Neuron Start Running
${modbus_tcp1_id} = Get Node ID ${NODE_DRIVER} ${modbus-tcp-1}
${tag3_id} = Get Tag ID ${modbus_tcp1_id} ${test_gconfig1} tag3
${res} = Del Tags ${modbus_tcp1_id} ${test_gconfig1} ${tag3_id}
Check Response Status ${res} 200
Neuron Stop Running ${process}
${process} Neuron Start Running
${res} = Get Tags ${modbus_tcp1_id} ${test_gconfig1}
${ret} = Tag Check ${res}[tags] tag1 4 ${test_gconfig1} 1 1!400001
Should Be Equal As Integers ${ret} 0
${ret} = Tag Check ${res}[tags] tag2 14 ${test_gconfig1} 3 1!00001
Should Be Equal As Integers ${ret} 0
${id} = Tag Find By Name ${res}[tags] tag3
Should Be Equal As Integers ${id} -1
[Teardown] Neuron Stop Running ${process}
Get the update tags after stopping ande restarting Neuron, it should return the correct information
Skip If Not Http API
${process} = Neuron Start Running
${modbus_tcp1_id} = Get Node ID ${NODE_DRIVER} ${modbus-tcp-1}
${tag1_id} = Get Tag ID ${modbus_tcp1_id} ${test_gconfig1} tag1
Should Not Be Equal As Integers ${tag1_id} 0
${res} = Update Tags ${modbus_tcp1_id} ${test_gconfig1} {"id": ${tag1_id}, "name": "tag1", "type": 4, "attribute": 1, "address": "1!400002"}
Check Response Status ${res} 200
Neuron Stop Running ${process}
${process} = Neuron Start Running
${res} = Get Tags ${modbus_tcp1_id} ${test_gconfig1}
Check Response Status ${res} 200
${ret} = Tag Check ${res}[tags] tag1 4 ${test_gconfig1} 1 1!400002
Should Be Equal As Integers ${ret} 0
${ret} = Tag Check ${res}[tags] tag2 14 ${test_gconfig1} 3 1!00001
Should Be Equal As Integers ${ret} 0
[Teardown] Neuron Stop Running ${process}
Get the subscribed groups after stopping and restarting Neuron, it should return success
Skip If Not Http API
${process} = Neuron Start Running
${modbus_tcp1_id} = Get Node ID ${NODE_DRIVER} ${modbus-tcp-1}
${mqtt_id} = Get Node ID ${NODE_MQTT} ${mqtt-1}
${res} = Subscribe Group ${modbus_tcp1_id} ${mqtt_id} ${test_gconfig1}
Check Response Status ${res} 200
${res} = Subscribe Group ${modbus_tcp1_id} ${mqtt_id} ${test_gconfig2}
Check Response Status ${res} 200
Neuron Stop Running ${process}
${process} = Neuron Start Running
${res} = Get Subscribe Group ${mqtt_id}
Check Response Status ${res} 200
${ret} = Subscribe Check ${res}[groups] ${modbus_tcp1_id} ${test_gconfig1}
Should Be Equal As Integers ${ret} 0
${ret} = Subscribe Check ${res}[groups] ${modbus_tcp1_id} ${test_gconfig2}
Should Be Equal As Integers ${ret} 0
[Teardown] Neuron Stop Running ${process}
Get the unsubscribed groups after stopping ande restarting Neuron, it should return failure
Skip If Not Http API
${process} = Neuron Start Running
${modbus_tcp1_id} = Get Node ID ${NODE_DRIVER} ${modbus-tcp-1}
${mqtt_id} = Get Node ID ${NODE_MQTT} ${mqtt-1}
${res} = Unsubscribe Group ${modbus_tcp1_id} ${mqtt_id} ${test_gconfig2}
Check Response Status ${res} 200
Neuron Stop Running ${process}
${process} = Neuron Start Running
${res} = Get Subscribe Group ${mqtt_id}
Check Response Status ${res} 200
${ret} = Subscribe Check ${res}[groups] ${modbus_tcp1_id} ${test_gconfig1}
Should Be Equal As Integers ${ret} 0
${ret} = Subscribe Check ${res}[groups] ${modbus_tcp1_id} ${test_gconfig2}
Should Not Be Equal As Integers ${ret} 0
[Teardown] Neuron Stop Running ${process}
*** Keywords ***
Neuron Context Ready
Import Neuron API Resource
Remove Persistence
Neuron Context Stop
Remove Persistence
Neuron Start Running
${p} = Start Neuron
Sleep 3
LOGIN
[Return] ${p}
Neuron Stop Running
[Arguments] ${p}
Sleep 1
LOGOUT
End Neuron ${p}