blob: c44d32d519a68d564a7721463564bbb7fe1648db [file] [log] [blame]
adminbae64d82013-08-01 10:50:15 -07001#!/usr/bin/env python
kelvin8ec71442015-01-15 16:57:00 -08002"""
adminbae64d82013-08-01 10:50:15 -07003Created on 26-Oct-2012
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -07004Copyright 2012 Open Networking Foundation ( ONF )
Jeremy Songsterae01bba2016-07-11 15:39:17 -07005
6Please refer questions to either the onos test mailing list at <onos-test@onosproject.org>,
7the System Testing Plans and Results wiki page at <https://wiki.onosproject.org/x/voMg>,
8or the System Testing Guide page at <https://wiki.onosproject.org/x/WYQg>
adminbae64d82013-08-01 10:50:15 -07009
kelvin8ec71442015-01-15 16:57:00 -080010author:: Anil Kumar ( anilkumar.s@paxterrasolutions.com )
adminbae64d82013-08-01 10:50:15 -070011
12
13 TestON is free software: you can redistribute it and/or modify
14 it under the terms of the GNU General Public License as published by
15 the Free Software Foundation, either version 2 of the License, or
kelvin8ec71442015-01-15 16:57:00 -080016 ( at your option ) any later version.
adminbae64d82013-08-01 10:50:15 -070017
18 TestON is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License for more details.
22
23 You should have received a copy of the GNU General Public License
kelvin8ec71442015-01-15 16:57:00 -080024 along with TestON. If not, see <http://www.gnu.org/licenses/>.
adminbae64d82013-08-01 10:50:15 -070025
26
27fvtapidriver is the basic driver which will handle the fvtapidriver functions
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070028""""""
adminbae64d82013-08-01 10:50:15 -070029There are two changes required in flowvisor-test framework :
30
311. In ~/flowvisortests/tests/templatetest.py line : 15 comment 'basic_logger = None'
322. In ~/flowvisortests/tests/testutils.py line : 50 specify config file path CONFIG_FILE = "~/flowvisor-test/tests/tests-base.json"
33
kelvin8ec71442015-01-15 16:57:00 -080034"""
adminbae64d82013-08-01 10:50:15 -070035import pexpect
36import struct
37import fcntl
38import os
39import signal
40import re
41import sys
adminbae64d82013-08-01 10:50:15 -070042from common.apidriver import API
43import logging
44
kelvin8ec71442015-01-15 16:57:00 -080045sys.path.append( path + "/lib/flowvisor-test/tests" )
46sys.path.append( path + "/lib/flowvisor-test/src/python/" )
adminbae64d82013-08-01 10:50:15 -070047
48import templatetest
49import testutils
50import oftest.cstruct as ofp
51import oftest.message as message
52import oftest.parse as parse
53import oftest.action as action
54import oftest.error as error
55import socket
56import __builtin__
57
58config_default = {
kelvin8ec71442015-01-15 16:57:00 -080059 "param": None,
60 "fv_cmd": "/home/openflow/flowvisor/scripts/flowvisor.sh",
61 "platform": "local",
62 "controller_host": "127.0.0.1",
Charles Chan029be652015-08-24 01:46:10 +080063 "controller_port": 6653,
kelvin8ec71442015-01-15 16:57:00 -080064 "timeout": 3,
65 "port_count": 4,
66 "base_of_port": 1,
67 "base_if_index": 1,
68 "test_spec": "all",
69 "test_dir": ".",
70 "log_file": "/home/openflow/fvt.log",
71 "list": False,
72 "debug": "debug",
73 "dbg_level": logging.DEBUG,
74 "port_map": {},
75 "test_params": "None"
adminbae64d82013-08-01 10:50:15 -070076}
77
kelvin8ec71442015-01-15 16:57:00 -080078
79def test_set_init( config ):
adminbae64d82013-08-01 10:50:15 -070080 """
81 Set up function for basic test classes
kelvin8ec71442015-01-15 16:57:00 -080082 config: The configuration dictionary; see fvt
adminbae64d82013-08-01 10:50:15 -070083 """
84 global basic_port_map
85 global basic_fv_cmd
86 global basic_logger
87 global basic_timeout
88 global basic_config
89 global baisc_logger
90
kelvin8ec71442015-01-15 16:57:00 -080091 basic_fv_cmd = config[ "fv_cmd" ]
92 basic_timeout = config[ "timeout" ]
93 basic_port_map = config[ "port_map" ]
adminbae64d82013-08-01 10:50:15 -070094 basic_config = config
95
adminbae64d82013-08-01 10:50:15 -070096
kelvin8ec71442015-01-15 16:57:00 -080097class FvtApiDriver( API, templatetest.TemplateTest ):
98
99 def __init__( self ):
Devin Limdc78e202017-06-09 18:30:07 -0700100 super( FvtApiDriver, self ).__init__()
adminbae64d82013-08-01 10:50:15 -0700101 print 'init'
adminbae64d82013-08-01 10:50:15 -0700102
kelvin8ec71442015-01-15 16:57:00 -0800103 def connect( self, **connectargs ):
adminbae64d82013-08-01 10:50:15 -0700104 for key in connectargs:
kelvin8ec71442015-01-15 16:57:00 -0800105 vars( self )[ key ] = connectargs[ key ]
adminbae64d82013-08-01 10:50:15 -0700106
kelvin8ec71442015-01-15 16:57:00 -0800107 self.name = self.options[ 'name' ]
108 connect_result = super( API, self ).connect()
109 self.logFileName = main.logdir + "/" + self.name + ".session"
110 config_default[ "log_file" ] = self.logFileName
111 test_set_init( config_default )
112 __builtin__.basic_logger = vars( main )[ self.name + 'log' ]
113 __builtin__.basic_logger.info( "Calling my test setup" )
114 self.setUp( basic_logger )
115
116 ( self.fv, self.sv, sv_ret, ctl_ret, sw_ret ) = testutils.setUpTestEnv(
117 self, fv_cmd=basic_fv_cmd )
118
119 self.chkSetUpCondition( self.fv, sv_ret, ctl_ret, sw_ret )
adminbae64d82013-08-01 10:50:15 -0700120 return main.TRUE
121
kelvin8ec71442015-01-15 16:57:00 -0800122 def simplePacket( self, dl_src ):
123 dl_src = vars( testutils )[ dl_src ]
124 return testutils.simplePacket( dl_src=dl_src )
125
126 def genPacketIn( self, in_port, pkt ):
127 return testutils.genPacketIn( in_port=in_port, pkt=pkt )
128
129 def ofmsgSndCmp( self, snd_list, exp_list, xid_ignore=True, hdr_only=True ):
130 return testutils.ofmsgSndCmp( self, snd_list, exp_list, xid_ignore, hdr_only )
131
132 def setRule( self, sv, rule, num_try ):
133 return testutils.setRule( self, sv, rule, num_try )
134
135 def chkFlowdb( self, controller_number, switch_number, exp_count, exp_rewrites ):
136 return testutils.chkFlowdb( self, controller_number, switch_number, exp_count, exp_rewrites )
137
138 def chkSwitchStats( self, switch_number, ofproto, exp_snd_count, exp_rcv_count ):
139 return testutils.chkSwitchStats( self, switch_number, ofproto, exp_snd_count, exp_rcv_count )
140
141 def chkSliceStats( self, controller_number, ofproto, exp_snd_count, exp_rcv_count ):
142 return testutils.chkSliceStats( self, controller_number, ofproto, exp_snd_count, exp_rcv_count )
143
144 def recvStats( self, swId, typ ):
145 return testutils.recvStats( self, swId, typ )
146
147 def ofmsgSndCmpWithXid( self, snd_list, exp_list, xid_ignore, hdr_only ):
148 return testutils.ofmsgSndCmpWithXid( self, snd_list, exp_list, xid_ignore, hdr_only )
149
150 def genPacketOut( self, xid, buffer_id, in_port, action_ports, pkt ):
151 return testutils.genPacketOut( self, xid, buffer_id, in_port, action_ports, pkt )
152
153 def genFlowModFlush( self ):
adminbae64d82013-08-01 10:50:15 -0700154 return testutils.genFlowModFlush()
kelvin8ec71442015-01-15 16:57:00 -0800155
156 def genPhyPort( self, name, addr, port_no ):
157 return testutils.genPhyPort( name, addr, port_no )
158
159 def disconnect( self, handle ):
adminbae64d82013-08-01 10:50:15 -0700160 response = ''
kelvin8ec71442015-01-15 16:57:00 -0800161 """
adminbae64d82013-08-01 10:50:15 -0700162 if self.handle:
163 self.handle = handle
kelvin8ec71442015-01-15 16:57:00 -0800164 response = self.execute( cmd="exit",prompt="(.*)",timeout=120 )
adminbae64d82013-08-01 10:50:15 -0700165 else :
kelvin8ec71442015-01-15 16:57:00 -0800166 main.log.error( "Connection failed to the host" )
adminbae64d82013-08-01 10:50:15 -0700167 response = main.FALSE
kelvin8ec71442015-01-15 16:57:00 -0800168 """
169 return response
170
171 def setUp( self, basic_logger ):
adminbae64d82013-08-01 10:50:15 -0700172 self.logger = basic_logger
kelvin8ec71442015-01-15 16:57:00 -0800173 # basic_logger.info( "** START TEST CASE " + str( self ) )
adminbae64d82013-08-01 10:50:15 -0700174 if basic_timeout == 0:
175 self.timeout = None
176 else:
177 self.timeout = basic_timeout
178 self.fv = None
179 self.sv = None
180 self.controllers = []
181 self.switches = []
kelvin8ec71442015-01-15 16:57:00 -0800182
183 def close_log_handles( self ):
184 self.tearDown()
185 vars( main )[ self.name + 'log' ].removeHandler( self.log_handler )
186 # if self.logfile_handler:
adminbae64d82013-08-01 10:50:15 -0700187 # self.logfile_handler.close()
kelvin8ec71442015-01-15 16:57:00 -0800188
adminbae64d82013-08-01 10:50:15 -0700189 return main.TRUE