Change URI to specific ovsdb node
[integration/test.git] / tools / Robot_Tool / libraries / TopologyManager.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 *  # noqa
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
20         'sudo mn --controller=remote,ip=127.0.0.1 --mac --topo tree,2'
21     """
22
23     def __init__(self, restSubContext='/controller/nb/v2/topology', user=DEFAULT_USER, password=DEFAULT_PWD,
24                  container=DEFAULT_CONTAINER, contentType='json', prefix=DEFAULT_PREFIX):
25         super(self.__class__, self).__init__(restSubContext, user, password, container, contentType, prefix)
26
27     def get_topology(self):
28         """
29         The name is suggested to match the NB API.
30         Get the topology
31         """
32         return super(self.__class__, self).get_entries()
33
34     def get_userlinks(self):
35         """
36         The name is suggested to match the NB API.
37         Show the userlinks.
38         """
39         suffix = 'userLinks'
40         r = super(self.__class__, self).read(suffix)
41         if r:
42             return r
43
44     def add_userlink(self, name, body):
45         """
46         Add a userlink.
47         """
48         suffix = 'userLink'
49         r = super(self.__class__, self).update(suffix + '/' + name, body)
50         return r
51
52     def remove_userlink(self, name):
53         """
54         Remove a userlink.
55         """
56         suffix = 'userLink'
57         r = super(self.__class__, self).delete(suffix + '/' + name)
58         return r
59
60     def test_get_topology(self):
61         """
62         The name is suggested to match the NB API.
63         Test the topology
64         >>> TopologyManager().test_get_topology()
65         True
66         """
67         result = []
68         r = self.get_topology()
69         if r:
70             v = [e['edge'] for e in r['edgeProperties']]
71             result.append({u'tailNodeConnector': {u'node': {u'type': u'OF', u'id': u'00:00:00:00:00:00:00:01'},
72                                                   u'type': u'OF', u'id': u'2'},
73                            u'headNodeConnector': {u'node': {u'type': u'OF', u'id': u'00:00:00:00:00:00:00:03'},
74                                                   u'type': u'OF', u'id': u'3'}} in v)
75             result.append({u'tailNodeConnector': {u'node': {u'type': u'OF', u'id': u'00:00:00:00:00:00:00:03'},
76                                                   u'type': u'OF', u'id': u'3'},
77                            u'headNodeConnector': {u'node': {u'type': u'OF', u'id': u'00:00:00:00:00:00:00:01'},
78                                                   u'type': u'OF', u'id': u'2'}} in v)
79             result.append({u'tailNodeConnector': {u'node': {u'type': u'OF', u'id': u'00:00:00:00:00:00:00:02'},
80                                                   u'type': u'OF', u'id': u'3'},
81                            u'headNodeConnector': {u'node': {u'type': u'OF', u'id': u'00:00:00:00:00:00:00:01'},
82                                                   u'type': u'OF', u'id': u'1'}} in v)
83             result.append({u'tailNodeConnector': {u'node': {u'type': u'OF', u'id': u'00:00:00:00:00:00:00:01'},
84                                                   u'type': u'OF', u'id': u'1'},
85                            u'headNodeConnector': {u'node': {u'type': u'OF', u'id': u'00:00:00:00:00:00:00:02'},
86                                                   u'type': u'OF', u'id': u'3'}} in v)
87             print result == [True, True, True, True]
88
89     def test_userlink_operations(self, name, body):
90         """
91         Test userlink operations, like adding and removing.
92         >>> TopologyManager().test_userlink_operations('link1',
93                 {'status':'Success','name':'link1',
94                 'srcNodeConnector':'OF|1@OF|00:00:00:00:00:00:00:02',
95                 'dstNodeConnector':'OF|1@OF|00:00:00:00:00:00:00:03'})
96         True
97         """
98         return super(self.__class__, self).test_add_remove_operations('userLinks', 'userLink', name, body, 'userLinks')