コード例 #1
0
ファイル: Test_DataIntegrityDB.py プロジェクト: vingar/DIRAC
def test():
  """ Some test cases
  """

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

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

  diDB = DataIntegrityDB()
  assert diDB._connect()['OK']

  source = 'Test'
  prognosis = 'TestError'
  prodID = 1234
  lfn = '/Test/%08d/File1' % prodID
  fileMetadata1 = {lfn: {'Prognosis': prognosis, 'PFN': 'File1', 'SE': 'Test-SE'}}
  fileOut1 = {'FileID': 1L, 'LFN': lfn, 'PFN': 'File1', 'Prognosis': prognosis,
              'GUID': None, 'SE': 'Test-SE', 'Size': None}
  newStatus = 'Solved'
  newPrognosis = 'AnotherError'

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

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

    result = diDB.insertProblematic( source, fileMetadata1 )
    assert result['OK']
    assert result['Value'] == {'Successful': {lfn: True}, 'Failed': {}}

    result = diDB.insertProblematic( source, fileMetadata1 )
    assert result['OK']
    assert result['Value'] == {'Successful': {lfn: 'Already exists'}, 'Failed': {}}

    result = diDB.getProblematicsSummary()
    assert result['OK']
    assert result['Value'] == {'TestError': {'New': 1}}

    result = diDB.getDistinctPrognosis()
    assert result['OK']
    assert result['Value'] == ['TestError']

    result = diDB.getProblematic()
    assert result['OK']
    assert result['Value'] == fileOut1

    result = diDB.incrementProblematicRetry( result['Value']['FileID'] )
    assert result['OK']
    assert result['Value'] == 1

    result = diDB.getProblematic()
    assert result['OK']
    assert result['Value'] == fileOut1

    result = diDB.getPrognosisProblematics( prognosis )
    assert result['OK']
    assert result['Value'] == [fileOut1]

    result = diDB.getTransformationProblematics( prodID )
    assert result['OK']
    assert result['Value'][lfn] == 1

    result = diDB.setProblematicStatus( 1, newStatus )
    assert result['OK']
    assert result['Value'] == 1

    result = diDB.changeProblematicPrognosis( 1, newPrognosis )
    assert result['OK']
    assert result['Value'] == 1

    result = diDB.getPrognosisProblematics( prognosis )
    assert result['OK']
    assert result['Value'] == []

    result = diDB.removeProblematic( 1 )
    assert result['OK']
    assert result['Value'] == 1

    result = diDB.getProblematicsSummary()
    assert result['OK']
    assert result['Value'] == {}

    gLogger.info( '\n Removing Table\n' )
    result = diDB._update( 'DROP TABLE `%s`' % diDB.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 )
コード例 #2
0
ファイル: Test_DataIntegrityDB.py プロジェクト: pmusset/DIRAC
def test_DataIntegrityDB():
    """ Some test cases
  """

    diDB = DataIntegrityDB()

    source = 'Test'
    prognosis = 'TestError'
    prodID = 1234
    lfn = '/Test/%08d/File1' % prodID
    fileMetadata1 = {
        lfn: {
            'Prognosis': prognosis,
            'PFN': 'File1',
            'SE': 'Test-SE'
        }
    }
    fileOut1 = {
        'FileID': 1,
        'LFN': lfn,
        'PFN': 'File1',
        'Prognosis': prognosis,
        'GUID': None,
        'SE': 'Test-SE',
        'Size': None
    }
    newStatus = 'Solved'
    newPrognosis = 'AnotherError'

    result = diDB.insertProblematic(source, fileMetadata1)
    assert result['OK']
    assert result['Value'] == {'Successful': {lfn: True}, 'Failed': {}}

    result = diDB.insertProblematic(source, fileMetadata1)
    assert result['OK']
    assert result['Value'] == {
        'Successful': {
            lfn: 'Already exists'
        },
        'Failed': {}
    }

    result = diDB.getProblematicsSummary()
    assert result['OK']
    assert result['Value'] == {'TestError': {'New': 1}}

    result = diDB.getDistinctPrognosis()
    assert result['OK']
    assert result['Value'] == ['TestError']

    result = diDB.getProblematic()
    assert result['OK']
    assert result['Value'] == fileOut1

    result = diDB.incrementProblematicRetry(result['Value']['FileID'])
    assert result['OK']
    assert result['Value'] == 1

    result = diDB.getProblematic()
    assert result['OK']
    assert result['Value'] == fileOut1

    result = diDB.getPrognosisProblematics(prognosis)
    assert result['OK']
    assert result['Value'] == [fileOut1]

    result = diDB.getTransformationProblematics(prodID)
    assert result['OK']
    assert result['Value'][lfn] == 1

    result = diDB.setProblematicStatus(1, newStatus)
    assert result['OK']
    assert result['Value'] == 1

    result = diDB.changeProblematicPrognosis(1, newPrognosis)
    assert result['OK']
    assert result['Value'] == 1

    result = diDB.getPrognosisProblematics(prognosis)
    assert result['OK']
    assert result['Value'] == []

    result = diDB.removeProblematic(1)
    assert result['OK']
    assert result['Value'] == 1

    result = diDB.getProblematicsSummary()
    assert result['OK']
    assert result['Value'] == {}

    gLogger.info('\n OK\n')
コード例 #3
0
def test_DataIntegrityDB():
    """Some test cases"""
    source = "Test"
    prognosis = "TestError"
    prodID = 1234
    timestamp = int(time.time())
    lfn = "/Test/%08d/File1/%d" % (prodID, timestamp)
    pfn = "File1/%d" % (timestamp)
    fileMetadata1 = {
        lfn: {
            "Prognosis": prognosis,
            "PFN": pfn,
            "SE": "Test-SE"
        }
    }
    fileOut1 = {
        "LFN": lfn,
        "PFN": pfn,
        "Prognosis": prognosis,
        "GUID": None,
        "SE": "Test-SE",
        "Size": None
    }
    newStatus = "Solved"
    newPrognosis = "AnotherError"

    diDB = DataIntegrityDB()

    # Clean up the database if required
    result = diDB.getTransformationProblematics(1234)
    assert result["OK"], result["Message"]
    for fileID in result["Value"].values():
        result = diDB.removeProblematic(fileID)
        assert result["OK"], result["Message"]
    result = diDB.getProblematicsSummary()
    assert result["OK"], result["Message"]
    assert result["Value"] == {}

    # Run the actual test
    result = diDB.insertProblematic(source, fileMetadata1)
    assert result["OK"], result["Message"]
    assert result["Value"] == {"Successful": {lfn: True}, "Failed": {}}

    result = diDB.insertProblematic(source, fileMetadata1)
    assert result["OK"], result["Message"]
    assert result["Value"] == {
        "Successful": {
            lfn: "Already exists"
        },
        "Failed": {}
    }

    result = diDB.getProblematicsSummary()
    assert result["OK"], result["Message"]
    assert result["Value"] == {"TestError": {"New": 1}}

    result = diDB.getDistinctPrognosis()
    assert result["OK"], result["Message"]
    assert result["Value"] == ["TestError"]

    result = diDB.getProblematic()
    assert result["OK"], result["Message"]
    fileOut1["FileID"] = result["Value"]["FileID"]
    assert result["Value"] == fileOut1

    result = diDB.incrementProblematicRetry(result["Value"]["FileID"])
    assert result["OK"], result["Message"]
    assert result["Value"] == 1

    result = diDB.getProblematic()
    assert result["OK"], result["Message"]
    assert result["Value"] == fileOut1

    result = diDB.getPrognosisProblematics(prognosis)
    assert result["OK"], result["Message"]
    assert result["Value"] == [fileOut1]

    result = diDB.getTransformationProblematics(prodID)
    assert result["OK"], result["Message"]
    assert result["Value"][lfn] == fileOut1["FileID"]

    result = diDB.setProblematicStatus(fileOut1["FileID"], newStatus)
    assert result["OK"], result["Message"]
    assert result["Value"] == 1

    result = diDB.changeProblematicPrognosis(fileOut1["FileID"], newPrognosis)
    assert result["OK"], result["Message"]
    assert result["Value"] == 1

    result = diDB.getPrognosisProblematics(prognosis)
    assert result["OK"], result["Message"]
    assert result["Value"] == []

    result = diDB.removeProblematic(fileOut1["FileID"])
    assert result["OK"], result["Message"]
    assert result["Value"] == 1

    result = diDB.getProblematicsSummary()
    assert result["OK"], result["Message"]
    assert result["Value"] == {}

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