Init the test directory with CSIT_Test tool code.
[integration/test.git] / test / tools / CSIT_Test / base / cases / host_tracker.py
1 """
2 CSIT test tools.
3 Authors: Baohua Yang@IBM, Denghui Huang@IBM
4 Updated: 2013-11-06
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 HostTracker(TestModule):
17     """
18     Test for the host tracker..
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     def __init__(self,restSubContext='/controller/nb/v2/hosttracker',user=DEFAULT_USER, password=DEFAULT_PWD,container=DEFAULT_CONTAINER,contentType='json',prefix=DEFAULT_PREFIX):
22        super(self.__class__,self).__init__(restSubContext,user,password,container,contentType,prefix)
23
24     def get_hosts(self):
25         """
26         The name is suggested to match the NB API.
27         list all active hosts, should be done after using h1 ping h2 in mininet
28         """
29         return super(self.__class__, self).get_entries(['hosts/active', 'hosts/inactive'], 'hostConfig')
30
31     def add_host(self, name, body):
32         """
33         Add a host.
34         """
35         r = super(self.__class__, self).add_entry('address', name, body)
36
37     def remove_host(self, name):
38         """
39         Remove a host.
40         """
41         r = super(self.__class__, self).remove_entry('address', name)
42
43     def test_host_operations(self, name, body):
44         """
45         Test host operations, like adding and removing.
46         >>> HostTracker().test_host_operations('10.0.1.4',{'nodeType': 'OF', 'dataLayerAddress': '5e:bf:79:84:10:a6', 'vlan': '1', 'nodeId': '00:00:00:00:00:00:00:03', 'nodeConnectorId': '9', 'networkAddress': '10.0.1.4', 'staticHost': True, 'nodeConnectorType': 'OF'})
47         True
48         """
49         return super(self.__class__, self).test_add_remove_operations(['hosts/active', 'hosts/inactive'], 'address',
50                                                                       name, body,
51                                                                       'hostConfig')