Migrate portmapping functional tests to RFC8040
[transportpce.git] / tests / transportpce_tests / 1.2.1 / test02_topo_portmapping.py
1 #!/usr/bin/env python
2
3 ##############################################################################
4 # Copyright (c) 2017 Orange, Inc. and others.  All rights reserved.
5 #
6 # All rights reserved. This program and the accompanying materials
7 # are made available under the terms of the Apache License, Version 2.0
8 # which accompanies this distribution, and is available at
9 # http://www.apache.org/licenses/LICENSE-2.0
10 ##############################################################################
11
12 # pylint: disable=no-member
13 # pylint: disable=too-many-public-methods
14 # a pylint false positive due to unittest
15 # pylint: disable=no-self-use
16
17 import time
18 import unittest
19 import requests
20 import sys
21 sys.path.append('transportpce_tests/common/')
22 import test_utils_rfc8040  # nopep8
23
24
25 class TransportPCEtesting(unittest.TestCase):
26
27     processes = None
28     NODE_VERSION = '1.2.1'
29
30     @classmethod
31     def setUpClass(cls):
32         cls.processes = test_utils_rfc8040.start_tpce()
33         cls.processes = test_utils_rfc8040.start_sims([('xpdra', cls.NODE_VERSION), ('roadma', cls.NODE_VERSION)])
34
35     @classmethod
36     def tearDownClass(cls):
37         # pylint: disable=not-an-iterable
38         for process in cls.processes:
39             test_utils_rfc8040.shutdown_process(process)
40         print("all processes killed")
41
42     def setUp(self):
43         time.sleep(10)
44
45     # Connect the ROADMA
46     def test_01_connect_rdm(self):
47         response = test_utils_rfc8040.mount_device("ROADMA01", ('roadma', self.NODE_VERSION))
48         self.assertEqual(response.status_code, requests.codes.created, test_utils_rfc8040.CODE_SHOULD_BE_201)
49
50     # Verify the termination points of the ROADMA
51     def test_02_compare_Openroadm_topology_portmapping_rdm(self):
52         responseTopo = test_utils_rfc8040.get_request(test_utils_rfc8040.URL_CONFIG_ORDM_TOPO)
53         resTopo = responseTopo.json()
54         firstEntry = resTopo['ietf-network:network'][0]['node']
55         for i in range(0, len(firstEntry)):
56             nodeId = firstEntry[i]['node-id']
57             nodeMapId = nodeId.split("-")[0]
58             response = test_utils_rfc8040.get_portmapping_node_info(nodeMapId)
59             self.assertEqual(response['status_code'], requests.codes.ok)
60             nbTp = len(firstEntry[i]['ietf-network-topology:termination-point'])
61             for j in range(0, nbTp):
62                 tpId = firstEntry[i]['ietf-network-topology:termination-point'][j]['tp-id']
63                 if((not "CP" in tpId) and (not "CTP" in tpId)):
64                     response2 = test_utils_rfc8040.portmapping_request(nodeMapId, tpId)
65                     self.assertEqual(response2['status_code'], requests.codes.ok)
66
67     # Disconnect the ROADMA
68     def test_03_disconnect_rdm(self):
69         response = test_utils_rfc8040.unmount_device("ROADMA01")
70         self.assertIn(response.status_code, (requests.codes.ok, requests.codes.no_content))
71
72 #     #Connect the XPDRA
73     def test_04_connect_xpdr(self):
74         response = test_utils_rfc8040.mount_device("XPDRA01", ('xpdra', self.NODE_VERSION))
75         self.assertEqual(response.status_code, requests.codes.created, test_utils_rfc8040.CODE_SHOULD_BE_201)
76
77 #     #Verify the termination points related to XPDR
78     def test_05_compare_Openroadm_topology_portmapping_xpdr(self):
79         self.test_02_compare_Openroadm_topology_portmapping_rdm()
80
81     # Disconnect the XPDRA
82     def test_06_disconnect_device(self):
83         response = test_utils_rfc8040.unmount_device("XPDRA01")
84         self.assertIn(response.status_code, (requests.codes.ok, requests.codes.no_content))
85
86
87 if __name__ == "__main__":
88     # logging.basicConfig(filename='./transportpce_tests/log/response.log',filemode='w',level=logging.DEBUG)
89     #logging.debug('I am there')
90     unittest.main(verbosity=2)