def testPubSubStaticConf(): logger = TapLogger("pubsub_server_test.tap") pubsubserver = PubSubServer(DEFAULT_URI, NID_CONFIGURATION, NID_START_STOP, NID_STATUS) defaultXml2Restore = False try: # secure channel connection pubsubserver.connect() # # TC 1 : Test with Static Publisher and Subscriber configuration => subscriber variables change through Pub/Sub # logger.begin_section("TC 1 : Subscriber variables change through Pub/Sub") # Set Publisher variables and test change in Subscriber variables helpTestSetValue(pubsubserver, NID_PUB_BOOL, False, logger) helpTestSetValue(pubsubserver, NID_PUB_UINT, 8500, logger) helpTestSetValue(pubsubserver, NID_PUB_INT, -300, logger) sleep(STATIC_CONF_PUB_INTERVAL) logger.add_test('Subscriber bool is changed ', False == pubsubserver.getValue(NID_SUB_BOOL)) logger.add_test('Subscriber uint is changed ', 8500 == pubsubserver.getValue(NID_SUB_UINT)) logger.add_test('Subscriber int is changed ', -300 == pubsubserver.getValue(NID_SUB_INT)) # Set Publisher variables and test change in Subscriber variables helpTestSetValue(pubsubserver, NID_PUB_BOOL, True, logger) helpTestSetValue(pubsubserver, NID_PUB_UINT, 5800, logger) helpTestSetValue(pubsubserver, NID_PUB_INT, -30, logger) sleep(STATIC_CONF_PUB_INTERVAL) logger.add_test('Subscriber bool is changed ', True == pubsubserver.getValue(NID_SUB_BOOL)) logger.add_test('Subscriber uint is changed ', 5800 == pubsubserver.getValue(NID_SUB_UINT)) logger.add_test('Subscriber int is changed ', -30 == pubsubserver.getValue(NID_SUB_INT)) # # TC 2 : Pub-Sub server is stopped => no change in Subscriber variables # logger.begin_section("TC 2 : Pub-Sub server is stopped") pubsubserver.stop() logger.add_test('PubSub Module is stopped' , not pubsubserver.isStart()) helpTestSetValue(pubsubserver, NID_PUB_BOOL, False, logger) helpTestSetValue(pubsubserver, NID_PUB_UINT, 7777, logger) helpTestSetValue(pubsubserver, NID_PUB_INT, 123654, logger) sleep(STATIC_CONF_PUB_INTERVAL) logger.add_test('Subscriber bool is changed ', True == pubsubserver.getValue(NID_SUB_BOOL)) logger.add_test('Subscriber uint is changed ', 5800 == pubsubserver.getValue(NID_SUB_UINT)) logger.add_test('Subscriber int is changed ', -30 == pubsubserver.getValue(NID_SUB_INT)) # # TC 3 : Pub-Sub server is restarted => Subscriber variables changed # logger.begin_section("TC 3 : Pub-Sub server is restarted") pubsubserver.start() logger.add_test('PubSub Module is started' , pubsubserver.isStart()) sleep(STATIC_CONF_PUB_INTERVAL) logger.add_test('Subscriber bool is changed ', False == pubsubserver.getValue(NID_SUB_BOOL)) logger.add_test('Subscriber uint is changed ', 7777 == pubsubserver.getValue(NID_SUB_UINT)) logger.add_test('Subscriber int is changed ', 123654 == pubsubserver.getValue(NID_SUB_INT)) # # TC 4 : Change Pub-Sub server configuration => configuration cannot be changed in static mode # logger.begin_section("TC 4 : Change Pub-Sub server configuration") # Change Pub-Sub configuration node and check file is not change helpConfigurationChangeAndStart(pubsubserver, XML_SUBSCRIBER_ONLY, logger, static=True) # Check Pub-Sub module is still running helpTestSetValue(pubsubserver, NID_PUB_BOOL, True, logger) helpTestSetValue(pubsubserver, NID_PUB_UINT, 1245, logger) helpTestSetValue(pubsubserver, NID_PUB_INT, 9874, logger) sleep(STATIC_CONF_PUB_INTERVAL) logger.add_test('Subscriber bool is changed ', True == pubsubserver.getValue(NID_SUB_BOOL)) logger.add_test('Subscriber uint is changed ', 1245 == pubsubserver.getValue(NID_SUB_UINT)) logger.add_test('Subscriber int is changed ', 9874 == pubsubserver.getValue(NID_SUB_INT)) finally: pubsubserver.disconnect() logger.add_test('Not connected to OPCUA Server', not pubsubserver.isConnected()) logger.finalize_report()
def testPubSubDynamicConf(): logger = TapLogger("pubsub_server_test.tap") pubsubserver = PubSubServer(DEFAULT_URI, NID_CONFIGURATION, NID_START_STOP, NID_STATUS) defaultXml2Restore = False try: # backup of default XML file copyfile(DEFAULT_XML_PATH, DEFAULT_XML_PATH + ".bakup") defaultXml2Restore = True # secure channel connection pubsubserver.connect() # # TC 1 : Test with Publisher only configuration => only pub variables change # logger.begin_section("TC 1 : Publisher only") helpConfigurationChangeAndStart(pubsubserver, XML_PUBLISHER_ONLY, logger) # Init Subscriber variables helpTestSetValue(pubsubserver, NID_SUB_BOOL, True, logger) helpTestSetValue(pubsubserver, NID_SUB_UINT16, 500, logger) helpTestSetValue(pubsubserver, NID_SUB_INT, 100, logger) # Set Publisher variables helpTestSetValue(pubsubserver, NID_PUB_BOOL, False, logger) helpTestSetValue(pubsubserver, NID_PUB_UINT16, 1500, logger) helpTestSetValue(pubsubserver, NID_PUB_INT, -50, logger) sleep(DYN_CONF_PUB_INTERVAL_1000) logger.add_test('Subscriber bool is not changed ', True == pubsubserver.getValue(NID_SUB_BOOL)) logger.add_test('Subscriber uint16 is not changed ', 500 == pubsubserver.getValue(NID_SUB_UINT16)) logger.add_test('Subscriber int is not changed ', 100 == pubsubserver.getValue(NID_SUB_INT)) pubsubserver.stop() helpTestStopStart(pubsubserver, False, logger) # # TC 2 : Test with Subscriber only configuration => no variables change # logger.begin_section("TC 2 : Subscriber only") # Init Subscriber variables helpTestSetValue(pubsubserver, NID_SUB_BOOL, True, logger) helpTestSetValue(pubsubserver, NID_SUB_UINT16, 500, logger) helpTestSetValue(pubsubserver, NID_SUB_INT, 100, logger) helpConfigurationChangeAndStart(pubsubserver, XML_SUBSCRIBER_ONLY, logger) sleep(DYN_CONF_PUB_INTERVAL_1000) logger.add_test('Subscriber bool is not changed ', True == pubsubserver.getValue(NID_SUB_BOOL)) logger.add_test('Subscriber uint16 is not changed ', 500 == pubsubserver.getValue(NID_SUB_UINT16)) logger.add_test('Subscriber int is not changed ', 100 == pubsubserver.getValue(NID_SUB_INT)) pubsubserver.stop() helpTestStopStart(pubsubserver, False, logger) # # TC 3 : Test with Publisher and Subscriber configuration => subscriber variables change through Pub/Sub # logger.begin_section("TC 3 : Publisher Subscriber Loop") # Init Subscriber variables helpTestSetValue(pubsubserver, NID_SUB_BOOL, True, logger) helpTestSetValue(pubsubserver, NID_SUB_UINT16, 500, logger) helpTestSetValue(pubsubserver, NID_SUB_INT, 100, logger) helpConfigurationChangeAndStart(pubsubserver, XML_PUBSUB_LOOP, logger) sleep(DYN_CONF_PUB_INTERVAL_200) logger.add_test('Subscriber bool is changed ', False == pubsubserver.getValue(NID_SUB_BOOL)) logger.add_test('Subscriber uint16 is changed ', 1500 == pubsubserver.getValue(NID_SUB_UINT16)) logger.add_test('Subscriber int is changed ', -50 == pubsubserver.getValue(NID_SUB_INT)) pubsubserver.stop() helpTestStopStart(pubsubserver, False, logger) # # TC 4 : Stop Pub/Sub module => subscriber variables do not change # logger.begin_section("TC 4 : Publisher Subscriber Loop") # Change Publisher variables helpTestSetValue(pubsubserver, NID_PUB_BOOL, True, logger) helpTestSetValue(pubsubserver, NID_PUB_UINT16, 6500, logger) helpTestSetValue(pubsubserver, NID_PUB_INT, -600, logger) sleep(DYN_CONF_PUB_INTERVAL_200) logger.add_test('Subscriber bool is not changed ', False == pubsubserver.getValue(NID_SUB_BOOL)) logger.add_test('Subscriber uint16 is not changed ', 1500 == pubsubserver.getValue(NID_SUB_UINT16)) logger.add_test('Subscriber int is not changed ', -50 == pubsubserver.getValue(NID_SUB_INT)) # Start to change Subscriber variables pubsubserver.start() helpTestStopStart(pubsubserver, True, logger) sleep(DYN_CONF_PUB_INTERVAL_200) logger.add_test('Subscriber bool is changed ', True == pubsubserver.getValue(NID_SUB_BOOL)) logger.add_test('Subscriber uint16 is changed ', 6500 == pubsubserver.getValue(NID_SUB_UINT16)) logger.add_test('Subscriber int is changed ', -600 == pubsubserver.getValue(NID_SUB_INT)) pubsubserver.stop() helpTestStopStart(pubsubserver, False, logger) # # TC 5 : Test with Publisher and Subscriber configuration. DataType is NULL # => subscriber variables change through Pub/Sub # logger.begin_section("TC 5 : Publisher Subscriber Loop (DataType is Null)") # Init Publisher variables helpTestSetValue(pubsubserver, NID_PUB_BOOL, False, logger) helpTestSetValue(pubsubserver, NID_PUB_UINT16, 8500, logger) helpTestSetValue(pubsubserver, NID_PUB_INT, -300, logger) # Init Subscriber variables helpTestSetValue(pubsubserver, NID_SUB_BOOL, True, logger) helpTestSetValue(pubsubserver, NID_SUB_UINT16, 500, logger) helpTestSetValue(pubsubserver, NID_SUB_INT, 100, logger) helpConfigurationChangeAndStart(pubsubserver, XML_PUBSUB_LOOP_NULL, logger) sleep(DYN_CONF_PUB_INTERVAL_200) logger.add_test('Subscriber bool is changed ', False == pubsubserver.getValue(NID_SUB_BOOL)) logger.add_test('Subscriber uint16 is changed ', 8500 == pubsubserver.getValue(NID_SUB_UINT16)) logger.add_test('Subscriber int is changed ', -300 == pubsubserver.getValue(NID_SUB_INT)) pubsubserver.stop() helpTestStopStart(pubsubserver, False, logger) # # TC 6 : Test with Publisher and Subscriber configuration => subscriber variables change through Pub/Sub # logger.begin_section("TC 6 : Test with Publisher and Subscriber configuration (MQTT) => subscriber variables change through Pub/Sub") helpConfigurationChangeAndStart(pubsubserver, XML_PUBSUB_LOOP_MQTT, logger) sleep(DYN_CONF_PUB_INTERVAL_1000) # Init Publisher variables helpTestSetValue(pubsubserver, NID_PUB_BOOL, False, logger) helpTestSetValue(pubsubserver, NID_PUB_UINT16, 8500, logger) helpTestSetValue(pubsubserver, NID_PUB_INT, -300, logger) helpTestSetValue(pubsubserver, NID_PUB_STRING, "Test MQTT From Publisher", logger) # Init Subscriber variables helpTestSetValue(pubsubserver, NID_SUB_BOOL, True, logger) helpTestSetValue(pubsubserver, NID_SUB_UINT16, 500, logger) helpTestSetValue(pubsubserver, NID_SUB_INT, 100, logger) helpTestSetValue(pubsubserver, NID_SUB_STRING, "Test MQTT Not set", logger) sleep(DYN_CONF_PUB_INTERVAL_1000) logger.add_test('Subscriber bool is changed ', False == pubsubserver.getValue(NID_SUB_BOOL)) logger.add_test('Subscriber uint16 is changed ', 8500 == pubsubserver.getValue(NID_SUB_UINT16)) logger.add_test('Subscriber int is changed ', -300 == pubsubserver.getValue(NID_SUB_INT)) logger.add_test('Subscriber string is changed ', "Test MQTT From Publisher" == pubsubserver.getValue(NID_SUB_STRING)) sleep(DYN_CONF_PUB_INTERVAL_1000) pubsubserver.stop() helpTestStopStart(pubsubserver, False, logger) # # TC 7 : Test with configuration message not consistent between the one on Publisher # and the one on Subscriber => subscriber variables do not change # logger.begin_section("TC 7 : Publisher Subscriber not consistent") helpConfigurationChangeAndStart(pubsubserver, XML_PUBSUB_LOOP_MESSAGE_NOT_COMPATIBLE, logger) # Init Subscriber variables helpTestSetValue(pubsubserver, NID_SUB_BOOL, False, logger) helpTestSetValue(pubsubserver, NID_SUB_UINT16, 500, logger) helpTestSetValue(pubsubserver, NID_SUB_INT, 100, logger) # Change Publisher variables helpTestSetValue(pubsubserver, NID_PUB_BOOL, True, logger) helpTestSetValue(pubsubserver, NID_PUB_UINT16, 6500, logger) helpTestSetValue(pubsubserver, NID_PUB_INT, -600, logger) sleep(DYN_CONF_PUB_INTERVAL_200) logger.add_test('Subscriber bool is not changed ', False == pubsubserver.getValue(NID_SUB_BOOL)) logger.add_test('Subscriber uint16 is not changed ', 500 == pubsubserver.getValue(NID_SUB_UINT16)) logger.add_test('Subscriber int is not changed ', 100 == pubsubserver.getValue(NID_SUB_INT)) # # TC 8 : Test with a bad formed configuration => Pub/Sub status is 0 # logger.begin_section("TC 8 : Bad formed configuration") helpConfigurationChange(pubsubserver, XML_PUBSUB_BAD_FORMED_CONFIGURATION, logger) pubsubserver.stop() helpTestStopStart(pubsubserver, False, logger) logger.add_test('Start Server', True) pubsubserver.start() status = pubsubserver.getStatus() logger.add_test('PubSub Module Status should be 0 : %d' % status , 0 == status) # # TC 9 : Start and Stop empty configuration # logger.begin_section("TC 9 : Empty configuration") helpConfigurationChange(pubsubserver, XML_EMPTY, logger) status = pubsubserver.getStatus() logger.add_test('PubSub Module Status should be 0 : %d' % status , 0 == status) # # TC 10 : Test with message configured with security mode encrypt and sign for publisher # but no security for subscriber => subscriber variables do not change # logger.begin_section("TC 10 : Security mode not consistent - message is encrypt and sign but no security for subscriber") helpConfigurationChangeAndStart(pubsubserver, XML_PUBSUB_LOOP_SECU_FAIL_1, logger, possibleFail=True) # Init Subscriber variables helpTestSetValue(pubsubserver, NID_SUB_BOOL, False, logger) helpTestSetValue(pubsubserver, NID_SUB_UINT16, 1456, logger) helpTestSetValue(pubsubserver, NID_SUB_INT, 123654, logger) # Change Publisher variables helpTestSetValue(pubsubserver, NID_PUB_BOOL, True, logger) helpTestSetValue(pubsubserver, NID_PUB_UINT16, 6500, logger) helpTestSetValue(pubsubserver, NID_PUB_INT, -600, logger) sleep(DYN_CONF_PUB_INTERVAL_200) logger.add_test('Subscriber bool is not changed ', False == pubsubserver.getValue(NID_SUB_BOOL)) logger.add_test('Subscriber uint16 is not changed ', 1456 == pubsubserver.getValue(NID_SUB_UINT16)) logger.add_test('Subscriber int is not changed ', 123654 == pubsubserver.getValue(NID_SUB_INT)) expStatus = 3 # Error state retrievedStatus = pubsubserver.getStatus() logger.add_test('PubSub Module Status should be %d : %d' % (expStatus, retrievedStatus) , expStatus == retrievedStatus) # # TC 11 : Test with message configured with security mode encrypt and sign for publisher # but only sign for subscriber => subscriber variables do not change # logger.begin_section("TC 11 : Security mode not consistent - message is encrypt and sign but only sign mode for subscriber") helpConfigurationChangeAndStart(pubsubserver, XML_PUBSUB_LOOP_SECU_FAIL_2, logger, possibleFail=True) # Init Subscriber variables helpTestSetValue(pubsubserver, NID_SUB_BOOL, False, logger) helpTestSetValue(pubsubserver, NID_SUB_UINT16, 1456, logger) helpTestSetValue(pubsubserver, NID_SUB_INT, 123654, logger) # Change Publisher variables helpTestSetValue(pubsubserver, NID_PUB_BOOL, True, logger) helpTestSetValue(pubsubserver, NID_PUB_UINT16, 6500, logger) helpTestSetValue(pubsubserver, NID_PUB_INT, -600, logger) sleep(DYN_CONF_PUB_INTERVAL_200) logger.add_test('Subscriber bool is not changed ', False == pubsubserver.getValue(NID_SUB_BOOL)) logger.add_test('Subscriber uint16 is not changed ', 1456 == pubsubserver.getValue(NID_SUB_UINT16)) logger.add_test('Subscriber int is not changed ', 123654 == pubsubserver.getValue(NID_SUB_INT)) expStatus = 3 # Error state retrievedStatus = pubsubserver.getStatus() logger.add_test('PubSub Module Status should be %d : %d' % (expStatus, retrievedStatus) , expStatus == retrievedStatus) # # TC 12 : Test with message configured with security mode sign for publisher # but encrypt and sign for subscriber => subscriber variables do not change # logger.begin_section("TC 12 : Security mode not consistent - message is sign but sign and encrypt for subscriber") helpConfigurationChangeAndStart(pubsubserver, XML_PUBSUB_LOOP_SECU_FAIL_3, logger, possibleFail=True) # Init Subscriber variables helpTestSetValue(pubsubserver, NID_SUB_BOOL, False, logger) helpTestSetValue(pubsubserver, NID_SUB_UINT16, 1456, logger) helpTestSetValue(pubsubserver, NID_SUB_INT, 123654, logger) # Change Publisher variables helpTestSetValue(pubsubserver, NID_PUB_BOOL, True, logger) helpTestSetValue(pubsubserver, NID_PUB_UINT16, 6500, logger) helpTestSetValue(pubsubserver, NID_PUB_INT, -600, logger) sleep(DYN_CONF_PUB_INTERVAL_200) logger.add_test('Subscriber bool is not changed ', False == pubsubserver.getValue(NID_SUB_BOOL)) logger.add_test('Subscriber uint16 is not changed ', 1456 == pubsubserver.getValue(NID_SUB_UINT16)) logger.add_test('Subscriber int is not changed ', 123654 == pubsubserver.getValue(NID_SUB_INT)) expStatus = 3 # Error state retrievedStatus = pubsubserver.getStatus() logger.add_test('PubSub Module Status should be %d : %d' % (expStatus, retrievedStatus) , expStatus == retrievedStatus) # # TC 13 : Test with message configured with security mode sign and encrypt # for both publisher and subscriber => subscriber variables change # logger.begin_section("TC 13 : Security mode sign and encrypt") helpConfigurationChangeAndStart(pubsubserver, XML_PUBSUB_LOOP_SECU_ENCRYPT_SIGN_SUCCEED, logger) # Init Subscriber variables helpTestSetValue(pubsubserver, NID_SUB_BOOL, False, logger) helpTestSetValue(pubsubserver, NID_SUB_UINT16, 1456, logger) helpTestSetValue(pubsubserver, NID_SUB_INT, 123654, logger) # Change Publisher variables helpTestSetValue(pubsubserver, NID_PUB_BOOL, True, logger) helpTestSetValue(pubsubserver, NID_PUB_UINT16, 852, logger) helpTestSetValue(pubsubserver, NID_PUB_INT, 2658, logger) sleep(DYN_CONF_PUB_INTERVAL_200) logger.add_test('Subscriber bool is changed ', True == pubsubserver.getValue(NID_SUB_BOOL)) logger.add_test('Subscriber uint16 is changed ', 852 == pubsubserver.getValue(NID_SUB_UINT16)) logger.add_test('Subscriber int is changed ', 2658 == pubsubserver.getValue(NID_SUB_INT)) # # TC 14 : Test with message configured with security mode sign # for both publisher and subscriber => subscriber variables change # logger.begin_section("TC 14 : Security mode sign") helpConfigurationChangeAndStart(pubsubserver, XML_PUBSUB_LOOP_SECU_SIGN_SUCCEED, logger) # Init Subscriber variables helpTestSetValue(pubsubserver, NID_SUB_BOOL, False, logger) helpTestSetValue(pubsubserver, NID_SUB_UINT16, 1456, logger) helpTestSetValue(pubsubserver, NID_SUB_INT, 123654, logger) # Change Publisher variables helpTestSetValue(pubsubserver, NID_PUB_BOOL, True, logger) helpTestSetValue(pubsubserver, NID_PUB_UINT16, 528, logger) helpTestSetValue(pubsubserver, NID_PUB_INT, 7896, logger) sleep(DYN_CONF_PUB_INTERVAL_200) logger.add_test('Subscriber bool is changed ', True == pubsubserver.getValue(NID_SUB_BOOL)) logger.add_test('Subscriber uint16 is changed ', 528 == pubsubserver.getValue(NID_SUB_UINT16)) logger.add_test('Subscriber int is changed ', 7896 == pubsubserver.getValue(NID_SUB_INT)) # # TC 15 : Test with message configured with security mode sign only # for publisher => subscriber variables do not change # logger.begin_section("TC 15 : Security mode sign only publisher") helpConfigurationChangeAndStart(pubsubserver, XML_PUBSUB_LOOP_SECU_SIGN_FAIL_4, logger, possibleFail=True) # Init Subscriber variables helpTestSetValue(pubsubserver, NID_SUB_BOOL, False, logger) helpTestSetValue(pubsubserver, NID_SUB_UINT16, 1456, logger) helpTestSetValue(pubsubserver, NID_SUB_INT, 123654, logger) # Change Publisher variables helpTestSetValue(pubsubserver, NID_PUB_BOOL, True, logger) helpTestSetValue(pubsubserver, NID_PUB_UINT16, 456, logger) helpTestSetValue(pubsubserver, NID_PUB_INT, 789, logger) sleep(DYN_CONF_PUB_INTERVAL_200) logger.add_test('Subscriber bool is not changed ', False == pubsubserver.getValue(NID_SUB_BOOL)) logger.add_test('Subscriber uint16 is not changed ', 1456 == pubsubserver.getValue(NID_SUB_UINT16)) logger.add_test('Subscriber int is not changed ', 123654 == pubsubserver.getValue(NID_SUB_INT)) expStatus = 3 # Error state retrievedStatus = pubsubserver.getStatus() logger.add_test('PubSub Module Status should be %d : %d' % (expStatus, retrievedStatus) , expStatus == retrievedStatus) finally: # restore default XML file if defaultXml2Restore: move(DEFAULT_XML_PATH + ".bakup", DEFAULT_XML_PATH) pubsubserver.disconnect() logger.add_test('Not connected to OPCUA Server', not pubsubserver.isConnected()) logger.finalize_report()
from view_basic import browse_tests from translate_browse_path import translate_browse_paths_to_node_ids_tests from common import sUri, create_client from tap_logger import TapLogger from opcua.crypto import security_policies if __name__ == '__main__': # tests with one connexion print('Connecting to', sUri) client = create_client() logger = TapLogger("validation.tap") headerString = "******************* Beginning {0} tests with one connexion *********************" for sp in [SecurityPolicy, security_policies.SecurityPolicyBasic256]: #for sp in [SecurityPolicy]: logger.begin_section("security policy {0}".format( re.split("#", sp.URI)[-1])) try: # secure channel connection secure_channels_connect(client, sp) # discovery server services discovery_server_tests(client, logger) # check endpoints discovery_get_endpoints_tests(client, logger) # Read tests print(headerString.format("Read")) attribute_read_tests(client, logger) # Force renew secure channel (nominal case)
## remove keep alive # END MODIFICATION return response if __name__=='__main__': # Tests with one connexion print('Connecting to', sUri) client = Client2(sUri) logger = TapLogger("session_timeout.tap") headerString = "******************* {0} *********************" # Test revised session timeout for l_session_timeout in [5000, 360000, 45000000]: try: logger.begin_section("Requested session timeout {0}".format(l_session_timeout)) client.session_timeout = l_session_timeout # secure channel connection print(headerString.format("SC connection and session establishment with requested timeout {0}" .format(l_session_timeout))) secure_channels_connect(client, SecurityPolicy) print(headerString.format("Check revised session timeout value")) if (l_session_timeout < MIN_SESSION_TIMEOUT and client.session_timeout == MIN_SESSION_TIMEOUT): logger.add_test("- Revised timeout set to min value {}".format(client.session_timeout), True) elif (l_session_timeout > MAX_SESSION_TIMEOUT and client.session_timeout == MAX_SESSION_TIMEOUT): logger.add_test("- Revised timeout set to max value {}".format(client.session_timeout), True) elif (l_session_timeout >= MIN_SESSION_TIMEOUT and l_session_timeout <= MAX_SESSION_TIMEOUT and client.session_timeout == l_session_timeout):
def testPubSubDynamicConf(): logger = TapLogger("pubsub_server_test.tap") pubsubserver = PubSubServer(DEFAULT_URI, NID_CONFIGURATION, NID_START_STOP, NID_STATUS) defaultXml2Restore = False try: # backup of default XML file copyfile(DEFAULT_XML_PATH, DEFAULT_XML_PATH + ".bakup") defaultXml2Restore = True # secure channel connection pubsubserver.connect() # # TC 1 : Test with Publisher only configuration => only pub variables change # logger.begin_section("TC 1 : Publisher only") helpConfigurationChangeAndStart(pubsubserver, XML_PUBLISHER_ONLY, logger) # Init Subscriber variables helpTestSetValue(pubsubserver, NID_SUB_BOOL, True, logger) helpTestSetValue(pubsubserver, NID_SUB_UINT16, 500, logger) helpTestSetValue(pubsubserver, NID_SUB_INT, 100, logger) # Set Publisher variables helpTestSetValue(pubsubserver, NID_PUB_BOOL, False, logger) helpTestSetValue(pubsubserver, NID_PUB_UINT16, 1500, logger) helpTestSetValue(pubsubserver, NID_PUB_INT, -50, logger) sleep(.400) logger.add_test('Subscriber bool is not changed ', True == pubsubserver.getValue(NID_SUB_BOOL)) logger.add_test('Subscriber uint16 is not changed ', 500 == pubsubserver.getValue(NID_SUB_UINT16)) logger.add_test('Subscriber int is not changed ', 100 == pubsubserver.getValue(NID_SUB_INT)) pubsubserver.stop() helpTestStopStart(pubsubserver, False, logger) # # TC 2 : Test with Subscriber only configuration => no variables change # logger.begin_section("TC 2 : Subscriber only") # Init Subscriber variables helpTestSetValue(pubsubserver, NID_SUB_BOOL, True, logger) helpTestSetValue(pubsubserver, NID_SUB_UINT16, 500, logger) helpTestSetValue(pubsubserver, NID_SUB_INT, 100, logger) helpConfigurationChangeAndStart(pubsubserver, XML_SUBSCRIBER_ONLY, logger) sleep(.400) logger.add_test('Subscriber bool is not changed ', True == pubsubserver.getValue(NID_SUB_BOOL)) logger.add_test('Subscriber uint16 is not changed ', 500 == pubsubserver.getValue(NID_SUB_UINT16)) logger.add_test('Subscriber int is not changed ', 100 == pubsubserver.getValue(NID_SUB_INT)) pubsubserver.stop() helpTestStopStart(pubsubserver, False, logger) # # TC 3 : Test with Publisher and Subscriber configuration => subscriber variables change through Pub/Sub # logger.begin_section("TC 3 : Publisher Subscriber Loop") # Init Subscriber variables helpTestSetValue(pubsubserver, NID_SUB_BOOL, True, logger) helpTestSetValue(pubsubserver, NID_SUB_UINT16, 500, logger) helpTestSetValue(pubsubserver, NID_SUB_INT, 100, logger) helpConfigurationChangeAndStart(pubsubserver, XML_PUBSUB_LOOP, logger) sleep(.400) logger.add_test('Subscriber bool is changed ', False == pubsubserver.getValue(NID_SUB_BOOL)) logger.add_test('Subscriber uint16 is changed ', 1500 == pubsubserver.getValue(NID_SUB_UINT16)) logger.add_test('Subscriber int is changed ', -50 == pubsubserver.getValue(NID_SUB_INT)) pubsubserver.stop() helpTestStopStart(pubsubserver, False, logger) # # TC 4 : Stop Pub/Sub module => subscriber variables do not change # logger.begin_section("TC 4 : Publisher Subscriber Loop") # Change Publisher variables helpTestSetValue(pubsubserver, NID_PUB_BOOL, True, logger) helpTestSetValue(pubsubserver, NID_PUB_UINT16, 6500, logger) helpTestSetValue(pubsubserver, NID_PUB_INT, -600, logger) sleep(.400) logger.add_test('Subscriber bool is not changed ', False == pubsubserver.getValue(NID_SUB_BOOL)) logger.add_test('Subscriber uint16 is not changed ', 1500 == pubsubserver.getValue(NID_SUB_UINT16)) logger.add_test('Subscriber int is not changed ', -50 == pubsubserver.getValue(NID_SUB_INT)) # Start to change Subscriber variables pubsubserver.start() helpTestStopStart(pubsubserver, True, logger) sleep(.400) logger.add_test('Subscriber bool is changed ', True == pubsubserver.getValue(NID_SUB_BOOL)) logger.add_test('Subscriber uint16 is changed ', 6500 == pubsubserver.getValue(NID_SUB_UINT16)) logger.add_test('Subscriber int is changed ', -600 == pubsubserver.getValue(NID_SUB_INT)) pubsubserver.stop() helpTestStopStart(pubsubserver, False, logger) # # TC 5 : Test with Publisher and Subscriber configuration. DataType is NULL # => subscriber variables change through Pub/Sub # logger.begin_section("TC 5 : Publisher Subscriber Loop (DataType is Null)") # Init Publisher variables helpTestSetValue(pubsubserver, NID_PUB_BOOL, False, logger) helpTestSetValue(pubsubserver, NID_PUB_UINT16, 8500, logger) helpTestSetValue(pubsubserver, NID_PUB_INT, -300, logger) # Init Subscriber variables helpTestSetValue(pubsubserver, NID_SUB_BOOL, True, logger) helpTestSetValue(pubsubserver, NID_SUB_UINT16, 500, logger) helpTestSetValue(pubsubserver, NID_SUB_INT, 100, logger) helpConfigurationChangeAndStart(pubsubserver, XML_PUBSUB_LOOP_NULL, logger) sleep(.400) logger.add_test('Subscriber bool is changed ', False == pubsubserver.getValue(NID_SUB_BOOL)) logger.add_test('Subscriber uint16 is changed ', 8500 == pubsubserver.getValue(NID_SUB_UINT16)) logger.add_test('Subscriber int is changed ', -300 == pubsubserver.getValue(NID_SUB_INT)) # # TC 6 : Test with configuration message not consistent between the one on Publisher # and the one on Subscriber => subscriber variables do not change # logger.begin_section("TC 6 : Publisher Subscriber not consistent") helpConfigurationChangeAndStart(pubsubserver, XML_PUBSUB_LOOP_MESSAGE_NOT_COMPATIBLE, logger) # Init Subscriber variables helpTestSetValue(pubsubserver, NID_SUB_BOOL, False, logger) helpTestSetValue(pubsubserver, NID_SUB_UINT16, 500, logger) helpTestSetValue(pubsubserver, NID_SUB_INT, 100, logger) # Change Publisher variables helpTestSetValue(pubsubserver, NID_PUB_BOOL, True, logger) helpTestSetValue(pubsubserver, NID_PUB_UINT16, 6500, logger) helpTestSetValue(pubsubserver, NID_PUB_INT, -600, logger) sleep(.400) logger.add_test('Subscriber bool is not changed ', False == pubsubserver.getValue(NID_SUB_BOOL)) logger.add_test('Subscriber uint16 is not changed ', 500 == pubsubserver.getValue(NID_SUB_UINT16)) logger.add_test('Subscriber int is not changed ', 100 == pubsubserver.getValue(NID_SUB_INT)) # # TC 7 : Test with a bad formed configuration => Pub/Sub status is 0 # logger.begin_section("TC 7 : Bad formed configuration") helpConfigurationChange(pubsubserver, XML_PUBSUB_BAD_FORMED_CONFIGURATION, logger) pubsubserver.stop() helpTestStopStart(pubsubserver, False, logger) logger.add_test('Start Server', True) pubsubserver.start() status = pubsubserver.getStatus() logger.add_test('PubSub Module Status should be 0 : %d' % status , 0 == status) # # TC 8 : Start and Stop empty configuration # logger.begin_section("TC 8 : Empty configuration") helpConfigurationChange(pubsubserver, XML_EMPTY, logger) status = pubsubserver.getStatus() logger.add_test('PubSub Module Status should be 0 : %d' % status , 0 == status) finally: # restore default XML file if defaultXml2Restore: move(DEFAULT_XML_PATH + ".bakup", DEFAULT_XML_PATH) pubsubserver.disconnect() logger.add_test('Not connected to OPCUA Server', not pubsubserver.isConnected()) logger.finalize_report()
print('Read Tests') connection.test_read() print('Write Tests') connection.test_write() print('Browse Tests') connection.test_browse() # Do the read/write with multiple connections print('Asynch Write/Reads on new connections') connections = [PyS2OPC.connect(cfg, ConnectionHandler) for cfg in configs] for conn in connections: conn.set_logger(logger_) conn.configure_subscription() try: # Do the write on one connection, reads on all others to assert the result. logger_.begin_section('ReadWrite Tests -') connA, *conns = connections connA.test_write_and_assert() for conn in conns: conn._test_read(readInitValues = False, onlyValues = True) connA.test_write_and_assert(resetInitValues = True) # Wait for subscriptions to end. Does not wait more than the publish cycle, # as the last notifications should be received by then. timeout = .001*max(cfg.parameters.get('publish_period_ms', 0.) for cfg in configs) for conn in connections: assert conn.subscriptionComplete.wait(timeout) logger_.add_test('Values all correctly notified', True) finally: for conn in connections: conn.disconnect()