From 6c1ab4af219da530d0fc7f273d30d9790c1b587c Mon Sep 17 00:00:00 2001 From: Baohua Yang Date: Thu, 28 Nov 2013 11:31:04 +0800 Subject: [PATCH] Rename cases to modules and minor bug fix Change-Id: Ib48f9135ebffdb362e5c5a5c161f24eff2c5cd6e Signed-off-by: Baohua Yang --- .../base/{cases => modules}/arp_handler.py | 2 +- .../{cases => modules}/container_manager.py | 8 +-- .../{cases => modules}/forwarding_manager.py | 6 +- .../forwarding_rule_manager.py | 0 .../base/{cases => modules}/host_tracker.py | 6 +- .../{cases => modules}/statistics_manager.py | 0 .../base/{cases => modules}/switch_manager.py | 4 +- .../{cases => modules}/topology_manager.py | 55 +++++++++++-------- test/tools/CSIT_Test/base/restlib.py | 2 +- test/tools/CSIT_Test/base/run.py | 8 +-- test/tools/CSIT_Test/base/testmodule.py | 10 ++++ 11 files changed, 60 insertions(+), 41 deletions(-) rename test/tools/CSIT_Test/base/{cases => modules}/arp_handler.py (98%) rename test/tools/CSIT_Test/base/{cases => modules}/container_manager.py (86%) rename test/tools/CSIT_Test/base/{cases => modules}/forwarding_manager.py (81%) rename test/tools/CSIT_Test/base/{cases => modules}/forwarding_rule_manager.py (100%) rename test/tools/CSIT_Test/base/{cases => modules}/host_tracker.py (84%) rename test/tools/CSIT_Test/base/{cases => modules}/statistics_manager.py (100%) rename test/tools/CSIT_Test/base/{cases => modules}/switch_manager.py (98%) rename test/tools/CSIT_Test/base/{cases => modules}/topology_manager.py (92%) diff --git a/test/tools/CSIT_Test/base/cases/arp_handler.py b/test/tools/CSIT_Test/base/modules/arp_handler.py similarity index 98% rename from test/tools/CSIT_Test/base/cases/arp_handler.py rename to test/tools/CSIT_Test/base/modules/arp_handler.py index f92b94218e..aa0eb41895 100644 --- a/test/tools/CSIT_Test/base/cases/arp_handler.py +++ b/test/tools/CSIT_Test/base/modules/arp_handler.py @@ -52,4 +52,4 @@ class ArpHandler(TestModule): if __name__ == '__main__': - print 'arp handler' + print 'arp handler' \ No newline at end of file diff --git a/test/tools/CSIT_Test/base/cases/container_manager.py b/test/tools/CSIT_Test/base/modules/container_manager.py similarity index 86% rename from test/tools/CSIT_Test/base/cases/container_manager.py rename to test/tools/CSIT_Test/base/modules/container_manager.py index 805405b567..b5808f248d 100644 --- a/test/tools/CSIT_Test/base/cases/container_manager.py +++ b/test/tools/CSIT_Test/base/modules/container_manager.py @@ -34,15 +34,13 @@ class ContainerManager(TestModule): """ Add a container """ - self.container = 'container' - super(self.__class__, self).add_entry('containermanager', name, body) + super(self.__class__, self).add_entry('container', name, body) def remove_container(self, name): """ Remove a container """ - self.container = 'container' - super(self.__class__, self).remove_entry('containermanager', name) + super(self.__class__, self).remove_entry('container', name) def test_container_operations(self, name, body): """ @@ -51,4 +49,4 @@ class ContainerManager(TestModule): True """ return super(self.__class__, self).test_add_remove_operations('containers', 'container', name, body, - 'container-config') + 'containerConfig') diff --git a/test/tools/CSIT_Test/base/cases/forwarding_manager.py b/test/tools/CSIT_Test/base/modules/forwarding_manager.py similarity index 81% rename from test/tools/CSIT_Test/base/cases/forwarding_manager.py rename to test/tools/CSIT_Test/base/modules/forwarding_manager.py index 5c34e2f9bb..82625fce1a 100644 --- a/test/tools/CSIT_Test/base/cases/forwarding_manager.py +++ b/test/tools/CSIT_Test/base/modules/forwarding_manager.py @@ -18,8 +18,10 @@ class ForwardingManager(TestModule): Test for the forwarding manager. Start 2-layer tree topology network. e.g., in Mininet, run 'sudo mn --controller=remote,ip=127.0.0.1 --mac --topo tree,2' """ - def __init__(self,restSubContext='/controller/nb/v2/staticroute',user=DEFAULT_USER, password=DEFAULT_PWD,container=DEFAULT_CONTAINER,contentType='json',prefix=DEFAULT_PREFIX): - super(self.__class__,self).__init__(restSubContext,user,password,container,contentType,prefix) + + def __init__(self, restSubContext='/controller/nb/v2/staticroute', user=DEFAULT_USER, password=DEFAULT_PWD, + container=DEFAULT_CONTAINER, contentType='json', prefix=DEFAULT_PREFIX): + super(self.__class__, self).__init__(restSubContext, user, password, container, contentType, prefix) def get_routes(self): """ diff --git a/test/tools/CSIT_Test/base/cases/forwarding_rule_manager.py b/test/tools/CSIT_Test/base/modules/forwarding_rule_manager.py similarity index 100% rename from test/tools/CSIT_Test/base/cases/forwarding_rule_manager.py rename to test/tools/CSIT_Test/base/modules/forwarding_rule_manager.py diff --git a/test/tools/CSIT_Test/base/cases/host_tracker.py b/test/tools/CSIT_Test/base/modules/host_tracker.py similarity index 84% rename from test/tools/CSIT_Test/base/cases/host_tracker.py rename to test/tools/CSIT_Test/base/modules/host_tracker.py index 2f81780d36..a6a6a2388b 100644 --- a/test/tools/CSIT_Test/base/cases/host_tracker.py +++ b/test/tools/CSIT_Test/base/modules/host_tracker.py @@ -18,8 +18,10 @@ class HostTracker(TestModule): Test for the host tracker.. Start 2-layer tree topology network. e.g., in Mininet, run 'sudo mn --controller=remote,ip=127.0.0.1 --mac --topo tree,2' """ - def __init__(self,restSubContext='/controller/nb/v2/hosttracker',user=DEFAULT_USER, password=DEFAULT_PWD,container=DEFAULT_CONTAINER,contentType='json',prefix=DEFAULT_PREFIX): - super(self.__class__,self).__init__(restSubContext,user,password,container,contentType,prefix) + + def __init__(self, restSubContext='/controller/nb/v2/hosttracker', user=DEFAULT_USER, password=DEFAULT_PWD, + container=DEFAULT_CONTAINER, contentType='json', prefix=DEFAULT_PREFIX): + super(self.__class__, self).__init__(restSubContext, user, password, container, contentType, prefix) def get_hosts(self): """ diff --git a/test/tools/CSIT_Test/base/cases/statistics_manager.py b/test/tools/CSIT_Test/base/modules/statistics_manager.py similarity index 100% rename from test/tools/CSIT_Test/base/cases/statistics_manager.py rename to test/tools/CSIT_Test/base/modules/statistics_manager.py diff --git a/test/tools/CSIT_Test/base/cases/switch_manager.py b/test/tools/CSIT_Test/base/modules/switch_manager.py similarity index 98% rename from test/tools/CSIT_Test/base/cases/switch_manager.py rename to test/tools/CSIT_Test/base/modules/switch_manager.py index 0f18736a72..d4492f5ae3 100644 --- a/test/tools/CSIT_Test/base/cases/switch_manager.py +++ b/test/tools/CSIT_Test/base/modules/switch_manager.py @@ -79,8 +79,8 @@ class SwitchManager(TestModule): """ result = [] r = self.get_nodes() - if r: - t = [e['node'] for e in r['nodeProperties']] + t = super(self.__class__, self).extract_properties(r, 'nodeProperties', 'node') + if t: result.append({u'type': u'OF', u'id': u'00:00:00:00:00:00:00:01'} in t) result.append({u'type': u'OF', u'id': u'00:00:00:00:00:00:00:02'} in t) result.append({u'type': u'OF', u'id': u'00:00:00:00:00:00:00:03'} in t) diff --git a/test/tools/CSIT_Test/base/cases/topology_manager.py b/test/tools/CSIT_Test/base/modules/topology_manager.py similarity index 92% rename from test/tools/CSIT_Test/base/cases/topology_manager.py rename to test/tools/CSIT_Test/base/modules/topology_manager.py index e7a5ca9727..72defc25a3 100644 --- a/test/tools/CSIT_Test/base/cases/topology_manager.py +++ b/test/tools/CSIT_Test/base/modules/topology_manager.py @@ -26,31 +26,9 @@ class TopologyManager(TestModule): def get_topology(self): """ The name is suggested to match the NB API. - Show the topology - >>> TopologyManager().get_topology() - True + Get the topology """ - result = [] - r = super(self.__class__, self).get_entries() - if r: - v = [e['edge'] for e in r['edgeProperties']] - result.append({u'tailNodeConnector': {u'node': {u'type': u'OF', u'id': u'00:00:00:00:00:00:00:01'}, - u'type': u'OF', u'id': u'2'}, - u'headNodeConnector': {u'node': {u'type': u'OF', u'id': u'00:00:00:00:00:00:00:03'}, - u'type': u'OF', u'id': u'3'}} in v) - result.append({u'tailNodeConnector': {u'node': {u'type': u'OF', u'id': u'00:00:00:00:00:00:00:03'}, - u'type': u'OF', u'id': u'3'}, - u'headNodeConnector': {u'node': {u'type': u'OF', u'id': u'00:00:00:00:00:00:00:01'}, - u'type': u'OF', u'id': u'2'}} in v) - result.append({u'tailNodeConnector': {u'node': {u'type': u'OF', u'id': u'00:00:00:00:00:00:00:02'}, - u'type': u'OF', u'id': u'3'}, - u'headNodeConnector': {u'node': {u'type': u'OF', u'id': u'00:00:00:00:00:00:00:01'}, - u'type': u'OF', u'id': u'1'}} in v) - result.append({u'tailNodeConnector': {u'node': {u'type': u'OF', u'id': u'00:00:00:00:00:00:00:01'}, - u'type': u'OF', u'id': u'1'}, - u'headNodeConnector': {u'node': {u'type': u'OF', u'id': u'00:00:00:00:00:00:00:02'}, - u'type': u'OF', u'id': u'3'}} in v) - print result == [True, True, True, True] + return super(self.__class__, self).get_entries() def get_userlinks(self): """ @@ -78,6 +56,35 @@ class TopologyManager(TestModule): r = super(self.__class__, self).delete(suffix + '/' + name) return r + def test_get_topology(self): + """ + The name is suggested to match the NB API. + Test the topology + >>> TopologyManager().test_get_topology() + True + """ + result = [] + r = self.get_topology() + if r: + v = [e['edge'] for e in r['edgeProperties']] + result.append({u'tailNodeConnector': {u'node': {u'type': u'OF', u'id': u'00:00:00:00:00:00:00:01'}, + u'type': u'OF', u'id': u'2'}, + u'headNodeConnector': {u'node': {u'type': u'OF', u'id': u'00:00:00:00:00:00:00:03'}, + u'type': u'OF', u'id': u'3'}} in v) + result.append({u'tailNodeConnector': {u'node': {u'type': u'OF', u'id': u'00:00:00:00:00:00:00:03'}, + u'type': u'OF', u'id': u'3'}, + u'headNodeConnector': {u'node': {u'type': u'OF', u'id': u'00:00:00:00:00:00:00:01'}, + u'type': u'OF', u'id': u'2'}} in v) + result.append({u'tailNodeConnector': {u'node': {u'type': u'OF', u'id': u'00:00:00:00:00:00:00:02'}, + u'type': u'OF', u'id': u'3'}, + u'headNodeConnector': {u'node': {u'type': u'OF', u'id': u'00:00:00:00:00:00:00:01'}, + u'type': u'OF', u'id': u'1'}} in v) + result.append({u'tailNodeConnector': {u'node': {u'type': u'OF', u'id': u'00:00:00:00:00:00:00:01'}, + u'type': u'OF', u'id': u'1'}, + u'headNodeConnector': {u'node': {u'type': u'OF', u'id': u'00:00:00:00:00:00:00:02'}, + u'type': u'OF', u'id': u'3'}} in v) + print result == [True, True, True, True] + def test_userlink_operations(self, name, body): """ Test userlink operations, like adding and removing. diff --git a/test/tools/CSIT_Test/base/restlib.py b/test/tools/CSIT_Test/base/restlib.py index 996f2770a3..f1f8858de7 100644 --- a/test/tools/CSIT_Test/base/restlib.py +++ b/test/tools/CSIT_Test/base/restlib.py @@ -16,7 +16,7 @@ DEFAULT_PREFIX = 'http://' + DEFAULT_CONTROLLER_IP + ':' + DEFAULT_PORT DEFAULT_CONTAINER = 'default' DEFAULT_USER = 'admin' DEFAULT_PWD = 'admin' -CASES_DIR = 'cases' +MODULES_DIR = 'modules' TIMEOUTS = 2 ''' diff --git a/test/tools/CSIT_Test/base/run.py b/test/tools/CSIT_Test/base/run.py index 929f7e6d1e..1a4dabc23b 100644 --- a/test/tools/CSIT_Test/base/run.py +++ b/test/tools/CSIT_Test/base/run.py @@ -14,7 +14,7 @@ import os from restlib import * -def test_case(module_name): +def test_module(module_name): ''' Run single test on given module. ''' @@ -30,10 +30,10 @@ def run(modules=None): ''' backup_dir = os.getcwd() if not modules: - modules = [e[:-3] for e in os.listdir(CASES_DIR) if e.endswith('.py')] - os.chdir(backup_dir + '/' + CASES_DIR) + modules = [e[:-3] for e in os.listdir(MODULES_DIR) if e.endswith('.py')] + os.chdir(backup_dir + '/' + MODULES_DIR) for name in modules: - test_case(name) + test_module(name) os.chdir(backup_dir) diff --git a/test/tools/CSIT_Test/base/testmodule.py b/test/tools/CSIT_Test/base/testmodule.py index 64df8773dd..928b67b0bf 100644 --- a/test/tools/CSIT_Test/base/testmodule.py +++ b/test/tools/CSIT_Test/base/testmodule.py @@ -22,6 +22,16 @@ class TestModule(object): self.contentType = contentType self.prefix = prefix + + def extract_properties(self, content, key, property): + """ + Return all nodes. + """ + if not isinstance(content, dict) or not content.has_key(key): + return None + else: + return [e.get(property) for e in content[key]] + def get_entries(self, suffix=None, key=None): """ Get the existed entries in the service. -- 2.36.6