2 Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
4 This program and the accompanying materials are made available under the
5 terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 and is available at http://www.eclipse.org/legal/epl-v10.html
8 Created on May 11, 2014
10 @author: <a href="mailto:vdemcak@cisco.com">Vaclav Demcak</a>
18 from crud.odl_flow_test import OF_CRUD_Test_Flows
19 from crud.odl_group_tests import OF_CRUD_Test_Groups
20 from crud.odl_meter_test import OF_CRUD_Test_Meters
21 from tools.crud_test_with_param_superclass import OF_CRUD_Test_Base
22 from tools.test_with_param_superclass import OF_TestXmlInputs_Base
25 # The input values for a mininet argument
26 class Input_MininetSwitchEnum( object ) :
31 def __returnFiles( test_nr = None, prefix_letter = None, path = 'xmls' ):
32 if prefix_letter is None :
33 raise ValueError( "Missing the test file input prefix" )
35 if test_nr is not None :
36 xml = map( int, test_nr.split( ',' ) )
42 xmlfiles = ( "%s%d.xml" % ( prefix_letter, flowId ) for flowId in xml if flowId != 0 )
44 xmlfiles = ( xmlFile for xmlFile in os.listdir( path )
45 if ( xmlFile.startswith( prefix_letter ) & xmlFile.endswith( '.xml' ) ) )
51 def suite( path = 'xmls' ):
52 suite = unittest.TestSuite()
53 # load the flow tests for every input file
54 flowXmlFiles = __returnFiles( in_args.fxmls, 'f', path )
55 for flow_input_file in flowXmlFiles :
57 suite.addTest( OF_TestXmlInputs_Base.load_file_name( OF_CRUD_Test_Flows, path_to_xml = os.path.join( path, flow_input_file ) ) )
58 # groups and meters are not implemented by OVS yet
59 if ( in_args.mininet == Input_MininetSwitchEnum.CPqD ) :
60 # load the meter tests for every input file
61 meterXmlFiles = __returnFiles( in_args.mxmls, 'm', path )
62 for meter_input_file in meterXmlFiles :
63 suite.addTest( OF_TestXmlInputs_Base.load_file_name( OF_CRUD_Test_Meters, path_to_xml = os.path.join( path, meter_input_file ) ) )
64 # load the group tests for every input file
65 groupXmlFiles = __returnFiles( in_args.gxmls, 'g', path )
66 for group_ipnut_file in groupXmlFiles :
67 suite.addTest( OF_TestXmlInputs_Base.load_file_name( OF_CRUD_Test_Groups, path_to_xml = os.path.join( path, group_ipnut_file ) ) )
68 # returns the completed test suite
72 if __name__ == "__main__":
74 log_level_dict = {1 : logging.DEBUG, 2 : logging.INFO, 3 : logging.ERROR}
75 # parse cmdline arguments
76 parser = argparse.ArgumentParser( description = 'ODL CRUD tests defined by the xml inputs.' )
78 parser.add_argument( '--odlhost', default = '127.0.0.1', help = 'host where '
79 'odl controller is running (default = 127.0.0.1) ' )
80 parser.add_argument( '--odlport', type = int, default = 8080, help = 'port on '
81 'which odl\'s RESTCONF is listening (default = 8080) ' )
82 parser.add_argument( '--loglev', type = int, default = 1, help = 'logging Level '
83 'definition (DEBUG = 1 | INFO = 2 | ERROR = 3 ) (default = 1)' )
84 parser.add_argument( '--mininet', type = int, default = 1, help = 'mininet can be implemented '
85 'by OVS = 1 or by CPqD = 2 (default = 1)' )
86 parser.add_argument( '--fxmls', default = None, help = 'generate the Flow tests for the selected xml from xmls DIR '
87 'only (i.e. 1,3,34), 0 means no test and None means all tests (default = None)' )
88 parser.add_argument( '--mxmls', default = None, help = 'generate the Meter tests for the selected xml from xmls DIR '
89 'only (i.e. 1,3,34), 0 means no test and None means all tests (default = None)' )
90 parser.add_argument( '--gxmls', default = None, help = 'generate the Group tests for the selected xml from xmls DIR '
91 'only (i.e. 1,3,34), 0 means no test and None means all tests (default = None)' )
92 parser.add_argument( '--confresp', type = int, default = 0, help = 'delay to the Configuration Data Store ' \
93 '(default = 0 second) Increase this value is important for a weaker controller machine' )
94 parser.add_argument( '--operresp', type = int, default = 3, help = 'delay to the Operational Data Store ' \
95 '(default = 3 second) Increase this value is important for a weaker controller machine' )
96 parser.add_argument( '--coloring', type = int, default = 0, help = 'coloring output '
97 'definition (coloring enabled = 1 | coloring disabled = 0 ) (default = 0)' )
99 in_args = parser.parse_args()
101 # check python version
102 current_ver = sys.version_info
103 if current_ver[0] != 2 or current_ver[1] != 6 :
104 print "Python in ver. 2.6 is required !"
107 logging.basicConfig( level = log_level_dict[in_args.loglev],
108 filename = 'crud_test.log',
109 # format = "%(asctime)s %(levelname)s %(message)s",
110 format = '[%(asctime)s] {%(pathname)s:%(lineno)d} %(levelname)s - %(message)s',
111 datefmt = '%Y-%m-%d %H:%M:%S' )
113 # set the host and the port input values for ODL controller to the test suite
114 OF_CRUD_Test_Base.port = in_args.odlport
115 OF_CRUD_Test_Base.host = in_args.odlhost
116 OF_CRUD_Test_Base.mininet = in_args.mininet
117 OF_CRUD_Test_Base.CONTROLLER_DELAY = in_args.confresp
118 OF_CRUD_Test_Base.CONTROLLER_OPERATION_DELAY = in_args.operresp
119 OF_CRUD_Test_Base.COLORING = in_args.coloring
122 console = logging.StreamHandler()
123 console.setLevel( log_level_dict[in_args.loglev] )
124 formatter = logging.Formatter( "%(asctime)s : %(levelname)s - %(message)s", "%H:%M:%S" )
125 console.setFormatter( formatter )
126 logging.getLogger( '' ).addHandler( console )
128 # TODO print input values
131 odl_crud_suite = suite()
133 unittest.TextTestRunner().run( odl_crud_suite )