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