X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=tests%2Ftransportpce_tests%2F1.2.1%2Ftest_portmapping.py;h=68b74d413aeb4702aaee8558ba397702a4c00249;hb=c8bd98e0844257ae2e40e01d54546a40596df26d;hp=bf42eb9d509ee41eed8b4353538cf000b20d25eb;hpb=31bc01d3dab733bbb6ad48cc43586de43cb6c5c9;p=transportpce.git diff --git a/tests/transportpce_tests/1.2.1/test_portmapping.py b/tests/transportpce_tests/1.2.1/test_portmapping.py index bf42eb9d5..68b74d413 100644 --- a/tests/transportpce_tests/1.2.1/test_portmapping.py +++ b/tests/transportpce_tests/1.2.1/test_portmapping.py @@ -15,69 +15,41 @@ import unittest import time import requests import psutil -import test_utils +from common import test_utils class TransportPCEPortMappingTesting(unittest.TestCase): - sim_process1 = None - sim_process2 = None - odl_process = None - restconf_baseurl = "http://localhost:8181/restconf" - -# START_IGNORE_XTESTING + processes = None @classmethod def setUpClass(cls): - cls.sim_process1 = test_utils.start_sim('xpdra') - time.sleep(20) - - cls.sim_process2 = test_utils.start_sim('roadma') - time.sleep(20) - - cls.odl_process = test_utils.start_tpce() - time.sleep(60) - print("opendaylight started") + cls.processes = test_utils.start_tpce() + cls.processes = test_utils.start_sims(['xpdra', 'roadma']) @classmethod def tearDownClass(cls): - for child in psutil.Process(cls.odl_process.pid).children(): - child.send_signal(signal.SIGINT) - child.wait() - cls.odl_process.send_signal(signal.SIGINT) - cls.odl_process.wait() - for child in psutil.Process(cls.sim_process1.pid).children(): - child.send_signal(signal.SIGINT) - child.wait() - cls.sim_process1.send_signal(signal.SIGINT) - cls.sim_process1.wait() - for child in psutil.Process(cls.sim_process2.pid).children(): - child.send_signal(signal.SIGINT) - child.wait() - cls.sim_process2.send_signal(signal.SIGINT) - cls.sim_process2.wait() + for process in cls.processes: + test_utils.shutdown_process(process) + print("all processes killed") def setUp(self): print("execution of {}".format(self.id().split(".")[-1])) time.sleep(10) -# END_IGNORE_XTESTING - # def test_01_restconfAPI(self): # url = ("{}/operational/network-topology:network-topology/topology/" -# "topology-netconf/node/controller-config".format(self.restconf_baseurl)) -# headers = {'content-type': 'application/json'} -# response = requests.request("GET", url, headers=headers, auth=('admin', 'admin')) +# "topology-netconf/node/controller-config".format(test_utils.RESTCONF_BASE_URL)) +# response = requests.request("GET", url, headers=test_utils.TYPE_APPLICATION_JSON, auth=(test_utils.ODL_LOGIN, test_utils.ODL_PWD)) # self.assertEqual(response.status_code, requests.codes.ok) # res = response.json() # self.assertEqual(res['node'] [0] ['netconf-node-topology:connection-status'], # 'connected') # def test_02_restconfAPI(self): -# url = ("{}/config/transportpce-portmapping:network/nodes/controller-config".format(self.restconf_baseurl)) -# headers = {'content-type': 'application/json'} +# url = ("{}/config/transportpce-portmapping:network/nodes/controller-config".format(test_utils.RESTCONF_BASE_URL)) # response = requests.request( -# "GET", url, headers=headers, auth=('admin', 'admin')) +# "GET", url, headers=test_utils.TYPE_APPLICATION_JSON, auth=(test_utils.ODL_LOGIN, test_utils.ODL_PWD)) # self.assertEqual(response.status_code, requests.codes.not_found) # res = response.json() # self.assertIn( @@ -85,32 +57,16 @@ class TransportPCEPortMappingTesting(unittest.TestCase): # "error-message":"Request could not be completed because the relevant data model content does not exist "}, # res['errors']['error']) - def test_01_rdm_device_connected(self): - url = ("{}/config/network-topology:" - "network-topology/topology/topology-netconf/node/ROADMA01" - .format(self.restconf_baseurl)) - data = {"node": [{ - "node-id": "ROADMA01", - "netconf-node-topology:username": "admin", - "netconf-node-topology:password": "admin", - "netconf-node-topology:host": "127.0.0.1", - "netconf-node-topology:port": test_utils.sims['roadma']['port'], - "netconf-node-topology:tcp-only": "false", - "netconf-node-topology:pass-through": {}}]} - headers = {'content-type': 'application/json'} - response = requests.request( - "PUT", url, data=json.dumps(data), headers=headers, - auth=('admin', 'admin')) - self.assertEqual(response.status_code, requests.codes.created) - time.sleep(20) + def test_01_rdm_device_connection(self): + response = test_utils.mount_device("ROADMA01", 'roadma') + self.assertEqual(response.status_code, requests.codes.created, test_utils.CODE_SHOULD_BE_201) def test_02_rdm_device_connected(self): url = ("{}/operational/network-topology:" "network-topology/topology/topology-netconf/node/ROADMA01" - .format(self.restconf_baseurl)) - headers = {'content-type': 'application/json'} + .format(test_utils.RESTCONF_BASE_URL)) response = requests.request( - "GET", url, headers=headers, auth=('admin', 'admin')) + "GET", url, headers=test_utils.TYPE_APPLICATION_JSON, auth=(test_utils.ODL_LOGIN, test_utils.ODL_PWD)) self.assertEqual(response.status_code, requests.codes.ok) res = response.json() self.assertEqual( @@ -121,10 +77,9 @@ class TransportPCEPortMappingTesting(unittest.TestCase): def test_03_rdm_portmapping_info(self): url = ("{}/config/transportpce-portmapping:network/" "nodes/ROADMA01/node-info" - .format(self.restconf_baseurl)) - headers = {'content-type': 'application/json'} + .format(test_utils.RESTCONF_BASE_URL)) response = requests.request( - "GET", url, headers=headers, auth=('admin', 'admin')) + "GET", url, headers=test_utils.TYPE_APPLICATION_JSON, auth=(test_utils.ODL_LOGIN, test_utils.ODL_PWD)) self.assertEqual(response.status_code, requests.codes.ok) res = response.json() self.assertEqual( @@ -139,10 +94,9 @@ class TransportPCEPortMappingTesting(unittest.TestCase): def test_04_rdm_portmapping_DEG1_TTP_TXRX(self): url = ("{}/config/transportpce-portmapping:network/" "nodes/ROADMA01/mapping/DEG1-TTP-TXRX" - .format(self.restconf_baseurl)) - headers = {'content-type': 'application/json'} + .format(test_utils.RESTCONF_BASE_URL)) response = requests.request( - "GET", url, headers=headers, auth=('admin', 'admin')) + "GET", url, headers=test_utils.TYPE_APPLICATION_JSON, auth=(test_utils.ODL_LOGIN, test_utils.ODL_PWD)) self.assertEqual(response.status_code, requests.codes.ok) res = response.json() self.assertIn( @@ -153,10 +107,9 @@ class TransportPCEPortMappingTesting(unittest.TestCase): def test_05_rdm_portmapping_SRG1_PP7_TXRX(self): url = ("{}/config/transportpce-portmapping:network/" "nodes/ROADMA01/mapping/SRG1-PP7-TXRX" - .format(self.restconf_baseurl)) - headers = {'content-type': 'application/json'} + .format(test_utils.RESTCONF_BASE_URL)) response = requests.request( - "GET", url, headers=headers, auth=('admin', 'admin')) + "GET", url, headers=test_utils.TYPE_APPLICATION_JSON, auth=(test_utils.ODL_LOGIN, test_utils.ODL_PWD)) self.assertEqual(response.status_code, requests.codes.ok) res = response.json() self.assertIn( @@ -167,10 +120,9 @@ class TransportPCEPortMappingTesting(unittest.TestCase): def test_06_rdm_portmapping_SRG3_PP1_TXRX(self): url = ("{}/config/transportpce-portmapping:network/" "nodes/ROADMA01/mapping/SRG3-PP1-TXRX" - .format(self.restconf_baseurl)) - headers = {'content-type': 'application/json'} + .format(test_utils.RESTCONF_BASE_URL)) response = requests.request( - "GET", url, headers=headers, auth=('admin', 'admin')) + "GET", url, headers=test_utils.TYPE_APPLICATION_JSON, auth=(test_utils.ODL_LOGIN, test_utils.ODL_PWD)) self.assertEqual(response.status_code, requests.codes.ok) res = response.json() self.assertIn( @@ -178,32 +130,16 @@ class TransportPCEPortMappingTesting(unittest.TestCase): 'logical-connection-point': 'SRG3-PP1-TXRX', 'port-direction': 'bidirectional'}, res['mapping']) - def test_07_xpdr_device_connected(self): - url = ("{}/config/network-topology:" - "network-topology/topology/topology-netconf/node/XPDRA01" - .format(self.restconf_baseurl)) - data = {"node": [{ - "node-id": "XPDRA01", - "netconf-node-topology:username": "admin", - "netconf-node-topology:password": "admin", - "netconf-node-topology:host": "127.0.0.1", - "netconf-node-topology:port": test_utils.sims['xpdra']['port'], - "netconf-node-topology:tcp-only": "false", - "netconf-node-topology:pass-through": {}}]} - headers = {'content-type': 'application/json'} - response = requests.request( - "PUT", url, data=json.dumps(data), headers=headers, - auth=('admin', 'admin')) - self.assertEqual(response.status_code, requests.codes.created) - time.sleep(20) + def test_07_xpdr_device_connection(self): + response = test_utils.mount_device("XPDRA01", 'xpdra') + self.assertEqual(response.status_code, requests.codes.created, test_utils.CODE_SHOULD_BE_201) def test_08_xpdr_device_connected(self): url = ("{}/operational/network-topology:" "network-topology/topology/topology-netconf/node/XPDRA01" - .format(self.restconf_baseurl)) - headers = {'content-type': 'application/json'} + .format(test_utils.RESTCONF_BASE_URL)) response = requests.request( - "GET", url, headers=headers, auth=('admin', 'admin')) + "GET", url, headers=test_utils.TYPE_APPLICATION_JSON, auth=(test_utils.ODL_LOGIN, test_utils.ODL_PWD)) self.assertEqual(response.status_code, requests.codes.ok) res = response.json() self.assertEqual( @@ -214,10 +150,9 @@ class TransportPCEPortMappingTesting(unittest.TestCase): def test_09_xpdr_portmapping_info(self): url = ("{}/config/transportpce-portmapping:network/" "nodes/XPDRA01/node-info" - .format(self.restconf_baseurl)) - headers = {'content-type': 'application/json'} + .format(test_utils.RESTCONF_BASE_URL)) response = requests.request( - "GET", url, headers=headers, auth=('admin', 'admin')) + "GET", url, headers=test_utils.TYPE_APPLICATION_JSON, auth=(test_utils.ODL_LOGIN, test_utils.ODL_PWD)) self.assertEqual(response.status_code, requests.codes.ok) res = response.json() self.assertEqual( @@ -232,10 +167,9 @@ class TransportPCEPortMappingTesting(unittest.TestCase): def test_10_xpdr_portmapping_NETWORK1(self): url = ("{}/config/transportpce-portmapping:network/" "nodes/XPDRA01/mapping/XPDR1-NETWORK1" - .format(self.restconf_baseurl)) - headers = {'content-type': 'application/json'} + .format(test_utils.RESTCONF_BASE_URL)) response = requests.request( - "GET", url, headers=headers, auth=('admin', 'admin')) + "GET", url, headers=test_utils.TYPE_APPLICATION_JSON, auth=(test_utils.ODL_LOGIN, test_utils.ODL_PWD)) self.assertEqual(response.status_code, requests.codes.ok) res = response.json() self.assertIn( @@ -248,10 +182,9 @@ class TransportPCEPortMappingTesting(unittest.TestCase): def test_11_xpdr_portmapping_NETWORK2(self): url = ("{}/config/transportpce-portmapping:network/" "nodes/XPDRA01/mapping/XPDR1-NETWORK2" - .format(self.restconf_baseurl)) - headers = {'content-type': 'application/json'} + .format(test_utils.RESTCONF_BASE_URL)) response = requests.request( - "GET", url, headers=headers, auth=('admin', 'admin')) + "GET", url, headers=test_utils.TYPE_APPLICATION_JSON, auth=(test_utils.ODL_LOGIN, test_utils.ODL_PWD)) self.assertEqual(response.status_code, requests.codes.ok) res = response.json() self.assertIn( @@ -264,10 +197,9 @@ class TransportPCEPortMappingTesting(unittest.TestCase): def test_12_xpdr_portmapping_CLIENT1(self): url = ("{}/config/transportpce-portmapping:network/" "nodes/XPDRA01/mapping/XPDR1-CLIENT1" - .format(self.restconf_baseurl)) - headers = {'content-type': 'application/json'} + .format(test_utils.RESTCONF_BASE_URL)) response = requests.request( - "GET", url, headers=headers, auth=('admin', 'admin')) + "GET", url, headers=test_utils.TYPE_APPLICATION_JSON, auth=(test_utils.ODL_LOGIN, test_utils.ODL_PWD)) self.assertEqual(response.status_code, requests.codes.ok) res = response.json() self.assertIn( @@ -281,10 +213,9 @@ class TransportPCEPortMappingTesting(unittest.TestCase): def test_13_xpdr_portmapping_CLIENT2(self): url = ("{}/config/transportpce-portmapping:network/" "nodes/XPDRA01/mapping/XPDR1-CLIENT2" - .format(self.restconf_baseurl)) - headers = {'content-type': 'application/json'} + .format(test_utils.RESTCONF_BASE_URL)) response = requests.request( - "GET", url, headers=headers, auth=('admin', 'admin')) + "GET", url, headers=test_utils.TYPE_APPLICATION_JSON, auth=(test_utils.ODL_LOGIN, test_utils.ODL_PWD)) self.assertEqual(response.status_code, requests.codes.ok) res = response.json() self.assertIn( @@ -298,10 +229,9 @@ class TransportPCEPortMappingTesting(unittest.TestCase): def test_14_xpdr_portmapping_CLIENT3(self): url = ("{}/config/transportpce-portmapping:network/" "nodes/XPDRA01/mapping/XPDR1-CLIENT3" - .format(self.restconf_baseurl)) - headers = {'content-type': 'application/json'} + .format(test_utils.RESTCONF_BASE_URL)) response = requests.request( - "GET", url, headers=headers, auth=('admin', 'admin')) + "GET", url, headers=test_utils.TYPE_APPLICATION_JSON, auth=(test_utils.ODL_LOGIN, test_utils.ODL_PWD)) self.assertEqual(response.status_code, requests.codes.ok) res = response.json() self.assertIn( @@ -315,10 +245,9 @@ class TransportPCEPortMappingTesting(unittest.TestCase): def test_15_xpdr_portmapping_CLIENT4(self): url = ("{}/config/transportpce-portmapping:network/" "nodes/XPDRA01/mapping/XPDR1-CLIENT4" - .format(self.restconf_baseurl)) - headers = {'content-type': 'application/json'} + .format(test_utils.RESTCONF_BASE_URL)) response = requests.request( - "GET", url, headers=headers, auth=('admin', 'admin')) + "GET", url, headers=test_utils.TYPE_APPLICATION_JSON, auth=(test_utils.ODL_LOGIN, test_utils.ODL_PWD)) self.assertEqual(response.status_code, requests.codes.ok) res = response.json() self.assertIn( @@ -328,23 +257,15 @@ class TransportPCEPortMappingTesting(unittest.TestCase): 'port-qual': 'xpdr-client', 'lcp-hash-val': '64b8effe7ba72211420bf267d0ca1ae0'}, res['mapping']) - def test_16_xpdr_device_disconnected(self): - url = ("{}/config/network-topology:" - "network-topology/topology/topology-netconf/node/XPDRA01" - .format(self.restconf_baseurl)) - headers = {'content-type': 'application/json'} - response = requests.request( - "DELETE", url, headers=headers, - auth=('admin', 'admin')) - self.assertEqual(response.status_code, requests.codes.ok) - time.sleep(20) + def test_16_xpdr_device_disconnection(self): + response = test_utils.unmount_device("XPDRA01") + self.assertEqual(response.status_code, requests.codes.ok, test_utils.CODE_SHOULD_BE_200) def test_17_xpdr_device_disconnected(self): url = ("{}/operational/network-topology:network-topology/topology/" - "topology-netconf/node/XPDRA01".format(self.restconf_baseurl)) - headers = {'content-type': 'application/json'} + "topology-netconf/node/XPDRA01".format(test_utils.RESTCONF_BASE_URL)) response = requests.request( - "GET", url, headers=headers, auth=('admin', 'admin')) + "GET", url, headers=test_utils.TYPE_APPLICATION_JSON, auth=(test_utils.ODL_LOGIN, test_utils.ODL_PWD)) self.assertEqual(response.status_code, requests.codes.not_found) res = response.json() self.assertIn( @@ -352,11 +273,10 @@ class TransportPCEPortMappingTesting(unittest.TestCase): "error-message": "Request could not be completed because the relevant data model content does not exist"}, res['errors']['error']) - def test_18_xpdr_device_disconnected(self): - url = ("{}/config/transportpce-portmapping:network/nodes/XPDRA01".format(self.restconf_baseurl)) - headers = {'content-type': 'application/json'} + def test_18_xpdr_device_not_connected(self): + url = ("{}/config/transportpce-portmapping:network/nodes/XPDRA01".format(test_utils.RESTCONF_BASE_URL)) response = requests.request( - "GET", url, headers=headers, auth=('admin', 'admin')) + "GET", url, headers=test_utils.TYPE_APPLICATION_JSON, auth=(test_utils.ODL_LOGIN, test_utils.ODL_PWD)) self.assertEqual(response.status_code, requests.codes.not_found) res = response.json() self.assertIn( @@ -364,22 +284,15 @@ class TransportPCEPortMappingTesting(unittest.TestCase): "error-message": "Request could not be completed because the relevant data model content does not exist"}, res['errors']['error']) - def test_19_rdm_device_disconnected(self): - url = ("{}/config/network-topology:network-topology/topology/topology-netconf/node/ROADMA01" - .format(self.restconf_baseurl)) - headers = {'content-type': 'application/json'} - response = requests.request( - "DELETE", url, headers=headers, - auth=('admin', 'admin')) - self.assertEqual(response.status_code, requests.codes.ok) - time.sleep(20) + def test_19_rdm_device_disconnection(self): + response = test_utils.unmount_device("ROADMA01") + self.assertEqual(response.status_code, requests.codes.ok, test_utils.CODE_SHOULD_BE_200) def test_20_rdm_device_disconnected(self): url = ("{}/operational/network-topology:network-topology/topology/topology-netconf/node/ROADMA01" - .format(self.restconf_baseurl)) - headers = {'content-type': 'application/json'} + .format(test_utils.RESTCONF_BASE_URL)) response = requests.request( - "GET", url, headers=headers, auth=('admin', 'admin')) + "GET", url, headers=test_utils.TYPE_APPLICATION_JSON, auth=(test_utils.ODL_LOGIN, test_utils.ODL_PWD)) self.assertEqual(response.status_code, requests.codes.not_found) res = response.json() self.assertIn( @@ -387,11 +300,10 @@ class TransportPCEPortMappingTesting(unittest.TestCase): "error-message": "Request could not be completed because the relevant data model content does not exist"}, res['errors']['error']) - def test_21_rdm_device_disconnected(self): - url = ("{}/config/transportpce-portmapping:network/nodes/ROADMA01".format(self.restconf_baseurl)) - headers = {'content-type': 'application/json'} + def test_21_rdm_device_not_connected(self): + url = ("{}/config/transportpce-portmapping:network/nodes/ROADMA01".format(test_utils.RESTCONF_BASE_URL)) response = requests.request( - "GET", url, headers=headers, auth=('admin', 'admin')) + "GET", url, headers=test_utils.TYPE_APPLICATION_JSON, auth=(test_utils.ODL_LOGIN, test_utils.ODL_PWD)) self.assertEqual(response.status_code, requests.codes.not_found) res = response.json() self.assertIn(