Ejemplo n.º 1
0
    def prepareExecution(self, execution, simpleCommandLine = None, complexCommandLine = None):
        """
        Client specific preparations for a specific execution.

        If any scripts for running the client on the host are needed, this is the place to build them.
        Be sure to take self.extraParameters into account, in that case.

        @param  execution           The execution to prepare this client for.
        """
        client.prepareExecution(self, execution, simpleCommandLine = './client_bin > "{0}/log.log"'.format( self.getExecutionLogDir( execution ) ) )
Ejemplo n.º 2
0
    def prepareExecution(self, execution):
        """
        Client specific preparations for a specific execution.

        If any scripts for running the client on the host are needed, this is the place to build them.
        Be sure to take self.extraParameters into account, in that case.

        @param  execution           The execution to prepare this client for.
        """
        client.prepareExecution(self, execution, simpleCommandLine="./opentracker -p {0} -P {0}".format( self.port ) )
Ejemplo n.º 3
0
    def prepareExecution(self, execution):
        """
        Client specific preparations for a specific execution.

        If any scripts for running the client on the host are needed, this is the place to build them.
        Be sure to take self.extraParameters into account, in that case.

        @param  execution           The execution to prepare this client for.
        """
        allParams = ""
        dataDir = posixpath.join( self.getExecutionClientDir(execution), 'data' )
        if execution.isSeeder():
            allParams += '-d "{0}"'.format( dataDir )
            if not self.wait:
                allParams += ' --wait 900s'
        else:
            count = 0
            fileparam = ' --hash {0} --file "{1}"'.format( '{0}', posixpath.join( self.getExecutionClientDir(execution), 'downloaded_file_{1}' ) )
            for f in execution.files:
                roothash = f.getRootHash(self.chunkSize / 1024)
                if not roothash:
                    raise Exception( "The swift client, when leeching, requires the correct root hash of each file to be set. Execution {0} of client {1} on host {2} is leeching, but file {3} does not have a root hash set for chunksize {4}.".format( execution.getNumber(), self.name, execution.host.name, f.name, self.chunkSize ) )
                allParams += fileparam.format( roothash,  count )
                count += 1
        if self.wait:
            allParams += ' --wait {0}s'.format( self.wait )
        if self.listenAddress:
            allParams += ' --listen {0}'.format( self.listenAddress )
        if self.chunkSize:
            allParams += ' --chunksize {0}'.format( self.chunkSize )
        if self.tracker:
            if self.tracker[0] == '@':
                indirecttracker = self.tracker[1:]
                colonindex = self.tracker.find(':')
                if colonindex != -1:
                    indirecttracker = self.tracker[1:colonindex]
                if indirecttracker not in self.scenario.getObjectsDict('host'):
                    raise Exception( "Swift client {0} has specified {1} as its indirect tracker, but host {2} does not exist.".format( self.name, self.tracker, indirecttracker ) )
                trackeraddress = self.scenario.getObjectsDict('host')[indirecttracker].getAddress()
                if trackeraddress == '':
                    raise Exception( "Swift client {0} has specified {1} as its indirect tracker, but host {2} can't give a specific address.".format( self.name, self.tracker, indirecttracker ) )
                if colonindex != -1:
                    trackeraddress += self.tracker[colonindex:]
                allParams += ' --tracker {0}'.format( trackeraddress )
            else:
                allParams += ' --tracker {0}'.format( self.tracker )
        if self.extraParameters:
            allParams += ' {0}'.format( self.extraParameters )
        if self.isInCleanup():
            return
        client.prepareExecution(self, execution, simpleCommandLine = 'LD_LIBRARY_PATH=$LD_LIBRARY_PATH:. ./swift --progress {0} 2> "{1}/log.log"'.format( allParams, self.getExecutionLogDir(execution) ), linkDataIn = dataDir )
Ejemplo n.º 4
0
    def prepareExecution(self, execution):
        """
        Client specific preparations for a specific execution.

        If any scripts for running the client on the host are needed, this is the place to build them.
        Be sure to take self.extraParameters into account, in that case.

        @param  execution           The execution to prepare this client for.
        """
        # The default implementation will create the client/execution specific directories, which can be found using
        # self.getExecutionClientDir(...) and self.getExecutionLogDir(...)
        #
        # The default implemenation can also build a runner script that can be used with the default start(...)
        # implementation. Subclassers are encouraged to use this possibility when they don't need much more elaborate
        # ways of running their client.
        #
        # The runner script can be created in two ways, both are well documented at client.prepareExecution(...).
        # This example below shows the most common use:
        #
        #   client.prepareExecution(self, execution, simpleCommandLine =
        #       "./yourClientBinary > {0}/log.log".format( self.getExecutionLogDir( execution ) ))
        #
        # This example is a bit more elaborate; the complexCommandLine is to be used if any but the last command
        # in the sequence takes significant time to run:
        #
        #   allParams = '{0} --logdir {1}'.format( self.extraParameters, self.getExecutionLogDir( execution ) )
        #   if self.protocolVersion:
        #       allParams += " --prot {0}".format(self.protocolVersion)
        #   if self.postFixParams:
        #       allParams += " {0}".format(self.postFixParams)
        #   if execution.isSeeder():
        #       client.prepareExecution(self, execution, simpleCommandLine =
        #           "./yourClientBinary --seed {0}".format( allParams ) )
        #   else:
        #       client.prepareExecution(self, execution, complexCommandLine =
        #           "./yourClientBinary --leech {0} && ./yourClientBinary --seed {0}".format( allParams ) )
        #
        # Together with the simpleCommandLine or complexCommandLine options the use of linkDataIn is very useful.
        # That option can link all data needed for seeding in a specified remote directory, which ensures not only
        # the availability, but also checks for duplicates (which mean trouble) and ensures that only the data you
        # need is available, preventing your execution from seeding more than intended. 
        #
        # Be sure to take self.extraParameters and your own parameters into account when building the command line
        # for the runner script. Also don't forget to make sure logs end up where you want them.
        #
        # The following implementation assumes you won't be using the runner script and is hence highly discouraged.
        #
        # TODO: Prepare the execution/client specific part on the host; specifically subclassers are encouraged to
        # use either the simpleCommandLine or complexCommandLine named arguments to client.prepareExecution(...) to
        # have a runner script built that will be used by the default implementation of start(...).
        client.prepareExecution(self, execution)
Ejemplo n.º 5
0
    def prepareExecution(self, execution):
        """
        Client specific preparations for a specific execution.

        If any scripts for running the client on the host are needed, this is the place to build them.
        Be sure to take self.extraParameters into account, in that case.

        @param  execution           The execution to prepare this client for.
        """
        # Initialize some directories
        torrentDir = '{0}/clients/{1}/exec_{2}/torrent_files'.format( execution.host.getTestDir(), self.name, execution.getNumber() )
        dataDir = posixpath.join( self.getExecutionClientDir(execution), 'download_data' )
        
        # Check sanity of files and torrents
        lnstring = 'ln "{0}" "{1}"; '.format( "{0}", posixpath.join( torrentDir, 'meta_file_{1}.torrent' ) )
        metafiles = execution.getMetaFileList(required = True)
        for f in metafiles:
            if f[-8:] != '.torrent':
                raise Exception( "In order to use uTorrent all files must have a .torrent file associated with them. The meta file {0} seems not to be a .torrent file.".format( f.name ) )
        torrentLinks = ''.join( lnstring.format( metafiles[i], i ) for i in range(len(metafiles)) )

        # Leecher specific settings
        stopWhenSeeding = 0
        if not execution.isSeeder() and self.stopWhenSeeding:
            stopWhenSeeding = 1
        
        dhtArg = 0
        if self.useDHT:
            dhtArg = 1
        
        # Build command and prepare
        client.prepareExecution(self, execution, simpleCommandLine = 
                                    '{5} LD_LIBRARY_PATH=$LD_LIBRARY_PATH:~/lib {0}/ut_server_logging.py {0} {1} {4} {6} 1 {2} 0 > {3}/log.log 2> {3}/errlog.log'.format( 
                                        self.getClientDir(execution.host),
                                        self.getExecutionClientDir(execution),
                                        torrentDir,  
                                        self.getExecutionLogDir(execution),
                                        stopWhenSeeding,
                                        torrentLinks,
                                        dhtArg
                                    ), # simpleCommandLine
                                    linkDataIn = dataDir
                                )
        execution.host.sendCommand( 'mkdir -p "{0}"'.format( torrentDir ) )
Ejemplo n.º 6
0
    def prepareExecution(self, execution):
        """
        Client specific preparations for a specific execution.

        If any scripts for running the client on the host are needed, this is the place to build them.
        Be sure to take self.extraParameters into account, in that case.

        @param  execution           The execution to prepare this client for.
        """
        if self.isInCleanup():
            return

        torrentDir = '{0}/clients/{1}/exec_{2}/torrent_files'.format( execution.host.getTestDir(), self.name, execution.getNumber() )
        dataDir = posixpath.join( self.getExecutionClientDir(execution), 'data' )
        
        torrentLinks = ''
        count = 0
        for f in execution.getMetaFileList(required = True):
            if f[-8:] != '.torrent':
                raise Exception( "In order to use libtorrent all files must have a .torrent file associated with them. The meta file {0} seems not to be a .torrent file.".format( f.name ) )
            torrentLinks += 'ln "{0}" "{1}"; '.format( f, posixpath.join( torrentDir, 'meta_file_{0}.torrent'.format(count) ) )
            count += 1
        
        seeding = ''
        if execution.isSeeder():
            seeding = '-s'

        client.prepareExecution(self, execution,
                                simpleCommandLine = '{4} LD_LIBRARY_PATH=~/lib:$LD_LIBRARY_PATH ./libtorrent {0} -o {1} -d {2} {5} 2> "{3}/log.log"'.format(
                                                    seeding,
                                                    dataDir,
                                                    torrentDir,
                                                    self.getExecutionLogDir(execution),
                                                    torrentLinks,
                                                    self.extraParameters
                                                    ),
                                linkDataIn = dataDir
                                )
        execution.host.sendCommand( 'mkdir -p "{0}"'.format( torrentDir ) )
Ejemplo n.º 7
0
    def prepareExecution(self, execution):
        """
        Client specific preparations for a specific execution.

        If any scripts for running the client on the host are needed, this is the place to build them.
        Be sure to take self.extraParameters into account, in that case.

        @param  execution           The execution to prepare this client for.
        """
        if execution.isSeeder():
            if len([f for f in execution.host.seedingFiles if f.getDataDir(execution.host) is not None]) < 1:
                Campaign.logger.log( 'WARNING! Client {0} is being prepared in seeding mode for execution {1} which has no seeding files associated. The execution will be a noop.' )
                command = 'echo "Not running: no files" > "{0}/log.log"; sleep 5'.format( self.getExecutionLogDir(execution) )
            else:
                ssl = "NOSSL"
                if self.useSSL:
                    ssl = "SSL"
                command = '"{0}/lighttpd_logging" "{1}" {2} {3} {4} > "{5}/log.log"'.format(
                                                                                            self.getClientDir(execution.host),
                                                                                            self.getExecutionClientDir(execution),
                                                                                            self.port,
                                                                                            ssl,
                                                                                            " ".join(['"'+d+'"' for d in execution.getDataDirList()]),
                                                                                            self.getExecutionLogDir(execution)
                                                                                            )
            client.prepareExecution(self, execution, simpleCommandLine=command)
        else:
            if len(execution.files) < 1:
                Campaign.logger.log( 'WARNING! Client {0} is being prepared for execution {1} which has no files associated. The execution will be a noop.' )
                client.prepareExecution(self, execution, simpleCommandLine='echo "Not running: no files" > "{0}/log.log"; sleep 5'.format( self.getExecutionLogDir(execution)))
                return
            # Figure out all the servers (yes, HTTP cheats by knowing all the servers ahead)
            servers = []
            for e in [e for e in self.scenario.getObjects('execution') if e.isSeeder()]:
                if e.host.getAddress() == '':
                    raise Exception( 'client:http requires each seeding host to return a valid address in their getAddress() method, but host {0} return ""'.format( e.host.name ) )
                p = self.port
                if isinstance(e.client, http):
                    p = e.client.port
                    if e.client.useSSL:
                        servers.append( 'https://{0}:{1}/'.format( e.host.getAddress(), p ) )
                    else:
                        servers.append( 'http://{0}:{1}/'.format( e.host.getAddress(), p ) )
                else:
                    if self.useSSL:
                        servers.append( 'https://{0}:{1}/'.format( e.host.getAddress(), p ) )
                    else:
                        servers.append( 'http://{0}:{1}/'.format( e.host.getAddress(), p ) )
            if len(servers) == 0:
                raise Exception( 'Client {0} could not find a single seeding execution in the scenario. This is not supported by client:http.'.format( self.name ) )
            # Build a URI list:
            # Each file should have its own line, each line should have multiple URIs for that file separated by \t
            URIlist = ''
            for file_ in execution.files:
                f = os.path.basename(file_.getFile(execution.host))
                URIlist += "\t".join( ["{0}/{1}".format( s, f ) for s in servers] ) + "\n"
            # Calculate other settings
            connperhost = len(servers) * 2
            if connperhost > 16:
                connperhost = 16
            # Build the huge command
            command = (
                        'echo | ./aria2c '
                        '-j {0} '                               # maximum concurrent downloads
                        '-s {0} '                               # split file in n parts
                        '-x {1} '                               # allow at most #seeders connection to each host (necessary for multiple servers on the same host, max 16!)
                        '--uri-selector=inorder '               # forces aria to choose the next URI whenver trying to download another piece
                        '--human-readable=false '               # full output
                        '--summary-interval=1 '                 # give output every 1 sec
                        '--no-conf=true '                       # don't read global conf
                        '--truncate-console-readout=false '     # don't truncate output
                        '-n '                                   # don't read global .netrc conf
                        '--max-tries=0 '                        # don't give up
                        '--retry-wait=1 '                       # wait 1 sec between retries
                        '--dir={2} '                            # save here
                        '--check-certificate=false '            # don't check our on-the-fly-generated self-signed certificates [SSL]
                        '--input-file=- '                       # read URI lists from stdin
                        '> {3}/log.log '                        # redirect log
                        '<<__EOF__\n'                           # start input of URI lists
                        '{4}'                                   # URI lists
                        '__EOF__\n'                             # end input of URI lists
                        # (SSL options are given anyway, since they don't matter for non-SSL)
                    ).format(
                             len(servers),
                             connperhost,
                             self.getExecutionClientDir(execution),
                             self.getExecutionLogDir(execution),
                             URIlist
                            )
            client.prepareExecution(self, execution, complexCommandLine=command)