Init the test directory with CSIT_Test tool code.
[integration/test.git] / test / tools / CSIT_Test / base / cases / 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         Show the topology
30         >>> TopologyManager().get_topology()
31         True
32         """
33         result = []
34         r = super(self.__class__, self).get_entries()
35         if r:
36             v = [e['edge'] for e in r['edgeProperties']]
37             result.append({u'tailNodeConnector': {u'node': {u'type': u'OF', u'id': u'00:00:00:00:00:00:00:01'},
38                                                   u'type': u'OF', u'id': u'2'},
39                            u'headNodeConnector': {u'node': {u'type': u'OF', u'id': u'00:00:00:00:00:00:00:03'},
40                                                   u'type': u'OF', u'id': u'3'}} in v)
41             result.append({u'tailNodeConnector': {u'node': {u'type': u'OF', u'id': u'00:00:00:00:00:00:00:03'},
42                                                   u'type': u'OF', u'id': u'3'},
43                            u'headNodeConnector': {u'node': {u'type': u'OF', u'id': u'00:00:00:00:00:00:00:01'},
44                                                   u'type': u'OF', u'id': u'2'}} in v)
45             result.append({u'tailNodeConnector': {u'node': {u'type': u'OF', u'id': u'00:00:00:00:00:00:00:02'},
46                                                   u'type': u'OF', u'id': u'3'},
47                            u'headNodeConnector': {u'node': {u'type': u'OF', u'id': u'00:00:00:00:00:00:00:01'},
48                                                   u'type': u'OF', u'id': u'1'}} in v)
49             result.append({u'tailNodeConnector': {u'node': {u'type': u'OF', u'id': u'00:00:00:00:00:00:00:01'},
50                                                   u'type': u'OF', u'id': u'1'},
51                            u'headNodeConnector': {u'node': {u'type': u'OF', u'id': u'00:00:00:00:00:00:00:02'},
52                                                   u'type': u'OF', u'id': u'3'}} in v)
53             print result == [True, True, True, True]
54
55     def get_userlinks(self):
56         """
57         The name is suggested to match the NB API.
58         Show the userlinks.
59         """
60         suffix = 'userLinks'
61         r = super(self.__class__, self).read(suffix)
62         if r:
63             return r
64
65     def add_userlink(self, name, body):
66         """
67         Add a userlink.
68         """
69         suffix = 'userLink'
70         r = super(self.__class__, self).update(suffix + '/' + name, body)
71         return r
72
73     def remove_userlink(self, name):
74         """
75         Remove a userlink.
76         """
77         suffix = 'userLink'
78         r = super(self.__class__, self).delete(suffix + '/' + name)
79         return r
80
81     def test_userlink_operations(self, name, body):
82         """
83         Test userlink operations, like adding and removing.
84         >>> 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'})
85         True
86         """
87         return super(self.__class__, self).test_add_remove_operations('userLinks', 'userLink', name, body, 'userLinks')