replace portmapping FNV1-128 by FNV1-64 + Base64
[transportpce.git] / tests / transportpce_tests / 2.2.1 / test_portmapping.py
index f532c4e231f10e64b20a93a2400554a1070a4195..73015c209a00a904ccacd1589a696a26fc60750b 100644 (file)
@@ -9,22 +9,15 @@
 # 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 test_utils
+import time
+import requests
+from common import test_utils
 
 
 class TransportPCEPortMappingTesting(unittest.TestCase):
 
     processes = None
-    restconf_baseurl = "http://localhost:8181/restconf"
 
     @classmethod
     def setUpClass(cls):
@@ -41,32 +34,16 @@ class TransportPCEPortMappingTesting(unittest.TestCase):
         print("execution of {}".format(self.id().split(".")[-1]))
         time.sleep(10)
 
-    def test_01_rdm_device_connected(self):
-        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": 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'))
-        self.assertEqual(response.status_code, requests.codes.created)
-        time.sleep(20)
+    def test_01_rdm_device_connection(self):
+        response = test_utils.mount_device("ROADM-A1", 'roadma')
+        self.assertEqual(response.status_code, requests.codes.created, test_utils.CODE_SHOULD_BE_201)
 
     def test_02_rdm_device_connected(self):
         url = ("{}/operational/network-topology:"
                "network-topology/topology/topology-netconf/node/ROADM-A1"
-               .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(
@@ -77,10 +54,9 @@ class TransportPCEPortMappingTesting(unittest.TestCase):
     def test_03_rdm_portmapping_info(self):
         url = ("{}/config/transportpce-portmapping:network/"
                "nodes/ROADM-A1/node-info"
-               .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(
@@ -95,10 +71,9 @@ class TransportPCEPortMappingTesting(unittest.TestCase):
     def test_04_rdm_portmapping_DEG1_TTP_TXRX(self):
         url = ("{}/config/transportpce-portmapping:network/"
                "nodes/ROADM-A1/mapping/DEG1-TTP-TXRX"
-               .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.assertIn(
@@ -109,10 +84,9 @@ class TransportPCEPortMappingTesting(unittest.TestCase):
     def test_05_rdm_portmapping_DEG2_TTP_TXRX_with_ots_oms(self):
         url = ("{}/config/transportpce-portmapping:network/"
                "nodes/ROADM-A1/mapping/DEG2-TTP-TXRX"
-               .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.assertIn(
@@ -125,10 +99,9 @@ class TransportPCEPortMappingTesting(unittest.TestCase):
     def test_06_rdm_portmapping_SRG1_PP3_TXRX(self):
         url = ("{}/config/transportpce-portmapping:network/"
                "nodes/ROADM-A1/mapping/SRG1-PP3-TXRX"
-               .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.assertIn(
@@ -139,10 +112,9 @@ class TransportPCEPortMappingTesting(unittest.TestCase):
     def test_07_rdm_portmapping_SRG3_PP1_TXRX(self):
         url = ("{}/config/transportpce-portmapping:network/"
                "nodes/ROADM-A1/mapping/SRG3-PP1-TXRX"
-               .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.assertIn(
@@ -150,32 +122,16 @@ class TransportPCEPortMappingTesting(unittest.TestCase):
              'logical-connection-point': 'SRG3-PP1-TXRX', 'port-direction': 'bidirectional'},
             res['mapping'])
 
-    def test_08_xpdr_device_connected(self):
-        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": 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)
+    def test_08_xpdr_device_connection(self):
+        response = test_utils.mount_device("XPDR-A1", 'xpdra')
+        self.assertEqual(response.status_code, requests.codes.created, test_utils.CODE_SHOULD_BE_201)
 
     def test_09_xpdr_device_connected(self):
         url = ("{}/operational/network-topology:"
                "network-topology/topology/topology-netconf/node/XPDR-A1"
-               .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(
@@ -186,10 +142,9 @@ class TransportPCEPortMappingTesting(unittest.TestCase):
     def test_10_xpdr_portmapping_info(self):
         url = ("{}/config/transportpce-portmapping:network/"
                "nodes/XPDR-A1/node-info"
-               .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(
@@ -204,10 +159,9 @@ class TransportPCEPortMappingTesting(unittest.TestCase):
     def test_11_xpdr_portmapping_NETWORK1(self):
         url = ("{}/config/transportpce-portmapping:network/"
                "nodes/XPDR-A1/mapping/XPDR1-NETWORK1"
-               .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.assertIn(
@@ -215,16 +169,15 @@ class TransportPCEPortMappingTesting(unittest.TestCase):
              'supporting-port': '1', 'supporting-circuit-pack-name': '1/0/1-PLUG-NET',
              'logical-connection-point': 'XPDR1-NETWORK1', 'port-qual': 'xpdr-network',
              'port-direction': 'bidirectional', 'connection-map-lcp': 'XPDR1-CLIENT1',
-             'lcp-hash-val': '8e128ba57560403cfd4ffafae38cd941'},
+             'lcp-hash-val': 'e54EtOovlcE='},
             res['mapping'])
 
     def test_12_xpdr_portmapping_NETWORK2(self):
         url = ("{}/config/transportpce-portmapping:network/"
                "nodes/XPDR-A1/mapping/XPDR1-NETWORK2"
-               .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.assertIn(
@@ -232,16 +185,15 @@ class TransportPCEPortMappingTesting(unittest.TestCase):
              'supporting-port': '1', 'supporting-circuit-pack-name': '1/0/2-PLUG-NET',
              'logical-connection-point': 'XPDR1-NETWORK2', 'port-direction': 'bidirectional',
              'connection-map-lcp': 'XPDR1-CLIENT2', 'port-qual': 'xpdr-network',
-             'lcp-hash-val': '8e128ba57560403cfd4ffafae38cd942'},
+             'lcp-hash-val': 'e54EtOovlcI='},
             res['mapping'])
 
     def test_13_xpdr_portmapping_CLIENT1(self):
         url = ("{}/config/transportpce-portmapping:network/"
                "nodes/XPDR-A1/mapping/XPDR1-CLIENT1"
-               .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.assertIn(
@@ -250,16 +202,15 @@ class TransportPCEPortMappingTesting(unittest.TestCase):
              'supporting-circuit-pack-name': '1/0/1-PLUG-CLIENT',
              'logical-connection-point': 'XPDR1-CLIENT1', 'port-direction': 'bidirectional',
              'connection-map-lcp': 'XPDR1-NETWORK1', 'port-qual': 'xpdr-client',
-             'lcp-hash-val': '3ed8ed1336784ac7c2f66c22f2f03d8'},
+             'lcp-hash-val': 'BIyxYXnFEFA='},
             res['mapping'])
 
     def test_14_xpdr_portmapping_CLIENT2(self):
         url = ("{}/config/transportpce-portmapping:network/"
                "nodes/XPDR-A1/mapping/XPDR1-CLIENT2"
-               .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.assertIn(
@@ -268,26 +219,18 @@ class TransportPCEPortMappingTesting(unittest.TestCase):
              'supporting-circuit-pack-name': '1/0/2-PLUG-CLIENT',
              'logical-connection-point': 'XPDR1-CLIENT2', 'port-direction': 'bidirectional',
              'connection-map-lcp': 'XPDR1-NETWORK2', 'port-qual': 'xpdr-client',
-             'lcp-hash-val': '3ed8ed1336784ac7c2f66c22f2f03db'},
+             'lcp-hash-val': 'BIyxYXnFEFM='},
             res['mapping'])
 
-    def test_15_xpdr_device_disconnected(self):
-        url = ("{}/config/network-topology:"
-               "network-topology/topology/topology-netconf/node/XPDR-A1"
-               .format(self.restconf_baseurl))
-        headers = {'content-type': 'application/json'}
-        response = requests.request(
-            "DELETE", url, headers=headers,
-            auth=('admin', 'admin'))
-        self.assertEqual(response.status_code, requests.codes.ok)
-        time.sleep(20)
+    def test_15_xpdr_device_disconnection(self):
+        response = test_utils.unmount_device("XPDR-A1")
+        self.assertEqual(response.status_code, requests.codes.ok, test_utils.CODE_SHOULD_BE_200)
 
     def test_16_xpdr_device_disconnected(self):
         url = ("{}/operational/network-topology:network-topology/topology/"
-               "topology-netconf/node/XPDR-A1".format(self.restconf_baseurl))
-        headers = {'content-type': 'application/json'}
+               "topology-netconf/node/XPDR-A1".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.not_found)
         res = response.json()
         self.assertIn(
@@ -295,11 +238,10 @@ class TransportPCEPortMappingTesting(unittest.TestCase):
              "error-message": "Request could not be completed because the relevant data model content does not exist"},
             res['errors']['error'])
 
-    def test_17_xpdr_device_disconnected(self):
-        url = ("{}/config/transportpce-portmapping:network/nodes/XPDR-A1".format(self.restconf_baseurl))
-        headers = {'content-type': 'application/json'}
+    def test_17_xpdr_device_not_connected(self):
+        url = ("{}/config/transportpce-portmapping:network/nodes/XPDR-A1".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.not_found)
         res = response.json()
         self.assertIn(
@@ -307,22 +249,15 @@ class TransportPCEPortMappingTesting(unittest.TestCase):
              "error-message": "Request could not be completed because the relevant data model content does not exist"},
             res['errors']['error'])
 
-    def test_18_rdm_device_disconnected(self):
-        url = ("{}/config/network-topology:network-topology/topology/topology-netconf/node/ROADM-A1"
-               .format(self.restconf_baseurl))
-        headers = {'content-type': 'application/json'}
-        response = requests.request(
-            "DELETE", url, headers=headers,
-            auth=('admin', 'admin'))
-        self.assertEqual(response.status_code, requests.codes.ok)
-        time.sleep(20)
+    def test_18_rdm_device_disconnection(self):
+        response = test_utils.unmount_device("ROADM-A1")
+        self.assertEqual(response.status_code, requests.codes.ok, test_utils.CODE_SHOULD_BE_200)
 
     def test_19_rdm_device_disconnected(self):
         url = ("{}/operational/network-topology:network-topology/topology/topology-netconf/node/ROADM-A1"
-               .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.not_found)
         res = response.json()
         self.assertIn(
@@ -330,11 +265,10 @@ class TransportPCEPortMappingTesting(unittest.TestCase):
              "error-message": "Request could not be completed because the relevant data model content does not exist"},
             res['errors']['error'])
 
-    def test_20_rdm_device_disconnected(self):
-        url = ("{}/config/transportpce-portmapping:network/nodes/ROADM-A1".format(self.restconf_baseurl))
-        headers = {'content-type': 'application/json'}
+    def test_20_rdm_device_not_connected(self):
+        url = ("{}/config/transportpce-portmapping:network/nodes/ROADM-A1".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.not_found)
         res = response.json()
         self.assertIn(