Exemplo n.º 1
0
    def prepareHost(self, host):
        """
        Client specific preparations on a host, irrespective of execution.

        This usually includes send files to the host, such as binaries.

        Note that the sendToHost and sendToSeedingHost methods of the file objects have not been called, yet.
        This means that any data files are not available.

        @param  host            The host on which to prepare the client.
        """
        client.prepareHost(self, host)
Exemplo n.º 2
0
    def prepareHost(self, host):
        """
        Client specific preparations on a host, irrespective of execution.

        This usually includes send files to the host, such as binaries.

        Note that the sendToHost and sendToSeedingHost methods of the file objects have not been called, yet.
        This means that any data files are not available.

        @param  host            The host on which to prepare the client.
        """
        # The default implementations takes care of creating client specific directories on the host, as well as
        # compilation of the client on the host, if needed. It also uploads or moves your client if you have
        # implemted getBinaryLayout(), getSourceLayout() and getExtraUploadLayout(). Be sure to call it.
        client.prepareHost(self, host)
Exemplo n.º 3
0
    def prepareHost(self, host):
        """
        Client specific preparations on a host, irrespective of execution.

        This usually includes send files to the host, such as binaries.

        Note that the sendToHost and sendToSeedingHost methods of the file objects have not been called, yet.
        This means that any data files are not available.

        @param  host            The host on which to prepare the client.
        """
        client.prepareHost(self, host)

        theDir = self.sourceObj.remoteLocation(self, host)
        if not client.isRemote:
            theDir = self.getClientDir(host)

        if self.isInCleanup():
            return
        host.sendCommand( 'touch "{0}/client_bin"'.format( theDir ) )
        if self.isInCleanup():
            return
        host.sendCommand( 'echo "#!/bin/bash" >> "{0}/client_bin"'.format( theDir ) )
        if self.isInCleanup():
            return
        host.sendCommand( 'echo "cat <<232EOF454" >> "{0}/client_bin"'.format( theDir ) )
        if self.isInCleanup():
            return
        host.sendCommand( 'echo "Full configuration of test client:" >> "{0}/client_bin"'.format( theDir ) )
        if self.isInCleanup():
            return
        host.sendCommand( 'echo "{1}: {2}" >> "{0}/client_bin"'.format( theDir, 'getClientDir(host)', self.getClientDir(host)) )
        if self.isInCleanup():
            return
        host.sendCommand( 'echo "{1}: {2}" >> "{0}/client_bin"'.format( theDir, 'getClientDir(host, True)', self.getClientDir(host, True)) )
        if self.isInCleanup():
            return
        host.sendCommand( 'echo "{1}: {2}" >> "{0}/client_bin"'.format( theDir, 'getLogDir(host)', self.getLogDir(host)) )
        if self.isInCleanup():
            return
        host.sendCommand( 'echo "{1}: {2}" >> "{0}/client_bin"'.format( theDir, 'getLogDir(host, True)', self.getLogDir(host, True)) )
        if self.isInCleanup():
            return
        host.sendCommand( 'echo "{1}: {2}" >> "{0}/client_bin"'.format( theDir, 'testTime', self.testTime) )
        if self.isInCleanup():
            return
        host.sendCommand( 'echo "{1}: {2}" >> "{0}/client_bin"'.format( theDir, 'extraParameters', self.extraParameters) )
        if self.isInCleanup():
            return
        if self.parsers:
            for p in self.parsers:
                host.sendCommand( 'echo "{1}: {2}" >> "{0}/client_bin"'.format( theDir, 'parser', p) )
                if self.isInCleanup():
                    return
        host.sendCommand( 'echo "{1}: {2}" >> "{0}/client_bin"'.format( theDir, 'source', self.source) )
        if self.isInCleanup():
            return
        host.sendCommand( 'echo "{1}: {2}" >> "{0}/client_bin"'.format( theDir, 'builder', self.builder) )
        if self.isInCleanup():
            return
        host.sendCommand( 'echo "{1}: {2}" >> "{0}/client_bin"'.format( theDir, 'location', self.location) )
        if self.isInCleanup():
            return
        host.sendCommand( 'echo "{1}: {2}" >> "{0}/client_bin"'.format( theDir, 'isRemote', self.isRemote) )
        if self.isInCleanup():
            return
        host.sendCommand( 'echo "232EOF454" >> "{0}/client_bin"'.format( theDir ) )
        if self.isInCleanup():
            return
        host.sendCommand( 'echo "sleep {1}" >> "{0}/client_bin"'.format( theDir, self.testTime ) )
        if self.isInCleanup():
            return
        host.sendCommand( 'chmod +x "{0}/client_bin"'.format( theDir ) )
Exemplo n.º 4
0
    def prepareHost(self, host):
        """
        Client specific preparations on a host, irrespective of execution.

        This usually includes send files to the host, such as binaries.

        Note that the sendToHost and sendToSeedingHost methods of the file objects have not been called, yet.
        This means that any data files are not available.

        @param  host            The host on which to prepare the client.
        """
        client.prepareHost(self, host)

        if self.isInCleanup():
            return
        
        # Make sure client is uploaded/present
        if self.isRemote:
            entries = []
            res = host.sendCommand( '[ -d "{0}"/lighttpd-*/src -a -f "{0}"/lighttpd-*/src/lighttpd ] && echo "E" || echo "N"'.format( self.sourceObj.remoteLocation( self, host ) ) )
            if res.splitlines()[-1] == 'E':
                # Remote source location of lighttpd with in-place build
                entries += ['/'.join(['lighttpd-*']+f) for f in http.sourcelocations_lighttpd]
            else:
                # Remote binary installation of lighttpd
                entries += ['/'.join(f) for f in http.binarylocations_lighttpd]
            res = host.sendCommand( '[ -d "{0}"/aria2-*/src -a -f "{0}"/aria2-*/src/aria2c ] && echo "E" || echo "N"'.format( self.sourceObj.remoteLocation( self, host ) ) )
            if res.splitlines()[-1] == 'E':
                # Remote source location of aria2 with in-place build
                entries += ['/'.join(['aria2-*']+f) for f in http.sourcelocations_aria]
            else:
                # Remote binary installation of aria2
                entries += ['/'.join(f) for f in http.binarylocations_aria]
            for entry in entries:
                if self.isInCleanup():
                    return
                res = host.sendCommand( '[ -f "{0}"/{1} ] && cp "{0}"/{1} "{2}/" && echo "OK"'.format( self.sourceObj.remoteLocation( self, host ), entry, self.getClientDir(host) ) )
                if res != "OK":
                    raise Exception( "Client {0} failed to prepare host {1}: checking for existence of file {2} after building and copying it failed. Response: {4}.".format( self.name, host.name, entry, res ) )
        else:
            entries = []
            dirs = [d for d in os.listdir(self.sourceObj.localLocation( self )) if d[:9] == 'lighttpd-']
            if len(dirs) > 0 and os.path.isfile( os.path.join( self.sourceObj.localLocation( self ), dirs[0], 'src', 'lighttpd' ) ):
                # Local source location of lighttpd with in-place build
                entries += [[dirs[0]] + f for f in http.sourcelocations_lighttpd]
            else:
                # Local binary installation of lighttpd
                entries += [f for f in http.binarylocations_lighttpd]
            dirs = [d for d in os.listdir(self.sourceObj.localLocation( self )) if d[:6] == 'aria2-']
            if len(dirs) > 0 and os.path.isfile( os.path.join( self.sourceObj.localLocation( self ), dirs[0], 'src', 'aria2c' ) ):
                # Local source location of aria2 with in-place build
                entries += [[dirs[0]] + f for f in http.sourcelocations_aria]
            else:
                # Local binary installation of aria2
                entries += [f for f in http.binarylocations_lighttpd]
            for entry in entries:
                # pylint: disable-msg=W0142
                f = os.path.join( self.sourceObj.localLocation( self ), *entry )
                # pylint: enable-msg=W0142
                if not os.path.isfile( f ):
                    raise Exception( "Client {0} failed to prepare host {1}: local file {2} is missing".format( self.name, host.name, f ) )
                host.sendFile( f, '{0}/{1}'.format( self.getClientDir(host), entry[-1] ), True )
        f = os.path.join( Campaign.testEnvDir, 'ClientWrappers', 'lighttpd', 'lighttpd_logging' )
        if not os.path.isfile( f ):
            raise Exception( "Client {0} failed to prepare host {1} since the client wrapper for lighttpd seems to be missing: {2} not found.".format( self.name, host.name, f ) )
        host.sendFile( f, '{0}/lighttpd_logging'.format( self.getClientDir(host) ) )
Exemplo n.º 5
0
    def prepareHost(self, host):
        """
        Client specific preparations on a host, irrespective of execution.

        This usually includes send files to the host, such as binaries.

        Note that the sendToHost and sendToSeedingHost methods of the file objects have not been called, yet.
        This means that any data files are not available.

        @param  host            The host on which to prepare the client.
        """
        client.prepareHost(self, host)
        
        if not self.hasUpdatedTrackers and ( len( self.changeTrackers ) > 0 or len( self.changeClientTrackers ) > 0 ):
            # Figure out the new tracker
            self.hasUpdatedTrackers = True
            newTracker = host.getAddress()
            if not newTracker:
                raise Exception( "Client {0} was instructed to change some torrent files to update their trackers, but host {1} won't give an address for that.".format( self.name, host.name ) )
            newTracker = 'http://{0}:{1}/announce'.format( newTracker, self.port )
            # Grab all executions for clients in our changeClientTrackers list and go over their files, adding them to changeTrackers as needed
            for e in [e for e in self.scenario.getObjects('execution') if e.client.getName() in self.changeClientTrackers]:
                for f in e.files:
                    if not f.metaFile or not os.path.exists( f.metaFile ) or os.path.isdir( f.metaFile ):
                        continue
                    if f.getName() not in self.changeTrackers:
                        self.changeTrackers.append( f.getName() )
            # Update all file objects mentioned in changeTrackers
            for f in self.changeTrackers:
                tmpfd = None
                tmpfobj = None
                tmpFile = None
                tmpSaved = False
                try:
                    tmpfd, tmpFile = tempfile.mkstemp('.torrent')
                    tmpfobj = os.fdopen(tmpfd, 'w')
                    tmpfd = None
                    try:
                        self.tempUpdatedFiles__lock.acquire()
                        if self.isInCleanup():
                            os.remove( tmpFile )
                            tmpFile = None
                            return
                        self.tempUpdatedFiles.append( tmpFile )
                        tmpSaved = True
                    finally:
                        self.tempUpdatedFiles__lock.release()
                    fobj = None
                    try:
                        fobj = open( self.scenario.getObjectsDict( 'file' )[f].metaFile, 'r' )
                        torrentdata = fobj.read( )
                    finally:
                        if fobj:
                            fobj.close()
                    torrentdict = external.bencode.bdecode( torrentdata )
                    if not torrentdict or not 'info' in torrentdict:
                        raise Exception( "Client {0} was instructed to change the torrent file of file {1}, but the metafile of the latter seems not to be a .torrent file." )
                    torrentdict['announce'] = newTracker
                    if 'announce-list' in torrentdict:
                        torrentdict['announce-list'] = [[newTracker]]
                    torrentdata = external.bencode.bencode( torrentdict )
                    tmpfobj.write( torrentdata )
                    tmpfobj.flush()
                finally:
                    if tmpfobj:
                        tmpfobj.close()
                    elif tmpfd is not None:
                        os.close(tmpfd)
                    if tmpFile and not tmpSaved:
                        try:
                            self.tempUpdatedFiles__lock.acquire()
                            if tmpFile not in self.tempUpdatedFiles:
                                os.remove( tmpFile )
                        finally:
                            self.tempUpdatedFiles__lock.release()
                self.scenario.getObjectsDict( 'file' )[f].metaFile = tmpFile