You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 1 | """ |
| 2 | This file contains classes for CHOTestMonkey that are related to check event |
| 3 | Author: you@onlab.us |
| 4 | """ |
| 5 | from tests.CHOTestMonkey.dependencies.events.Event import EventType, EventStates, Event |
| 6 | |
| 7 | class TestEvent( Event ): |
| 8 | def __init__( self ): |
| 9 | Event.__init__( self ) |
| 10 | |
| 11 | def startTestEvent( self ): |
| 12 | return EventStates().PASS |
| 13 | |
| 14 | def startEvent( self, args ): |
| 15 | with self.eventLock: |
| 16 | main.log.info( "%s - starting event" % ( self.typeString ) ) |
| 17 | result = self.startTestEvent( args ) |
| 18 | return result |
| 19 | |
| 20 | class TestPause( TestEvent ): |
| 21 | def __init__( self ): |
| 22 | TestEvent.__init__( self ) |
| 23 | self.typeString = main.params[ 'EVENT' ][ self.__class__.__name__ ][ 'typeString' ] |
| 24 | self.typeIndex = int( main.params[ 'EVENT' ][ self.__class__.__name__ ][ 'typeIndex' ] ) |
| 25 | |
| 26 | def startTestEvent( self, args=None ): |
| 27 | result = EventStates().PASS |
| 28 | main.eventScheduler.setRunningState( False ) |
| 29 | return result |
| 30 | |
| 31 | class TestResume( TestEvent ): |
| 32 | def __init__( self ): |
| 33 | TestEvent.__init__( self ) |
| 34 | self.typeString = main.params[ 'EVENT' ][ self.__class__.__name__ ][ 'typeString' ] |
| 35 | self.typeIndex = int( main.params[ 'EVENT' ][ self.__class__.__name__ ][ 'typeIndex' ] ) |
| 36 | |
| 37 | def startTestEvent( self, args=None ): |
| 38 | result = EventStates().PASS |
| 39 | main.eventScheduler.setRunningState( True ) |
| 40 | return result |
| 41 | |
| 42 | class TestSleep( TestEvent ): |
| 43 | def __init__( self ): |
| 44 | TestEvent.__init__( self ) |
| 45 | self.typeString = main.params[ 'EVENT' ][ self.__class__.__name__ ][ 'typeString' ] |
| 46 | self.typeIndex = int( main.params[ 'EVENT' ][ self.__class__.__name__ ][ 'typeIndex' ] ) |
| 47 | |
| 48 | def startTestEvent( self, args ): |
| 49 | import time |
| 50 | result = EventStates().PASS |
| 51 | if len( args ) < 1: |
| 52 | main.log.warn( "%s - Not enough arguments: %s" % ( self.typeString, args ) ) |
| 53 | result = EventStates().ABORT |
| 54 | elif len( args ) > 1: |
| 55 | main.log.warn( "%s - Too many arguments: %s" % ( self.typeString, args ) ) |
| 56 | result = EventStates().ABORT |
| 57 | sleepTime = int( args[ 0 ] ) |
| 58 | time.sleep( sleepTime ) |
| 59 | return result |