From 78881abcc31dc039c374bcc15266030e8dabcf87 Mon Sep 17 00:00:00 2001 From: "guillaume.lambert" Date: Tue, 23 Jun 2020 00:55:11 +0200 Subject: [PATCH] fix some pylint issues Signed-off-by: guillaume.lambert Change-Id: I88f3d068d8199610556e18faaaf850a2f97ebf32 --- tests/transportpce_tests/1.2.1/simulators.py | 6 +- .../transportpce_tests/1.2.1/test_end2end.py | 14 ++--- tests/transportpce_tests/1.2.1/test_gnpy.py | 6 +- tests/transportpce_tests/1.2.1/test_olm.py | 9 +-- tests/transportpce_tests/1.2.1/test_pce.py | 8 +-- .../1.2.1/test_portmapping.py | 3 - .../test_renderer_service_path_nominal.py | 11 +--- .../1.2.1/test_topoPortMapping.py | 3 - .../transportpce_tests/1.2.1/test_topology.py | 2 - tests/transportpce_tests/2.2.1/simulators.py | 6 +- .../transportpce_tests/2.2.1/test_end2end.py | 13 ++-- tests/transportpce_tests/2.2.1/test_olm.py | 9 +-- .../2.2.1/test_otn_renderer.py | 10 +--- .../2.2.1/test_otn_topology.py | 10 +--- .../2.2.1/test_portmapping.py | 10 +--- .../test_renderer_service_path_nominal.py | 59 ++++++++++--------- tests/transportpce_tests/2.2.1/test_tapi.py | 8 +-- .../2.2.1/test_topoPortMapping.py | 10 +--- .../transportpce_tests/2.2.1/test_topology.py | 11 +--- tests/transportpce_tests/common/test_utils.py | 40 +++++++------ 20 files changed, 91 insertions(+), 157 deletions(-) diff --git a/tests/transportpce_tests/1.2.1/simulators.py b/tests/transportpce_tests/1.2.1/simulators.py index a44c4660a..79bbcd8f6 100644 --- a/tests/transportpce_tests/1.2.1/simulators.py +++ b/tests/transportpce_tests/1.2.1/simulators.py @@ -9,7 +9,7 @@ ############################################################################## import os -sims = { +SIMS = { 'xpdra': {'port': '17830', 'configfile': 'oper-XPDRA.xml', 'logfile': 'oper-XPDRA.log'}, 'roadma': {'port': '17831', 'configfile': 'oper-ROADMA.xml', 'logfile': 'oper-ROADMA.log'}, 'roadmb': {'port': '17832', 'configfile': 'oper-ROADMB.xml', 'logfile': 'oper-ROADMB.log'}, @@ -19,9 +19,9 @@ sims = { 'roadmc-full': {'port': '17823', 'configfile': 'oper-ROADMC-full.xml', 'logfile': 'oper-ROADMC.log'} } -honeynode_executable = os.path.join( +HONEYNODE_EXECUTABLE = os.path.join( os.path.dirname(os.path.realpath(__file__)), "..", "..", "honeynode", "1.2.1", "honeynode-simulator", "honeycomb-tpce") -samples_directory = os.path.join( +SAMPLES_DIRECTORY = os.path.join( os.path.dirname(os.path.realpath(__file__)), "..", "..", "sample_configs", "openroadm", "1.2.1") diff --git a/tests/transportpce_tests/1.2.1/test_end2end.py b/tests/transportpce_tests/1.2.1/test_end2end.py index 03481040a..f23790b3b 100644 --- a/tests/transportpce_tests/1.2.1/test_end2end.py +++ b/tests/transportpce_tests/1.2.1/test_end2end.py @@ -10,11 +10,9 @@ import json -import signal import time import unittest -import psutil import requests from common import test_utils @@ -405,12 +403,8 @@ class TransportPCEFulltesting(unittest.TestCase): for ele in liste_tp: if ele['tp-id'] == 'XPDR1-NETWORK1': self.assertEqual({u'frequency': 196.1, u'width': 40}, - ele[ - 'org-openroadm-network-topology:' - 'xpdr-network-attributes'][ - 'wavelength']) - if ele['tp-id'] == 'XPDR1-CLIENT1' or \ - ele['tp-id'] == 'XPDR1-CLIENT3': + ele['org-openroadm-network-topology:xpdr-network-attributes']['wavelength']) + if ele['tp-id'] == 'XPDR1-CLIENT1' or ele['tp-id'] == 'XPDR1-CLIENT3': self.assertNotIn( 'org-openroadm-network-topology:xpdr-client-attributes', dict.keys(ele)) @@ -1568,7 +1562,7 @@ class TransportPCEFulltesting(unittest.TestCase): def test_49_loop_create_eth_service(self): for i in range(1, 6): - print("trial number {}".format(i)) + print("iteration number {}".format(i)) print("eth service creation") self.test_11_create_eth_service1() print("check xc in ROADMA01") @@ -1607,7 +1601,7 @@ class TransportPCEFulltesting(unittest.TestCase): time.sleep(5) for i in range(1, 6): - print("trial number {}".format(i)) + print("iteration number {}".format(i)) print("oc service creation") self.test_36_create_oc_service1() print("check xc in ROADMA01") diff --git a/tests/transportpce_tests/1.2.1/test_gnpy.py b/tests/transportpce_tests/1.2.1/test_gnpy.py index e7f3a4849..26ab184b9 100644 --- a/tests/transportpce_tests/1.2.1/test_gnpy.py +++ b/tests/transportpce_tests/1.2.1/test_gnpy.py @@ -9,13 +9,11 @@ # http://www.apache.org/licenses/LICENSE-2.0 ############################################################################## +import unittest import json import os -import psutil -import requests -import signal import time -import unittest +import requests from common import test_utils diff --git a/tests/transportpce_tests/1.2.1/test_olm.py b/tests/transportpce_tests/1.2.1/test_olm.py index 1f5b736dd..6f32b83a5 100644 --- a/tests/transportpce_tests/1.2.1/test_olm.py +++ b/tests/transportpce_tests/1.2.1/test_olm.py @@ -10,15 +10,10 @@ ############################################################################# import unittest -import requests import time -import subprocess -import signal import json -import os -import psutil -import shutil -from unittest.result import failfast +#from unittest.result import failfast +import requests from common import test_utils diff --git a/tests/transportpce_tests/1.2.1/test_pce.py b/tests/transportpce_tests/1.2.1/test_pce.py index fb824f80d..c33af419a 100644 --- a/tests/transportpce_tests/1.2.1/test_pce.py +++ b/tests/transportpce_tests/1.2.1/test_pce.py @@ -8,15 +8,11 @@ # http://www.apache.org/licenses/LICENSE-2.0 ############################################################################## +import unittest import json import os -import psutil -import requests -import signal -import shutil -import subprocess import time -import unittest +import requests from common import test_utils diff --git a/tests/transportpce_tests/1.2.1/test_portmapping.py b/tests/transportpce_tests/1.2.1/test_portmapping.py index 68b74d413..8b495fa6f 100644 --- a/tests/transportpce_tests/1.2.1/test_portmapping.py +++ b/tests/transportpce_tests/1.2.1/test_portmapping.py @@ -9,12 +9,9 @@ # http://www.apache.org/licenses/LICENSE-2.0 ############################################################################## -import json -import signal import unittest import time import requests -import psutil from common import test_utils diff --git a/tests/transportpce_tests/1.2.1/test_renderer_service_path_nominal.py b/tests/transportpce_tests/1.2.1/test_renderer_service_path_nominal.py index 8d2d33de5..68ee4102b 100644 --- a/tests/transportpce_tests/1.2.1/test_renderer_service_path_nominal.py +++ b/tests/transportpce_tests/1.2.1/test_renderer_service_path_nominal.py @@ -10,15 +10,10 @@ ############################################################################# import unittest -import requests -import time -import subprocess -import signal import json -import os -import psutil -import shutil -from unittest.result import failfast +import time +#from unittest.result import failfast +import requests from common import test_utils diff --git a/tests/transportpce_tests/1.2.1/test_topoPortMapping.py b/tests/transportpce_tests/1.2.1/test_topoPortMapping.py index 369cea38f..712dfe179 100644 --- a/tests/transportpce_tests/1.2.1/test_topoPortMapping.py +++ b/tests/transportpce_tests/1.2.1/test_topoPortMapping.py @@ -9,12 +9,9 @@ # http://www.apache.org/licenses/LICENSE-2.0 ############################################################################## -import json -import signal import time import unittest import requests -import psutil from common import test_utils diff --git a/tests/transportpce_tests/1.2.1/test_topology.py b/tests/transportpce_tests/1.2.1/test_topology.py index 5f5d5abf7..24847612b 100644 --- a/tests/transportpce_tests/1.2.1/test_topology.py +++ b/tests/transportpce_tests/1.2.1/test_topology.py @@ -10,11 +10,9 @@ ############################################################################## import json -import signal import time import unittest import requests -import psutil from common import test_utils diff --git a/tests/transportpce_tests/2.2.1/simulators.py b/tests/transportpce_tests/2.2.1/simulators.py index 8892226c8..730acbab7 100644 --- a/tests/transportpce_tests/2.2.1/simulators.py +++ b/tests/transportpce_tests/2.2.1/simulators.py @@ -10,7 +10,7 @@ import os -sims = { +SIMS = { 'xpdra': {'port': '17840', 'configfile': 'oper-XPDRA.xml', 'logfile': 'oper-XPDRA.log'}, 'roadma': {'port': '17841', 'configfile': 'oper-ROADMA.xml', 'logfile': 'oper-ROADMA.log'}, 'roadmb': {'port': '17842', 'configfile': 'oper-ROADMB.xml', 'logfile': 'oper-ROADMB.log'}, @@ -20,9 +20,9 @@ sims = { 'spdrav1': {'port': '17846', 'configfile': 'oper-SPDRAv1.xml', 'logfile': 'oper-SPDRAv1.log'} } -honeynode_executable = os.path.join( +HONEYNODE_EXECUTABLE = os.path.join( os.path.dirname(os.path.realpath(__file__)), "..", "..", "honeynode", "2.2.1", "honeynode-simulator", "honeycomb-tpce") -samples_directory = os.path.join( +SAMPLES_DIRECTORY = os.path.join( os.path.dirname(os.path.realpath(__file__)), "..", "..", "sample_configs", "openroadm", "2.2.1") diff --git a/tests/transportpce_tests/2.2.1/test_end2end.py b/tests/transportpce_tests/2.2.1/test_end2end.py index dd92540c4..6555bcf15 100644 --- a/tests/transportpce_tests/2.2.1/test_end2end.py +++ b/tests/transportpce_tests/2.2.1/test_end2end.py @@ -9,15 +9,10 @@ ############################################################################## +import unittest import json -import os -import psutil -import requests -import signal -import shutil -import subprocess import time -import unittest +import requests from common import test_utils @@ -1370,7 +1365,7 @@ class TransportPCEFulltesting(unittest.TestCase): def test_49_loop_create_eth_service(self): for i in range(1, 6): - print("trial number {}".format(i)) + print("iteration number {}".format(i)) print("eth service creation") self.test_11_create_eth_service1() print("check xc in ROADM-A1") @@ -1405,7 +1400,7 @@ class TransportPCEFulltesting(unittest.TestCase): time.sleep(5) for i in range(1, 6): - print("trial number {}".format(i)) + print("iteration number {}".format(i)) print("oc service creation") self.test_36_create_oc_service1() print("check xc in ROADM-A1") diff --git a/tests/transportpce_tests/2.2.1/test_olm.py b/tests/transportpce_tests/2.2.1/test_olm.py index f52325bfe..8c59393a6 100644 --- a/tests/transportpce_tests/2.2.1/test_olm.py +++ b/tests/transportpce_tests/2.2.1/test_olm.py @@ -10,15 +10,10 @@ ############################################################################# import unittest -import requests import time -import subprocess -import signal import json -import os -import psutil -import shutil -from unittest.result import failfast +#from unittest.result import failfast +import requests from common import test_utils diff --git a/tests/transportpce_tests/2.2.1/test_otn_renderer.py b/tests/transportpce_tests/2.2.1/test_otn_renderer.py index 6b72ede01..6157b038a 100644 --- a/tests/transportpce_tests/2.2.1/test_otn_renderer.py +++ b/tests/transportpce_tests/2.2.1/test_otn_renderer.py @@ -9,16 +9,10 @@ # http://www.apache.org/licenses/LICENSE-2.0 ############################################################################## +import unittest import json -import os -import psutil -import requests -import signal -import shutil -import subprocess import time -import unittest -import logging +import requests from common import test_utils diff --git a/tests/transportpce_tests/2.2.1/test_otn_topology.py b/tests/transportpce_tests/2.2.1/test_otn_topology.py index 1be82ab69..97b6d4e92 100644 --- a/tests/transportpce_tests/2.2.1/test_otn_topology.py +++ b/tests/transportpce_tests/2.2.1/test_otn_topology.py @@ -9,16 +9,10 @@ # http://www.apache.org/licenses/LICENSE-2.0 ############################################################################## -import json -import os -import psutil -import requests -import signal -import shutil -import subprocess -import time import unittest +import time import logging +import requests from common import test_utils diff --git a/tests/transportpce_tests/2.2.1/test_portmapping.py b/tests/transportpce_tests/2.2.1/test_portmapping.py index 68d59d543..551bae62e 100644 --- a/tests/transportpce_tests/2.2.1/test_portmapping.py +++ b/tests/transportpce_tests/2.2.1/test_portmapping.py @@ -9,15 +9,9 @@ # http://www.apache.org/licenses/LICENSE-2.0 ############################################################################## -import json -import os -import psutil -import requests -import signal -import shutil -import subprocess -import time import unittest +import time +import requests from common import test_utils diff --git a/tests/transportpce_tests/2.2.1/test_renderer_service_path_nominal.py b/tests/transportpce_tests/2.2.1/test_renderer_service_path_nominal.py index 9134fb92d..29f4556e7 100644 --- a/tests/transportpce_tests/2.2.1/test_renderer_service_path_nominal.py +++ b/tests/transportpce_tests/2.2.1/test_renderer_service_path_nominal.py @@ -10,15 +10,9 @@ ############################################################################# import unittest -import requests -import time -import subprocess -import signal import json -import os -import psutil -import shutil -from unittest.result import failfast +#from unittest.result import failfast +import requests from common import test_utils @@ -422,9 +416,10 @@ class TransportPCERendererTesting(unittest.TestCase): "GET", url, headers=headers, auth=(test_utils.ODL_LOGIN, test_utils.ODL_PWD)) self.assertEqual(response.status_code, requests.codes.not_found) res = response.json() - self.assertIn( - {"error-type": "application", "error-tag": "data-missing", - "error-message": "Request could not be completed because the relevant data model content does not exist"}, + self.assertIn({ + "error-type": "application", + "error-tag": "data-missing", + "error-message": "Request could not be completed because the relevant data model content does not exist"}, res['errors']['error']) def test_21_service_path_delete_rdm_check(self): @@ -437,9 +432,10 @@ class TransportPCERendererTesting(unittest.TestCase): "GET", url, headers=headers, auth=(test_utils.ODL_LOGIN, test_utils.ODL_PWD)) self.assertEqual(response.status_code, requests.codes.not_found) res = response.json() - self.assertIn( - {"error-type": "application", "error-tag": "data-missing", - "error-message": "Request could not be completed because the relevant data model content does not exist"}, + self.assertIn({ + "error-type": "application", + "error-tag": "data-missing", + "error-message": "Request could not be completed because the relevant data model content does not exist"}, res['errors']['error']) def test_22_service_path_delete_rdm_check(self): @@ -452,9 +448,10 @@ class TransportPCERendererTesting(unittest.TestCase): "GET", url, headers=headers, auth=(test_utils.ODL_LOGIN, test_utils.ODL_PWD)) self.assertEqual(response.status_code, requests.codes.not_found) res = response.json() - self.assertIn( - {"error-type": "application", "error-tag": "data-missing", - "error-message": "Request could not be completed because the relevant data model content does not exist"}, + self.assertIn({ + "error-type": "application", + "error-tag": "data-missing", + "error-message": "Request could not be completed because the relevant data model content does not exist"}, res['errors']['error']) def test_23_service_path_delete_xpdr_check(self): @@ -467,9 +464,10 @@ class TransportPCERendererTesting(unittest.TestCase): "GET", url, headers=headers, auth=(test_utils.ODL_LOGIN, test_utils.ODL_PWD)) self.assertEqual(response.status_code, requests.codes.not_found) res = response.json() - self.assertIn( - {"error-type": "application", "error-tag": "data-missing", - "error-message": "Request could not be completed because the relevant data model content does not exist"}, + self.assertIn({ + "error-type": "application", + "error-tag": "data-missing", + "error-message": "Request could not be completed because the relevant data model content does not exist"}, res['errors']['error']) def test_24_service_path_delete_xpdr_check(self): @@ -482,9 +480,10 @@ class TransportPCERendererTesting(unittest.TestCase): "GET", url, headers=headers, auth=(test_utils.ODL_LOGIN, test_utils.ODL_PWD)) self.assertEqual(response.status_code, requests.codes.not_found) res = response.json() - self.assertIn( - {"error-type": "application", "error-tag": "data-missing", - "error-message": "Request could not be completed because the relevant data model content does not exist"}, + self.assertIn({ + "error-type": "application", + "error-tag": "data-missing", + "error-message": "Request could not be completed because the relevant data model content does not exist"}, res['errors']['error']) def test_25_service_path_delete_xpdr_check(self): @@ -497,9 +496,10 @@ class TransportPCERendererTesting(unittest.TestCase): "GET", url, headers=headers, auth=(test_utils.ODL_LOGIN, test_utils.ODL_PWD)) self.assertEqual(response.status_code, requests.codes.not_found) res = response.json() - self.assertIn( - {"error-type": "application", "error-tag": "data-missing", - "error-message": "Request could not be completed because the relevant data model content does not exist"}, + self.assertIn({ + "error-type": "application", + "error-tag": "data-missing", + "error-message": "Request could not be completed because the relevant data model content does not exist"}, res['errors']['error']) def test_26_service_path_delete_xpdr_check(self): @@ -512,9 +512,10 @@ class TransportPCERendererTesting(unittest.TestCase): "GET", url, headers=headers, auth=(test_utils.ODL_LOGIN, test_utils.ODL_PWD)) self.assertEqual(response.status_code, requests.codes.not_found) res = response.json() - self.assertIn( - {"error-type": "application", "error-tag": "data-missing", - "error-message": "Request could not be completed because the relevant data model content does not exist"}, + self.assertIn({ + "error-type": "application", + "error-tag": "data-missing", + "error-message": "Request could not be completed because the relevant data model content does not exist"}, res['errors']['error']) def test_27_service_path_delete_xpdr_check(self): diff --git a/tests/transportpce_tests/2.2.1/test_tapi.py b/tests/transportpce_tests/2.2.1/test_tapi.py index e1c67477b..b5796895c 100644 --- a/tests/transportpce_tests/2.2.1/test_tapi.py +++ b/tests/transportpce_tests/2.2.1/test_tapi.py @@ -8,7 +8,7 @@ # http://www.apache.org/licenses/LICENSE-2.0 ############################################################################## import os -import re +import sys import time import unittest @@ -35,15 +35,15 @@ class TransportTapitesting(unittest.TestCase): result = test_utils.install_karaf_feature("odl-transportpce-tapi") if result.returncode != 0: cls.init_failed = True - print("Restarting opendaylight...") + print("Restarting OpenDaylight...") test_utils.shutdown_process(cls.processes[0]) cls.processes = test_utils.start_tpce() cls.init_failed = not test_utils.wait_until_log_contains( - test_utils.karaf_log, test_utils.KARAF_OK_START_MSG, time_to_wait=60) + test_utils.KARAF_LOG, test_utils.KARAF_OK_START_MSG, time_to_wait=60) if cls.init_failed: print("tapi installaiton feature failed...") test_utils.shutdown_process(cls.odl_processes[0]) - exit(2) + sys.exit(2) cls.processes = test_utils.start_sims(['xpdra', 'roadma', 'roadmc', 'xpdrc', 'spdrav2']) @classmethod diff --git a/tests/transportpce_tests/2.2.1/test_topoPortMapping.py b/tests/transportpce_tests/2.2.1/test_topoPortMapping.py index 36e52bd0d..6fcfa9912 100644 --- a/tests/transportpce_tests/2.2.1/test_topoPortMapping.py +++ b/tests/transportpce_tests/2.2.1/test_topoPortMapping.py @@ -9,16 +9,10 @@ # http://www.apache.org/licenses/LICENSE-2.0 ############################################################################## +import unittest import json -import os -import psutil -import requests -import signal -import shutil -import subprocess import time -import unittest -import logging +import requests from common import test_utils diff --git a/tests/transportpce_tests/2.2.1/test_topology.py b/tests/transportpce_tests/2.2.1/test_topology.py index 27da88a84..2b0e7b358 100644 --- a/tests/transportpce_tests/2.2.1/test_topology.py +++ b/tests/transportpce_tests/2.2.1/test_topology.py @@ -9,16 +9,11 @@ # http://www.apache.org/licenses/LICENSE-2.0 ############################################################################## -import json -import os -import psutil -import requests -import signal -import shutil -import subprocess -import time import unittest +import time +import json import logging +import requests from common import test_utils diff --git a/tests/transportpce_tests/common/test_utils.py b/tests/transportpce_tests/common/test_utils.py index e3af5fe2f..7f2cc1d33 100644 --- a/tests/transportpce_tests/common/test_utils.py +++ b/tests/transportpce_tests/common/test_utils.py @@ -9,6 +9,7 @@ ############################################################################## import json import os +import sys import re import signal import subprocess @@ -18,9 +19,9 @@ import requests import simulators -sims = simulators.sims -honeynode_executable = simulators.honeynode_executable -samples_directory = simulators.samples_directory +SIMS = simulators.SIMS +HONEYNODE_EXECUTABLE = simulators.HONEYNODE_EXECUTABLE +SAMPLES_DIRECTORY = simulators.SAMPLES_DIRECTORY HONEYNODE_OK_START_MSG = "Netconf SSH endpoint started successfully at 0.0.0.0" KARAF_OK_START_MSG = re.escape( @@ -39,24 +40,25 @@ TYPE_APPLICATION_XML = {'Content-Type': 'application/xml', 'Accept': 'applicatio CODE_SHOULD_BE_200 = 'Http status code should be 200' CODE_SHOULD_BE_201 = 'Http status code should be 201' -log_directory = os.path.dirname(os.path.realpath(__file__)) +LOG_DIRECTORY = os.path.dirname(os.path.realpath(__file__)) -karaf_log = os.path.join( +KARAF_LOG = os.path.join( os.path.dirname(os.path.realpath(__file__)), "..", "..", "..", "karaf", "target", "assembly", "data", "log", "karaf.log") process_list = [] if "USE_LIGHTY" in os.environ and os.environ['USE_LIGHTY'] == 'True': - tpce_log = 'odl.log' + TPCE_LOG = 'odl.log' else: - tpce_log = karaf_log + TPCE_LOG = KARAF_LOG + def start_sims(sims_list): for sim in sims_list: print("starting simulator for " + sim + "...") - log_file = os.path.join(log_directory, sims[sim]['logfile']) - process = start_honeynode(log_file, sims[sim]['port'], sims[sim]['configfile']) + log_file = os.path.join(LOG_DIRECTORY, SIMS[sim]['logfile']) + process = start_honeynode(log_file, SIMS[sim]['port'], SIMS[sim]['configfile']) if wait_until_log_contains(log_file, HONEYNODE_OK_START_MSG, 100): print("simulator for " + sim + " started") else: @@ -64,7 +66,7 @@ def start_sims(sims_list): shutdown_process(process) for pid in process_list: shutdown_process(pid) - exit(3) + sys.exit(3) process_list.append(process) return process_list @@ -76,14 +78,14 @@ def start_tpce(): # TODO: add some sort of health check similar to Karaf below else: process = start_karaf() - if wait_until_log_contains(karaf_log, KARAF_OK_START_MSG, time_to_wait=60): + if wait_until_log_contains(KARAF_LOG, KARAF_OK_START_MSG, time_to_wait=60): print("OpenDaylight started !") else: print("OpenDaylight failed to start !") shutdown_process(process) for pid in process_list: shutdown_process(pid) - exit(1) + sys.exit(1) process_list.append(process) return process_list @@ -145,11 +147,11 @@ def mount_device(node_id, sim): "netconf-node-topology:username": NODES_LOGIN, "netconf-node-topology:password": NODES_PWD, "netconf-node-topology:host": "127.0.0.1", - "netconf-node-topology:port": sims[sim]['port'], + "netconf-node-topology:port": SIMS[sim]['port'], "netconf-node-topology:tcp-only": "false", "netconf-node-topology:pass-through": {}}]} response = put_request(url, headers, ODL_LOGIN, ODL_PWD) - if wait_until_log_contains(tpce_log, re.escape("Triggering notification stream NETCONF for node "+node_id), 60): + if wait_until_log_contains(TPCE_LOG, re.escape("Triggering notification stream NETCONF for node "+node_id), 60): print("Node "+node_id+" correctly added to tpce topology", end='... ', flush=True) else: print("Node "+node_id+" still not added to tpce topology", end='... ', flush=True) @@ -163,7 +165,7 @@ def unmount_device(node_id): url = ("{}/config/network-topology:network-topology/topology/topology-netconf/node/" + node_id).format(RESTCONF_BASE_URL) response = delete_request(url, ODL_LOGIN, ODL_PWD) - if wait_until_log_contains(tpce_log, re.escape("onDeviceDisConnected: "+node_id), 60): + if wait_until_log_contains(TPCE_LOG, re.escape("onDeviceDisConnected: "+node_id), 60): print("Node "+node_id+" correctly deleted from tpce topology", end='... ', flush=True) else: print("Node "+node_id+" still not deleted from tpce topology", end='... ', flush=True) @@ -196,10 +198,10 @@ def shutdown_process(process): def start_honeynode(log_file: str, node_port: str, node_config_file_name: str): - if os.path.isfile(honeynode_executable): + if os.path.isfile(HONEYNODE_EXECUTABLE): with open(log_file, 'w') as outfile: return subprocess.Popen( - [honeynode_executable, node_port, os.path.join(samples_directory, node_config_file_name)], + [HONEYNODE_EXECUTABLE, node_port, os.path.join(SAMPLES_DIRECTORY, node_config_file_name)], stdout=outfile, stderr=outfile) @@ -207,7 +209,7 @@ def wait_until_log_contains(log_file, regexp, time_to_wait=20): found = False tail = None try: - with timeout(seconds=time_to_wait): + with TimeOut(seconds=time_to_wait): print("Searching for pattern '"+regexp+"' in "+os.path.basename(log_file), end='... ', flush=True) tail = subprocess.Popen(['tail', '-F', log_file], stdout=subprocess.PIPE, stderr=subprocess.PIPE) compiled_regexp = re.compile(regexp) @@ -230,7 +232,7 @@ def wait_until_log_contains(log_file, regexp, time_to_wait=20): # TODO try to find an alternative to subprocess+tail -f (such as https://pypi.org/project/tailhead/) -class timeout: +class TimeOut: def __init__(self, seconds=1, error_message='Timeout'): self.seconds = seconds self.error_message = error_message -- 2.36.6