fix some pylint issues
[transportpce.git] / tests / transportpce_tests / 1.2.1 / test_topoPortMapping.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 import time
13 import unittest
14 import requests
15 from common import test_utils
16
17
18 class TransportPCEtesting(unittest.TestCase):
19
20     processes = None
21
22     @classmethod
23     def setUpClass(cls):
24         cls.processes = test_utils.start_tpce()
25         cls.processes = test_utils.start_sims(['xpdra', 'roadma'])
26
27     @classmethod
28     def tearDownClass(cls):
29         for process in cls.processes:
30             test_utils.shutdown_process(process)
31         print("all processes killed")
32
33     def setUp(self):
34         time.sleep(10)
35
36     # Connect the ROADMA
37     def test_01_connect_rdm(self):
38         response = test_utils.mount_device("ROADMA01", 'roadma')
39         self.assertEqual(response.status_code, requests.codes.created, test_utils.CODE_SHOULD_BE_201)
40
41     # Verify the termination points of the ROADMA
42     def test_02_compareOpenroadmTopologyPortMapping_rdm(self):
43         urlTopo = ("{}/config/ietf-network:networks/network/openroadm-topology"
44                    .format(test_utils.RESTCONF_BASE_URL))
45         responseTopo = requests.request("GET", urlTopo, headers=test_utils.TYPE_APPLICATION_JSON,
46                                         auth=(test_utils.ODL_LOGIN, test_utils.ODL_PWD))
47         resTopo = responseTopo.json()
48         nbNode = len(resTopo['network'][0]['node'])
49         nbMapCumul = 0
50         nbMappings = 0
51         for i in range(0, nbNode):
52             nodeId = resTopo['network'][0]['node'][i]['node-id']
53             nodeMapId = nodeId.split("-")[0]
54             urlMapList = "{}/config/transportpce-portmapping:network/nodes/" + nodeMapId
55             urlMapListFull = urlMapList.format(test_utils.RESTCONF_BASE_URL)
56             responseMapList = requests.request("GET", urlMapListFull, headers=test_utils.TYPE_APPLICATION_JSON,
57                                                auth=(test_utils.ODL_LOGIN, test_utils.ODL_PWD))
58             resMapList = responseMapList.json()
59
60             nbMappings = len(resMapList['nodes'][0]['mapping']) - nbMapCumul
61             nbTp = len(resTopo['network'][0]['node'][i]['ietf-network-topology:termination-point'])
62             nbMapCurrent = 0
63             for j in range(0, nbTp):
64                 tpId = resTopo['network'][0]['node'][i]['ietf-network-topology:termination-point'][j]['tp-id']
65                 if((not "CP" in tpId) and (not "CTP" in tpId)):
66                     urlMap = "{}/config/transportpce-portmapping:network/nodes/" + nodeMapId + "/mapping/" + tpId
67                     urlMapFull = urlMap.format(test_utils.RESTCONF_BASE_URL)
68                     responseMap = requests.request("GET", urlMapFull, headers=test_utils.TYPE_APPLICATION_JSON,
69                                                    auth=(test_utils.ODL_LOGIN, test_utils.ODL_PWD))
70                     self.assertEqual(responseMap.status_code, requests.codes.ok)
71                     if responseMap.status_code == requests.codes.ok:
72                         nbMapCurrent += 1
73             nbMapCumul += nbMapCurrent
74         nbMappings -= nbMapCurrent
75         self.assertEqual(nbMappings, 0)
76
77     # Disconnect the ROADMA
78     def test_03_disconnect_rdm(self):
79         response = test_utils.unmount_device("ROADMA01")
80         self.assertEqual(response.status_code, requests.codes.ok, test_utils.CODE_SHOULD_BE_200)
81
82 #     #Connect the XPDRA
83     def test_04_connect_xpdr(self):
84         response = test_utils.mount_device("XPDRA01", 'xpdra')
85         self.assertEqual(response.status_code, requests.codes.created, test_utils.CODE_SHOULD_BE_201)
86
87 #     #Verify the termination points related to XPDR
88     def test_05_compareOpenroadmTopologyPortMapping_xpdr(self):
89         self.test_02_compareOpenroadmTopologyPortMapping_rdm()
90
91     # Disconnect the XPDRA
92     def test_06_disconnect_device(self):
93         response = test_utils.unmount_device("XPDRA01")
94         self.assertEqual(response.status_code, requests.codes.ok, test_utils.CODE_SHOULD_BE_200)
95
96
97 if __name__ == "__main__":
98     # logging.basicConfig(filename='./transportpce_tests/log/response.log',filemode='w',level=logging.DEBUG)
99     #logging.debug('I am there')
100     unittest.main(verbosity=2)