Set port states in portMapping
[transportpce.git] / tests / transportpce_tests / 2.2.1 / test_portmapping.py
index de1dbcfc8eccdbf23de45e6c2f19a3a1042974b9..831cf0d99c514285deee720d23b7b3578025d5cd 100644 (file)
 # http://www.apache.org/licenses/LICENSE-2.0
 ##############################################################################
 
-import json
-import os
-import psutil
-import requests
-import signal
-import shutil
-import subprocess
-import time
+# pylint: disable=no-member
+# pylint: disable=too-many-public-methods
+
 import unittest
+import time
+import requests
+from common import test_utils
 
 
 class TransportPCEPortMappingTesting(unittest.TestCase):
 
-    honeynode_process1 = None
-    honeynode_process2 = None
-    odl_process = None
-    restconf_baseurl = "http://localhost:8181/restconf"
-
-    @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))
+    processes = None
 
     @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()
+        # pylint: disable=not-an-iterable
+        for process in cls.processes:
+            test_utils.shutdown_process(process)
+        print("all processes killed")
 
     def setUp(self):
-        print ("execution of {}".format(self.id().split(".")[-1]))
+        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": "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)
+    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'}
-        response = requests.request(
-            "GET", url, headers=headers, auth=('admin', 'admin'))
+        response = test_utils.get_netconf_oper_request("ROADM-A1")
         self.assertEqual(response.status_code, requests.codes.ok)
         res = response.json()
         self.assertEqual(
@@ -119,89 +51,67 @@ class TransportPCEPortMappingTesting(unittest.TestCase):
             'connected')
         time.sleep(10)
 
-    def test_03_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'}
-        response = requests.request(
-            "GET", url, headers=headers, auth=('admin', 'admin'))
+    def test_03_rdm_portmapping_info(self):
+        response = test_utils.portmapping_request("ROADM-A1/node-info")
+        self.assertEqual(response.status_code, requests.codes.ok)
+        res = response.json()
+        self.assertEqual(
+            {u'node-info': {u'node-type': u'rdm',
+                            u'node-ip-address': u'127.0.0.11',
+                            u'node-clli': u'NodeA',
+                            u'openroadm-version': u'2.2.1', u'node-vendor': u'vendorA',
+                            u'node-model': u'model2'}},
+            res)
+        time.sleep(3)
+
+    def test_04_rdm_portmapping_DEG1_TTP_TXRX(self):
+        response = test_utils.portmapping_request("ROADM-A1/mapping/DEG1-TTP-TXRX")
         self.assertEqual(response.status_code, requests.codes.ok)
         res = response.json()
         self.assertIn(
             {'supporting-port': 'L1', 'supporting-circuit-pack-name': '1/0',
-             'logical-connection-point': 'DEG1-TTP-TXRX'},
+             'logical-connection-point': 'DEG1-TTP-TXRX', 'port-direction': 'bidirectional',
+             'port-admin-state': 'InService', 'port-oper-state': 'InService'},
             res['mapping'])
 
-    def test_04_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'}
-        response = requests.request(
-            "GET", url, headers=headers, auth=('admin', 'admin'))
+    def test_05_rdm_portmapping_DEG2_TTP_TXRX_with_ots_oms(self):
+        response = test_utils.portmapping_request("ROADM-A1/mapping/DEG2-TTP-TXRX")
         self.assertEqual(response.status_code, requests.codes.ok)
         res = response.json()
         self.assertIn(
             {'supporting-port': 'L1', 'supporting-circuit-pack-name': '2/0',
              'logical-connection-point': 'DEG2-TTP-TXRX',
-             'supporting-oms': 'OMS-DEG2-TTP-TXRX', 'supporting-ots': 'OTS-DEG2-TTP-TXRX'},
+             'supporting-oms': 'OMS-DEG2-TTP-TXRX', 'supporting-ots': 'OTS-DEG2-TTP-TXRX',
+             'port-direction': 'bidirectional',
+             'port-admin-state': 'InService', 'port-oper-state': 'InService'},
             res['mapping'])
 
-    def test_05_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'}
-        response = requests.request(
-            "GET", url, headers=headers, auth=('admin', 'admin'))
+    def test_06_rdm_portmapping_SRG1_PP3_TXRX(self):
+        response = test_utils.portmapping_request("ROADM-A1/mapping/SRG1-PP3-TXRX")
         self.assertEqual(response.status_code, requests.codes.ok)
         res = response.json()
         self.assertIn(
             {'supporting-port': 'C3', 'supporting-circuit-pack-name': '3/0',
-             'logical-connection-point': 'SRG1-PP3-TXRX'},
+             'logical-connection-point': 'SRG1-PP3-TXRX', 'port-direction': 'bidirectional',
+             'port-admin-state': 'InService', 'port-oper-state': 'InService'},
             res['mapping'])
 
-    def test_06_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'}
-        response = requests.request(
-            "GET", url, headers=headers, auth=('admin', 'admin'))
+    def test_07_rdm_portmapping_SRG3_PP1_TXRX(self):
+        response = test_utils.portmapping_request("ROADM-A1/mapping/SRG3-PP1-TXRX")
         self.assertEqual(response.status_code, requests.codes.ok)
         res = response.json()
         self.assertIn(
             {'supporting-port': 'C1', 'supporting-circuit-pack-name': '5/0',
-             'logical-connection-point': 'SRG3-PP1-TXRX'},
+             'logical-connection-point': 'SRG3-PP1-TXRX', 'port-direction': 'bidirectional',
+             'port-admin-state': 'InService', 'port-oper-state': 'InService'},
             res['mapping'])
 
-    def test_07_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": "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)
+    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_08_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'}
-        response = requests.request(
-            "GET", url, headers=headers, auth=('admin', 'admin'))
+    def test_09_xpdr_device_connected(self):
+        response = test_utils.get_netconf_oper_request("XPDR-A1")
         self.assertEqual(response.status_code, requests.codes.ok)
         res = response.json()
         self.assertEqual(
@@ -209,133 +119,115 @@ class TransportPCEPortMappingTesting(unittest.TestCase):
             'connected')
         time.sleep(10)
 
-    def test_09_xpdr_portmapping_NETWORK1(self):
-        url = ("{}/config/transportpce-portmapping:network/"
-               "nodes/XPDR-A1/mapping/XPDR1-NETWORK1"
-               .format(self.restconf_baseurl))
-        headers = {'content-type': 'application/json'}
-        response = requests.request(
-            "GET", url, headers=headers, auth=('admin', 'admin'))
+    def test_10_xpdr_portmapping_info(self):
+        response = test_utils.portmapping_request("XPDR-A1/node-info")
+        self.assertEqual(response.status_code, requests.codes.ok)
+        res = response.json()
+        self.assertEqual(
+            {u'node-info': {u'node-type': u'xpdr',
+                            u'node-ip-address': u'1.2.3.4',
+                            u'node-clli': u'NodeA',
+                            u'openroadm-version': u'2.2.1', u'node-vendor': u'vendorA',
+                            u'node-model': u'model2'}},
+            res)
+        time.sleep(3)
+
+    def test_11_xpdr_portmapping_NETWORK1(self):
+        response = test_utils.portmapping_request("XPDR-A1/mapping/XPDR1-NETWORK1")
         self.assertEqual(response.status_code, requests.codes.ok)
         res = response.json()
         self.assertIn(
-            {'supporting-port': '1', 'supporting-circuit-pack-name': '1/0/1-PLUG-NET',
-             'logical-connection-point': 'XPDR1-NETWORK1'},
+            {'supported-interface-capability': ['org-openroadm-port-types:if-OCH'],
+             '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': 'AMkDwQ7xTmRI',
+             'port-admin-state': 'InService', 'port-oper-state': 'InService'},
             res['mapping'])
 
-    def test_10_xpdr_portmapping_NETWORK2(self):
-        url = ("{}/config/transportpce-portmapping:network/"
-               "nodes/XPDR-A1/mapping/XPDR1-NETWORK2"
-               .format(self.restconf_baseurl))
-        headers = {'content-type': 'application/json'}
-        response = requests.request(
-            "GET", url, headers=headers, auth=('admin', 'admin'))
+    def test_12_xpdr_portmapping_NETWORK2(self):
+        response = test_utils.portmapping_request("XPDR-A1/mapping/XPDR1-NETWORK2")
         self.assertEqual(response.status_code, requests.codes.ok)
         res = response.json()
         self.assertIn(
-            {'supporting-port': '1', 'supporting-circuit-pack-name': '1/0/2-PLUG-NET',
-             'logical-connection-point': 'XPDR1-NETWORK2'},
+            {'supported-interface-capability': ['org-openroadm-port-types:if-OCH'],
+             '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': 'AMkDwQ7xTmRL',
+             'port-admin-state': 'InService', 'port-oper-state': 'InService'},
             res['mapping'])
 
-    def test_11_xpdr_portmapping_CLIENT1(self):
-        url = ("{}/config/transportpce-portmapping:network/"
-               "nodes/XPDR-A1/mapping/XPDR1-CLIENT1"
-               .format(self.restconf_baseurl))
-        headers = {'content-type': 'application/json'}
-        response = requests.request(
-            "GET", url, headers=headers, auth=('admin', 'admin'))
+    def test_13_xpdr_portmapping_CLIENT1(self):
+        response = test_utils.portmapping_request("XPDR-A1/mapping/XPDR1-CLIENT1")
         self.assertEqual(response.status_code, requests.codes.ok)
         res = response.json()
         self.assertIn(
-            {'supporting-port': 'C1',
+            {'supported-interface-capability': ['org-openroadm-port-types:if-100GE'],
+             'supporting-port': 'C1',
              'supporting-circuit-pack-name': '1/0/1-PLUG-CLIENT',
-             'logical-connection-point': 'XPDR1-CLIENT1'},
+             'logical-connection-point': 'XPDR1-CLIENT1', 'port-direction': 'bidirectional',
+             'connection-map-lcp': 'XPDR1-NETWORK1', 'port-qual': 'xpdr-client',
+             'lcp-hash-val': 'AJUUr6I5fALj',
+             'port-admin-state': 'InService', 'port-oper-state': 'InService'},
             res['mapping'])
 
-    def test_12_xpdr_portmapping_CLIENT2(self):
-        url = ("{}/config/transportpce-portmapping:network/"
-               "nodes/XPDR-A1/mapping/XPDR1-CLIENT2"
-               .format(self.restconf_baseurl))
-        headers = {'content-type': 'application/json'}
-        response = requests.request(
-            "GET", url, headers=headers, auth=('admin', 'admin'))
+    def test_14_xpdr_portmapping_CLIENT2(self):
+        response = test_utils.portmapping_request("XPDR-A1/mapping/XPDR1-CLIENT2")
         self.assertEqual(response.status_code, requests.codes.ok)
         res = response.json()
         self.assertIn(
-            {'supporting-port': 'C1',
-                 'supporting-circuit-pack-name': '1/0/2-PLUG-CLIENT',
-                 'logical-connection-point': 'XPDR1-CLIENT2'},
+            {'supported-interface-capability': ['org-openroadm-port-types:if-100GE'],
+             'supporting-port': 'C1',
+             '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': 'AJUUr6I5fALg',
+             'port-admin-state': 'InService', 'port-oper-state': 'InService'},
             res['mapping'])
 
-    def test_13_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_14_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'}
-        response = requests.request(
-            "GET", url, headers=headers, auth=('admin', 'admin'))
-        self.assertEqual(response.status_code, requests.codes.not_found)
+    def test_16_xpdr_device_disconnected(self):
+        response = test_utils.get_netconf_oper_request("XPDR-A1")
+        self.assertEqual(response.status_code, requests.codes.conflict)
         res = response.json()
         self.assertIn(
-            {"error-type":"application", "error-tag":"data-missing",
-             "error-message":"Request could not be completed because the relevant data model content does not exist"},
+            {"error-type": "application", "error-tag": "data-missing",
+             "error-message": "Request could not be completed because the relevant data model content does not exist"},
             res['errors']['error'])
 
-    def test_15_xpdr_device_disconnected(self):
-        url = ("{}/config/transportpce-portmapping:network/nodes/XPDR-A1".format(self.restconf_baseurl))
-        headers = {'content-type': 'application/json'}
-        response = requests.request(
-            "GET", url, headers=headers, auth=('admin', 'admin'))
-        self.assertEqual(response.status_code, requests.codes.not_found)
+    def test_17_xpdr_device_not_connected(self):
+        response = test_utils.portmapping_request("XPDR-A1")
+        self.assertEqual(response.status_code, requests.codes.conflict)
         res = response.json()
         self.assertIn(
-            {"error-type":"application", "error-tag":"data-missing",
-             "error-message":"Request could not be completed because the relevant data model content does not exist"},
+            {"error-type": "application", "error-tag": "data-missing",
+             "error-message": "Request could not be completed because the relevant data model content does not exist"},
             res['errors']['error'])
 
-    def test_16_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_17_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'}
-        response = requests.request(
-            "GET", url, headers=headers, auth=('admin', 'admin'))
-        self.assertEqual(response.status_code, requests.codes.not_found)
+    def test_19_rdm_device_disconnected(self):
+        response = test_utils.get_netconf_oper_request("ROADM-A1")
+        self.assertEqual(response.status_code, requests.codes.conflict)
         res = response.json()
         self.assertIn(
-            {"error-type":"application", "error-tag":"data-missing",
-             "error-message":"Request could not be completed because the relevant data model content does not exist"},
+            {"error-type": "application", "error-tag": "data-missing",
+             "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/transportpce-portmapping:network/nodes/ROADM-A1".format(self.restconf_baseurl))
-        headers = {'content-type': 'application/json'}
-        response = requests.request(
-            "GET", url, headers=headers, auth=('admin', 'admin'))
-        self.assertEqual(response.status_code, requests.codes.not_found)
+    def test_20_rdm_device_not_connected(self):
+        response = test_utils.portmapping_request("ROADM-A1")
+        self.assertEqual(response.status_code, requests.codes.conflict)
         res = response.json()
         self.assertIn(
-            {"error-type":"application", "error-tag":"data-missing",
-             "error-message":"Request could not be completed because the relevant data model content does not exist"},
+            {"error-type": "application", "error-tag": "data-missing",
+             "error-message": "Request could not be completed because the relevant data model content does not exist"},
             res['errors']['error'])