def run_test( self, installerPath, vm, testcase, res ):  
        steps = testcase.steps()
        if len( steps ) == 0:
            raise ControlException( "No steps found for testcase {0}".format( testcase.name() ) )

        revertStatus, _ = vm.revertToSnapshot()
        if revertStatus != 0:
            raise VMException( "Failed to revert to snapshot '{0}'".format( vm.snapshot() ) )

        
        time.sleep( 5 ) # Trying to avoid a possible race between restore and start
        
        vm.start()

        try:
            try:
                vm.checkPythonInstalled()        
                wrapperpath = vm.copyToTemp( utils.execution_path( 'guest.py' ) )
                
                for stepNum in range( len( steps ) ):
                    needSnapshot = False
                    step = steps[stepNum]
                    if stepNum == 0:               
                        executableguestpath = vm.copyToTemp( installerPath )
                    else:
                        executableguestpath = testcase.maintenanceToolLocation()
    
                    outputFileName = 'output{0}.log'.format( stepNum )
                    outputpath = vm.mkTempPath( outputFileName  )
                    scriptguestpath = vm.copyToTemp( step.installscript() )
                    timeout = step.timeout()
                    checkerguestpath = vm.copyToTemp( step.checkerTestDir(), "checkerTestDir{0}".format( stepNum ) ) if len( string.strip( step.checkerTestDir() ) ) > 0 else None
                    vm.command( 'Execute installer', "runProgramInGuest", "'{0}' '{1}' '{2}' '{3}' '{4}' --script '{5}'".format( vm.python(), wrapperpath, outputpath, timeout, executableguestpath, scriptguestpath ) )            
                    vm.copyFromTemp( outputFileName, outputFileName )
                    r = ConfigParser.SafeConfigParser()
                    r.read( outputFileName )
                    try:
                        s = r.get( 'Result', 'ExitCode' )
                        exitCode = int( s )
                    except ValueError:
                        res.addInternalError( "Could not parse integer exit code from '{0}'".format( r.get( 'Result', 'ExitCode' ) ) )                
                        exitCode = -1
                    try:
                        s = r.get( 'Result', 'ExecutionTime' )
                        executionTime = float( s )
                    except ValueError:
                        res.addInternalError( "Could not parse float execution time from '{0}'".format( r.get( 'Result', 'ExecutionTime' ) ) )                
                        executionTime = 0.0 
        
                    exitStatus = result.exitStatusFromString( r.get( 'Result', 'ExitStatus' ) )
                    instR = result.ExecutionResult( exitCode, exitStatus, executionTime )
                    
                    if instR.hasError():
                        needSnapshot = True
                    
                    checkerResults = []
                    if checkerguestpath and not instR.hasError():
                        if ( platform.system() == "Darwin" ):
                            # Have to sleep to work around VMware Fusion bug
                            time.sleep( 30 )
                        run_py = vm.copyToTemp( self._checkerDir ) + vm.pathSep() + "run.py"
                        if ( platform.system() == "Darwin" ):
                            # Have to sleep to work around VMware Fusion bug
                            time.sleep( 30 )
                        checkeroutputFileName = 'checker-output{0}.xml'.format( stepNum )
                        checkeroutput = vm.mkTempPath( checkeroutputFileName )
                        vm.command( 'Execute checker tests', "runProgramInGuest", "'{0}' '{1}' '{2}' -o '{3}' -p '{4}'".format( vm.python(), run_py, checkerguestpath, checkeroutput, testcase.targetDirectory() ) )            
                        vm.copyFromTemp( checkeroutputFileName, checkeroutputFileName )
                        self.convertCheckerResults( localcheckeroutput, checkerResults )
                        if res.hasCheckerErrors():
                            needSnapshot = True
                    if self._createErrorSnapshots and needSnapshot:
                        snapshot = 'error-{0}-{1}'.format( datetime.datetime.now().strftime( '%Y%m%d_%H%M%S' ), utils.randomString( 4 ) )
                        status, _ = vm.createSnapshot( snapshot )
                        if status == 0:
                            res.setErrorSnapshot( snapshot )
                        else:
                            res.addInternalError( 'Could not create error snapshot "{0}"'.format( snapshot ) )
                    res.addStepResult( result.StepResult( instR, checkerResults ) )
                #TODO handle timeouts?
            finally:
                vm.kill()
        except e:
            print( e )
            res.addInternalError( str( e ) )
Exemple #2
0
    def run_test(self, installerPath, vm, testcase, res):
        steps = testcase.steps()
        if len(steps) == 0:
            raise ControlException("No steps found for testcase {0}".format(
                testcase.name()))

        revertStatus, _ = vm.revertToSnapshot()
        if revertStatus != 0:
            raise VMException("Failed to revert to snapshot '{0}'".format(
                vm.snapshot()))

        time.sleep(
            5)  # Trying to avoid a possible race between restore and start

        vm.start()

        try:
            try:
                vm.checkPythonInstalled()
                wrapperpath = vm.copyToTemp(utils.execution_path('guest.py'))

                for stepNum in range(len(steps)):
                    needSnapshot = False
                    step = steps[stepNum]
                    if stepNum == 0:
                        executableguestpath = vm.copyToTemp(installerPath)
                    else:
                        executableguestpath = testcase.maintenanceToolLocation(
                        )

                    outputFileName = 'output{0}.log'.format(stepNum)
                    outputpath = vm.mkTempPath(outputFileName)
                    scriptguestpath = vm.copyToTemp(step.installscript())
                    timeout = step.timeout()
                    checkerguestpath = vm.copyToTemp(
                        step.checkerTestDir(),
                        "checkerTestDir{0}".format(stepNum)) if len(
                            string.strip(step.checkerTestDir())) > 0 else None
                    vm.command(
                        'Execute installer', "runProgramInGuest",
                        "'{0}' '{1}' '{2}' '{3}' '{4}' --script '{5}'".format(
                            vm.python(), wrapperpath, outputpath, timeout,
                            executableguestpath, scriptguestpath))
                    vm.copyFromTemp(outputFileName, outputFileName)
                    r = ConfigParser.SafeConfigParser()
                    r.read(outputFileName)
                    try:
                        s = r.get('Result', 'ExitCode')
                        exitCode = int(s)
                    except ValueError:
                        res.addInternalError(
                            "Could not parse integer exit code from '{0}'".
                            format(r.get('Result', 'ExitCode')))
                        exitCode = -1
                    try:
                        s = r.get('Result', 'ExecutionTime')
                        executionTime = float(s)
                    except ValueError:
                        res.addInternalError(
                            "Could not parse float execution time from '{0}'".
                            format(r.get('Result', 'ExecutionTime')))
                        executionTime = 0.0

                    exitStatus = result.exitStatusFromString(
                        r.get('Result', 'ExitStatus'))
                    instR = result.ExecutionResult(exitCode, exitStatus,
                                                   executionTime)

                    if instR.hasError():
                        needSnapshot = True

                    checkerResults = []
                    if checkerguestpath and not instR.hasError():
                        if (platform.system() == "Darwin"):
                            # Have to sleep to work around VMware Fusion bug
                            time.sleep(30)
                        run_py = vm.copyToTemp(
                            self._checkerDir) + vm.pathSep() + "run.py"
                        if (platform.system() == "Darwin"):
                            # Have to sleep to work around VMware Fusion bug
                            time.sleep(30)
                        checkeroutputFileName = 'checker-output{0}.xml'.format(
                            stepNum)
                        checkeroutput = vm.mkTempPath(checkeroutputFileName)
                        vm.command(
                            'Execute checker tests', "runProgramInGuest",
                            "'{0}' '{1}' '{2}' -o '{3}' -p '{4}'".format(
                                vm.python(), run_py, checkerguestpath,
                                checkeroutput, testcase.targetDirectory()))
                        vm.copyFromTemp(checkeroutputFileName,
                                        checkeroutputFileName)
                        self.convertCheckerResults(localcheckeroutput,
                                                   checkerResults)
                        if res.hasCheckerErrors():
                            needSnapshot = True
                    if self._createErrorSnapshots and needSnapshot:
                        snapshot = 'error-{0}-{1}'.format(
                            datetime.datetime.now().strftime('%Y%m%d_%H%M%S'),
                            utils.randomString(4))
                        status, _ = vm.createSnapshot(snapshot)
                        if status == 0:
                            res.setErrorSnapshot(snapshot)
                        else:
                            res.addInternalError(
                                'Could not create error snapshot "{0}"'.format(
                                    snapshot))
                    res.addStepResult(result.StepResult(instR, checkerResults))
                #TODO handle timeouts?
            finally:
                vm.kill()
        except e:
            print(e)
            res.addInternalError(str(e))
Exemple #3
0
 def init(font="captcha.ttf", size=25):
     self._font = ImageFont.truetype(execution_path(font), size)