Esempio n. 1
0
    def parseSetting(self, key, value):
        """
        Parse a single setting for this object.

        Settings are written in text files in a key=value fashion.
        For each such setting that belongs to this object this method will be called.

        After all settings have been given, the method checkSettings will be called.

        If a setting does not parse correctly, this method raises an Exception with a descriptive message.

        Subclassers should first parse their own settings and then call this implementation to have the
        generic settings parsed and to have any unknown settings raise an Exception.
        
        @param  key     The name of the parameter, i.e. the key from the key=value pair.
        @param  value   The value of the parameter, i.e. the value from the key=value pair.
        """
        if key == 'duration':
            if self.duration:
                parseError( "Duration was already specified: {0}".format( self.duration ) )
            if self.rate:
                parseError( "Rate was already specified: {0}".format( self.rate ) )
            if not isPositiveFloat( value, True ):
                parseError( "Duration should be a non-zero positive floating point number." )
            self.duration = float(value)
        elif key == 'rate':
            if self.duration:
                parseError( "Duration was already specified: {0}".format( self.duration ) )
            if self.rate:
                parseError( "Rate was already specified: {0}".format( self.rate ) )
            if not isPositiveFloat( value, True ):
                parseError( "Rate should be a non-zero positive floating point number." )
            self.rate = float(value)
        else:
            workload.parseSetting(self, key, value)
Esempio n. 2
0
    def parseSetting(self, key, value):
        """
        Parse a single setting for this object.

        Settings are written in text files in a key=value fashion.
        For each such setting that belongs to this object this method will be called.

        After all settings have been given, the method checkSettings will be called.

        If a setting does not parse correctly, this method raises an Exception with a descriptive message.

        Subclassers should first parse their own settings and then call this implementation to have the
        generic settings parsed and to have any unknown settings raise an Exception.
        
        @param  key     The name of the parameter, i.e. the key from the key=value pair.
        @param  value   The value of the parameter, i.e. the value from the key=value pair.
        """
        if key == 'apply':
            if not self.applyList:
                self.applyList = [value]
            else:
                self.applyList.append( value )
        elif key == 'offset':
            if self.offset != None:
                parseError( "Offset has already been set: {0}".format( self.offset ) )
            if not isPositiveFloat( value ):
                parseError( "Offset should be a non-negative floating point number" )
            self.offset = float(value)
        elif key == 'applyToSeeders':
            if value == 'yes':
                self.applySeeders = True
        else:
            parseError( 'Unknown parameter name: {0}'.format( key ) )
Esempio n. 3
0
    def parseSetting(self, key, value):
        """
        Parse a single setting for this object.

        Settings are written in text files in a key=value fashion.
        For each such setting that belongs to this object this method will be called.

        After all settings have been given, the method checkSettings will be called.

        If a setting does not parse correctly, this method raises an Exception with a descriptive message.

        Subclassers should first parse their own settings and then call this implementation to have the
        generic settings parsed and to have any unknown settings raise an Exception.
        
        @param  key     The name of the parameter, i.e. the key from the key=value pair.
        @param  value   The value of the parameter, i.e. the value from the key=value pair.
        """
        if key == 'name':
            if self.name != '':
                parseError( 'Name already set: {0}'.format( self.name ) )
            if not isValidName( value ):
                parseError( '"{0}" is not a valid name'.format( value ) )
            if value in self.scenario.getObjectsDict('host'):
                parseError( 'Host object called {0} already exists'.format( value ) )
            self.name = value
        elif key == 'preparation':
            parseError( 'The preparation parameter was badly supported under version 1 and has been deprecated. If you need this parameter, please contact the developers of the framework to discuss support.' )
        elif key == 'cleanup':
            parseError( 'The cleanup parameter was badly supported under version 1 and has been deprecated. If you need this parameter, please contact the developers of the framework to discuss support.' )
        elif key == 'remoteFolder' or key == 'remoteDirectory':
            if self.remoteDirectory:
                parseError( 'Remote directory already set' )
            if value != '':
                self.remoteDirectory = value
        elif key == 'tc_iface' or key == 'tcInterface':
            if self.tcInterface:
                parseError( 'Only one interface for TC allowed' )
            if value == '':
                parseError( 'Empty interface for TC found, but an interface is required' )
            self.tcInterface = value
            self.tcParamsSet = True
        elif key == 'tc_down' or key == 'tcMaxDownSpeed':
            if self.tcDown != 0:
                parseError( 'Maximum download speed for TC already set' )
            self.tcDown = checkSpeedValue( value, 'Maximum download speed' )
            self.tcParamsSet = True
        elif key == 'tc_down_burst' or key == 'tcMaxDownBurst':
            if self.tcDownBurst != 0:
                parseError( 'Maximum download burst for TC already set' )
            self.tcDownBurst = checkSpeedValue( value, 'Maximum download burst' )
            self.tcParamsSet = True
        elif key == 'tc_up' or key == 'tcMaxUpSpeed':
            if self.tcUp != 0:
                parseError( 'Maximum upload speed for TC already set' )
            self.tcUp = checkSpeedValue( value, 'Maximum upload speed' )
            self.tcParamsSet = True
        elif key == 'tc_up_burst' or key == 'tcMaxUpBurst':
            if self.tcUpBurst != 0:
                parseError( 'Maximum upload burst for TC already set' )
            self.tcUpBurst = checkSpeedValue( value, 'Maximum upload burst' )
            self.tcParamsSet = True
        elif key == 'tc':
            if self.tc != '':
                parseError( 'TC module already set' )
            if value == '':
                return
            if not isValidName( value ):
                parseError( 'Name given as name of TC module is not a valid name: {0}'.format( value ) )
            __import__( 'modules.tc.'+value, globals(), locals(), value )    # Just checks availability
            self.tc = value
        elif key == 'tc_loss' or key == 'tcLossChance':
            if self.tcLoss != 0:
                parseError( 'Loss chance for TC already set' )
            if (not isPositiveFloat( value )) or float(value) > 100:
                parseError( 'Loss chance for TC should be a floating point number >= 0.0 and <= 100.0, unlike {0}'.format( value ) )
            self.tcLoss = float(value)
        elif key == 'tc_corruption' or key == 'tcCorruptionChance':
            if self.tcCorruption != 0:
                parseError( 'Corruption chance for TC already set' )
            if (not isPositiveFloat( value )) or float(value) > 100:
                parseError( 'Corruption chance for TC should be a floating point number >= 0.0 and <= 100.0, unlike {0}'.format( value ) )
            self.tcCorruption = float(value)
        elif key == 'tc_duplication' or key == 'tcDuplicationChance':
            if self.tcDuplication != 0:
                parseError( 'Duplication chance for TC already set' )
            if (not isPositiveFloat( value )) or float(value) > 100:
                parseError( 'Duplication chance for TC should be a floating point number >= 0.0 and <= 100.0, unlike {0}'.format( value ) )
            self.tcDuplication = float(value)
        elif key == 'tc_delay' or key == 'tcDelay':
            if self.tcDelay != 0:
                parseError( 'Delay for TC already set' )
            if not isPositiveInt( value ):
                parseError( 'Delay for TC should be a positive integer denoting the delay in ms, unlike {0}'.format( value ) )
            self.tcDelay = int(value)
        elif key == 'tc_jitter' or key == 'tcJitter':
            if self.tcJitter != 0:
                parseError( 'Jitter in the delay for TC already set' )
            if not isPositiveInt( value ):
                parseError( 'Jitter in the delay for TC should be a positive integer denoting the maximum deviation in the delay for TC in ms, unlike {0}'.format( value ) )
            self.tcJitter = int(value)
        else:
            parseError( 'Unknown parameter name: {0}'.format( key ) )
Esempio n. 4
0
    def parseSetting(self, key, value):
        """
        Parse a single setting for this object.

        Settings are written in text files in a key=value fashion.
        For each such setting that belongs to this object this method will be called.

        After all settings have been given, the method checkSettings will be called.

        If a setting does not parse correctly, this method raises an Exception with a descriptive message.

        Subclassers should first parse their own settings and then call this implementation to have the
        generic settings parsed and to have any unknown settings raise an Exception.
        
        @param  key     The name of the parameter, i.e. the key from the key=value pair.
        @param  value   The value of the parameter, i.e. the value from the key=value pair.
        """
        if key == 'host':
            if self.hostName:
                parseError( "A host was already given: {0}".format( self.hostName ) )
            if not isValidName( value ):
                if not isValidName( value[:value.find('@')]):
                    parseError( "{0} is not a valid host object name".format( value ) )
            self.hostName = value
        elif key == 'client':
            if self.clientName:
                parseError( "A client was already given: {0}".format( self.clientName ) )
            if not isValidName( value ):
                if not isValidName( value[:value.find('@')]):
                    parseError( "{0} is not a valid client object name".format( value ) )
            self.clientName = value
        elif key == 'file':
            if not isValidName( value ):
                if not isValidName( value[:value.find('@')]):
                    parseError( "{0} is not a valid file object name".format( value ) )
            if not self.fileNames:
                self.fileNames = [value]
            elif value not in self.fileNames:
                self.fileNames.append(value)
            else:
                Campaign.logger.log( "Warning for execution object on line {0}: file object {1} already added".format( Campaign.currentLineNumber, value ) )
        elif key == 'parser':
            if not isValidName( value ):
                parseError( "{0} is not a valif parser object name".format( value ) )
            if not self.parserNames:
                self.parserNames = []
            self.parserNames.append( value )
        elif key == 'seeder':
            if value != '':
                self.seeder = True
        elif key == 'timeout':
            if self.timeout != None:
                parseError( "The timeout was already set: {0}".format( self.timeout ) )
            if not isPositiveFloat( value ):
                parseError( "The timeout must be a non-negative floating point number." )
            self.timeout = float(value)
        elif key == 'keepSeeding':
            if value != '':
                self.keepSeeding = True
        elif key == 'multiply':
            if self.multiply is not None:
                parseError( "Multiply already set: {0}".format( self.multiply ) )
            if not isPositiveInt(value, True):
                parseError( "The multiply parameter must be a non-zero positive integer." )
            self.multiply = int(value)
        else:
            parseError( 'Unknown parameter name: {0}'.format( key ) )