Beispiel #1
0
 def resolveNames(self):
     """
     Resolve any names given in the parameters.
     
     This methods is called after all objects have been initialized.
     """
     pdict = self.scenario.getObjectsDict('parser')
     if self.parserNames:
         for parser in self.parserNames:
             if parser not in pdict:
                 try:
                     Campaign.loadModule( 'parser', parser )
                 except ImportError:
                     raise Exception( "Execution defined at line {0} refers to parser {1} which is never declared".format( self.declarationLine, parser ) )
     self.host = self.scenario.resolveObjectName( 'host', self.hostName )
     self.client = self.scenario.resolveObjectName( 'client', self.clientName )
     self.files = []
     if self.fileNames:
         for fileName in self.fileNames:
             self.files.append( self.scenario.resolveObjectName( 'file', fileName ) )
     if self.parserNames:
         self.parsers = []
         for parser in self.parserNames:
             if parser in pdict:
                 self.parsers.append( pdict[parser] )
             else:
                 modclass = Campaign.loadModule( 'parser', parser )
                 # *Sigh*. PyLint. Dynamic loading!
                 # pylint: disable-msg=E1121
                 obj = modclass( self.scenario )
                 # pylint: enable-msg=E1121
                 obj.checkSettings()
                 self.parsers.append( obj )
Beispiel #2
0
    def loadDefaultParsers(self, execution):
        """
        Loads the default parsers for the given execution.

        The order in which parsers are determined is this (first hit goes):
        - The parsers given in the execution object
        - The parsers given in the client object
        - The parser object with the same name as the client
        - The parser with the same name as the client
        The second, third and fourth are to be loaded by this method.
        
        @param  execution       The execution for which to load a parser.

        @return The list of parser instances.
        """
        if self.parsers:
            return client.loadDefaultParsers(self, execution)
        else:
            if execution.isSeeder():
                parserType = 'lighttpd'
            else:
                parserType = 'aria2'
            if parserType in self.scenario.getObjectsDict( 'parser' ):
                return [self.scenario.getObjectsDict( 'parser' )[parserType]]
            else:
                modclass = Campaign.loadModule( 'parser', parserType )
                # *Sigh*. PyLint. Dynamic loading!
                # pylint: disable-msg=E1121
                obj = modclass( self.scenario )
                # pylint: enable-msg=E1121
                obj.checkSettings()
                return [obj]
Beispiel #3
0
 def writeCommandLog(self, log):
     try:
         self.the__lock.acquire()
         f = open(
             os.path.join(
                 Campaign.getCurrentCampaign().campaignResultsDir, "__host__test__{0}__.log".format(self.name)
             ),
             "a",
         )
         f.write(log)
         f.close()
     finally:
         try:
             self.the__lock.release()
         except RuntimeError:
             pass
Beispiel #4
0
    def checkSettings(self):
        """
        Check the sanity of the settings in this object.

        This method is called after all calls to parseSetting(...) have been done.
        Any defaults may be set here as well.

        An Exception is raised in the case of insanity.
        """
        core.file.file.checkSettings(self)

        if not self.path:
            raise Exception( "file:local {0} must have a local path specified".format( self.name ) )
        if self.metaFile and self.generateTorrent:
            raise Exception( "file:local {0} has requested automated torrent generation, but a meta file was already given".format( self.name ) )
        for cs in self.generateRootHashes:
            if cs in self.rootHashes:
                raise Exception( "Generation of root hash for chunksize {0} was requested, but that root hash was already set on the file.".format( cs ) )
        if os.path.isdir( self.path ):
            if len(self.generateRootHashes) > 0:
                raise Exception( "file:local {0} has requested automated root hash calculation, but {1} is a directory, for which root hashes aren't supported".format( self.name, self.path ) )
            if self.renameFile:
                raise Exception( "file:local {0} has requested the uploaded file to be renamed, but {1} is a directory, for which this is not supported".format( self.name, self.path ) )
        if len(self.generateRootHashes) > 0 or self.generateTorrent:
            meta = Campaign.loadCoreModule('meta')
            # PyLint really doesn't understand dynamic loading
            # pylint: disable-msg=E1101
            for cs in self.generateRootHashes:
                if type(cs) != int and cs[-1:] == 'L':
                    self.rootHashes[cs] = meta.calculateMerkleRootHash( self.path, False, int(cs[:-1]) ).encode( 'hex' )
                else:
                    self.rootHashes[cs] = meta.calculateMerkleRootHash( self.path, True, cs).encode( 'hex' )
                if cs == 1:
                    self.rootHash = self.rootHashes[1]
            if self.generateTorrent:
                if self.isInCleanup():
                    return
                tempfd, self.tempMetaFile = tempfile.mkstemp('.torrent')
                os.close(tempfd)
                self.metaFile = self.tempMetaFile
                meta.generateTorrentFile( self.path, self.metaFile )