Package TestON :: Package drivers :: Package common :: Package api :: Module fvtapidriver
[hide private]
[frames] | no frames]

Source Code for Module TestON.drivers.common.api.fvtapidriver

  1  #!/usr/bin/env python 
  2  ''' 
  3  Created on 26-Oct-2012 
  4   
  5  @author: Anil Kumar (anilkumar.s@paxterrasolutions.com) 
  6   
  7  fvtapidriver is the basic driver which will handle the fvtapidriver functions 
  8  ''' 
  9  ''' 
 10  There are two changes required in flowvisor-test framework : 
 11   
 12  1. In ~/flowvisortests/tests/templatetest.py line : 15 comment 'basic_logger = None' 
 13  2. In ~/flowvisortests/tests/testutils.py line : 50 specify config file path CONFIG_FILE = "~/flowvisor-test/tests/tests-base.json" 
 14   
 15  ''' 
 16  import pexpect 
 17  import struct 
 18  import fcntl 
 19  import os 
 20  import signal 
 21  import re 
 22  import sys 
 23  import core.ofautomation 
 24  sys.path.append("../") 
 25  from common.apidriver import API 
 26  import logging 
 27   
 28  sys.path.append(path+"/lib/flowvisor-test/tests") 
 29  sys.path.append(path+"/lib/flowvisor-test/src/python/") 
 30   
 31  import templatetest 
 32  import testutils 
 33  import oftest.cstruct as ofp 
 34  import oftest.message as message 
 35  import oftest.parse as parse 
 36  import oftest.action as action 
 37  import oftest.error as error 
 38  import socket 
 39  import __builtin__ 
 40   
 41  config_default = { 
 42      "param"              : None, 
 43      "fv_cmd"             : "/home/openflow/flowvisor/scripts/flowvisor.sh", 
 44      "platform"           : "local", 
 45      "controller_host"    : "127.0.0.1", 
 46      "controller_port"    : 6633, 
 47      "timeout"            : 3, 
 48      "port_count"         : 4, 
 49      "base_of_port"       : 1, 
 50      "base_if_index"      : 1, 
 51      "test_spec"          : "all", 
 52      "test_dir"           : ".", 
 53      "log_file"           : "/home/openflow/fvt.log", 
 54      "list"               : False, 
 55      "debug"              : "debug", 
 56      "dbg_level"          : logging.DEBUG, 
 57      "port_map"           : {}, 
 58      "test_params"        : "None" 
 59  } 
 60   
61 -def test_set_init(config):
62 """ 63 Set up function for basic test classes 64 @param config The configuration dictionary; see fvt 65 """ 66 global basic_port_map 67 global basic_fv_cmd 68 global basic_logger 69 global basic_timeout 70 global basic_config 71 global baisc_logger 72 73 basic_fv_cmd = config["fv_cmd"] 74 basic_timeout = config["timeout"] 75 basic_port_map = config["port_map"] 76 basic_config = config
77
78 -class FvtApiDriver(API,templatetest.TemplateTest):
79
80 - def __init__(self):
81 super(API, self).__init__() 82 print 'init'
83 84
85 - def connect(self,**connectargs):
86 for key in connectargs: 87 vars(self)[key] = connectargs[key] 88 89 self.name = self.options['name'] 90 connect_result = super(API,self).connect() 91 self.logFileName = main.logdir+"/"+self.name+".session" 92 config_default["log_file"] = self.logFileName 93 test_set_init(config_default) 94 __builtin__.basic_logger = vars(main)[self.name+'log'] 95 __builtin__.basic_logger.info("Calling my test setup") 96 self.setUp(basic_logger) 97 98 (self.fv, self.sv, sv_ret, ctl_ret, sw_ret) = testutils.setUpTestEnv(self, fv_cmd=basic_fv_cmd) 99 100 self.chkSetUpCondition(self.fv, sv_ret, ctl_ret, sw_ret) 101 return main.TRUE
102
103 - def simplePacket(self,dl_src):
104 dl_src = vars(testutils)[dl_src] 105 return testutils.simplePacket(dl_src = dl_src)
106
107 - def genPacketIn(self, in_port, pkt):
108 return testutils.genPacketIn(in_port=in_port, pkt=pkt)
109
110 - def ofmsgSndCmp(self, snd_list, exp_list, xid_ignore=True, hdr_only=True):
111 return testutils.ofmsgSndCmp(self, snd_list, exp_list, xid_ignore, hdr_only)
112
113 - def setRule(self,sv,rule,num_try) :
114 return testutils.setRule(self,sv,rule,num_try)
115
116 - def chkFlowdb(self,controller_number,switch_number,exp_count,exp_rewrites) :
117 return testutils.chkFlowdb(self,controller_number,switch_number,exp_count,exp_rewrites)
118
119 - def chkSwitchStats(self, switch_number, ofproto, exp_snd_count, exp_rcv_count):
120 return testutils.chkSwitchStats(self, switch_number, ofproto, exp_snd_count, exp_rcv_count)
121
122 - def chkSliceStats(self,controller_number,ofproto,exp_snd_count,exp_rcv_count) :
123 return testutils.chkSliceStats(self,controller_number,ofproto,exp_snd_count,exp_rcv_count)
124
125 - def recvStats(self,swId,typ) :
126 return testutils.recvStats(self,swId,typ)
127
128 - def ofmsgSndCmpWithXid(self,snd_list,exp_list,xid_ignore,hdr_only) :
129 return testutils.ofmsgSndCmpWithXid(self,snd_list,exp_list,xid_ignore,hdr_only)
130
131 - def genPacketOut(self,xid,buffer_id,in_port,action_ports,pkt) :
132 return testutils.genPacketOut(self,xid,buffer_id,in_port,action_ports,pkt)
133
134 - def genFlowModFlush(self) :
135 return testutils.genFlowModFlush()
136
137 - def genPhyPort(self,name,addr,port_no) :
138 return testutils.genPhyPort(name,addr,port_no)
139
140 - def disconnect(self,handle):
141 response = '' 142 ''' 143 if self.handle: 144 self.handle = handle 145 response = self.execute(cmd="exit",prompt="(.*)",timeout=120) 146 else : 147 main.log.error("Connection failed to the host") 148 response = main.FALSE 149 ''' 150 return response
151
152 - def setUp(self,basic_logger):
153 self.logger = basic_logger 154 #basic_logger.info("** START TEST CASE " + str(self)) 155 if basic_timeout == 0: 156 self.timeout = None 157 else: 158 self.timeout = basic_timeout 159 self.fv = None 160 self.sv = None 161 self.controllers = [] 162 self.switches = []
163
164 - def close_log_handles(self) :
165 self.tearDown() 166 vars(main)[self.name+'log'].removeHandler(self.log_handler) 167 #if self.logfile_handler: 168 # self.logfile_handler.close() 169 170 return main.TRUE
171