3 Authors: Baohua Yang@IBM, Denghui Huang@IBM
11 from testmodule import TestModule
16 class SwitchManager(TestModule):
18 Test for the switch manager, including read switch nodes.
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'
22 def __init__(self, restSubContext='/controller/nb/v2/switchmanager', 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)
28 The name is suggested to match the NB API.
29 list all nodes and their properties
32 r = super(self.__class__, self).read(suffix)
36 def get_node(self, suffix):
38 The name is suggested to match the NB API.
39 list nodeconnector and properties of a node.
41 r = super(self.__class__, self).read(suffix)
45 def add_property_to_node(self, node_type, node_id, property, value):
47 Add a property to given node.
49 suffix = 'node/' + node_type + '/' + node_id + '/property'
50 r = super(self.__class__, self).update(suffix + '/' + property + '/' + str(value))
52 def remove_property_from_node(self, node_type, node_id, property):
54 Remove a property from given node.
56 suffix = 'node/' + node_type + '/' + node_id + '/property'
57 r = super(self.__class__, self).delete(suffix + '/' + property)
59 def add_property_to_nodeconnector(self, node_type, node_id, nc_type, nc_id, property, value):
61 Add a property to given node.
63 suffix = 'nodeconnector/' + node_type + '/' + node_id + '/' + nc_type + '/' + nc_id + '/property'
64 r = super(self.__class__, self).update(suffix + '/' + property + '/' + str(value))
66 def remove_property_from_nodeconnector(self, node_type, node_id, nc_type, nc_id, property):
68 Add a property to given node.
70 suffix = 'nodeconnector/' + node_type + '/' + node_id + '/' + nc_type + '/' + nc_id + '/property'
71 r = super(self.__class__, self).delete(suffix + '/' + property)
73 def test_list_nodes(self):
75 The name is suggested to match the NB API.
76 list all nodes and their properties
77 >>> SwitchManager().test_list_nodes()
83 t = [e['node'] for e in r['nodeProperties']]
84 result.append({u'type': u'OF', u'id': u'00:00:00:00:00:00:00:01'} in t)
85 result.append({u'type': u'OF', u'id': u'00:00:00:00:00:00:00:02'} in t)
86 result.append({u'type': u'OF', u'id': u'00:00:00:00:00:00:00:03'} in t)
87 return result == [True, True, True]
89 def test_node_property_operations(self, node_type, node_id, property, value):
91 Test the add,remove,show actions on node properties.
93 >>> SwitchManager().test_node_property_operations('OF','00:00:00:00:00:00:00:01','description','Switch1')
95 >>> SwitchManager().test_node_property_operations('OF','00:00:00:00:00:00:00:02','description','Switch2')
97 >>> SwitchManager().test_node_property_operations('OF','00:00:00:00:00:00:00:03','description','Switch3')
101 #current node properties should not include description
103 v = [e['properties'].get(property) for e in r['nodeProperties'] if
104 e['node'] == {u'type': node_type, u'id': node_id}]
105 result.append(v == [{u'value': u'None'}] or v == [None])
106 #After adding, current node properties should include description
107 self.add_property_to_node(node_type, node_id, property, value)
109 v = [e['properties'].get(property) for e in r['nodeProperties'] if
110 e['node'] == {u'type': node_type, u'id': node_id}]
111 result.append(v == [{u'value': value}])
112 #After removing, current node properties should not include description
113 self.remove_property_from_node(node_type, node_id, property)
115 v = [e['properties'].get(property) for e in r['nodeProperties'] if
116 e['node'] == {u'type': node_type, u'id': node_id}]
117 result.append(v == [{u'value': u'None'}] or v == [None])
118 return result == [True, True, True]
120 def test_nodeconnector_property_operations(self, node_type, node_id, nc_type, nc_id, property, value):
122 Test the add,remove,show actions on nodeconnector properties.
124 >>> SwitchManager().test_nodeconnector_property_operations('OF','00:00:00:00:00:00:00:01','OF','1','bandwidth',1000)
128 node_suffix = 'node/' + node_type + '/' + node_id
129 #default bw should be 10000000000L
130 r = self.get_node(node_suffix)
131 default_value = [e['properties'][property] for e in r['nodeConnectorProperties'] if
132 property in e['properties'] and e['nodeconnector'] == {
133 u'node': {u'type': node_type, u'id': node_id}, u'type': nc_type, u'id': nc_id}]
134 #After setting, the value should be the value
135 self.add_property_to_nodeconnector(node_type, node_id, nc_type, nc_id, property, value)
136 r = self.get_node(node_suffix)
137 current_value = [e['properties'][property] for e in r['nodeConnectorProperties'] if
138 property in e['properties'] and e['nodeconnector'] == {
139 u'node': {u'type': node_type, u'id': node_id}, u'type': nc_type, u'id': nc_id}]
140 result.append(current_value == [{'value': value}])
141 #After removing, and restoring the default value, the bandwidth property should be default
142 self.remove_property_from_nodeconnector(node_type, node_id, nc_type, nc_id, property)
143 r = self.get_node(node_suffix)
144 v = [e['properties'][property] for e in r['nodeConnectorProperties'] if
145 property in e['properties'] and e['nodeconnector'] == {u'node': {u'type': node_type, u'id': node_id},
146 u'type': nc_type, u'id': nc_id}]
147 result.append(v == [])
148 self.add_property_to_nodeconnector(node_type, node_id, nc_type, nc_id, property, default_value[0]['value'])
149 r = self.get_node(node_suffix)
150 current_value = [e['properties'][property] for e in r['nodeConnectorProperties'] if
151 property in e['properties'] and e['nodeconnector'] == {
152 u'node': {u'type': node_type, u'id': node_id}, u'type': nc_type, u'id': nc_id}]
153 result.append(current_value == default_value)
154 return result == [True, True, True]