Topo-PortMapping functional tests 18/83018/15
authorGilles Thouenon <gilles.thouenon@orange.com>
Thu, 11 Jul 2019 11:41:50 +0000 (13:41 +0200)
committerGilles Thouenon <gilles.thouenon@orange.com>
Thu, 1 Aug 2019 14:55:03 +0000 (16:55 +0200)
- simplify the existing functional test suite for device 1.2.1
- create equivalent functional test suite for device 2.2.1

JIRA: TRNSPRTPCE-109

Change-Id: I3154530b44577c95d970aca170bce22568c71180
Signed-off-by: Gilles Thouenon <gilles.thouenon@orange.com>
Co-authored-by: Christophe Betoule <christophe.betoule@orange.com>
tests/transportpce_tests/1.2.1/test_topoPortMapping.py
tests/transportpce_tests/2.2.1/test_topoPortMapping.py [new file with mode: 0644]

index f941846ca5032461e9f8b36c3433aac3897f9fc5..cdc409c2a4c13572f83ad94b94bbd32ced9f7321 100644 (file)
@@ -29,13 +29,6 @@ class TransportPCEtesting(unittest.TestCase):
 
 #START_IGNORE_XTESTING
 
-    @classmethod
-    def __init_logfile(cls):
-        if not os.path.exists("transportpce_tests/log"):
-                os.makedirs("transportpce_tests/log")
-        if os.path.isfile("./transportpce_tests/log/topoPortMap.log"):
-            os.remove("transportpce_tests/log/topoPortMap.log")
-
     @classmethod
     def __start_honeynode1(cls):
         executable = ("./honeynode/2.1/honeynode-distribution/target/honeynode-distribution-1.18.01-hc"
@@ -46,7 +39,6 @@ class TransportPCEtesting(unittest.TestCase):
                     [executable, "17830", "sample_configs/openroadm/2.1/oper-XPDRA.xml"],
                     stdout=outfile)
 
-
     @classmethod
     def __start_honeynode2(cls):
         executable = ("./honeynode/2.1/honeynode-distribution/target/honeynode-distribution-1.18.01-hc"
@@ -57,19 +49,16 @@ class TransportPCEtesting(unittest.TestCase):
                     [executable, "17831", "sample_configs/openroadm/2.1/oper-ROADMA.xml"],
                     stdout=outfile)
 
-
     @classmethod
     def __start_odl(cls):
         executable = "../karaf/target/assembly/bin/karaf"
-        with open('transportpce_tests/log/odl.log', 'w') as outfile:
+        with open('odl.log', 'w') as outfile:
             cls.odl_process = subprocess.Popen(
                 ["bash", executable, "server"], stdout=outfile,
                 stdin=open(os.devnull))
 
     @classmethod
     def setUpClass(cls):
-        cls.__init_logfile()
-        time.sleep(2)
         cls.__start_honeynode1()
         time.sleep(20)
         cls.__start_honeynode2()
@@ -101,7 +90,7 @@ class TransportPCEtesting(unittest.TestCase):
 #END_IGNORE_XTESTING
 
     #Connect the ROADMA
-    def test_01_connect_roadma(self):
+    def test_01_connect_rdm(self):
         #Config ROADMA
         url = ("{}/config/network-topology:"
                 "network-topology/topology/topology-netconf/node/ROADMA"
@@ -119,65 +108,47 @@ class TransportPCEtesting(unittest.TestCase):
              "PUT", url, data=json.dumps(data), headers=headers,
              auth=('admin', 'admin'))
         self.assertEqual(response.status_code, requests.codes.created)
-        #seems sometimes to return 200 instead of 201
-        #self.assertEqual(response.status_code, requests.codes.ok)
-        time.sleep(10)
+        time.sleep(20)
 
     #Verify the termination points of the ROADMA
-    def test_02_compareOpenroadmTopologyPortMapping(self):
-        #Verify the termination points related to the SRGs
-        nbSrg=1
-        for s in range(1,nbSrg+1):
-            url_topo="{}/config/ietf-network:networks/network/openroadm-topology/node/ROADMA-SRG"+`s`
-            with open('./transportpce_tests/log/topoPortMap.log', 'a') as outfile1:
-                outfile1.write('Config: '+`s`+' : '+url_topo+'\n')
-            url = (url_topo.format(self.restconf_baseurl))
-            headers = {'content-type': 'application/json'}
-            response_topo = requests.request(
-                "GET", url, headers=headers, auth=('admin', 'admin'))
-            self.assertEqual(response_topo.status_code, requests.codes.ok)
-            res_topo = response_topo.json()
-            nbTP=len(res_topo['node'][0]['ietf-network-topology:termination-point'])
-            for i in range(0,nbTP):
-                tp_id=res_topo['node'][0]['ietf-network-topology:termination-point'][i]['tp-id']
-                if(not "CP" in tp_id):
-                    url_map="{}/config/transportpce-portmapping:network/nodes/ROADMA/mapping/"+tp_id
-                    with open('./transportpce_tests/log/topoPortMap.log', 'a') as outfile1:
-                        outfile1.write('Config: '+`i`+'/'+ `nbTP`+' : '+url_map+'\n')
-                    url = (url_map.format(self.restconf_baseurl))
-                    headers = {'content-type': 'application/json'}
-                    response_portMap = requests.request(
-                        "GET", url, headers=headers, auth=('admin', 'admin'))
-                    self.assertEqual(response_portMap.status_code, requests.codes.ok)
-
-        #Verify the termination points related to the degrees
-        nbDeg=2
-        for d in range(1,nbDeg+1):
-            url_topo="{}/config/ietf-network:networks/network/openroadm-topology/node/ROADMA-DEG"+`d`
-            with open('./transportpce_tests/log/topoPortMap.log', 'a') as outfile1:
-                outfile1.write(url_topo+'\n')
-            url = (url_topo.format(self.restconf_baseurl))
-            headers = {'content-type': 'application/json'}
-            response_topo = requests.request(
-                "GET", url, headers=headers, auth=('admin', 'admin'))
-            self.assertEqual(response_topo.status_code, requests.codes.ok)
-            res_topo = response_topo.json()
-            nbTP=len(res_topo['node'][0]['ietf-network-topology:termination-point'])
-            for i in range(0,nbTP):
-                tp_id=res_topo['node'][0]['ietf-network-topology:termination-point'][i]['tp-id']
-                if(not "CTP" in tp_id):
-                    url_map ="{}/config/transportpce-portmapping:network/nodes/ROADMA/mapping/"+tp_id
-                    with open('./transportpce_tests/log/topoPortMap.log', 'a') as outfile1:
-                        outfile1.write('Config: '+`i`+'/'+ `nbTP`+' : '+url_map+'\n')
-                    url = (url_map.format(self.restconf_baseurl))
-                    headers = {'content-type': 'application/json'}
-                    response_portMap = requests.request(
-                        "GET", url, headers=headers, auth=('admin', 'admin'))
-                    self.assertEqual(response_portMap.status_code, requests.codes.ok)
-        time.sleep(1)
+    def test_02_compareOpenroadmTopologyPortMapping_rdm(self):
+        urlTopo = ("{}/config/ietf-network:networks/network/openroadm-topology"
+            .format(self.restconf_baseurl))
+        headers = {'content-type': 'application/json'}
+        responseTopo = requests.request(
+            "GET", urlTopo, headers=headers, auth=('admin', 'admin'))
+        resTopo = responseTopo.json()
+        nbNode = len(resTopo['network'][0]['node'])
+        nbMapCumul = 0
+        nbMappings = 0
+        for i in range(0, nbNode):
+            nodeId = resTopo['network'][0]['node'][i]['node-id']
+            nodeMapId = nodeId.split("-")[0]
+            urlMapList = "{}/config/transportpce-portmapping:network/nodes/" + nodeMapId
+            urlMapListFull = urlMapList.format(self.restconf_baseurl)
+            responseMapList = requests.request(
+                        "GET", urlMapListFull, headers=headers, auth=('admin', 'admin'))
+            resMapList = responseMapList.json()
+
+            nbMappings = len(resMapList['nodes'][0]['mapping']) - nbMapCumul
+            nbTp = len(resTopo['network'][0]['node'][i]['ietf-network-topology:termination-point'])
+            nbMapCurrent = 0
+            for j in range(0, nbTp):
+                tpId = resTopo['network'][0]['node'][i]['ietf-network-topology:termination-point'][j]['tp-id']
+                if((not "CP" in tpId) and (not "CTP" in tpId)):
+                     urlMap = "{}/config/transportpce-portmapping:network/nodes/" + nodeMapId + "/mapping/" + tpId
+                     urlMapFull = urlMap.format(self.restconf_baseurl)
+                     responseMap = requests.request(
+                        "GET", urlMapFull, headers=headers, auth=('admin', 'admin'))
+                     self.assertEqual(responseMap.status_code, requests.codes.ok)
+                     if(responseMap.status_code == requests.codes.ok):
+                        nbMapCurrent += 1
+            nbMapCumul += nbMapCurrent
+        nbMappings -= nbMapCurrent
+        self.assertEqual(nbMappings, 0)
 
     #Disconnect the ROADMA
-    def test_03_disconnect_device(self):
+    def test_03_disconnect_rdm(self):
         url = ("{}/config/network-topology:"
                 "network-topology/topology/topology-netconf/node/ROADMA"
                .format(self.restconf_baseurl))
@@ -187,18 +158,8 @@ class TransportPCEtesting(unittest.TestCase):
              "DELETE", url, data=json.dumps(data), headers=headers,
              auth=('admin', 'admin'))
         self.assertEqual(response.status_code, requests.codes.ok)
-        #Delete in the openroadm-network
-#         url = ("{}/config/ietf-network:networks/network/openroadm-network/node/ROADMA"
-#                .format(self.restconf_baseurl))
-#         data = {}
-#         headers = {'content-type': 'application/json'}
-#         response = requests.request(
-#              "DELETE", url, data=json.dumps(data), headers=headers,
-#              auth=('admin', 'admin'))
-#         self.assertEqual(response.status_code, requests.codes.ok)
-#         time.sleep(5)
 
-    #Connect the XPDRA
+    #Connect the XPDRA
     def test_04_connect_xpdr(self):
          #Config XPDRA
          url = ("{}/config/network-topology:"
@@ -217,59 +178,11 @@ class TransportPCEtesting(unittest.TestCase):
               "PUT", url, data=json.dumps(data), headers=headers,
               auth=('admin', 'admin'))
          self.assertEqual(response.status_code, requests.codes.created)
-         #seems sometimes to return 200 instead of 201
-         #self.assertEqual(response.status_code, requests.codes.ok)
-         time.sleep(15)
+         time.sleep(20)
 
-    #Verify the termination points related to XPDR
-    @unittest.expectedFailure
-    def test_05_compareOpenroadmTopologyPortMapping(self):
-        nbXPDR=1
-        for p in(1,nbXPDR+1):
-            if(p > nbXPDR):
-                break;
-            url_topo = "{}/config/ietf-network:networks/network/openroadm-topology/node/XPDRA-XPDR"+`p`
-            with open('./transportpce_tests/log/topoPortMap.log', 'a') as outfile1:
-                outfile1.write('Config: '+`p`+' : '+url_topo+'\n')
-            url = (url_topo.format(self.restconf_baseurl))
-            headers = {'content-type': 'application/json'}
-            response_topo = requests.request(
-                "GET", url, headers=headers, auth=('admin', 'admin'))
-            self.assertEqual(response_topo.status_code, requests.codes.ok)
-            res_topo = response_topo.json()
-            nbTP=len(res_topo['node'][0]['ietf-network-topology:termination-point'])
-            for i in range(0,nbTP):
-                tp_id=res_topo['node'][0]['ietf-network-topology:termination-point'][i]['tp-id']
-                url_map = "{}/config/transportpce-portmapping:network/nodes/XPDRA/mapping/"+tp_id
-                with open('./transportpce_tests/log/topoPortMap.log', 'a') as outfile1:
-                    outfile1.write('Config: '+`i`+'/'+ `nbTP`+' : '+url_map+'\n')
-                url = url_map.format(self.restconf_baseurl)
-                headers = {'content-type': 'application/json'}
-                response_portMap = requests.request(
-                    "GET", url, headers=headers, auth=('admin', 'admin'))
-                self.assertEqual(response_portMap.status_code, requests.codes.ok)
-                if("CLIENT" in tp_id):
-                    #Verify the tail equipment id of the client
-                    xpdr_client=res_topo['node'][0]['ietf-network-topology:termination-point'][i]["org-openroadm-network-topology:xpdr-client-attributes"]["tail-equipment-id"]
-                    url_map = "{}/config/transportpce-portmapping:network/nodes/XPDRA/mapping/"+xpdr_client
-                    with open('./transportpce_tests/log/topoPortMap.log', 'a') as outfile1:
-                        outfile1.write('Config: '+`i`+'/'+ `nbTP`+' : '+xpdr_client+'\n')
-                    url = url_map.format(self.restconf_baseurl)
-                    headers = {'content-type': 'application/json'}
-                    response_xpdrClient = requests.request(
-                        "GET", url, headers=headers, auth=('admin', 'admin'))
-                    self.assertEqual(response_xpdrClient.status_code, requests.codes.ok)
-                if("NETWORK" in tp_id):
-                    #Verify the tail equipment id of the network
-                    xpdr_network=res_topo['node'][0]['ietf-network-topology:termination-point'][i]["org-openroadm-network-topology:xpdr-network-attributes"]["tail-equipment-id"]
-                    url_map = "{}/config/transportpce-portmapping:network/nodes/XPDRA/mapping/"+xpdr_network
-                    with open('./transportpce_tests/log/topoPortMap.log', 'a') as outfile1:
-                        outfile1.write('Config: '+`i`+'/'+ `nbTP`+' : '+xpdr_network+'\n')
-                    url = url_map.format(self.restconf_baseurl)
-                    headers = {'content-type': 'application/json'}
-                    response_xpdrNetwork = requests.request(
-                        "GET", url, headers=headers, auth=('admin', 'admin'))
-                    self.assertEqual(response_xpdrNetwork.status_code, requests.codes.ok)
+#     #Verify the termination points related to XPDR
+    def test_05_compareOpenroadmTopologyPortMapping_xpdr(self):
+        self.test_02_compareOpenroadmTopologyPortMapping_rdm()
 
     #Disconnect the XPDRA
     def test_06_disconnect_device(self):
@@ -282,16 +195,6 @@ class TransportPCEtesting(unittest.TestCase):
             "DELETE", url, data=json.dumps(data), headers=headers,
             auth=('admin', 'admin'))
         self.assertEqual(response.status_code, requests.codes.ok)
-        #Delete in the openroadm-network
-#         url = ("{}/config/ietf-network:networks/network/openroadm-network/node/XPDRA"
-#                .format(self.restconf_baseurl))
-#         data = {}
-#         headers = {'content-type': 'application/json'}
-#         response = requests.request(
-#              "DELETE", url, data=json.dumps(data), headers=headers,
-#              auth=('admin', 'admin'))
-#         self.assertEqual(response.status_code, requests.codes.ok)
-
 
 if __name__ == "__main__":
     #logging.basicConfig(filename='./transportpce_tests/log/response.log',filemode='w',level=logging.DEBUG)
diff --git a/tests/transportpce_tests/2.2.1/test_topoPortMapping.py b/tests/transportpce_tests/2.2.1/test_topoPortMapping.py
new file mode 100644 (file)
index 0000000..8a58e68
--- /dev/null
@@ -0,0 +1,204 @@
+#!/usr/bin/env python
+
+##############################################################################
+#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
+# which accompanies this distribution, and is available at
+# http://www.apache.org/licenses/LICENSE-2.0
+##############################################################################
+
+import json
+import os
+import psutil
+import requests
+import signal
+import shutil
+import subprocess
+import time
+import unittest
+import logging
+
+class TransportPCEtesting(unittest.TestCase):
+
+    honeynode_process1 = None
+    honeynode_process2 = None
+    odl_process = None
+    restconf_baseurl = "http://localhost:8181/restconf"
+
+#START_IGNORE_XTESTING
+
+    @classmethod
+    def __start_honeynode1(cls):
+        executable = ("./honeynode/2.2.1/honeynode-distribution/target/honeynode-distribution-1.18.01-hc"
+                      "/honeynode-distribution-1.18.01/honeycomb-tpce")
+        if os.path.isfile(executable):
+            with open('honeynode1.log', 'w') as outfile:
+                cls.honeynode_process1 = subprocess.Popen(
+                    [executable, "17840", "sample_configs/openroadm/2.2.1/oper-XPDRA.xml"],
+                    stdout=outfile)
+
+    @classmethod
+    def __start_honeynode2(cls):
+        executable = ("./honeynode/2.2.1/honeynode-distribution/target/honeynode-distribution-1.18.01-hc"
+                      "/honeynode-distribution-1.18.01/honeycomb-tpce")
+        if os.path.isfile(executable):
+            with open('honeynode2.log', 'w') as outfile:
+                cls.honeynode_process2 = subprocess.Popen(
+                    [executable, "17841", "sample_configs/openroadm/2.2.1/oper-ROADMA.xml"],
+                    stdout=outfile)
+
+    @classmethod
+    def __start_odl(cls):
+        executable = "../karaf/target/assembly/bin/karaf"
+        with open('odl.log', 'w') as outfile:
+            cls.odl_process = subprocess.Popen(
+                ["bash", executable, "server"], stdout=outfile,
+                stdin=open(os.devnull))
+
+    @classmethod
+    def setUpClass(cls):
+        cls.__start_honeynode1()
+        time.sleep(20)
+        cls.__start_honeynode2()
+        time.sleep(20)
+        cls.__start_odl()
+        time.sleep(60)
+
+    @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.honeynode_process1.pid).children():
+            child.send_signal(signal.SIGINT)
+            child.wait()
+        cls.honeynode_process1.send_signal(signal.SIGINT)
+        cls.honeynode_process1.wait()
+        for child in psutil.Process(cls.honeynode_process2.pid).children():
+            child.send_signal(signal.SIGINT)
+            child.wait()
+        cls.honeynode_process2.send_signal(signal.SIGINT)
+        cls.honeynode_process2.wait()
+
+    def setUp(self):
+        time.sleep(10)
+
+#END_IGNORE_XTESTING
+
+    #Connect the ROADMA
+    def test_01_connect_rdm(self):
+        #Config ROADMA
+        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": "17841",
+             "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)
+
+    #Verify the termination points of the ROADMA
+    def test_02_compareOpenroadmTopologyPortMapping_rdm(self):
+        urlTopo = ("{}/config/ietf-network:networks/network/openroadm-topology"
+            .format(self.restconf_baseurl))
+        headers = {'content-type': 'application/json'}
+        responseTopo = requests.request(
+            "GET", urlTopo, headers=headers, auth=('admin', 'admin'))
+        resTopo = responseTopo.json()
+        nbNode = len(resTopo['network'][0]['node'])
+        nbMapCumul = 0
+        nbMappings = 0
+        for i in range(0, nbNode):
+            nodeId = resTopo['network'][0]['node'][i]['node-id']
+            print("nodeId={}".format(nodeId))
+            nodeMapId = nodeId.split("-")[0] + "-" + nodeId.split("-")[1]
+            print("nodeMapId={}".format(nodeMapId))
+            urlMapList = "{}/config/transportpce-portmapping:network/nodes/" + nodeMapId
+            urlMapListFull = urlMapList.format(self.restconf_baseurl)
+            responseMapList = requests.request(
+                        "GET", urlMapListFull, headers=headers, auth=('admin', 'admin'))
+            resMapList = responseMapList.json()
+
+            nbMappings = len(resMapList['nodes'][0]['mapping']) - nbMapCumul
+            nbTp = len(resTopo['network'][0]['node'][i]['ietf-network-topology:termination-point'])
+            nbMapCurrent = 0
+            for j in range(0, nbTp):
+                tpId = resTopo['network'][0]['node'][i]['ietf-network-topology:termination-point'][j]['tp-id']
+                if((not "CP" in tpId) and (not "CTP" in tpId)):
+                     urlMap = "{}/config/transportpce-portmapping:network/nodes/" + nodeMapId + "/mapping/" + tpId
+                     urlMapFull = urlMap.format(self.restconf_baseurl)
+                     responseMap = requests.request(
+                        "GET", urlMapFull, headers=headers, auth=('admin', 'admin'))
+                     self.assertEqual(responseMap.status_code, requests.codes.ok)
+                     if(responseMap.status_code == requests.codes.ok):
+                        nbMapCurrent += 1
+            nbMapCumul += nbMapCurrent
+        nbMappings -= nbMapCurrent
+        self.assertEqual(nbMappings, 0)
+
+    #Disconnect the ROADMA
+    def test_03_disconnect_rdm(self):
+        url = ("{}/config/network-topology:"
+                "network-topology/topology/topology-netconf/node/ROADM-A1"
+               .format(self.restconf_baseurl))
+        data = {}
+        headers = {'content-type': 'application/json'}
+        response = requests.request(
+             "DELETE", url, data=json.dumps(data), headers=headers,
+             auth=('admin', 'admin'))
+        self.assertEqual(response.status_code, requests.codes.ok)
+
+#     #Connect the XPDRA
+    def test_04_connect_xpdr(self):
+         #Config XPDRA
+         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": "17840",
+              "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)
+
+#     #Verify the termination points related to XPDR
+    def test_05_compareOpenroadmTopologyPortMapping_xpdr(self):
+        self.test_02_compareOpenroadmTopologyPortMapping_rdm()
+
+    #Disconnect the XPDRA
+    def test_06_disconnect_device(self):
+        url = ("{}/config/network-topology:"
+               "network-topology/topology/topology-netconf/node/XPDR-A1"
+              .format(self.restconf_baseurl))
+        data = {}
+        headers = {'content-type': 'application/json'}
+        response = requests.request(
+            "DELETE", url, data=json.dumps(data), headers=headers,
+            auth=('admin', 'admin'))
+        self.assertEqual(response.status_code, requests.codes.ok)
+
+if __name__ == "__main__":
+    #logging.basicConfig(filename='./transportpce_tests/log/response.log',filemode='w',level=logging.DEBUG)
+    #logging.debug('I am there')
+    unittest.main(verbosity=2)