X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=tests%2Ftransportpce_tests%2F2.2.1%2Ftest_portmapping.py;h=68d59d5434068f6a15db22ed31a0a072b536491e;hb=c8bd98e0844257ae2e40e01d54546a40596df26d;hp=f28beb45f43e4ba31f0b797e3dfb578a6928bb7a;hpb=38788ce8eedd77f7b1dc089df00d9e2a9bcfc1f8;p=transportpce.git diff --git a/tests/transportpce_tests/2.2.1/test_portmapping.py b/tests/transportpce_tests/2.2.1/test_portmapping.py index f28beb45f..68d59d543 100644 --- a/tests/transportpce_tests/2.2.1/test_portmapping.py +++ b/tests/transportpce_tests/2.2.1/test_portmapping.py @@ -18,70 +18,38 @@ import shutil import subprocess import time import unittest -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" + processes = None @classmethod def setUpClass(cls): - cls.odl_process = test_utils.start_tpce() - cls.sim_process1 = test_utils.start_sim('xpdra') - cls.sim_process2 = test_utils.start_sim('roadma') + 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) - def test_01_rdm_device_connected(self): - url = ("{}/config/network-topology:" - "network-topology/topology/topology-netconf/node/ROADM-A1" - .format(self.restconf_baseurl)) - data = {"node": [{ - "node-id": "ROADM-A1", - "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("ROADM-A1", '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/ROADM-A1" - .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( @@ -92,10 +60,9 @@ class TransportPCEPortMappingTesting(unittest.TestCase): def test_03_rdm_portmapping_info(self): url = ("{}/config/transportpce-portmapping:network/" "nodes/ROADM-A1/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( @@ -110,10 +77,9 @@ class TransportPCEPortMappingTesting(unittest.TestCase): def test_04_rdm_portmapping_DEG1_TTP_TXRX(self): url = ("{}/config/transportpce-portmapping:network/" "nodes/ROADM-A1/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( @@ -124,10 +90,9 @@ class TransportPCEPortMappingTesting(unittest.TestCase): def test_05_rdm_portmapping_DEG2_TTP_TXRX_with_ots_oms(self): url = ("{}/config/transportpce-portmapping:network/" "nodes/ROADM-A1/mapping/DEG2-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( @@ -140,10 +105,9 @@ class TransportPCEPortMappingTesting(unittest.TestCase): def test_06_rdm_portmapping_SRG1_PP3_TXRX(self): url = ("{}/config/transportpce-portmapping:network/" "nodes/ROADM-A1/mapping/SRG1-PP3-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( @@ -154,10 +118,9 @@ class TransportPCEPortMappingTesting(unittest.TestCase): def test_07_rdm_portmapping_SRG3_PP1_TXRX(self): url = ("{}/config/transportpce-portmapping:network/" "nodes/ROADM-A1/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( @@ -165,32 +128,16 @@ class TransportPCEPortMappingTesting(unittest.TestCase): 'logical-connection-point': 'SRG3-PP1-TXRX', 'port-direction': 'bidirectional'}, res['mapping']) - def test_08_xpdr_device_connected(self): - url = ("{}/config/network-topology:" - "network-topology/topology/topology-netconf/node/XPDR-A1" - .format(self.restconf_baseurl)) - data = {"node": [{ - "node-id": "XPDR-A1", - "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_08_xpdr_device_connection(self): + response = test_utils.mount_device("XPDR-A1", 'xpdra') + self.assertEqual(response.status_code, requests.codes.created, test_utils.CODE_SHOULD_BE_201) def test_09_xpdr_device_connected(self): url = ("{}/operational/network-topology:" "network-topology/topology/topology-netconf/node/XPDR-A1" - .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( @@ -201,10 +148,9 @@ class TransportPCEPortMappingTesting(unittest.TestCase): def test_10_xpdr_portmapping_info(self): url = ("{}/config/transportpce-portmapping:network/" "nodes/XPDR-A1/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( @@ -219,10 +165,9 @@ class TransportPCEPortMappingTesting(unittest.TestCase): def test_11_xpdr_portmapping_NETWORK1(self): url = ("{}/config/transportpce-portmapping:network/" "nodes/XPDR-A1/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( @@ -236,10 +181,9 @@ class TransportPCEPortMappingTesting(unittest.TestCase): def test_12_xpdr_portmapping_NETWORK2(self): url = ("{}/config/transportpce-portmapping:network/" "nodes/XPDR-A1/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( @@ -253,10 +197,9 @@ class TransportPCEPortMappingTesting(unittest.TestCase): def test_13_xpdr_portmapping_CLIENT1(self): url = ("{}/config/transportpce-portmapping:network/" "nodes/XPDR-A1/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( @@ -271,10 +214,9 @@ class TransportPCEPortMappingTesting(unittest.TestCase): def test_14_xpdr_portmapping_CLIENT2(self): url = ("{}/config/transportpce-portmapping:network/" "nodes/XPDR-A1/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( @@ -286,23 +228,15 @@ class TransportPCEPortMappingTesting(unittest.TestCase): 'lcp-hash-val': '3ed8ed1336784ac7c2f66c22f2f03db'}, res['mapping']) - def test_15_xpdr_device_disconnected(self): - url = ("{}/config/network-topology:" - "network-topology/topology/topology-netconf/node/XPDR-A1" - .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_15_xpdr_device_disconnection(self): + response = test_utils.unmount_device("XPDR-A1") + self.assertEqual(response.status_code, requests.codes.ok, test_utils.CODE_SHOULD_BE_200) def test_16_xpdr_device_disconnected(self): url = ("{}/operational/network-topology:network-topology/topology/" - "topology-netconf/node/XPDR-A1".format(self.restconf_baseurl)) - headers = {'content-type': 'application/json'} + "topology-netconf/node/XPDR-A1".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( @@ -310,11 +244,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_17_xpdr_device_disconnected(self): - url = ("{}/config/transportpce-portmapping:network/nodes/XPDR-A1".format(self.restconf_baseurl)) - headers = {'content-type': 'application/json'} + def test_17_xpdr_device_not_connected(self): + url = ("{}/config/transportpce-portmapping:network/nodes/XPDR-A1".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( @@ -322,22 +255,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_18_rdm_device_disconnected(self): - url = ("{}/config/network-topology:network-topology/topology/topology-netconf/node/ROADM-A1" - .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_18_rdm_device_disconnection(self): + response = test_utils.unmount_device("ROADM-A1") + self.assertEqual(response.status_code, requests.codes.ok, test_utils.CODE_SHOULD_BE_200) def test_19_rdm_device_disconnected(self): url = ("{}/operational/network-topology:network-topology/topology/topology-netconf/node/ROADM-A1" - .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( @@ -345,11 +271,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_20_rdm_device_disconnected(self): - url = ("{}/config/transportpce-portmapping:network/nodes/ROADM-A1".format(self.restconf_baseurl)) - headers = {'content-type': 'application/json'} + def test_20_rdm_device_not_connected(self): + url = ("{}/config/transportpce-portmapping:network/nodes/ROADM-A1".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(