Change key of container manager from 'container-config' to 'containerConfig' to match...
[integration/test.git] / test / tools / CSIT_Test / base / modules / topology_manager.py
1 """
2 CSIT test tools.
3 Authors: Baohua Yang@IBM, Denghui Huang@IBM
4 Updated: 2013-11-01
5 """
6
7 import sys
8
9 sys.path.append('..')
10 from restlib import *
11 from testmodule import TestModule
12
13 sys.path.remove('..')
14
15
16 class TopologyManager(TestModule):
17     """
18     Test for the topology manager.
19     Start 2-layer tree topology network. e.g., in Mininet, run  'sudo mn --controller=remote,ip=127.0.0.1 --mac --topo tree,2'
20     """
21
22     def __init__(self, restSubContext='/controller/nb/v2/topology', user=DEFAULT_USER, password=DEFAULT_PWD,
23                  container=DEFAULT_CONTAINER, contentType='json', prefix=DEFAULT_PREFIX):
24         super(self.__class__, self).__init__(restSubContext, user, password, container, contentType, prefix)
25
26     def get_topology(self):
27         """
28         The name is suggested to match the NB API.
29         Get the topology
30         """
31         return super(self.__class__, self).get_entries()
32
33     def get_userlinks(self):
34         """
35         The name is suggested to match the NB API.
36         Show the userlinks.
37         """
38         suffix = 'userLinks'
39         r = super(self.__class__, self).read(suffix)
40         if r:
41             return r
42
43     def add_userlink(self, name, body):
44         """
45         Add a userlink.
46         """
47         suffix = 'userLink'
48         r = super(self.__class__, self).update(suffix + '/' + name, body)
49         return r
50
51     def remove_userlink(self, name):
52         """
53         Remove a userlink.
54         """
55         suffix = 'userLink'
56         r = super(self.__class__, self).delete(suffix + '/' + name)
57         return r
58
59     def test_get_topology(self):
60         """
61         The name is suggested to match the NB API.
62         Test the topology
63         >>> TopologyManager().test_get_topology()
64         True
65         """
66         result = []
67         r = self.get_topology()
68         if r:
69             v = [e['edge'] for e in r['edgeProperties']]
70             result.append({u'tailNodeConnector': {u'node': {u'type': u'OF', u'id': u'00:00:00:00:00:00:00:01'},
71                                                   u'type': u'OF', u'id': u'2'},
72                            u'headNodeConnector': {u'node': {u'type': u'OF', u'id': u'00:00:00:00:00:00:00:03'},
73                                                   u'type': u'OF', u'id': u'3'}} in v)
74             result.append({u'tailNodeConnector': {u'node': {u'type': u'OF', u'id': u'00:00:00:00:00:00:00:03'},
75                                                   u'type': u'OF', u'id': u'3'},
76                            u'headNodeConnector': {u'node': {u'type': u'OF', u'id': u'00:00:00:00:00:00:00:01'},
77                                                   u'type': u'OF', u'id': u'2'}} in v)
78             result.append({u'tailNodeConnector': {u'node': {u'type': u'OF', u'id': u'00:00:00:00:00:00:00:02'},
79                                                   u'type': u'OF', u'id': u'3'},
80                            u'headNodeConnector': {u'node': {u'type': u'OF', u'id': u'00:00:00:00:00:00:00:01'},
81                                                   u'type': u'OF', u'id': u'1'}} in v)
82             result.append({u'tailNodeConnector': {u'node': {u'type': u'OF', u'id': u'00:00:00:00:00:00:00:01'},
83                                                   u'type': u'OF', u'id': u'1'},
84                            u'headNodeConnector': {u'node': {u'type': u'OF', u'id': u'00:00:00:00:00:00:00:02'},
85                                                   u'type': u'OF', u'id': u'3'}} in v)
86             print result == [True, True, True, True]
87
88     def test_userlink_operations(self, name, body):
89         """
90         Test userlink operations, like adding and removing.
91         >>> TopologyManager().test_userlink_operations('link1', {'status':'Success','name':'link1','srcNodeConnector':'OF|1@OF|00:00:00:00:00:00:00:02','dstNodeConnector':'OF|1@OF|00:00:00:00:00:00:00:03'})
92         True
93         """
94         return super(self.__class__, self).test_add_remove_operations('userLinks', 'userLink', name, body, 'userLinks')