author | GP Orcullo <kinsamanka@gmail.com> |
Mon, 20 Feb 2023 08:56:25 +0800 | |
branch | python3 |
changeset 3789 | 8def429216ca |
parent 3718 | 7841b651d601 |
child 3820 | 46f3ca3f0157 |
permissions | -rw-r--r-- |
3543
6210c08c1c41
tests: CLI: add simple test running python example
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
1 |
#!/bin/bash |
6210c08c1c41
tests: CLI: add simple test running python example
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
2 |
|
3676
2f79540660f6
Tests: add encrypted OPCUA browsing test.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3672
diff
changeset
|
3 |
echo "Instant encrypted OPC-UA server for test" |
2f79540660f6
Tests: add encrypted OPCUA browsing test.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3672
diff
changeset
|
4 |
|
2f79540660f6
Tests: add encrypted OPCUA browsing test.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3672
diff
changeset
|
5 |
yes "" | openssl req -x509 -newkey rsa:2048 -keyout my_private_key.pem -out my_cert.pem \ |
2f79540660f6
Tests: add encrypted OPCUA browsing test.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3672
diff
changeset
|
6 |
-days 355 -nodes -addext "subjectAltName = URI:urn:example.org:FreeOpcUa:python-opcua" |
2f79540660f6
Tests: add encrypted OPCUA browsing test.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3672
diff
changeset
|
7 |
openssl x509 -outform der -in my_cert.pem -out my_cert.der |
2f79540660f6
Tests: add encrypted OPCUA browsing test.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3672
diff
changeset
|
8 |
|
2f79540660f6
Tests: add encrypted OPCUA browsing test.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3672
diff
changeset
|
9 |
PROJECT_FILES_DIR=$BEREMIZPATH/tests/projects/opcua_browse_encrypted/project_files |
2f79540660f6
Tests: add encrypted OPCUA browsing test.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3672
diff
changeset
|
10 |
mkdir $PROJECT_FILES_DIR |
2f79540660f6
Tests: add encrypted OPCUA browsing test.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3672
diff
changeset
|
11 |
cp my_cert.der my_private_key.pem $PROJECT_FILES_DIR |
2f79540660f6
Tests: add encrypted OPCUA browsing test.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3672
diff
changeset
|
12 |
|
2f79540660f6
Tests: add encrypted OPCUA browsing test.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3672
diff
changeset
|
13 |
echo "CERTS READY" |
3543
6210c08c1c41
tests: CLI: add simple test running python example
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
14 |
|
3549
0af7b6a96c53
CLI: fix fake_wx for OPC-UA in CLI, match with test and requirements
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3543
diff
changeset
|
15 |
# Run server |
3672
230c8b90f3dc
Tests: Add OPC-UA server browsing and veriable picking UI test.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3549
diff
changeset
|
16 |
exec $BEREMIZPYTHONPATH - << EOF |
3543
6210c08c1c41
tests: CLI: add simple test running python example
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
17 |
|
3549
0af7b6a96c53
CLI: fix fake_wx for OPC-UA in CLI, match with test and requirements
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3543
diff
changeset
|
18 |
import sys |
3718
7841b651d601
Tests: OPCUA tests can now use OPCUA_DEFAULT_HOST environment variable to force host to something else than "127.0.0.1" or "localhost"
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3676
diff
changeset
|
19 |
import os |
3549
0af7b6a96c53
CLI: fix fake_wx for OPC-UA in CLI, match with test and requirements
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3543
diff
changeset
|
20 |
import time |
0af7b6a96c53
CLI: fix fake_wx for OPC-UA in CLI, match with test and requirements
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3543
diff
changeset
|
21 |
|
0af7b6a96c53
CLI: fix fake_wx for OPC-UA in CLI, match with test and requirements
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3543
diff
changeset
|
22 |
from opcua import ua, Server |
0af7b6a96c53
CLI: fix fake_wx for OPC-UA in CLI, match with test and requirements
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3543
diff
changeset
|
23 |
|
0af7b6a96c53
CLI: fix fake_wx for OPC-UA in CLI, match with test and requirements
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3543
diff
changeset
|
24 |
server = Server() |
3718
7841b651d601
Tests: OPCUA tests can now use OPCUA_DEFAULT_HOST environment variable to force host to something else than "127.0.0.1" or "localhost"
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3676
diff
changeset
|
25 |
host = os.environ.get("OPCUA_DEFAULT_HOST", "127.0.0.1") |
7841b651d601
Tests: OPCUA tests can now use OPCUA_DEFAULT_HOST environment variable to force host to something else than "127.0.0.1" or "localhost"
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3676
diff
changeset
|
26 |
endpoint = "opc.tcp://"+host+":4840/freeopcua/server/" |
7841b651d601
Tests: OPCUA tests can now use OPCUA_DEFAULT_HOST environment variable to force host to something else than "127.0.0.1" or "localhost"
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3676
diff
changeset
|
27 |
server.set_endpoint(endpoint) |
3549
0af7b6a96c53
CLI: fix fake_wx for OPC-UA in CLI, match with test and requirements
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3543
diff
changeset
|
28 |
|
3676
2f79540660f6
Tests: add encrypted OPCUA browsing test.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3672
diff
changeset
|
29 |
server.set_security_policy([ua.SecurityPolicyType.Basic256Sha256_SignAndEncrypt]) |
2f79540660f6
Tests: add encrypted OPCUA browsing test.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3672
diff
changeset
|
30 |
server.load_certificate("my_cert.der") |
2f79540660f6
Tests: add encrypted OPCUA browsing test.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3672
diff
changeset
|
31 |
server.load_private_key("my_private_key.pem") |
2f79540660f6
Tests: add encrypted OPCUA browsing test.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3672
diff
changeset
|
32 |
|
3549
0af7b6a96c53
CLI: fix fake_wx for OPC-UA in CLI, match with test and requirements
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3543
diff
changeset
|
33 |
uri = "http://beremiz.github.io" |
0af7b6a96c53
CLI: fix fake_wx for OPC-UA in CLI, match with test and requirements
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3543
diff
changeset
|
34 |
idx = server.register_namespace(uri) |
0af7b6a96c53
CLI: fix fake_wx for OPC-UA in CLI, match with test and requirements
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3543
diff
changeset
|
35 |
|
0af7b6a96c53
CLI: fix fake_wx for OPC-UA in CLI, match with test and requirements
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3543
diff
changeset
|
36 |
objects = server.get_objects_node() |
0af7b6a96c53
CLI: fix fake_wx for OPC-UA in CLI, match with test and requirements
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3543
diff
changeset
|
37 |
|
0af7b6a96c53
CLI: fix fake_wx for OPC-UA in CLI, match with test and requirements
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3543
diff
changeset
|
38 |
testobj = objects.add_object(idx, "TestObject") |
0af7b6a96c53
CLI: fix fake_wx for OPC-UA in CLI, match with test and requirements
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3543
diff
changeset
|
39 |
testvarout = testobj.add_variable(idx, "TestOut", 1.2) |
0af7b6a96c53
CLI: fix fake_wx for OPC-UA in CLI, match with test and requirements
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3543
diff
changeset
|
40 |
testvar = testobj.add_variable(idx, "TestIn", 5.6) |
0af7b6a96c53
CLI: fix fake_wx for OPC-UA in CLI, match with test and requirements
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3543
diff
changeset
|
41 |
testvar.set_writable() |
0af7b6a96c53
CLI: fix fake_wx for OPC-UA in CLI, match with test and requirements
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3543
diff
changeset
|
42 |
|
0af7b6a96c53
CLI: fix fake_wx for OPC-UA in CLI, match with test and requirements
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3543
diff
changeset
|
43 |
server.start() |
0af7b6a96c53
CLI: fix fake_wx for OPC-UA in CLI, match with test and requirements
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3543
diff
changeset
|
44 |
|
0af7b6a96c53
CLI: fix fake_wx for OPC-UA in CLI, match with test and requirements
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3543
diff
changeset
|
45 |
try: |
0af7b6a96c53
CLI: fix fake_wx for OPC-UA in CLI, match with test and requirements
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3543
diff
changeset
|
46 |
while True: |
0af7b6a96c53
CLI: fix fake_wx for OPC-UA in CLI, match with test and requirements
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3543
diff
changeset
|
47 |
time.sleep(1) |
3672
230c8b90f3dc
Tests: Add OPC-UA server browsing and veriable picking UI test.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3549
diff
changeset
|
48 |
inval=testvar.get_value() |
230c8b90f3dc
Tests: Add OPC-UA server browsing and veriable picking UI test.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3549
diff
changeset
|
49 |
print inval |
230c8b90f3dc
Tests: Add OPC-UA server browsing and veriable picking UI test.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3549
diff
changeset
|
50 |
testvarout.set_value(inval*2) |
3549
0af7b6a96c53
CLI: fix fake_wx for OPC-UA in CLI, match with test and requirements
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3543
diff
changeset
|
51 |
sys.stdout.flush() |
0af7b6a96c53
CLI: fix fake_wx for OPC-UA in CLI, match with test and requirements
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3543
diff
changeset
|
52 |
finally: |
0af7b6a96c53
CLI: fix fake_wx for OPC-UA in CLI, match with test and requirements
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3543
diff
changeset
|
53 |
server.stop() |
0af7b6a96c53
CLI: fix fake_wx for OPC-UA in CLI, match with test and requirements
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3543
diff
changeset
|
54 |
EOF |