fix some pylint issues
[transportpce.git] / tests / transportpce_tests / 2.2.1 / test_otn_topology.py
index 7505306cc77dd58a9f4e3f0470c577364ca44cd2..97b6d4e9234fc832b872cccdf7fbf670577d4f10 100644 (file)
@@ -9,69 +9,41 @@
 # 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 time
 import logging
-import test_utils
+import requests
+from common import test_utils
 
 
 class TransportPCEtesting(unittest.TestCase):
 
-    sim_process1 = None
-    odl_process = None
-    restconf_baseurl = "http://localhost:8181/restconf"
+    processes = None
 
     @classmethod
     def setUpClass(cls):
-        cls.odl_process = test_utils.start_tpce()
-        cls.sim_process1 = test_utils.start_sim('spdrav2')
+        cls.processes = test_utils.start_tpce()
+        cls.processes = test_utils.start_sims(['spdrav2'])
 
     @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.sim_process1.pid).children():
-            child.send_signal(signal.SIGINT)
-            child.wait()
-        cls.sim_process1.send_signal(signal.SIGINT)
-        cls.sim_process1.wait()
+        for process in cls.processes:
+            test_utils.shutdown_process(process)
+        print("all processes killed")
 
     def setUp(self):
         time.sleep(5)
 
     def test_01_connect_SPDR_SA1(self):
-        url = ("{}/config/network-topology:"
-               "network-topology/topology/topology-netconf/node/SPDR-SA1"
-               .format(self.restconf_baseurl))
-        data = {"node": [{
-            "node-id": "SPDR-SA1",
-            "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['spdrav2']['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)
+        response = test_utils.mount_device("SPDR-SA1", 'spdrav2')
+        self.assertEqual(response.status_code, requests.codes.created, test_utils.CODE_SHOULD_BE_201)
         time.sleep(10)
+
         url = ("{}/operational/network-topology:"
                "network-topology/topology/topology-netconf/node/SPDR-SA1"
-               .format(self.restconf_baseurl))
+               .format(test_utils.RESTCONF_BASE_URL))
         response = requests.request(
-            "GET", url, headers=headers, auth=('admin', 'admin'))
+            "GET", url, headers=test_utils.TYPE_APPLICATION_JSON, auth=(test_utils.ODL_LOGIN, test_utils.ODL_PWD))
         self.assertEqual(response.status_code, requests.codes.ok)
         res = response.json()
         self.assertEqual(
@@ -80,10 +52,9 @@ class TransportPCEtesting(unittest.TestCase):
 
     def test_02_getClliNetwork(self):
         url = ("{}/config/ietf-network:networks/network/clli-network"
-               .format(self.restconf_baseurl))
-        headers = {'content-type': 'application/json'}
+               .format(test_utils.RESTCONF_BASE_URL))
         response = requests.request(
-            "GET", url, headers=headers, auth=('admin', 'admin'))
+            "GET", url, headers=test_utils.TYPE_APPLICATION_JSON, auth=(test_utils.ODL_LOGIN, test_utils.ODL_PWD))
         self.assertEqual(response.status_code, requests.codes.ok)
         res = response.json()
         logging.info(res)
@@ -92,10 +63,9 @@ class TransportPCEtesting(unittest.TestCase):
 
     def test_03_getOpenRoadmNetwork(self):
         url = ("{}/config/ietf-network:networks/network/openroadm-network"
-               .format(self.restconf_baseurl))
-        headers = {'content-type': 'application/json'}
+               .format(test_utils.RESTCONF_BASE_URL))
         response = requests.request(
-            "GET", url, headers=headers, auth=('admin', 'admin'))
+            "GET", url, headers=test_utils.TYPE_APPLICATION_JSON, auth=(test_utils.ODL_LOGIN, test_utils.ODL_PWD))
         self.assertEqual(response.status_code, requests.codes.ok)
         res = response.json()
         self.assertEqual(res['network'][0]['node'][0]['node-id'], 'SPDR-SA1')
@@ -108,10 +78,9 @@ class TransportPCEtesting(unittest.TestCase):
 
     def test_04_getLinks_OpenroadmTopology(self):
         url = ("{}/config/ietf-network:networks/network/openroadm-topology"
-               .format(self.restconf_baseurl))
-        headers = {'content-type': 'application/json'}
+               .format(test_utils.RESTCONF_BASE_URL))
         response = requests.request(
-            "GET", url, headers=headers, auth=('admin', 'admin'))
+            "GET", url, headers=test_utils.TYPE_APPLICATION_JSON, auth=(test_utils.ODL_LOGIN, test_utils.ODL_PWD))
         self.assertEqual(response.status_code, requests.codes.ok)
         res = response.json()
         # Tests related to links
@@ -119,10 +88,9 @@ class TransportPCEtesting(unittest.TestCase):
 
     def test_05_getNodes_OpenRoadmTopology(self):
         url = ("{}/config/ietf-network:networks/network/openroadm-topology"
-               .format(self.restconf_baseurl))
-        headers = {'content-type': 'application/json'}
+               .format(test_utils.RESTCONF_BASE_URL))
         response = requests.request(
-            "GET", url, headers=headers, auth=('admin', 'admin'))
+            "GET", url, headers=test_utils.TYPE_APPLICATION_JSON, auth=(test_utils.ODL_LOGIN, test_utils.ODL_PWD))
         res = response.json()
         # Tests related to nodes
         self.assertEqual(response.status_code, requests.codes.ok)
@@ -178,20 +146,18 @@ class TransportPCEtesting(unittest.TestCase):
 
     def test_06_getLinks_OtnTopology(self):
         url = ("{}/config/ietf-network:networks/network/otn-topology"
-               .format(self.restconf_baseurl))
-        headers = {'content-type': 'application/json'}
+               .format(test_utils.RESTCONF_BASE_URL))
         response = requests.request(
-            "GET", url, headers=headers, auth=('admin', 'admin'))
+            "GET", url, headers=test_utils.TYPE_APPLICATION_JSON, auth=(test_utils.ODL_LOGIN, test_utils.ODL_PWD))
         self.assertEqual(response.status_code, requests.codes.ok)
         res = response.json()
         self.assertNotIn('ietf-network-topology:link', res['network'][0])
 
     def test_07_getNodes_OtnTopology(self):
         url = ("{}/config/ietf-network:networks/network/otn-topology"
-               .format(self.restconf_baseurl))
-        headers = {'content-type': 'application/json'}
+               .format(test_utils.RESTCONF_BASE_URL))
         response = requests.request(
-            "GET", url, headers=headers, auth=('admin', 'admin'))
+            "GET", url, headers=test_utils.TYPE_APPLICATION_JSON, auth=(test_utils.ODL_LOGIN, test_utils.ODL_PWD))
         res = response.json()
         self.assertEqual(response.status_code, requests.codes.ok)
         nbNode = len(res['network'][0]['node'])
@@ -303,22 +269,14 @@ class TransportPCEtesting(unittest.TestCase):
         self.assertEqual(len(listNode), 0)
 
     def test_08_disconnect_SPDR_SA1(self):
-        url = ("{}/config/network-topology:"
-               "network-topology/topology/topology-netconf/node/SPDR-SA1"
-               .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)
+        response = test_utils.unmount_device("SPDR-SA1")
+        self.assertEqual(response.status_code, requests.codes.ok, test_utils.CODE_SHOULD_BE_200)
 
     def test_09_getClliNetwork(self):
         url = ("{}/config/ietf-network:networks/network/clli-network"
-               .format(self.restconf_baseurl))
-        headers = {'content-type': 'application/json'}
+               .format(test_utils.RESTCONF_BASE_URL))
         response = requests.request(
-            "GET", url, headers=headers, auth=('admin', 'admin'))
+            "GET", url, headers=test_utils.TYPE_APPLICATION_JSON, auth=(test_utils.ODL_LOGIN, test_utils.ODL_PWD))
         self.assertEqual(response.status_code, requests.codes.ok)
         res = response.json()
         nbNode = len(res['network'][0]['node'])
@@ -327,29 +285,26 @@ class TransportPCEtesting(unittest.TestCase):
 
     def test_10_getOpenRoadmNetwork(self):
         url = ("{}/config/ietf-network:networks/network/openroadm-network"
-               .format(self.restconf_baseurl))
-        headers = {'content-type': 'application/json'}
+               .format(test_utils.RESTCONF_BASE_URL))
         response = requests.request(
-            "GET", url, headers=headers, auth=('admin', 'admin'))
+            "GET", url, headers=test_utils.TYPE_APPLICATION_JSON, auth=(test_utils.ODL_LOGIN, test_utils.ODL_PWD))
         self.assertEqual(response.status_code, requests.codes.ok)
         res = response.json()
         self.assertNotIn('node', res['network'][0])
 
     def test_11_getNodes_OpenRoadmTopology(self):
         url = ("{}/config/ietf-network:networks/network/openroadm-topology"
-               .format(self.restconf_baseurl))
-        headers = {'content-type': 'application/json'}
+               .format(test_utils.RESTCONF_BASE_URL))
         response = requests.request(
-            "GET", url, headers=headers, auth=('admin', 'admin'))
+            "GET", url, headers=test_utils.TYPE_APPLICATION_JSON, auth=(test_utils.ODL_LOGIN, test_utils.ODL_PWD))
         res = response.json()
         self.assertNotIn('node', res['network'][0])
 
     def test_12_getNodes_OtnTopology(self):
         url = ("{}/config/ietf-network:networks/network/otn-topology"
-               .format(self.restconf_baseurl))
-        headers = {'content-type': 'application/json'}
+               .format(test_utils.RESTCONF_BASE_URL))
         response = requests.request(
-            "GET", url, headers=headers, auth=('admin', 'admin'))
+            "GET", url, headers=test_utils.TYPE_APPLICATION_JSON, auth=(test_utils.ODL_LOGIN, test_utils.ODL_PWD))
         res = response.json()
         self.assertNotIn('node', res['network'][0])