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 Songster | ae01bba | 2016-07-11 15:39:17 -0700 | [diff] [blame] | 4 | Modified 2015 by ON.Lab |
| 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 |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 28 | """ |
| 29 | """ |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 30 | There are two changes required in flowvisor-test framework : |
| 31 | |
| 32 | 1. In ~/flowvisortests/tests/templatetest.py line : 15 comment 'basic_logger = None' |
| 33 | 2. In ~/flowvisortests/tests/testutils.py line : 50 specify config file path CONFIG_FILE = "~/flowvisor-test/tests/tests-base.json" |
| 34 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 35 | """ |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 36 | import pexpect |
| 37 | import struct |
| 38 | import fcntl |
| 39 | import os |
| 40 | import signal |
| 41 | import re |
| 42 | import sys |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 43 | from common.apidriver import API |
| 44 | import logging |
| 45 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 46 | sys.path.append( path + "/lib/flowvisor-test/tests" ) |
| 47 | sys.path.append( path + "/lib/flowvisor-test/src/python/" ) |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 48 | |
| 49 | import templatetest |
| 50 | import testutils |
| 51 | import oftest.cstruct as ofp |
| 52 | import oftest.message as message |
| 53 | import oftest.parse as parse |
| 54 | import oftest.action as action |
| 55 | import oftest.error as error |
| 56 | import socket |
| 57 | import __builtin__ |
| 58 | |
| 59 | config_default = { |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 60 | "param": None, |
| 61 | "fv_cmd": "/home/openflow/flowvisor/scripts/flowvisor.sh", |
| 62 | "platform": "local", |
| 63 | "controller_host": "127.0.0.1", |
Charles Chan | 029be65 | 2015-08-24 01:46:10 +0800 | [diff] [blame] | 64 | "controller_port": 6653, |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 65 | "timeout": 3, |
| 66 | "port_count": 4, |
| 67 | "base_of_port": 1, |
| 68 | "base_if_index": 1, |
| 69 | "test_spec": "all", |
| 70 | "test_dir": ".", |
| 71 | "log_file": "/home/openflow/fvt.log", |
| 72 | "list": False, |
| 73 | "debug": "debug", |
| 74 | "dbg_level": logging.DEBUG, |
| 75 | "port_map": {}, |
| 76 | "test_params": "None" |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 77 | } |
| 78 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 79 | |
| 80 | def test_set_init( config ): |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 81 | """ |
| 82 | Set up function for basic test classes |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 83 | config: The configuration dictionary; see fvt |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 84 | """ |
| 85 | global basic_port_map |
| 86 | global basic_fv_cmd |
| 87 | global basic_logger |
| 88 | global basic_timeout |
| 89 | global basic_config |
| 90 | global baisc_logger |
| 91 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 92 | basic_fv_cmd = config[ "fv_cmd" ] |
| 93 | basic_timeout = config[ "timeout" ] |
| 94 | basic_port_map = config[ "port_map" ] |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 95 | basic_config = config |
| 96 | |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 97 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 98 | class FvtApiDriver( API, templatetest.TemplateTest ): |
| 99 | |
| 100 | def __init__( self ): |
Devin Lim | dc78e20 | 2017-06-09 18:30:07 -0700 | [diff] [blame] | 101 | super( FvtApiDriver, self ).__init__() |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 102 | print 'init' |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 103 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 104 | def connect( self, **connectargs ): |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 105 | for key in connectargs: |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 106 | vars( self )[ key ] = connectargs[ key ] |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 107 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 108 | self.name = self.options[ 'name' ] |
| 109 | connect_result = super( API, self ).connect() |
| 110 | self.logFileName = main.logdir + "/" + self.name + ".session" |
| 111 | config_default[ "log_file" ] = self.logFileName |
| 112 | test_set_init( config_default ) |
| 113 | __builtin__.basic_logger = vars( main )[ self.name + 'log' ] |
| 114 | __builtin__.basic_logger.info( "Calling my test setup" ) |
| 115 | self.setUp( basic_logger ) |
| 116 | |
| 117 | ( self.fv, self.sv, sv_ret, ctl_ret, sw_ret ) = testutils.setUpTestEnv( |
| 118 | self, fv_cmd=basic_fv_cmd ) |
| 119 | |
| 120 | self.chkSetUpCondition( self.fv, sv_ret, ctl_ret, sw_ret ) |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 121 | return main.TRUE |
| 122 | |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 123 | def simplePacket( self, dl_src ): |
| 124 | dl_src = vars( testutils )[ dl_src ] |
| 125 | return testutils.simplePacket( dl_src=dl_src ) |
| 126 | |
| 127 | def genPacketIn( self, in_port, pkt ): |
| 128 | return testutils.genPacketIn( in_port=in_port, pkt=pkt ) |
| 129 | |
| 130 | def ofmsgSndCmp( self, snd_list, exp_list, xid_ignore=True, hdr_only=True ): |
| 131 | return testutils.ofmsgSndCmp( self, snd_list, exp_list, xid_ignore, hdr_only ) |
| 132 | |
| 133 | def setRule( self, sv, rule, num_try ): |
| 134 | return testutils.setRule( self, sv, rule, num_try ) |
| 135 | |
| 136 | def chkFlowdb( self, controller_number, switch_number, exp_count, exp_rewrites ): |
| 137 | return testutils.chkFlowdb( self, controller_number, switch_number, exp_count, exp_rewrites ) |
| 138 | |
| 139 | def chkSwitchStats( self, switch_number, ofproto, exp_snd_count, exp_rcv_count ): |
| 140 | return testutils.chkSwitchStats( self, switch_number, ofproto, exp_snd_count, exp_rcv_count ) |
| 141 | |
| 142 | def chkSliceStats( self, controller_number, ofproto, exp_snd_count, exp_rcv_count ): |
| 143 | return testutils.chkSliceStats( self, controller_number, ofproto, exp_snd_count, exp_rcv_count ) |
| 144 | |
| 145 | def recvStats( self, swId, typ ): |
| 146 | return testutils.recvStats( self, swId, typ ) |
| 147 | |
| 148 | def ofmsgSndCmpWithXid( self, snd_list, exp_list, xid_ignore, hdr_only ): |
| 149 | return testutils.ofmsgSndCmpWithXid( self, snd_list, exp_list, xid_ignore, hdr_only ) |
| 150 | |
| 151 | def genPacketOut( self, xid, buffer_id, in_port, action_ports, pkt ): |
| 152 | return testutils.genPacketOut( self, xid, buffer_id, in_port, action_ports, pkt ) |
| 153 | |
| 154 | def genFlowModFlush( self ): |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 155 | return testutils.genFlowModFlush() |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 156 | |
| 157 | def genPhyPort( self, name, addr, port_no ): |
| 158 | return testutils.genPhyPort( name, addr, port_no ) |
| 159 | |
| 160 | def disconnect( self, handle ): |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 161 | response = '' |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 162 | """ |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 163 | if self.handle: |
| 164 | self.handle = handle |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 165 | response = self.execute( cmd="exit",prompt="(.*)",timeout=120 ) |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 166 | else : |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 167 | main.log.error( "Connection failed to the host" ) |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 168 | response = main.FALSE |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 169 | """ |
| 170 | return response |
| 171 | |
| 172 | def setUp( self, basic_logger ): |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 173 | self.logger = basic_logger |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 174 | # basic_logger.info( "** START TEST CASE " + str( self ) ) |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 175 | if basic_timeout == 0: |
| 176 | self.timeout = None |
| 177 | else: |
| 178 | self.timeout = basic_timeout |
| 179 | self.fv = None |
| 180 | self.sv = None |
| 181 | self.controllers = [] |
| 182 | self.switches = [] |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 183 | |
| 184 | def close_log_handles( self ): |
| 185 | self.tearDown() |
| 186 | vars( main )[ self.name + 'log' ].removeHandler( self.log_handler ) |
| 187 | # if self.logfile_handler: |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 188 | # self.logfile_handler.close() |
kelvin | 8ec7144 | 2015-01-15 16:57:00 -0800 | [diff] [blame] | 189 | |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 190 | return main.TRUE |
| 191 | |