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 |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 4 | Copyright 2012 Open Networking Foundation ( ONF ) |
Jeremy Songster | ae01bba | 2016-07-11 15:39:17 -0700 | [diff] [blame] | 5 | |
| 6 | Please refer questions to either the onos test mailing list at <onos-test@onosproject.org>, |
| 7 | the System Testing Plans and Results wiki page at <https://wiki.onosproject.org/x/voMg>, |
| 8 | or the System Testing Guide page at <https://wiki.onosproject.org/x/WYQg> |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 9 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 10 | author:: Anil Kumar ( anilkumar.s@paxterrasolutions.com ) |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 11 | |
| 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 |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 16 | ( at your option ) any later version. |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 17 | |
| 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 |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 24 | along with TestON. If not, see <http://www.gnu.org/licenses/>. |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 25 | |
| 26 | |
| 27 | fvtapidriver is the basic driver which will handle the fvtapidriver functions |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 28 | """""" |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 29 | There are two changes required in flowvisor-test framework : |
| 30 | |
| 31 | 1. In ~/flowvisortests/tests/templatetest.py line : 15 comment 'basic_logger = None' |
| 32 | 2. In ~/flowvisortests/tests/testutils.py line : 50 specify config file path CONFIG_FILE = "~/flowvisor-test/tests/tests-base.json" |
| 33 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 34 | """ |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 35 | import pexpect |
| 36 | import struct |
| 37 | import fcntl |
| 38 | import os |
| 39 | import signal |
| 40 | import re |
| 41 | import sys |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 42 | from common.apidriver import API |
| 43 | import logging |
| 44 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 45 | sys.path.append( path + "/lib/flowvisor-test/tests" ) |
| 46 | sys.path.append( path + "/lib/flowvisor-test/src/python/" ) |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 47 | |
| 48 | import templatetest |
| 49 | import testutils |
| 50 | import oftest.cstruct as ofp |
| 51 | import oftest.message as message |
| 52 | import oftest.parse as parse |
| 53 | import oftest.action as action |
| 54 | import oftest.error as error |
| 55 | import socket |
| 56 | import __builtin__ |
| 57 | |
| 58 | config_default = { |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 59 | "param": None, |
| 60 | "fv_cmd": "/home/openflow/flowvisor/scripts/flowvisor.sh", |
| 61 | "platform": "local", |
| 62 | "controller_host": "127.0.0.1", |
Charles Chan | 029be65 | 2015-08-24 01:46:10 +0800 | [diff] [blame] | 63 | "controller_port": 6653, |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 64 | "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" |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 76 | } |
| 77 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 78 | |
| 79 | def test_set_init( config ): |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 80 | """ |
| 81 | Set up function for basic test classes |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 82 | config: The configuration dictionary; see fvt |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 83 | """ |
| 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 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 91 | basic_fv_cmd = config[ "fv_cmd" ] |
| 92 | basic_timeout = config[ "timeout" ] |
| 93 | basic_port_map = config[ "port_map" ] |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 94 | basic_config = config |
| 95 | |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 96 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 97 | class FvtApiDriver( API, templatetest.TemplateTest ): |
| 98 | |
| 99 | def __init__( self ): |
Devin Lim | dc78e20 | 2017-06-09 18:30:07 -0700 | [diff] [blame] | 100 | super( FvtApiDriver, self ).__init__() |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 101 | print 'init' |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 102 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 103 | def connect( self, **connectargs ): |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 104 | for key in connectargs: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 105 | vars( self )[ key ] = connectargs[ key ] |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 106 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 107 | 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 ) |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 120 | return main.TRUE |
| 121 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 122 | 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 ): |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 154 | return testutils.genFlowModFlush() |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 155 | |
| 156 | def genPhyPort( self, name, addr, port_no ): |
| 157 | return testutils.genPhyPort( name, addr, port_no ) |
| 158 | |
| 159 | def disconnect( self, handle ): |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 160 | response = '' |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 161 | """ |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 162 | if self.handle: |
| 163 | self.handle = handle |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 164 | response = self.execute( cmd="exit",prompt="(.*)",timeout=120 ) |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 165 | else : |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 166 | main.log.error( "Connection failed to the host" ) |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 167 | response = main.FALSE |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 168 | """ |
| 169 | return response |
| 170 | |
| 171 | def setUp( self, basic_logger ): |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 172 | self.logger = basic_logger |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 173 | # basic_logger.info( "** START TEST CASE " + str( self ) ) |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 174 | 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 = [] |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 182 | |
| 183 | def close_log_handles( self ): |
| 184 | self.tearDown() |
| 185 | vars( main )[ self.name + 'log' ].removeHandler( self.log_handler ) |
| 186 | # if self.logfile_handler: |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 187 | # self.logfile_handler.close() |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 188 | |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 189 | return main.TRUE |