test topoPortMapping adapted to Honeynode
[transportpce.git] / tests / transportpce_tests / test_topoPortMapping.py
index 40d07a2ee3b1581c7bc370326c19b69a860680f9..415ef9bb28f9d7b2e2fd3a25f58df331ddef0363 100644 (file)
@@ -22,30 +22,41 @@ import logging
 
 class TransportPCEtesting(unittest.TestCase):
 
-    testtools_process1 = None
-    testtools_process2 = None
+    honeynode_process1 = None
+    honeynode_process2 = None
     odl_process = None
     restconf_baseurl = "http://localhost:8181/restconf"
 
+#START_IGNORE_XTESTING
+
     @classmethod
-    def __start_testtools(cls):
-        executable = ("./netconf/netconf/tools/netconf-testtool/target/"
-                      "netconf-testtool-1.5.0-executable.jar")
-        if os.path.isfile(executable):
-            if not os.path.exists("transportpce_tests/log"):
+    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")
-            with open('transportpce_tests/log/testtools_ROADMA.log', 'w') as outfile1:
-                cls.testtools_process1 = subprocess.Popen(
-                    ["java", "-jar", executable, "--schemas-dir", "schemas",
-                     "--initial-config-xml", "sample_configs/nodes_config/sample-config-ROADMA.xml","--starting-port","17831"],
-                    stdout=outfile1)
-            with open('transportpce_tests/log/testtools_XPDRA.log', 'w') as outfile2:
-                cls.testtools_process2 = subprocess.Popen(
-                    ["java", "-jar", executable, "--schemas-dir", "schemas",
-                     "--initial-config-xml", "sample_configs/nodes_config/sample-config-XPDRA.xml","--starting-port","17830"],
-                    stdout=outfile2)
+        if os.path.isfile("./transportpce_tests/log/topoPortMap.log"):
+            os.remove("transportpce_tests/log/topoPortMap.log")
+
+    @classmethod
+    def __start_honeynode1(cls):
+        executable = ("./honeynode/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, "17830", "sample_configs/openroadm/2.1/oper-XPDRA.xml"],
+                    stdout=outfile)
+
+
+    @classmethod
+    def __start_honeynode2(cls):
+        executable = ("./honeynode/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, "17831", "sample_configs/openroadm/2.1/oper-ROADMA.xml"],
+                    stdout=outfile)
+
 
     @classmethod
     def __start_odl(cls):
@@ -57,25 +68,38 @@ class TransportPCEtesting(unittest.TestCase):
 
     @classmethod
     def setUpClass(cls):
-        cls.__start_testtools()
+        cls.__init_logfile()
+        time.sleep(2)
+        cls.__start_honeynode1()
+        time.sleep(20)
+        cls.__start_honeynode2()
+        time.sleep(20)
         cls.__start_odl()
-        time.sleep(40)
+        time.sleep(60)
 
     @classmethod
     def tearDownClass(cls):
-        cls.testtools_process1.send_signal(signal.SIGINT)
-        cls.testtools_process1.wait()
-        cls.testtools_process2.send_signal(signal.SIGINT)
-        cls.testtools_process2.wait()
         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_roadma(self):
         #Config ROADMA
@@ -104,7 +128,7 @@ class TransportPCEtesting(unittest.TestCase):
         #Verify the termination points related to the SRGs
         nbSrg=1
         for s in range(1,nbSrg+1):
-            url_topo="{}/config/ietf-network:network/openroadm-topology/node/ROADMA-SRG"+`s`
+            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))
@@ -117,7 +141,7 @@ class TransportPCEtesting(unittest.TestCase):
             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/portmapping:network/nodes/ROADMA/mapping/"+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))
@@ -129,7 +153,7 @@ class TransportPCEtesting(unittest.TestCase):
         #Verify the termination points related to the degrees
         nbDeg=2
         for d in range(1,nbDeg+1):
-            url_topo="{}/config/ietf-network:network/openroadm-topology/node/ROADMA-DEG"+`d`
+            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))
@@ -142,7 +166,7 @@ class TransportPCEtesting(unittest.TestCase):
             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/portmapping:network/nodes/ROADMA/mapping/"+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))
@@ -163,25 +187,16 @@ 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 clli-network
-        url = ("{}/config/ietf-network:network/clli-network/node/NodeA"
-               .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)
         #Delete in the openroadm-network
-        url = ("{}/config/ietf-network: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)
+#         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
     def test_04_connect_xpdr(self):
@@ -210,7 +225,9 @@ class TransportPCEtesting(unittest.TestCase):
     def test_05_compareOpenroadmTopologyPortMapping(self):
         nbXPDR=1
         for p in(1,nbXPDR+1):
-            url_topo = "{}/config/ietf-network:network/openroadm-topology/node/XPDRA-XPDR"+`p`
+            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))
@@ -222,7 +239,7 @@ class TransportPCEtesting(unittest.TestCase):
             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/portmapping:network/nodes/XPDRA/mapping/"+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)
@@ -230,26 +247,28 @@ class TransportPCEtesting(unittest.TestCase):
                 response_portMap = requests.request(
                     "GET", url, headers=headers, auth=('admin', 'admin'))
                 self.assertEqual(response_portMap.status_code, requests.codes.ok)
-                #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/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)
-                #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/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)
+                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)
 
     #Disconnect the XPDRA
     def test_06_disconnect_device(self):
@@ -263,14 +282,14 @@ class TransportPCEtesting(unittest.TestCase):
             auth=('admin', 'admin'))
         self.assertEqual(response.status_code, requests.codes.ok)
         #Delete in the openroadm-network
-        url = ("{}/config/ietf-network: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)
+#         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__":