Align 1.2.1 tests sims/tpce management to 2.2.1
[transportpce.git] / tests / transportpce_tests / 1.2.1 / test_topoPortMapping.py
index cdc409c2a4c13572f83ad94b94bbd32ced9f7321..2a41e52f8d9b51ba714ac92bd7c0c58bf443bddb 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
 ##############################################################################
 
 import json
-import os
-import psutil
-import requests
 import signal
-import shutil
-import subprocess
 import time
 import unittest
-import logging
+import requests
+import psutil
+from common import test_utils
+
 
 class TransportPCEtesting(unittest.TestCase):
 
-    honeynode_process1 = None
-    honeynode_process2 = None
-    odl_process = None
+    processes = None
     restconf_baseurl = "http://localhost:8181/restconf"
 
-#START_IGNORE_XTESTING
-
-    @classmethod
-    def __start_honeynode1(cls):
-        executable = ("./honeynode/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, "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"
-                      "/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):
-        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)
+        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.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()
+        for process in cls.processes:
+            test_utils.shutdown_process(process)
+        print("all processes killed")
 
     def setUp(self):
         time.sleep(10)
 
-#END_IGNORE_XTESTING
-
-    #Connect the ROADMA
+    # Connect the ROADMA
     def test_01_connect_rdm(self):
-        #Config ROADMA
+        # Config ROADMA
         url = ("{}/config/network-topology:"
-                "network-topology/topology/topology-netconf/node/ROADMA"
+               "network-topology/topology/topology-netconf/node/ROADMA01"
                .format(self.restconf_baseurl))
         data = {"node": [{
-             "node-id": "ROADMA",
-             "netconf-node-topology:username": "admin",
-             "netconf-node-topology:password": "admin",
-             "netconf-node-topology:host": "127.0.0.1",
-             "netconf-node-topology:port": "17831",
-             "netconf-node-topology:tcp-only": "false",
-             "netconf-node-topology:pass-through": {}}]}
+            "node-id": "ROADMA01",
+            "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'))
+            "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
+    # 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))
+                   .format(self.restconf_baseurl))
         headers = {'content-type': 'application/json'}
-        responseTopo = requests.request(
-            "GET", urlTopo, headers=headers, auth=('admin', 'admin'))
+        responseTopo = requests.request("GET", urlTopo, headers=headers, auth=('admin', 'admin'))
         resTopo = responseTopo.json()
         nbNode = len(resTopo['network'][0]['node'])
         nbMapCumul = 0
@@ -126,8 +73,7 @@ class TransportPCEtesting(unittest.TestCase):
             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'))
+            responseMapList = requests.request("GET", urlMapListFull, headers=headers, auth=('admin', 'admin'))
             resMapList = responseMapList.json()
 
             nbMappings = len(resMapList['nodes'][0]['mapping']) - nbMapCumul
@@ -136,59 +82,58 @@ class TransportPCEtesting(unittest.TestCase):
             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):
+                    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
+    # Disconnect the ROADMA
     def test_03_disconnect_rdm(self):
         url = ("{}/config/network-topology:"
-                "network-topology/topology/topology-netconf/node/ROADMA"
+               "network-topology/topology/topology-netconf/node/ROADMA01"
                .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)
 
 #     #Connect the XPDRA
     def test_04_connect_xpdr(self):
-         #Config XPDRA
-         url = ("{}/config/network-topology:"
-                 "network-topology/topology/topology-netconf/node/XPDRA"
-                .format(self.restconf_baseurl))
-         data = {"node": [{
-              "node-id": "XPDRA",
-              "netconf-node-topology:username": "admin",
-              "netconf-node-topology:password": "admin",
-              "netconf-node-topology:host": "127.0.0.1",
-              "netconf-node-topology:port": "17830",
-              "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)
+        Config XPDRA
+        url = ("{}/config/network-topology:"
+               "network-topology/topology/topology-netconf/node/XPDRA01"
+               .format(self.restconf_baseurl))
+        data = {"node": [{
+            "node-id": "XPDRA01",
+            "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)
 
 #     #Verify the termination points related to XPDR
     def test_05_compareOpenroadmTopologyPortMapping_xpdr(self):
         self.test_02_compareOpenroadmTopologyPortMapping_rdm()
 
-    #Disconnect the XPDRA
+    # Disconnect the XPDRA
     def test_06_disconnect_device(self):
         url = ("{}/config/network-topology:"
-               "network-topology/topology/topology-netconf/node/XPDRA"
-              .format(self.restconf_baseurl))
+               "network-topology/topology/topology-netconf/node/XPDRA01"
+               .format(self.restconf_baseurl))
         data = {}
         headers = {'content-type': 'application/json'}
         response = requests.request(
@@ -196,7 +141,8 @@ class TransportPCEtesting(unittest.TestCase):
             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.basicConfig(filename='./transportpce_tests/log/response.log',filemode='w',level=logging.DEBUG)
     #logging.debug('I am there')
     unittest.main(verbosity=2)