Change way to start simulators
[transportpce.git] / tests / transportpce_tests / 1.2.1 / test_pce.py
index 4b8d6b2ca3182a2e52e1380cf46476af7e3b78a4..bbed914aaa9fd0346ba07fcc8ac9d2732c1b0bdc 100644 (file)
@@ -16,7 +16,8 @@ import os
 import sys
 import time
 import requests
-from common import test_utils
+sys.path.append('transportpce_tests/common/')
+import test_utils
 
 
 class TransportPCEtesting(unittest.TestCase):
@@ -24,10 +25,12 @@ class TransportPCEtesting(unittest.TestCase):
     simple_topo_bi_dir_data = None
     simple_topo_uni_dir_data = None
     complex_topo_uni_dir_data = None
+    port_mapping_data = None
     processes = None
 
     @classmethod
     def setUpClass(cls):
+        # pylint: disable=bare-except
         try:
             sample_files_parsed = False
             TOPO_BI_DIR_FILE = os.path.join(os.path.dirname(os.path.realpath(__file__)),
@@ -45,6 +48,10 @@ class TransportPCEtesting(unittest.TestCase):
                                                      "..", "..", "sample_configs", "NW-for-test-5-4.xml")
             with open(TOPO_UNI_DIR_COMPLEX_FILE, 'r') as topo_uni_dir_complex:
                 cls.complex_topo_uni_dir_data = topo_uni_dir_complex.read()
+            PORT_MAPPING_FILE = os.path.join(os.path.dirname(os.path.realpath(__file__)),
+                                                     "..", "..", "sample_configs", "pce_portmapping_121.json")
+            with open(PORT_MAPPING_FILE, 'r') as port_mapping:
+                cls.port_mapping_data = port_mapping.read()
             sample_files_parsed = True
         except PermissionError as err:
             print("Permission Error when trying to read sample files\n", err)
@@ -63,6 +70,7 @@ class TransportPCEtesting(unittest.TestCase):
 
     @classmethod
     def tearDownClass(cls):
+        # pylint: disable=not-an-iterable
         for process in cls.processes:
             test_utils.shutdown_process(process)
         print("all processes killed")
@@ -70,6 +78,12 @@ class TransportPCEtesting(unittest.TestCase):
     def setUp(self):  # instruction executed before each test method
         time.sleep(1)
 
+     # Load port mapping
+    def test_00_load_port_mapping(self):
+        response = test_utils.rawpost_request(test_utils.URL_FULL_PORTMAPPING, self.port_mapping_data)
+        self.assertEqual(response.status_code, requests.codes.no_content)
+        time.sleep(2)
+
      # Load simple bidirectional topology
     def test_01_load_simple_topology_bi(self):
         response = test_utils.put_xmlrequest(test_utils.URL_CONFIG_ORDM_TOPO, self.simple_topo_bi_dir_data)
@@ -191,9 +205,9 @@ class TransportPCEtesting(unittest.TestCase):
         for i in range(0, 15):
             atoz = res['output']['response-parameters']['path-description']['aToZ-direction']['aToZ'][i]
             ztoa = res['output']['response-parameters']['path-description']['zToA-direction']['zToA'][i]
-            if (atoz['id'] == '14'):
+            if atoz['id'] == '14':
                 self.assertEqual(atoz['resource']['tp-id'], 'SRG1-PP1-TX')
-            if (ztoa['id'] == '0'):
+            if ztoa['id'] == '0':
                 self.assertEqual(ztoa['resource']['tp-id'], 'SRG1-PP1-RX')
         time.sleep(5)
 
@@ -340,12 +354,12 @@ class TransportPCEtesting(unittest.TestCase):
         nbElmPath = len(res['output']['response-parameters']['path-description']
                         ['aToZ-direction']['aToZ'])
         self.assertEqual(31, nbElmPath)
-        link = {"link-id": "OpenROADM-1-3-DEG2-to-OpenROADM-1-2-DEG2"}
+        link = {"link-id": "OpenROADM-1-3-DEG2-to-OpenROADM-1-2-DEG2", "state":"inService"}
         find = False
         for i in range(0, nbElmPath):
             resource_i = (res['output']['response-parameters']['path-description']['aToZ-direction']['aToZ'][i]
                              ['resource'])
-            if(resource_i == link):
+            if resource_i == link:
                 find = True
         self.assertEqual(find, True)
         time.sleep(5)
@@ -370,12 +384,12 @@ class TransportPCEtesting(unittest.TestCase):
         nbElmPath = len(res['output']['response-parameters']['path-description']
                         ['aToZ-direction']['aToZ'])
         self.assertEqual(47, nbElmPath)
-        link = {"link-id": "OpenROADM-1-3-DEG2-to-OpenROADM-1-2-DEG2"}
+        link = {"link-id": "OpenROADM-1-3-DEG2-to-OpenROADM-1-2-DEG2", "state":"inService"}
         find = False
         for i in range(0, nbElmPath):
             resource_i = (res['output']['response-parameters']['path-description']['aToZ-direction']['aToZ'][i]
                              ['resource'])
-            if (resource_i == link):
+            if resource_i == link:
                 find = True
         self.assertNotEqual(find, True)
         time.sleep(5)
@@ -392,6 +406,12 @@ class TransportPCEtesting(unittest.TestCase):
         self.assertEqual(response.status_code, requests.codes.conflict)
         time.sleep(1)
 
+    # Delete portmapping
+    def test_26_delete_port_mapping(self):
+        response = test_utils.delete_request(test_utils.URL_FULL_PORTMAPPING)
+        self.assertEqual(response.status_code, requests.codes.ok)
+        time.sleep(2)
+
 
 if __name__ == "__main__":
     unittest.main(verbosity=2)