From: Gilles Thouenon Date: Wed, 31 Aug 2022 09:41:35 +0000 (+0200) Subject: Fix new pylint issues in functional tests X-Git-Tag: 6.0.0~35 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=transportpce.git;a=commitdiff_plain;h=refs%2Fchanges%2F56%2F102256%2F1 Fix new pylint issues in functional tests - add timeout in requests.request methods - remove useless disable pylint warning Signed-off-by: Gilles Thouenon Change-Id: I2acd0f10b458fe8f7ee1be65644880fd0b41d943 --- diff --git a/tests/transportpce_tests/1.2.1/test02_topo_portmapping.py b/tests/transportpce_tests/1.2.1/test02_topo_portmapping.py index 1f902c3e7..03a02307a 100644 --- a/tests/transportpce_tests/1.2.1/test02_topo_portmapping.py +++ b/tests/transportpce_tests/1.2.1/test02_topo_portmapping.py @@ -12,7 +12,6 @@ # pylint: disable=no-member # pylint: disable=too-many-public-methods # a pylint false positive due to unittest -# pylint: disable=no-self-use import time import unittest diff --git a/tests/transportpce_tests/common/test_utils.py b/tests/transportpce_tests/common/test_utils.py index 65ca5e212..4b2b7f1d0 100644 --- a/tests/transportpce_tests/common/test_utils.py +++ b/tests/transportpce_tests/common/test_utils.py @@ -69,6 +69,8 @@ URL_TAPI_GET_NOTIFICATION_LIST = "{}/operations/tapi-notification:get-notificati TYPE_APPLICATION_JSON = {'Content-Type': 'application/json', 'Accept': 'application/json'} TYPE_APPLICATION_XML = {'Content-Type': 'application/xml', 'Accept': 'application/xml'} +REQUEST_TIMEOUT = 10 + CODE_SHOULD_BE_200 = 'Http status code should be 200' CODE_SHOULD_BE_201 = 'Http status code should be 201' @@ -170,7 +172,8 @@ def get_request(url): return requests.request( "GET", url.format(RESTCONF_BASE_URL), headers=TYPE_APPLICATION_JSON, - auth=(ODL_LOGIN, ODL_PWD)) + auth=(ODL_LOGIN, ODL_PWD), + timeout=REQUEST_TIMEOUT) def post_request(url, data): @@ -180,12 +183,14 @@ def post_request(url, data): "POST", url.format(RESTCONF_BASE_URL), data=json.dumps(data), headers=TYPE_APPLICATION_JSON, - auth=(ODL_LOGIN, ODL_PWD)) + auth=(ODL_LOGIN, ODL_PWD), + timeout=REQUEST_TIMEOUT) return requests.request( "POST", url.format(RESTCONF_BASE_URL), headers=TYPE_APPLICATION_JSON, - auth=(ODL_LOGIN, ODL_PWD)) + auth=(ODL_LOGIN, ODL_PWD), + timeout=REQUEST_TIMEOUT) def post_xmlrequest(url, data): @@ -194,7 +199,8 @@ def post_xmlrequest(url, data): "POST", url.format(RESTCONF_BASE_URL), data=data, headers=TYPE_APPLICATION_XML, - auth=(ODL_LOGIN, ODL_PWD)) + auth=(ODL_LOGIN, ODL_PWD), + timeout=REQUEST_TIMEOUT) return None @@ -203,7 +209,8 @@ def put_request(url, data): "PUT", url.format(RESTCONF_BASE_URL), data=json.dumps(data), headers=TYPE_APPLICATION_JSON, - auth=(ODL_LOGIN, ODL_PWD)) + auth=(ODL_LOGIN, ODL_PWD), + timeout=REQUEST_TIMEOUT) def put_xmlrequest(url, data): @@ -211,7 +218,8 @@ def put_xmlrequest(url, data): "PUT", url.format(RESTCONF_BASE_URL), data=data, headers=TYPE_APPLICATION_XML, - auth=(ODL_LOGIN, ODL_PWD)) + auth=(ODL_LOGIN, ODL_PWD), + timeout=REQUEST_TIMEOUT) def put_jsonrequest(url, data): @@ -219,7 +227,8 @@ def put_jsonrequest(url, data): "PUT", url.format(RESTCONF_BASE_URL), data=data, headers=TYPE_APPLICATION_JSON, - auth=(ODL_LOGIN, ODL_PWD)) + auth=(ODL_LOGIN, ODL_PWD), + timeout=REQUEST_TIMEOUT) def rawput_request(url, data): @@ -227,7 +236,8 @@ def rawput_request(url, data): "PUT", url.format(RESTCONF_BASE_URL), data=data, headers=TYPE_APPLICATION_JSON, - auth=(ODL_LOGIN, ODL_PWD)) + auth=(ODL_LOGIN, ODL_PWD), + timeout=REQUEST_TIMEOUT) def rawpost_request(url, data): @@ -235,14 +245,16 @@ def rawpost_request(url, data): "POST", url.format(RESTCONF_BASE_URL), data=data, headers=TYPE_APPLICATION_JSON, - auth=(ODL_LOGIN, ODL_PWD)) + auth=(ODL_LOGIN, ODL_PWD), + timeout=REQUEST_TIMEOUT) def delete_request(url): return requests.request( "DELETE", url.format(RESTCONF_BASE_URL), headers=TYPE_APPLICATION_JSON, - auth=(ODL_LOGIN, ODL_PWD)) + auth=(ODL_LOGIN, ODL_PWD), + timeout=REQUEST_TIMEOUT) def mount_device(node_id, sim): diff --git a/tests/transportpce_tests/common/test_utils_rfc8040.py b/tests/transportpce_tests/common/test_utils_rfc8040.py index 9f0c33710..bcbe35ef4 100644 --- a/tests/transportpce_tests/common/test_utils_rfc8040.py +++ b/tests/transportpce_tests/common/test_utils_rfc8040.py @@ -40,6 +40,8 @@ NODES_PWD = 'admin' TYPE_APPLICATION_JSON = {'Content-Type': 'application/json', 'Accept': 'application/json'} TYPE_APPLICATION_XML = {'Content-Type': 'application/xml', 'Accept': 'application/xml'} +REQUEST_TIMEOUT = 10 + CODE_SHOULD_BE_200 = 'Http status code should be 200' CODE_SHOULD_BE_201 = 'Http status code should be 201' @@ -87,7 +89,8 @@ def get_request(url): return requests.request( 'GET', url.format(RESTCONF_BASE_URL), headers=TYPE_APPLICATION_JSON, - auth=(ODL_LOGIN, ODL_PWD)) + auth=(ODL_LOGIN, ODL_PWD), + timeout=REQUEST_TIMEOUT) def put_request(url, data): @@ -95,14 +98,16 @@ def put_request(url, data): 'PUT', url.format(RESTCONF_BASE_URL), data=json.dumps(data), headers=TYPE_APPLICATION_JSON, - auth=(ODL_LOGIN, ODL_PWD)) + auth=(ODL_LOGIN, ODL_PWD), + timeout=REQUEST_TIMEOUT) def delete_request(url): return requests.request( 'DELETE', url.format(RESTCONF_BASE_URL), headers=TYPE_APPLICATION_JSON, - auth=(ODL_LOGIN, ODL_PWD)) + auth=(ODL_LOGIN, ODL_PWD), + timeout=REQUEST_TIMEOUT) def post_request(url, data): @@ -111,11 +116,13 @@ def post_request(url, data): "POST", url.format(RESTCONF_BASE_URL), data=json.dumps(data), headers=TYPE_APPLICATION_JSON, - auth=(ODL_LOGIN, ODL_PWD)) + auth=(ODL_LOGIN, ODL_PWD), + timeout=REQUEST_TIMEOUT) return requests.request( "POST", url.format(RESTCONF_BASE_URL), headers=TYPE_APPLICATION_JSON, - auth=(ODL_LOGIN, ODL_PWD)) + auth=(ODL_LOGIN, ODL_PWD), + timeout=REQUEST_TIMEOUT) # # Process management diff --git a/tests/transportpce_tests/hybrid/test01_device_change_notifications.py b/tests/transportpce_tests/hybrid/test01_device_change_notifications.py index 238e8081e..489ca60fb 100644 --- a/tests/transportpce_tests/hybrid/test01_device_change_notifications.py +++ b/tests/transportpce_tests/hybrid/test01_device_change_notifications.py @@ -208,7 +208,8 @@ class TransportPCEFulltesting(unittest.TestCase): "port-qual": "xpdr-network"}]} response = requests.request("PUT", url.format("http://127.0.0.1:8130/restconf"), data=json.dumps(body), headers=test_utils_rfc8040.TYPE_APPLICATION_JSON, - auth=(test_utils_rfc8040.ODL_LOGIN, test_utils_rfc8040.ODL_PWD)) + auth=(test_utils_rfc8040.ODL_LOGIN, test_utils_rfc8040.ODL_PWD), + timeout=test_utils_rfc8040.REQUEST_TIMEOUT) self.assertEqual(response.status_code, requests.codes.ok) time.sleep(2) @@ -281,7 +282,8 @@ class TransportPCEFulltesting(unittest.TestCase): "port-qual": "xpdr-network"}]} response = requests.request("PUT", url.format("http://127.0.0.1:8130/restconf"), data=json.dumps(body), headers=test_utils_rfc8040.TYPE_APPLICATION_JSON, - auth=(test_utils_rfc8040.ODL_LOGIN, test_utils_rfc8040.ODL_PWD)) + auth=(test_utils_rfc8040.ODL_LOGIN, test_utils_rfc8040.ODL_PWD), + timeout=test_utils_rfc8040.REQUEST_TIMEOUT) self.assertEqual(response.status_code, requests.codes.ok) time.sleep(2) @@ -328,7 +330,8 @@ class TransportPCEFulltesting(unittest.TestCase): "port-qual": "roadm-external"}]} response = requests.request("PUT", url.format("http://127.0.0.1:8141/restconf"), data=json.dumps(body), headers=test_utils_rfc8040.TYPE_APPLICATION_JSON, - auth=(test_utils_rfc8040.ODL_LOGIN, test_utils_rfc8040.ODL_PWD)) + auth=(test_utils_rfc8040.ODL_LOGIN, test_utils_rfc8040.ODL_PWD), + timeout=test_utils_rfc8040.REQUEST_TIMEOUT) self.assertEqual(response.status_code, requests.codes.ok) time.sleep(2) @@ -394,7 +397,8 @@ class TransportPCEFulltesting(unittest.TestCase): "port-qual": "roadm-external"}]} response = requests.request("PUT", url.format("http://127.0.0.1:8141/restconf"), data=json.dumps(body), headers=test_utils_rfc8040.TYPE_APPLICATION_JSON, - auth=(test_utils_rfc8040.ODL_LOGIN, test_utils_rfc8040.ODL_PWD)) + auth=(test_utils_rfc8040.ODL_LOGIN, test_utils_rfc8040.ODL_PWD), + timeout=test_utils_rfc8040.REQUEST_TIMEOUT) self.assertEqual(response.status_code, requests.codes.ok) time.sleep(2) @@ -418,7 +422,8 @@ class TransportPCEFulltesting(unittest.TestCase): "port-qual": "roadm-external"}]} response = requests.request("PUT", url.format("http://127.0.0.1:8141/restconf"), data=json.dumps(body), headers=test_utils_rfc8040.TYPE_APPLICATION_JSON, - auth=(test_utils_rfc8040.ODL_LOGIN, test_utils_rfc8040.ODL_PWD)) + auth=(test_utils_rfc8040.ODL_LOGIN, test_utils_rfc8040.ODL_PWD), + timeout=test_utils_rfc8040.REQUEST_TIMEOUT) self.assertEqual(response.status_code, requests.codes.ok) time.sleep(2) @@ -484,7 +489,8 @@ class TransportPCEFulltesting(unittest.TestCase): "port-qual": "roadm-external"}]} response = requests.request("PUT", url.format("http://127.0.0.1:8141/restconf"), data=json.dumps(body), headers=test_utils_rfc8040.TYPE_APPLICATION_JSON, - auth=(test_utils_rfc8040.ODL_LOGIN, test_utils_rfc8040.ODL_PWD)) + auth=(test_utils_rfc8040.ODL_LOGIN, test_utils_rfc8040.ODL_PWD), + timeout=test_utils_rfc8040.REQUEST_TIMEOUT) self.assertEqual(response.status_code, requests.codes.ok) time.sleep(2) @@ -506,7 +512,8 @@ class TransportPCEFulltesting(unittest.TestCase): "port-qual": "xpdr-network"}]} response = requests.request("PUT", url.format("http://127.0.0.1:8154/restconf"), data=json.dumps(body), headers=test_utils_rfc8040.TYPE_APPLICATION_JSON, - auth=(test_utils_rfc8040.ODL_LOGIN, test_utils_rfc8040.ODL_PWD)) + auth=(test_utils_rfc8040.ODL_LOGIN, test_utils_rfc8040.ODL_PWD), + timeout=test_utils_rfc8040.REQUEST_TIMEOUT) self.assertEqual(response.status_code, requests.codes.ok) time.sleep(2) @@ -570,7 +577,8 @@ class TransportPCEFulltesting(unittest.TestCase): "port-qual": "xpdr-network"}]} response = requests.request("PUT", url.format("http://127.0.0.1:8154/restconf"), data=json.dumps(body), headers=test_utils_rfc8040.TYPE_APPLICATION_JSON, - auth=(test_utils_rfc8040.ODL_LOGIN, test_utils_rfc8040.ODL_PWD)) + auth=(test_utils_rfc8040.ODL_LOGIN, test_utils_rfc8040.ODL_PWD), + timeout=test_utils_rfc8040.REQUEST_TIMEOUT) self.assertEqual(response.status_code, requests.codes.ok) time.sleep(2) @@ -594,7 +602,8 @@ class TransportPCEFulltesting(unittest.TestCase): "port-qual": "roadm-external"}]} response = requests.request("PUT", url.format("http://127.0.0.1:8141/restconf"), data=json.dumps(body), headers=test_utils_rfc8040.TYPE_APPLICATION_JSON, - auth=(test_utils_rfc8040.ODL_LOGIN, test_utils_rfc8040.ODL_PWD)) + auth=(test_utils_rfc8040.ODL_LOGIN, test_utils_rfc8040.ODL_PWD), + timeout=test_utils_rfc8040.REQUEST_TIMEOUT) self.assertEqual(response.status_code, requests.codes.ok) time.sleep(2) diff --git a/tests/transportpce_tests/hybrid/test03_autonomous_reroute.py b/tests/transportpce_tests/hybrid/test03_autonomous_reroute.py index 36997c808..a456d8a1d 100644 --- a/tests/transportpce_tests/hybrid/test03_autonomous_reroute.py +++ b/tests/transportpce_tests/hybrid/test03_autonomous_reroute.py @@ -1064,7 +1064,8 @@ class TransportPCEtesting(unittest.TestCase): } response = requests.request("POST", url.format("http://127.0.0.1:8141/restconf"), data=json.dumps(body), headers=test_utils_rfc8040.TYPE_APPLICATION_JSON, - auth=(test_utils_rfc8040.ODL_LOGIN, test_utils_rfc8040.ODL_PWD)) + auth=(test_utils_rfc8040.ODL_LOGIN, test_utils_rfc8040.ODL_PWD), + timeout=test_utils_rfc8040.REQUEST_TIMEOUT) self.assertEqual(response.status_code, requests.codes.ok) self.assertEqual(response.json()['output']['status-message'], "The PMs has been successfully set !") time.sleep(self.WAITING * 2) @@ -1141,7 +1142,8 @@ class TransportPCEtesting(unittest.TestCase): } response = requests.request("POST", url.format("http://127.0.0.1:8141/restconf"), data=json.dumps(body), headers=test_utils_rfc8040.TYPE_APPLICATION_JSON, - auth=(test_utils_rfc8040.ODL_LOGIN, test_utils_rfc8040.ODL_PWD)) + auth=(test_utils_rfc8040.ODL_LOGIN, test_utils_rfc8040.ODL_PWD), + timeout=test_utils_rfc8040.REQUEST_TIMEOUT) self.assertEqual(response.status_code, requests.codes.ok) self.assertEqual(response.json()['output']['status-message'], "The PMs has been successfully released !") time.sleep(2) diff --git a/tests/transportpce_tests/tapi/test03_tapi_device_change_notifications.py b/tests/transportpce_tests/tapi/test03_tapi_device_change_notifications.py index 8c029aa1c..3e105a2f9 100644 --- a/tests/transportpce_tests/tapi/test03_tapi_device_change_notifications.py +++ b/tests/transportpce_tests/tapi/test03_tapi_device_change_notifications.py @@ -282,7 +282,8 @@ class TransportPCEFulltesting(unittest.TestCase): "port-qual": "xpdr-network"}]} response = requests.request("PUT", url.format("http://127.0.0.1:8144/restconf"), data=json.dumps(body), headers=test_utils.TYPE_APPLICATION_JSON, - auth=(test_utils.ODL_LOGIN, test_utils.ODL_PWD)) + auth=(test_utils.ODL_LOGIN, test_utils.ODL_PWD), + timeout=test_utils.REQUEST_TIMEOUT) self.assertEqual(response.status_code, requests.codes.ok) time.sleep(2) @@ -424,7 +425,8 @@ class TransportPCEFulltesting(unittest.TestCase): "port-qual": "xpdr-network"}]} response = requests.request("PUT", url.format("http://127.0.0.1:8144/restconf"), data=json.dumps(body), headers=test_utils.TYPE_APPLICATION_JSON, - auth=(test_utils.ODL_LOGIN, test_utils.ODL_PWD)) + auth=(test_utils.ODL_LOGIN, test_utils.ODL_PWD), + timeout=test_utils.REQUEST_TIMEOUT) self.assertEqual(response.status_code, requests.codes.ok) time.sleep(2) @@ -512,7 +514,8 @@ class TransportPCEFulltesting(unittest.TestCase): "port-qual": "roadm-external"}]} response = requests.request("PUT", url.format("http://127.0.0.1:8141/restconf"), data=json.dumps(body), headers=test_utils.TYPE_APPLICATION_JSON, - auth=(test_utils.ODL_LOGIN, test_utils.ODL_PWD)) + auth=(test_utils.ODL_LOGIN, test_utils.ODL_PWD), + timeout=test_utils.REQUEST_TIMEOUT) self.assertEqual(response.status_code, requests.codes.ok) time.sleep(2) @@ -628,7 +631,8 @@ class TransportPCEFulltesting(unittest.TestCase): "port-qual": "roadm-external"}]} response = requests.request("PUT", url.format("http://127.0.0.1:8141/restconf"), data=json.dumps(body), headers=test_utils.TYPE_APPLICATION_JSON, - auth=(test_utils.ODL_LOGIN, test_utils.ODL_PWD)) + auth=(test_utils.ODL_LOGIN, test_utils.ODL_PWD), + timeout=test_utils.REQUEST_TIMEOUT) self.assertEqual(response.status_code, requests.codes.ok) time.sleep(2) @@ -680,7 +684,8 @@ class TransportPCEFulltesting(unittest.TestCase): "port-qual": "roadm-external"}]} response = requests.request("PUT", url.format("http://127.0.0.1:8141/restconf"), data=json.dumps(body), headers=test_utils.TYPE_APPLICATION_JSON, - auth=(test_utils.ODL_LOGIN, test_utils.ODL_PWD)) + auth=(test_utils.ODL_LOGIN, test_utils.ODL_PWD), + timeout=test_utils.REQUEST_TIMEOUT) self.assertEqual(response.status_code, requests.codes.ok) time.sleep(2) @@ -796,7 +801,8 @@ class TransportPCEFulltesting(unittest.TestCase): "port-qual": "roadm-external"}]} response = requests.request("PUT", url.format("http://127.0.0.1:8141/restconf"), data=json.dumps(body), headers=test_utils.TYPE_APPLICATION_JSON, - auth=(test_utils.ODL_LOGIN, test_utils.ODL_PWD)) + auth=(test_utils.ODL_LOGIN, test_utils.ODL_PWD), + timeout=test_utils.REQUEST_TIMEOUT) self.assertEqual(response.status_code, requests.codes.ok) time.sleep(2) @@ -829,7 +835,8 @@ class TransportPCEFulltesting(unittest.TestCase): "port-qual": "roadm-external"}]} response = requests.request("PUT", url.format("http://127.0.0.1:8141/restconf"), data=json.dumps(body), headers=test_utils.TYPE_APPLICATION_JSON, - auth=(test_utils.ODL_LOGIN, test_utils.ODL_PWD)) + auth=(test_utils.ODL_LOGIN, test_utils.ODL_PWD), + timeout=test_utils.REQUEST_TIMEOUT) self.assertEqual(response.status_code, requests.codes.ok) time.sleep(2) diff --git a/tests/transportpce_tests/with_docker/test02_nbinotifications.py b/tests/transportpce_tests/with_docker/test02_nbinotifications.py index c1436658f..5e5edfae1 100644 --- a/tests/transportpce_tests/with_docker/test02_nbinotifications.py +++ b/tests/transportpce_tests/with_docker/test02_nbinotifications.py @@ -286,7 +286,8 @@ class TransportNbiNotificationstesting(unittest.TestCase): "port-qual": "roadm-external"}]} response = requests.request("PUT", url.format("http://127.0.0.1:8141/restconf"), data=json.dumps(body), headers=test_utils.TYPE_APPLICATION_JSON, - auth=(test_utils.ODL_LOGIN, test_utils.ODL_PWD)) + auth=(test_utils.ODL_LOGIN, test_utils.ODL_PWD), + timeout=test_utils.REQUEST_TIMEOUT) self.assertEqual(response.status_code, requests.codes.ok) time.sleep(2) @@ -318,7 +319,8 @@ class TransportNbiNotificationstesting(unittest.TestCase): "port-qual": "roadm-external"}]} response = requests.request("PUT", url.format("http://127.0.0.1:8141/restconf"), data=json.dumps(body), headers=test_utils.TYPE_APPLICATION_JSON, - auth=(test_utils.ODL_LOGIN, test_utils.ODL_PWD)) + auth=(test_utils.ODL_LOGIN, test_utils.ODL_PWD), + timeout=test_utils.REQUEST_TIMEOUT) self.assertEqual(response.status_code, requests.codes.ok) time.sleep(2) diff --git a/tests/transportpce_tests/with_docker/test03_tapi_nbinotifications.py b/tests/transportpce_tests/with_docker/test03_tapi_nbinotifications.py index d66f5e240..ca59c8162 100644 --- a/tests/transportpce_tests/with_docker/test03_tapi_nbinotifications.py +++ b/tests/transportpce_tests/with_docker/test03_tapi_nbinotifications.py @@ -352,7 +352,8 @@ class TransportNbiNotificationstesting(unittest.TestCase): "port-qual": "roadm-external"}]} response = requests.request("PUT", url.format("http://127.0.0.1:8141/restconf"), data=json.dumps(body), headers=test_utils.TYPE_APPLICATION_JSON, - auth=(test_utils.ODL_LOGIN, test_utils.ODL_PWD)) + auth=(test_utils.ODL_LOGIN, test_utils.ODL_PWD), + timeout=test_utils.REQUEST_TIMEOUT) self.assertEqual(response.status_code, requests.codes.ok) # If the gate fails is because of the waiting time not being enough time.sleep(2) @@ -379,7 +380,8 @@ class TransportNbiNotificationstesting(unittest.TestCase): "port-qual": "roadm-external"}]} response = requests.request("PUT", url.format("http://127.0.0.1:8141/restconf"), data=json.dumps(body), headers=test_utils.TYPE_APPLICATION_JSON, - auth=(test_utils.ODL_LOGIN, test_utils.ODL_PWD)) + auth=(test_utils.ODL_LOGIN, test_utils.ODL_PWD), + timeout=test_utils.REQUEST_TIMEOUT) self.assertEqual(response.status_code, requests.codes.ok) # If the gate fails is because of the waiting time not being enough time.sleep(2)