Speed up functional tests execution
[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
16 import time
17 import unittest
18 import requests
19 # pylint: disable=wrong-import-order
20 import sys
21 sys.path.append('transportpce_tests/common/')
22 # pylint: disable=wrong-import-position
23 # pylint: disable=import-error
24 import test_utils  # nopep8
25
26
27 class TransportPCEtesting(unittest.TestCase):
28
29     processes = None
30     NODE_VERSION = '1.2.1'
31
32     @classmethod
33     def setUpClass(cls):
34         cls.processes = test_utils.start_tpce()
35         cls.processes = test_utils.start_sims([('xpdra', cls.NODE_VERSION), ('roadma', cls.NODE_VERSION)])
36
37     @classmethod
38     def tearDownClass(cls):
39         # pylint: disable=not-an-iterable
40         for process in cls.processes:
41             test_utils.shutdown_process(process)
42         print("all processes killed")
43
44     def setUp(self):
45         time.sleep(2)
46
47     # Connect the ROADMA
48     def test_01_connect_rdm(self):
49         response = test_utils.mount_device("ROADMA01", ('roadma', self.NODE_VERSION))
50         self.assertEqual(response.status_code, requests.codes.created, test_utils.CODE_SHOULD_BE_201)
51
52     # Verify the termination points of the ROADMA
53     def test_02_compare_Openroadm_topology_portmapping_rdm(self):
54         resTopo = test_utils.get_ietf_network_request('openroadm-topology', 'config')
55         self.assertEqual(resTopo['status_code'], requests.codes.ok)
56         for node in resTopo['network'][0]['node']:
57             nodeId = node['node-id']
58             nodeMapId = nodeId.split("-")[0]
59             response = test_utils.get_portmapping_node_attr(nodeMapId, "node-info", None)
60             self.assertEqual(response['status_code'], requests.codes.ok)
61             for tp in node['ietf-network-topology:termination-point']:
62                 tpId = tp['tp-id']
63                 if (not "CP" in tpId) and (not "CTP" in tpId):
64                     response2 = test_utils.get_portmapping_node_attr(nodeMapId, "mapping", 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.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.mount_device("XPDRA01", ('xpdra', self.NODE_VERSION))
75         self.assertEqual(response.status_code, requests.codes.created, test_utils.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.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)