Merge "rationalize functional tests sims starters"
[transportpce.git] / tests / transportpce_tests / 1.2.1 / test_gnpy.py
index fd01a8932bf1009034bcf980132df107654495ec..64a88194a9a9dc471a66f302e38ca1e8fe0db7d3 100644 (file)
@@ -1,7 +1,7 @@
 #!/usr/bin/env python
 
 ##############################################################################
-#Copyright (c) 2017 Orange, Inc. and others.  All rights reserved.
+# Copyright (c) 2017 Orange, Inc. and others.  All rights reserved.
 #
 # All rights reserved. This program and the accompanying materials
 # are made available under the terms of the Apache License, Version 2.0
@@ -14,13 +14,11 @@ import os
 import psutil
 import requests
 import signal
-import shutil
-import subprocess
 import time
 import unittest
-import logging
 import test_utils
 
+
 class TransportGNPYtesting(unittest.TestCase):
 
     gnpy_process = None
@@ -34,10 +32,9 @@ class TransportGNPYtesting(unittest.TestCase):
 
     @classmethod
     def setUpClass(cls):
-        print ("starting opendaylight...")
         cls.odl_process = test_utils.start_tpce()
         time.sleep(30)
-        print ("opendaylight started")
+        print("opendaylight started")
 
     @classmethod
     def tearDownClass(cls):
@@ -50,54 +47,55 @@ class TransportGNPYtesting(unittest.TestCase):
     def setUp(self):
         time.sleep(2)
 
-    #Mount the different topologies
+    # Mount the different topologies
     def test_01_connect_clliNetwork(self):
         url = ("{}/config/ietf-network:networks/network/clli-network"
                .format(self.restconf_baseurl))
-        topo_clliNet_file = "sample_configs/gnpy/clliNetwork.json"
-        if os.path.isfile(topo_clliNet_file):
-            with open(topo_clliNet_file, 'r') as clli_net:
+        topo_cllinet_file = "sample_configs/gnpy/clliNetwork.json"
+        if os.path.isfile(topo_cllinet_file):
+            with open(topo_cllinet_file, 'r') as clli_net:
                 body = clli_net.read()
         headers = {'content-type': 'application/json'}
         response = requests.request(
-             "PUT", url, data=body, headers=headers,
-             auth=('admin', 'admin'))
+            "PUT", url, data=body, headers=headers,
+            auth=('admin', 'admin'))
         self.assertEqual(response.status_code, requests.codes.ok)
         time.sleep(3)
 
     def test_02_connect_openroadmNetwork(self):
         url = ("{}/config/ietf-network:networks/network/openroadm-network"
                .format(self.restconf_baseurl))
-        topo_ordNet_file = "sample_configs/gnpy/openroadmNetwork.json"
-        if os.path.isfile(topo_ordNet_file):
-            with open(topo_ordNet_file, 'r') as ord_net:
+        topo_ordnet_file = "sample_configs/gnpy/openroadmNetwork.json"
+        if os.path.isfile(topo_ordnet_file):
+            with open(topo_ordnet_file, 'r') as ord_net:
                 body = ord_net.read()
         headers = {'content-type': 'application/json'}
         response = requests.request(
-             "PUT", url, data=body, headers=headers,
-             auth=('admin', 'admin'))
+            "PUT", url, data=body, headers=headers,
+            auth=('admin', 'admin'))
         self.assertEqual(response.status_code, requests.codes.ok)
         time.sleep(3)
 
     def test_03_connect_openroadmTopology(self):
         url = ("{}/config/ietf-network:networks/network/openroadm-topology"
                .format(self.restconf_baseurl))
-        topo_ordTopo_file = "sample_configs/gnpy/openroadmTopology.json"
-        if os.path.isfile(topo_ordTopo_file):
-            with open(topo_ordTopo_file, 'r') as ord_topo:
+        topo_ordtopo_file = "sample_configs/gnpy/openroadmTopology.json"
+        if os.path.isfile(topo_ordtopo_file):
+            with open(topo_ordtopo_file, 'r') as ord_topo:
                 body = ord_topo.read()
         headers = {'content-type': 'application/json'}
         response = requests.request(
-             "PUT", url, data=body, headers=headers,
-             auth=('admin', 'admin'))
+            "PUT", url, data=body, headers=headers,
+            auth=('admin', 'admin'))
         self.assertEqual(response.status_code, requests.codes.ok)
         time.sleep(3)
 
-    #Path computed by PCE is not feasible and Gnpy computes a new one feasible
-    def test_04_path_computation_NotFeasibleWithPCE_FeasibleWithGnpy(self):
+    # Path computed by PCE is feasible according to Gnpy
+    def test_04_path_computation_FeasibleWithPCE(self):
         url = ("{}/operations/transportpce-pce:path-computation-request"
-              .format(self.restconf_baseurl))
-        body = {"input": {
+               .format(self.restconf_baseurl))
+        body = {
+            "input": {
                 "service-name": "service-1",
                 "resource-reserve": "true",
                 "pce-metric": "hop-count",
@@ -107,34 +105,44 @@ class TransportGNPYtesting(unittest.TestCase):
                 "service-a-end": {
                     "node-id": "XPONDER-1",
                     "service-rate": "100",
+                    "service-format": "Ethernet",
                     "clli": "Node1"
                 },
                 "service-z-end": {
                     "node-id": "XPONDER-5",
                     "service-rate": "100",
+                    "service-format": "Ethernet",
                     "clli": "Node5"
                 }
             }
         }
         headers = {'content-type': 'application/json',
-        "Accept": "application/json"}
+                   "Accept": "application/json"}
         response = requests.request(
             "POST", url, data=json.dumps(body), headers=headers,
             auth=('admin', 'admin'))
         self.assertEqual(response.status_code, requests.codes.ok)
         res = response.json()
-        self.assertEqual(res['output']['configuration-response-common']['response-code'], '200')
-        self.assertEqual(res['output']['gnpy-response'][0]['path-dir'], 'A-to-Z')
-        self.assertEqual(res['output']['gnpy-response'][0]['feasibility'],True)
-        self.assertEqual(res['output']['gnpy-response'][1]['path-dir'], 'Z-to-A')
-        self.assertEqual(res['output']['gnpy-response'][1]['feasibility'],True)
+        self.assertEqual(res['output']['configuration-response-common'][
+            'response-code'], '200')
+        self.assertEqual(res['output']['configuration-response-common'][
+            'response-message'],
+            'Path is calculated by PCE')
+        self.assertEqual(res['output']['gnpy-response'][0]['path-dir'],
+                         'A-to-Z')
+        self.assertEqual(res['output']['gnpy-response'][0]['feasibility'], True)
+        self.assertEqual(res['output']['gnpy-response'][1]['path-dir'],
+                         'Z-to-A')
+        self.assertEqual(res['output']['gnpy-response'][1]['feasibility'], True)
         time.sleep(5)
 
-    #Path computed by PCE is not feasible and Gnpy cannot find a new one because the constraints
-    def test_05_path_computation_NotFeasibleWithPCE_NotFeasibleWithGnpy_withConstraints(self):
+    # Path computed by PCE is not feasible by GNPy and GNPy cannot find
+    # another one (low SNR)
+    def test_05_path_computation_FoundByPCE_NotFeasibleByGnpy(self):
         url = ("{}/operations/transportpce-pce:path-computation-request"
-              .format(self.restconf_baseurl))
-        body = {"input": {
+               .format(self.restconf_baseurl))
+        body = {
+            "input": {
                 "service-name": "service-2",
                 "resource-reserve": "true",
                 "pce-metric": "hop-count",
@@ -144,11 +152,13 @@ class TransportGNPYtesting(unittest.TestCase):
                 "service-a-end": {
                     "node-id": "XPONDER-1",
                     "service-rate": "100",
+                    "service-format": "Ethernet",
                     "clli": "Node1"
                 },
                 "service-z-end": {
                     "node-id": "XPONDER-5",
                     "service-rate": "100",
+                    "service-format": "Ethernet",
                     "clli": "Node5"
                 },
                 "hard-constraints": {
@@ -157,13 +167,19 @@ class TransportGNPYtesting(unittest.TestCase):
                             {
                                 "hop-number": "0",
                                 "hop-type": {
-                                    "node-id": "XPONDER-1"
+                                    "node-id": "OpenROADM-2"
+                                }
+                            },
+                            {
+                                "hop-number": "1",
+                                "hop-type": {
+                                    "node-id": "OpenROADM-3"
                                 }
                             },
                             {
                                 "hop-number": "2",
                                 "hop-type": {
-                                    "node-id": "OpenROADM-2"
+                                    "node-id": "OpenROADM-4"
                                 }
                             }
                         ]
@@ -172,24 +188,33 @@ class TransportGNPYtesting(unittest.TestCase):
             }
         }
         headers = {'content-type': 'application/json',
-        "Accept": "application/json"}
+                   "Accept": "application/json"}
         response = requests.request(
             "POST", url, data=json.dumps(body), headers=headers,
             auth=('admin', 'admin'))
         self.assertEqual(response.status_code, requests.codes.ok)
         res = response.json()
-        self.assertEqual(res['output']['configuration-response-common']['response-code'], '500')
-        self.assertEqual(res['output']['gnpy-response'][0]['path-dir'], 'A-to-Z')
-        self.assertEqual(res['output']['gnpy-response'][0]['feasibility'],False)
-        self.assertEqual(res['output']['gnpy-response'][1]['path-dir'], 'Z-to-A')
-        self.assertEqual(res['output']['gnpy-response'][1]['feasibility'],False)
+        self.assertEqual(res['output']['configuration-response-common'][
+            'response-code'], '500')
+        self.assertEqual(res['output']['configuration-response-common'][
+            'response-message'],
+            'No path available by PCE and GNPy ')
+        self.assertEqual(res['output']['gnpy-response'][0]['path-dir'],
+                         'A-to-Z')
+        self.assertEqual(res['output']['gnpy-response'][0]['feasibility'],
+                         False)
+        self.assertEqual(res['output']['gnpy-response'][1]['path-dir'],
+                         'Z-to-A')
+        self.assertEqual(res['output']['gnpy-response'][1]['feasibility'],
+                         False)
         time.sleep(5)
 
-    #Path computed by PCE is feasible and Gnpy confirms the feasibility
-    def test_06_path_computation_FeasibleWithPCE_withConstraints(self):
+    # #PCE cannot find a path while GNPy finds a feasible one
+    def test_06_path_computation_NotFoundByPCE_FoundByGNPy(self):
         url = ("{}/operations/transportpce-pce:path-computation-request"
-              .format(self.restconf_baseurl))
-        body = {"input": {
+               .format(self.restconf_baseurl))
+        body = {
+            "input": {
                 "service-name": "service-3",
                 "resource-reserve": "true",
                 "pce-metric": "hop-count",
@@ -199,11 +224,13 @@ class TransportGNPYtesting(unittest.TestCase):
                 "service-a-end": {
                     "node-id": "XPONDER-1",
                     "service-rate": "100",
+                    "service-format": "Ethernet",
                     "clli": "Node1"
                 },
                 "service-z-end": {
-                    "node-id": "XPONDER-5",
+                    "node-id": "XPONDER-4",
                     "service-rate": "100",
+                    "service-format": "Ethernet",
                     "clli": "Node5"
                 },
                 "hard-constraints": {
@@ -212,20 +239,90 @@ class TransportGNPYtesting(unittest.TestCase):
                             {
                                 "hop-number": "0",
                                 "hop-type": {
-                                    "node-id": "XPONDER-1"
+                                    "node-id": "OpenROADM-2"
                                 }
                             },
                             {
-                                "hop-number": "2",
+                                "hop-number": "1",
+                                "hop-type": {
+                                    "node-id": "OpenROADM-3"
+                                }
+                            }
+                        ]
+                    }
+                }
+            }
+        }
+        headers = {'content-type': 'application/json',
+                   "Accept": "application/json"}
+        response = requests.request(
+            "POST", url, data=json.dumps(body), headers=headers,
+            auth=('admin', 'admin'))
+        self.assertEqual(response.status_code, requests.codes.ok)
+        res = response.json()
+        self.assertEqual(res['output']['configuration-response-common'][
+            'response-code'], '200')
+        self.assertEqual(res['output']['configuration-response-common'][
+            'response-message'],
+            'Path is calculated by GNPy')
+        self.assertEqual(res['output']['gnpy-response'][0]['path-dir'],
+                         'A-to-Z')
+        self.assertEqual(res['output']['gnpy-response'][0]['feasibility'], True)
+        self.assertEqual(res['output']['gnpy-response'][1]['path-dir'],
+                         'Z-to-A')
+        self.assertEqual(res['output']['gnpy-response'][1]['feasibility'], True)
+        time.sleep(5)
+
+    # Not found path by PCE and GNPy cannot find another one
+    def test_07_path_computation_FoundByPCE_NotFeasibleByGnpy(self):
+        url = ("{}/operations/transportpce-pce:path-computation-request"
+               .format(self.restconf_baseurl))
+        body = {
+            "input": {
+                "service-name": "service-4",
+                "resource-reserve": "true",
+                "pce-metric": "hop-count",
+                "service-handler-header": {
+                    "request-id": "request-4"
+                },
+                "service-a-end": {
+                    "node-id": "XPONDER-1",
+                    "service-rate": "100",
+                    "service-format": "Ethernet",
+                    "clli": "Node1"
+                },
+                "service-z-end": {
+                    "node-id": "XPONDER-4",
+                    "service-rate": "100",
+                    "service-format": "Ethernet",
+                    "clli": "Node5"
+                },
+                "hard-constraints": {
+                    "include_": {
+                        "ordered-hops": [
+                            {
+                                "hop-number": "0",
+                                "hop-type": {
+                                    "node-id": "OpenROADM-2"
+                                }
+                            },
+                            {
+                                "hop-number": "1",
                                 "hop-type": {
                                     "node-id": "OpenROADM-3"
                                 }
                             },
                             {
-                                "hop-number": "4",
+                                "hop-number": "2",
                                 "hop-type": {
                                     "node-id": "OpenROADM-4"
                                 }
+                            },
+                            {
+                                "hop-number": "3",
+                                "hop-type": {
+                                    "node-id": "OpenROADM-3"
+                                }
                             }
                         ]
                     }
@@ -233,53 +330,54 @@ class TransportGNPYtesting(unittest.TestCase):
             }
         }
         headers = {'content-type': 'application/json',
-        "Accept": "application/json"}
+                   "Accept": "application/json"}
         response = requests.request(
             "POST", url, data=json.dumps(body), headers=headers,
             auth=('admin', 'admin'))
         self.assertEqual(response.status_code, requests.codes.ok)
         res = response.json()
-        self.assertEqual(res['output']['configuration-response-common']['response-code'], '200')
-        self.assertEqual(res['output']['gnpy-response'][0]['path-dir'], 'A-to-Z')
-        self.assertEqual(res['output']['gnpy-response'][0]['feasibility'],True)
-        self.assertEqual(res['output']['gnpy-response'][1]['path-dir'], 'Z-to-A')
-        self.assertEqual(res['output']['gnpy-response'][1]['feasibility'],True)
+        self.assertEqual(res['output']['configuration-response-common'][
+            'response-code'], '500')
+        self.assertEqual(res['output']['configuration-response-common'][
+            'response-message'],
+            'No path available by PCE and GNPy ')
         time.sleep(5)
 
-    #Disconnect the different topologies
-    def test_07_disconnect_openroadmTopology(self):
+    # Disconnect the different topologies
+    def test_08_disconnect_openroadmTopology(self):
         url = ("{}/config/ietf-network:networks/network/openroadm-topology"
                .format(self.restconf_baseurl))
         data = {}
         headers = {'content-type': 'application/json'}
         response = requests.request(
-             "DELETE", url, data=json.dumps(data), headers=headers,
-             auth=('admin', 'admin'))
+            "DELETE", url, data=json.dumps(data), headers=headers,
+            auth=('admin', 'admin'))
         self.assertEqual(response.status_code, requests.codes.ok)
         time.sleep(3)
 
-    def test_08_disconnect_openroadmNetwork(self):
+    def test_09_disconnect_openroadmNetwork(self):
         url = ("{}/config/ietf-network:networks/network/openroadm-network"
                .format(self.restconf_baseurl))
         data = {}
         headers = {'content-type': 'application/json'}
         response = requests.request(
-             "DELETE", url, data=json.dumps(data), headers=headers,
-             auth=('admin', 'admin'))
+            "DELETE", url, data=json.dumps(data), headers=headers,
+            auth=('admin', 'admin'))
         self.assertEqual(response.status_code, requests.codes.ok)
         time.sleep(3)
 
-    def test_09_disconnect_clliNetwork(self):
+    def test_10_disconnect_clliNetwork(self):
         url = ("{}/config/ietf-network:networks/network/clli-network"
                .format(self.restconf_baseurl))
         data = {}
         headers = {'content-type': 'application/json'}
         response = requests.request(
-             "DELETE", url, data=json.dumps(data), headers=headers,
-             auth=('admin', 'admin'))
+            "DELETE", url, data=json.dumps(data), headers=headers,
+            auth=('admin', 'admin'))
         self.assertEqual(response.status_code, requests.codes.ok)
         time.sleep(3)
 
+
 if __name__ == "__main__":
-    #logging.basicConfig(filename='./transportpce_tests/log/response.log',filemode='w',level=logging.DEBUG)
+    # logging.basicConfig(filename='./transportpce_tests/log/response.log',filemode='w',level=logging.DEBUG)
     unittest.main(verbosity=2)