Ejemplo n.º 1
0
    def FillMessageRepository(self):
        """This function fills the MessageRepository with random values.
       It could be useful to test performance of the database.
    """
        self.__CreateAuxiliaryLists()
        LogLevels = [
            'ALWAYS', 'INFO', 'VERB', 'DEBUG', 'WARN', 'ERROR', 'EXCEPT',
            'FATAL'
        ]
        initialDate = dateTime()

        for i in range(1, 800):
            limitDate = toString(initialDate - randrange(0, 1680) * hour -
                                 randrange(0, 60) * minute -
                                 randrange(0, 60) * second)
            message = tupleToMessage([
                self.systemNames[randrange(0, 5)], LogLevels[randrange(0, 8)],
                limitDate, self.fixedMessages[randrange(0, 6)],
                'variable text %s' % randrange(0, 6), '',
                self.subSystemNames[randrange(0,
                                              5)], self.sites[randrange(0, 5)]
            ])
            userId = randrange(0, 12)
            result = self.insertMessageIntoDB(message, self.users[userId][0],
                                              self.users[userId][1],
                                              self.clientIPs[randrange(0, 20)])
            if not result['OK']:
                print result['Value']
Ejemplo n.º 2
0
  def FillMessageRepository(self):
    """This function fills the MessageRepository with random values.
       It could be useful to test performance of the database.
    """
    self.__CreateAuxiliaryLists()
    LogLevels = [ 'ALWAYS' , 'INFO', 'VERB', 'DEBUG', 'WARN',
                  'ERROR', 'EXCEPT', 'FATAL' ]
    initialDate=dateTime()

    for _i in range( 1, 800 ):
      limitDate = toString( initialDate - randrange(0,1680) * hour -
                            randrange( 0, 60) * minute -
                            randrange( 0, 60) * second )
      message = tupleToMessage ( [ self.systemNames[ randrange( 0, 5 ) ],
                          LogLevels[ randrange( 0, 8 ) ], limitDate,
                          self.fixedMessages[ randrange( 0, 6 ) ],
                          'variable text %s' % randrange( 0, 6 ), '',
                          self.subSystemNames[ randrange( 0, 5 ) ],
                          self.sites[ randrange( 0, 5 ) ] ] )
      userId = randrange( 0, 12 )
      result = self.insertMessageIntoDB( message, self.users[ userId ][ 0 ],
                                         self.users[ userId ][ 1 ],
                                         self.clientIPs[ randrange( 0, 20 ) ] )
      if not result['OK']:
        print result['Value']
Ejemplo n.º 3
0
  def test_addAndRemove(self):
    """ Some test cases
    """

    systemName = 'TestSystem'
    subSystemName = 'TestSubSystem'
    level = 10
    time = toString()
    msgTest = 'Hello'
    variableText = time
    frameInfo = ""
    message = tupleToMessage((systemName, level, time, msgTest, variableText, frameInfo, subSystemName))
    site = 'somewehere'
    longSite = 'somewehere1234567890123456789012345678901234567890123456789012345678901234567890'
    nodeFQDN = '127.0.0.1'
    userDN = 'Yo'
    userGroup = 'Us'
    remoteAddress = 'elsewhere'

    records = 10

    db = SystemLoggingDB()
    res = db._connect()
    self.assertTrue(res['OK'])

    gLogger.info('\n Inserting some records\n')
    for k in xrange(records):
      result = db.insertMessage(message, site, nodeFQDN, userDN, userGroup, remoteAddress)
      self.assertTrue(result['OK'])
      self.assertEqual(result['lastRowId'], k + 1)
      self.assertEqual(result['Value'], 1)

    result = db._queryDB(showFieldList=['SiteName'])
    self.assertTrue(result['OK'])
    self.assertEqual(result['Value'][0][0], site)

    result = db._queryDB(showFieldList=['SystemName'])
    self.assertTrue(result['OK'])
    self.assertEqual(result['Value'][0][0], systemName)

    result = db._queryDB(showFieldList=['SubSystemName'])
    self.assertTrue(result['OK'])
    self.assertEqual(result['Value'][0][0], subSystemName)

    result = db._queryDB(showFieldList=['OwnerGroup'])
    self.assertTrue(result['OK'])
    self.assertEqual(result['Value'][0][0], userGroup)

    result = db._queryDB(showFieldList=['FixedTextString'])
    self.assertTrue(result['OK'])
    self.assertEqual(result['Value'][0][0], msgTest)

    result = db._queryDB(showFieldList=['VariableText', 'SiteName'], count=True, groupColumn='VariableText')
    self.assertTrue(result['OK'])
    self.assertEqual(result['Value'][0][1], site)
    self.assertEqual(result['Value'][0][2], records)

    result = db.insertMessage(message, longSite, nodeFQDN, userDN, userGroup, remoteAddress)
    self.assertFalse(result['OK'])
Ejemplo n.º 4
0
 def export_addMessages( self, messagesList, site, nodeFQDN ):
   """ This is the interface to the service
       inputs:
          msgList contains a  list of Message Objects.
       outputs:
          S_OK if no exception was raised
          S_ERROR if an exception was raised
   """
   for messageTuple in messagesList:
     messageObject = tupleToMessage( messageTuple )
     result = self.__addMessage( messageObject, site, nodeFQDN )
     if not result['OK']:
       gLogger.error( 'The Log Message could not be inserted into the DB',
                      'because: "%s"' % result['Message'] )
       return S_ERROR( result['Message'] )
   return S_OK()
Ejemplo n.º 5
0
 def export_addMessages( self, messagesList, site, nodeFQDN ):
   """ This is the interface to the service
       inputs:
          msgList contains a  list of Message Objects.
       outputs:
          S_OK if no exception was raised
          S_ERROR if an exception was raised
   """
   for messageTuple in messagesList:
     messageObject = tupleToMessage( messageTuple )
     try:
       result = self.__addMessage( messageObject, site, nodeFQDN )
       if not result['OK']:
         gLogger.error('The Log Message could not be inserted into the DB',
                       'because: "%s"' % result['Message'])
     except Exception, v:
       errorString = 'Message was not added because of exception: '
       exceptionString = str(v)
       gLogger.exception( errorString ,exceptionString )
       return S_ERROR( "%s %s" % ( errorString, exceptionString ) )
Ejemplo n.º 6
0
 def export_addMessages(self, messagesList, site, nodeFQDN):
     """ This is the interface to the service
     inputs:
        msgList contains a  list of Message Objects.
     outputs:
        S_OK if no exception was raised
        S_ERROR if an exception was raised
 """
     for messageTuple in messagesList:
         messageObject = tupleToMessage(messageTuple)
         try:
             result = self.__addMessage(messageObject, site, nodeFQDN)
             if not result['OK']:
                 gLogger.error(
                     'The Log Message could not be inserted into the DB',
                     'because: "%s"' % result['Message'])
         except Exception, v:
             errorString = 'Message was not added because of exception: '
             exceptionString = str(v)
             gLogger.exception(errorString, exceptionString)
             return S_ERROR("%s %s" % (errorString, exceptionString))
Ejemplo n.º 7
0
def testSystemLoggingDB():
  """ Some test cases
  """

  # building up some fake CS values
  gConfig.setOptionValue( 'DIRAC/Setup', 'Test' )
  gConfig.setOptionValue( '/DIRAC/Setups/Test/Framework', 'Test' )

  host = '127.0.0.1'
  user = '******'
  pwd = 'Dirac'
  db = 'AccountingDB'

  gConfig.setOptionValue( '/Systems/Framework/Test/Databases/SystemLoggingDB/Host', host )
  gConfig.setOptionValue( '/Systems/Framework/Test/Databases/SystemLoggingDB/DBName', db )
  gConfig.setOptionValue( '/Systems/Framework/Test/Databases/SystemLoggingDB/User', user )
  gConfig.setOptionValue( '/Systems/Framework/Test/Databases/SystemLoggingDB/Password', pwd )

  from DIRAC.FrameworkSystem.private.logging.Message import tupleToMessage

  systemName = 'TestSystem'
  subSystemName = 'TestSubSystem'
  level = 10
  time = Time.toString()
  msgTest = 'Hello'
  variableText = time
  frameInfo = ""
  message = tupleToMessage( ( systemName, level, time, msgTest, variableText, frameInfo, subSystemName ) )
  site = 'somewehere'
  longSite = 'somewehere1234567890123456789012345678901234567890123456789012345678901234567890'
  nodeFQDN = '127.0.0.1'
  userDN = 'Yo'
  userGroup = 'Us'
  remoteAddress = 'elsewhere'

  records = 10

  db = SystemLoggingDB()
  assert db._connect()['OK']

  try:
    if False:
      for tableName in db.tableDict.keys():
        result = db._update( 'DROP TABLE  IF EXISTS `%s`' % tableName )
        assert result['OK']

      gLogger.info( '\n Creating Table\n' )
      # Make sure it is there and it has been created for this test
      result = db._checkTable()
      assert result['OK']

    result = db._checkTable()
    assert not result['OK']
    assert result['Message'] == 'The requested table already exist'

    gLogger.info( '\n Inserting some records\n' )
    for k in range( records ):
      result = db.insertMessage( message, site, nodeFQDN,
                                  userDN, userGroup, remoteAddress )
      assert result['OK']
      assert result['lastRowId'] == k + 1
      assert result['Value'] == 1

    result = db.insertMessage( message, longSite, nodeFQDN,
                                  userDN, userGroup, remoteAddress )
    assert not result['OK']

    result = db._queryDB( showFieldList = [ 'SiteName' ] )
    assert result['OK']
    assert result['Value'][0][0] == site

    result = db._queryDB( showFieldList = [ 'SystemName' ] )
    assert result['OK']
    assert result['Value'][0][0] == systemName

    result = db._queryDB( showFieldList = [ 'SubSystemName' ] )
    assert result['OK']
    assert result['Value'][0][0] == subSystemName

    result = db._queryDB( showFieldList = [ 'OwnerGroup' ] )
    assert result['OK']
    assert result['Value'][0][0] == userGroup

    result = db._queryDB( showFieldList = [ 'FixedTextString' ] )
    assert result['OK']
    assert result['Value'][0][0] == msgTest

    result = db._queryDB( showFieldList = [ 'VariableText', 'SiteName' ], count = True, groupColumn = 'VariableText' )
    assert result['OK']
    assert result['Value'][0][1] == site
    assert result['Value'][0][2] == records


    gLogger.info( '\n Removing Table\n' )
    for tableName in [ 'MessageRepository', 'FixedTextMessages', 'SubSystems', 'Systems',
                       'AgentPersistentData', 'ClientIPs', 'Sites', 'UserDNs' ]:
      result = db._update( 'DROP TABLE `%s`' % tableName )
      assert result['OK']

    gLogger.info( '\n OK\n' )


  except AssertionError:
    print 'ERROR ',
    if not result['OK']:
      print result['Message']
    else:
      print result


    sys.exit( 1 )
Ejemplo n.º 8
0
def testSystemLoggingDB():
    """ Some test cases
  """

    # building up some fake CS values
    gConfig.setOptionValue('DIRAC/Setup', 'Test')
    gConfig.setOptionValue('/DIRAC/Setups/Test/Framework', 'Test')

    host = '127.0.0.1'
    user = '******'
    pwd = 'Dirac'
    db = 'AccountingDB'

    gConfig.setOptionValue(
        '/Systems/Framework/Test/Databases/SystemLoggingDB/Host', host)
    gConfig.setOptionValue(
        '/Systems/Framework/Test/Databases/SystemLoggingDB/DBName', db)
    gConfig.setOptionValue(
        '/Systems/Framework/Test/Databases/SystemLoggingDB/User', user)
    gConfig.setOptionValue(
        '/Systems/Framework/Test/Databases/SystemLoggingDB/Password', pwd)

    from DIRAC.FrameworkSystem.private.logging.Message import tupleToMessage

    systemName = 'TestSystem'
    subSystemName = 'TestSubSystem'
    level = 10
    time = Time.toString()
    msgTest = 'Hello'
    variableText = time
    frameInfo = ""
    message = tupleToMessage((systemName, level, time, msgTest, variableText,
                              frameInfo, subSystemName))
    site = 'somewehere'
    longSite = 'somewehere1234567890123456789012345678901234567890123456789012345678901234567890'
    nodeFQDN = '127.0.0.1'
    userDN = 'Yo'
    userGroup = 'Us'
    remoteAddress = 'elsewhere'

    records = 10

    db = SystemLoggingDB()
    assert db._connect()['OK']

    try:
        if False:
            for tableName in db.tableDict.keys():
                result = db._update('DROP TABLE  IF EXISTS `%s`' % tableName)
                assert result['OK']

            gLogger.info('\n Creating Table\n')
            # Make sure it is there and it has been created for this test
            result = db._checkTable()
            assert result['OK']

        result = db._checkTable()
        assert not result['OK']
        assert result['Message'] == 'The requested table already exist'

        gLogger.info('\n Inserting some records\n')
        for k in range(records):
            result = db.insertMessage(message, site, nodeFQDN, userDN,
                                      userGroup, remoteAddress)
            assert result['OK']
            assert result['lastRowId'] == k + 1
            assert result['Value'] == 1

        result = db.insertMessage(message, longSite, nodeFQDN, userDN,
                                  userGroup, remoteAddress)
        assert not result['OK']

        result = db._queryDB(showFieldList=['SiteName'])
        assert result['OK']
        assert result['Value'][0][0] == site

        result = db._queryDB(showFieldList=['SystemName'])
        assert result['OK']
        assert result['Value'][0][0] == systemName

        result = db._queryDB(showFieldList=['SubSystemName'])
        assert result['OK']
        assert result['Value'][0][0] == subSystemName

        result = db._queryDB(showFieldList=['OwnerGroup'])
        assert result['OK']
        assert result['Value'][0][0] == userGroup

        result = db._queryDB(showFieldList=['FixedTextString'])
        assert result['OK']
        assert result['Value'][0][0] == msgTest

        result = db._queryDB(showFieldList=['VariableText', 'SiteName'],
                             count=True,
                             groupColumn='VariableText')
        assert result['OK']
        assert result['Value'][0][1] == site
        assert result['Value'][0][2] == records

        gLogger.info('\n Removing Table\n')
        for tableName in [
                'MessageRepository', 'FixedTextMessages', 'SubSystems',
                'Systems', 'AgentPersistentData', 'ClientIPs', 'Sites',
                'UserDNs'
        ]:
            result = db._update('DROP TABLE `%s`' % tableName)
            assert result['OK']

        gLogger.info('\n OK\n')

    except AssertionError:
        print 'ERROR ',
        if not result['OK']:
            print result['Message']
        else:
            print result

        sys.exit(1)