admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 1 | #!/usr/bin/env python |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 2 | """ |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 3 | Created on 26-Oct-2012 |
| 4 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 5 | author:: Anil Kumar ( anilkumar.s@paxterrasolutions.com ) |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 6 | |
| 7 | |
| 8 | TestON is free software: you can redistribute it and/or modify |
| 9 | it under the terms of the GNU General Public License as published by |
| 10 | the Free Software Foundation, either version 2 of the License, or |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 11 | ( at your option ) any later version. |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 12 | |
| 13 | TestON is distributed in the hope that it will be useful, |
| 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | GNU General Public License for more details. |
| 17 | |
| 18 | You should have received a copy of the GNU General Public License |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 19 | along with TestON. If not, see <http://www.gnu.org/licenses/>. |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 20 | |
| 21 | |
| 22 | fvtapidriver is the basic driver which will handle the fvtapidriver functions |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 23 | """ |
| 24 | """ |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 25 | There are two changes required in flowvisor-test framework : |
| 26 | |
| 27 | 1. In ~/flowvisortests/tests/templatetest.py line : 15 comment 'basic_logger = None' |
| 28 | 2. In ~/flowvisortests/tests/testutils.py line : 50 specify config file path CONFIG_FILE = "~/flowvisor-test/tests/tests-base.json" |
| 29 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 30 | """ |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 31 | import pexpect |
| 32 | import struct |
| 33 | import fcntl |
| 34 | import os |
| 35 | import signal |
| 36 | import re |
| 37 | import sys |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 38 | from common.apidriver import API |
| 39 | import logging |
| 40 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 41 | sys.path.append( path + "/lib/flowvisor-test/tests" ) |
| 42 | sys.path.append( path + "/lib/flowvisor-test/src/python/" ) |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 43 | |
| 44 | import templatetest |
| 45 | import testutils |
| 46 | import oftest.cstruct as ofp |
| 47 | import oftest.message as message |
| 48 | import oftest.parse as parse |
| 49 | import oftest.action as action |
| 50 | import oftest.error as error |
| 51 | import socket |
| 52 | import __builtin__ |
| 53 | |
| 54 | config_default = { |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 55 | "param": None, |
| 56 | "fv_cmd": "/home/openflow/flowvisor/scripts/flowvisor.sh", |
| 57 | "platform": "local", |
| 58 | "controller_host": "127.0.0.1", |
Charles Chan | 029be65 | 2015-08-24 01:46:10 +0800 | [diff] [blame] | 59 | "controller_port": 6653, |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 60 | "timeout": 3, |
| 61 | "port_count": 4, |
| 62 | "base_of_port": 1, |
| 63 | "base_if_index": 1, |
| 64 | "test_spec": "all", |
| 65 | "test_dir": ".", |
| 66 | "log_file": "/home/openflow/fvt.log", |
| 67 | "list": False, |
| 68 | "debug": "debug", |
| 69 | "dbg_level": logging.DEBUG, |
| 70 | "port_map": {}, |
| 71 | "test_params": "None" |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 72 | } |
| 73 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 74 | |
| 75 | def test_set_init( config ): |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 76 | """ |
| 77 | Set up function for basic test classes |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 78 | config: The configuration dictionary; see fvt |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 79 | """ |
| 80 | global basic_port_map |
| 81 | global basic_fv_cmd |
| 82 | global basic_logger |
| 83 | global basic_timeout |
| 84 | global basic_config |
| 85 | global baisc_logger |
| 86 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 87 | basic_fv_cmd = config[ "fv_cmd" ] |
| 88 | basic_timeout = config[ "timeout" ] |
| 89 | basic_port_map = config[ "port_map" ] |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 90 | basic_config = config |
| 91 | |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 92 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 93 | class FvtApiDriver( API, templatetest.TemplateTest ): |
| 94 | |
| 95 | def __init__( self ): |
| 96 | super( API, self ).__init__() |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 97 | print 'init' |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 98 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 99 | def connect( self, **connectargs ): |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 100 | for key in connectargs: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 101 | vars( self )[ key ] = connectargs[ key ] |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 102 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 103 | self.name = self.options[ 'name' ] |
| 104 | connect_result = super( API, self ).connect() |
| 105 | self.logFileName = main.logdir + "/" + self.name + ".session" |
| 106 | config_default[ "log_file" ] = self.logFileName |
| 107 | test_set_init( config_default ) |
| 108 | __builtin__.basic_logger = vars( main )[ self.name + 'log' ] |
| 109 | __builtin__.basic_logger.info( "Calling my test setup" ) |
| 110 | self.setUp( basic_logger ) |
| 111 | |
| 112 | ( self.fv, self.sv, sv_ret, ctl_ret, sw_ret ) = testutils.setUpTestEnv( |
| 113 | self, fv_cmd=basic_fv_cmd ) |
| 114 | |
| 115 | self.chkSetUpCondition( self.fv, sv_ret, ctl_ret, sw_ret ) |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 116 | return main.TRUE |
| 117 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 118 | def simplePacket( self, dl_src ): |
| 119 | dl_src = vars( testutils )[ dl_src ] |
| 120 | return testutils.simplePacket( dl_src=dl_src ) |
| 121 | |
| 122 | def genPacketIn( self, in_port, pkt ): |
| 123 | return testutils.genPacketIn( in_port=in_port, pkt=pkt ) |
| 124 | |
| 125 | def ofmsgSndCmp( self, snd_list, exp_list, xid_ignore=True, hdr_only=True ): |
| 126 | return testutils.ofmsgSndCmp( self, snd_list, exp_list, xid_ignore, hdr_only ) |
| 127 | |
| 128 | def setRule( self, sv, rule, num_try ): |
| 129 | return testutils.setRule( self, sv, rule, num_try ) |
| 130 | |
| 131 | def chkFlowdb( self, controller_number, switch_number, exp_count, exp_rewrites ): |
| 132 | return testutils.chkFlowdb( self, controller_number, switch_number, exp_count, exp_rewrites ) |
| 133 | |
| 134 | def chkSwitchStats( self, switch_number, ofproto, exp_snd_count, exp_rcv_count ): |
| 135 | return testutils.chkSwitchStats( self, switch_number, ofproto, exp_snd_count, exp_rcv_count ) |
| 136 | |
| 137 | def chkSliceStats( self, controller_number, ofproto, exp_snd_count, exp_rcv_count ): |
| 138 | return testutils.chkSliceStats( self, controller_number, ofproto, exp_snd_count, exp_rcv_count ) |
| 139 | |
| 140 | def recvStats( self, swId, typ ): |
| 141 | return testutils.recvStats( self, swId, typ ) |
| 142 | |
| 143 | def ofmsgSndCmpWithXid( self, snd_list, exp_list, xid_ignore, hdr_only ): |
| 144 | return testutils.ofmsgSndCmpWithXid( self, snd_list, exp_list, xid_ignore, hdr_only ) |
| 145 | |
| 146 | def genPacketOut( self, xid, buffer_id, in_port, action_ports, pkt ): |
| 147 | return testutils.genPacketOut( self, xid, buffer_id, in_port, action_ports, pkt ) |
| 148 | |
| 149 | def genFlowModFlush( self ): |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 150 | return testutils.genFlowModFlush() |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 151 | |
| 152 | def genPhyPort( self, name, addr, port_no ): |
| 153 | return testutils.genPhyPort( name, addr, port_no ) |
| 154 | |
| 155 | def disconnect( self, handle ): |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 156 | response = '' |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 157 | """ |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 158 | if self.handle: |
| 159 | self.handle = handle |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 160 | response = self.execute( cmd="exit",prompt="(.*)",timeout=120 ) |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 161 | else : |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 162 | main.log.error( "Connection failed to the host" ) |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 163 | response = main.FALSE |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 164 | """ |
| 165 | return response |
| 166 | |
| 167 | def setUp( self, basic_logger ): |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 168 | self.logger = basic_logger |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 169 | # basic_logger.info( "** START TEST CASE " + str( self ) ) |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 170 | if basic_timeout == 0: |
| 171 | self.timeout = None |
| 172 | else: |
| 173 | self.timeout = basic_timeout |
| 174 | self.fv = None |
| 175 | self.sv = None |
| 176 | self.controllers = [] |
| 177 | self.switches = [] |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 178 | |
| 179 | def close_log_handles( self ): |
| 180 | self.tearDown() |
| 181 | vars( main )[ self.name + 'log' ].removeHandler( self.log_handler ) |
| 182 | # if self.logfile_handler: |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 183 | # self.logfile_handler.close() |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 184 | |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 185 | return main.TRUE |
| 186 | |