Merge pull request #77 from opennetworkinglab/devl/testcase_exceptions
Devl/testcase exceptions
diff --git a/TestON/core/teston.py b/TestON/core/teston.py
index 3f07691..0925edd 100644
--- a/TestON/core/teston.py
+++ b/TestON/core/teston.py
@@ -146,6 +146,7 @@
'''
This method will initialize specified component
'''
+ import importlib
global driver_options
self.log.info("Creating component Handle: "+component)
driver_options = {}
@@ -157,7 +158,7 @@
driver_options ['type'] = driverName
classPath = self.getDriverPath(driverName.lower())
- driverModule = __import__(classPath, globals(), locals(), [driverName.lower()], -1)
+ driverModule = importlib.import_module(classPath)
driverClass = getattr(driverModule, driverName)
driverObject = driverClass()
@@ -240,8 +241,10 @@
exec code[testCaseNumber][step] in module.__dict__
self.stepCount = self.stepCount + 1
except TypeError,e:
+ print "Exception in the following section of code:"
+ print code[testCaseNumber][step]
self.stepCount = self.stepCount + 1
- self.log.error(e)
+ self.log.exception(e)
return main.TRUE
if cli.stop:
@@ -442,8 +445,8 @@
try :
import json
response_dict = json.loads(response)
- except Exception , e :
- print e
+ except Exception, e:
+ main.log.exception(e)
main.log.error("Json Parser is unable to parse the string")
return response_dict
@@ -461,7 +464,7 @@
try :
response_dict = xmldict.xml_to_dict("<response> "+str(response)+" </response>")
except Exception, e:
- main.log.error(e)
+ main.log.exception(e)
return response_dict
def dict_to_return_format(self,response,return_format,response_dict):
diff --git a/TestON/drivers/common/cli/onosdriver.py b/TestON/drivers/common/cli/onosdriver.py
index c2b3693..328ac0e 100644
--- a/TestON/drivers/common/cli/onosdriver.py
+++ b/TestON/drivers/common/cli/onosdriver.py
@@ -1590,3 +1590,49 @@
main.cleanup()
main.exit()
+ def detailed_status(self, log_filename):
+ '''
+ This method is used by STS to check the status of the controller
+ Reports RUNNING, STARTING, STOPPED, FROZEN, ERROR (and reason)
+ '''
+ import re
+ try:
+ self.handle.sendline( "" )
+ self.handle.expect( "\$" )
+ self.handle.sendline( "cd " + self.home )
+ self.handle.expect( "\$" )
+ self.handle.sendline( "service onos status" )
+ self.handle.expect( "\$" )
+ response = self.handle.before
+ if re.search( "onos start/running", response ):
+ # onos start/running, process 10457
+ return 'RUNNING'
+ # FIXME: Implement this case
+ # elif re.search( pattern, response ):
+ # return 'STARTING'
+ elif re.search( "onos stop/", response ):
+ # onos stop/waiting
+ # FIXME handle this differently?: onos stop/pre-stop
+ return 'STOPPED'
+ # FIXME: Implement this case
+ # elif re.search( pattern, response ):
+ # return 'FROZEN'
+ else:
+ main.log.warn( self.name +
+ " WARNING: status recieved unknown response" )
+ main.log.warn( response )
+ return 'ERROR', "Unknown response: %s" % response
+ except pexpect.TIMEOUT:
+ main.log.exception( self.name + ": Timeout exception in "
+ "setIpTables function" )
+ return 'ERROR', "Pexpect Timeout"
+ except pexpect.EOF:
+ main.log.error( self.name + ": EOF exception found" )
+ main.log.error( self.name + ": " + self.handle.before )
+ main.cleanup()
+ main.exit()
+ except:
+ main.log.exception( "Unknown error:")
+ main.cleanup()
+ main.exit()
+
diff --git a/TestON/drivers/component.py b/TestON/drivers/component.py
index 1e87d03..f05be55 100644
--- a/TestON/drivers/component.py
+++ b/TestON/drivers/component.py
@@ -23,9 +23,6 @@
"""
-import re
-from logging import Logger
-
class Component( object ):
@@ -35,30 +32,39 @@
def __init__( self ):
self.default = ''
self.wrapped = sys.modules[ __name__ ]
+ self.count = 0
def __getattr__( self, name ):
"""
This will invoke, if the attribute wasn't found the usual ways.
- Here it will look for assert_attribute and will execute when AttributeError occurs.
- It will return the result of the assert_attribute.
+ Here it will look for assert_attribute and will execute when
+ AttributeError occurs.
+ It will return the result of the assert_attribute.
"""
try:
return getattr( self.wrapped, name )
- except AttributeError:
+ except AttributeError as error:
+ # NOTE: The first time we load a driver module we get this error
+ if "'module' object has no attribute '__path__'" in error\
+ and self.count == 0:
+ self.count += 1
+ else:
+ main.log.error( str(error.__class__) + " " + str(error) )
try:
- def experimentHandling( **kwargs ):
+ def experimentHandling( *args, **kwargs ):
if main.EXPERIMENTAL_MODE == main.TRUE:
- result = self.experimentRun( **kwargs )
- main.log.info( "EXPERIMENTAL MODE. API " + str(
- name ) + " not yet implemented. Returning dummy values" )
+ result = self.experimentRun( *args, **kwargs )
+ main.log.info( "EXPERIMENTAL MODE. API " +
+ str( name ) +
+ " not yet implemented. " +
+ "Returning dummy values" )
return result
else:
return main.FALSE
return experimentHandling
except TypeError as e:
- main.log.error(
- "Arguments for experimental mode does not have key 'retruns'" +
- e )
+ main.log.error( "Arguments for experimental mode does not" +
+ " have key 'retruns'" + e )
def connect( self ):
@@ -110,7 +116,8 @@
def get_version( self ):
return "Version unknown"
- def experimentRun( self, **kwargs ):
+ def experimentRun( self, *args, **kwargs ):
+ # FIXME handle *args
args = utilities.parse_args( [ "RETURNS" ], **kwargs )
return args[ "RETURNS" ]