Exemplo n.º 1
0
    def test05Scheduled(self):
        """ scheduled request r/w """

        db = RequestDB()

        req = Request({"RequestName": "FTSTest"})
        op = Operation({
            "Type": "ReplicateAndRegister",
            "TargetSE": "CERN-USER"
        })
        op += File({
            "LFN": "/a/b/c",
            "Status": "Scheduled",
            "Checksum": "123456",
            "ChecksumType": "ADLER32"
        })
        req += op

        put = db.putRequest(req)
        self.assertEqual(put["OK"], True, "putRequest failed")

        peek = db.peekRequest(req.RequestName)
        self.assertEqual(peek["OK"], True, "peek failed ")

        peek = peek["Value"]
        for op in peek:
            opId = op.OperationID

        getFTS = db.getScheduledRequest(opId)
        self.assertEqual(getFTS["OK"], True, "getScheduled failed")
        self.assertEqual(getFTS["Value"].RequestName, "FTSTest",
                         "wrong request selected")
Exemplo n.º 2
0
  def test04Stress( self ):
    """ stress test """

    db = RequestDB()


    for i in range( self.stressRequests ):
      request = Request( { "RequestName": "test-%d" % i } )
      op = Operation( { "Type": "RemoveReplica", "TargetSE": "CERN-USER" } )
      op += File( { "LFN": "/lhcb/user/c/cibak/foo" } )
      request += op
      put = db.putRequest( request )
      self.assertEqual( put["OK"], True, "put failed" )

    startTime = time.time()

    for i in range( self.stressRequests ):
      get = db.getRequest( "test-%s" % i, True )
      if "Message" in get:
        print get["Message"]
      self.assertEqual( get["OK"], True, "get failed" )

    endTime = time.time()

    print "getRequest duration %s " % ( endTime - startTime )

    for i in range( self.stressRequests ):
      delete = db.deleteRequest( "test-%s" % i )
      self.assertEqual( delete["OK"], True, "delete failed" )
Exemplo n.º 3
0
    def test04Stress(self):
        """ stress test """

        db = RequestDB()

        for i in range(self.stressRequests):
            request = Request({"RequestName": "test-%d" % i})
            op = Operation({"Type": "RemoveReplica", "TargetSE": "CERN-USER"})
            op += File({"LFN": "/lhcb/user/c/cibak/foo"})
            request += op
            put = db.putRequest(request)
            self.assertEqual(put["OK"], True, "put failed")

        startTime = time.time()

        for i in range(self.stressRequests):
            get = db.getRequest("test-%s" % i, True)
            if "Message" in get:
                print get["Message"]
            self.assertEqual(get["OK"], True, "get failed")

        endTime = time.time()

        print "getRequest duration %s " % (endTime - startTime)

        for i in range(self.stressRequests):
            delete = db.deleteRequest("test-%s" % i)
            self.assertEqual(delete["OK"], True, "delete failed")
Exemplo n.º 4
0
  def test04StressBulk( self ):
    """ stress test bulk """

    db = RequestDB()

    for i in range( self.stressRequests ):
      request = Request( { "RequestName": "test-%d" % i } )
      op = Operation( { "Type": "RemoveReplica", "TargetSE": "CERN-USER" } )
      op += File( { "LFN": "/lhcb/user/c/cibak/foo" } )
      request += op
      put = db.putRequest( request )
      self.assertEqual( put["OK"], True, "put failed" )

    loops = self.stressRequests // self.bulkRequest + ( 1 if ( self.stressRequests % self.bulkRequest ) else 0 )
    totalSuccessful = 0

    startTime = time.time()

    for i in range( loops ):
      get = db.getRequests( self.bulkRequest, True )
      if "Message" in get:
        print get["Message"]
      self.assertEqual( get["OK"], True, "get failed" )

      totalSuccessful += len( get["Value"] )

    endTime = time.time()

    print "getRequests duration %s " % ( endTime - startTime )

    self.assertEqual( totalSuccessful, self.stressRequests, "Did not retrieve all the requests: %s instead of %s" % ( totalSuccessful, self.stressRequests ) )

    for i in range( self.stressRequests ):
      delete = db.deleteRequest( "test-%s" % i )
      self.assertEqual( delete["OK"], True, "delete failed" )
Exemplo n.º 5
0
  def test04Stress(self):
    """ stress test """

    db = RequestDB()

    reqIDs = []
    for i in xrange(self.stressRequests):
      request = Request({"RequestName": "test-%d" % i})
      op = Operation({"Type": "RemoveReplica", "TargetSE": "CERN-USER"})
      op += File({"LFN": "/lhcb/user/c/cibak/foo"})
      request += op
      put = db.putRequest(request)
      self.assertEqual(put["OK"], True, put['Message'] if 'Message' in put else 'OK')
      reqIDs.append(put['Value'])

    startTime = time.time()

    for reqID in reqIDs:
      get = db.getRequest(reqID)
      if "Message" in get:
        print get["Message"]
      self.assertEqual(get["OK"], True, get['Message'] if 'Message' in get else 'OK')

    endTime = time.time()

    print "getRequest duration %s " % (endTime - startTime)

    for reqID in reqIDs:
      delete = db.deleteRequest(reqID)
      self.assertEqual(delete["OK"], True, delete['Message'] if 'Message' in delete else 'OK')
Exemplo n.º 6
0
    def test01Stress(self):
        """ stress test """

        db = RequestDB()

        reqIDs = []
        for i in xrange(self.stressRequests):
            request = Request({"RequestName": "test-%d" % i})
            op = Operation({"Type": "RemoveReplica", "TargetSE": "CERN-USER"})
            op += File({"LFN": "/lhcb/user/c/cibak/foo"})
            request += op
            put = db.putRequest(request)
            self.assertEqual(put["OK"], True,
                             put['Message'] if 'Message' in put else 'OK')
            reqIDs.append(put['Value'])

        startTime = time.time()

        for reqID in reqIDs:
            get = db.getRequest(reqID)
            if "Message" in get:
                print(get["Message"])
            self.assertEqual(get["OK"], True,
                             get['Message'] if 'Message' in get else 'OK')

        endTime = time.time()

        print("getRequest duration %s " % (endTime - startTime))

        for reqID in reqIDs:
            delete = db.deleteRequest(reqID)
            self.assertEqual(
                delete["OK"], True,
                delete['Message'] if 'Message' in delete else 'OK')
Exemplo n.º 7
0
  def test05Scheduled(self):
    """ scheduled request r/w """

    db = RequestDB()

    req = Request({"RequestName": "FTSTest"})
    op = Operation({"Type": "ReplicateAndRegister", "TargetSE": "CERN-USER"})
    op += File({"LFN": "/a/b/c", "Status": "Scheduled",
                "Checksum": "123456", "ChecksumType": "ADLER32"})
    req += op

    put = db.putRequest(req)
    self.assertEqual(put["OK"], True, put['Message'] if 'Message' in put else 'OK')
    reqID = put['Value']

    peek = db.peekRequest(reqID)
    self.assertEqual(peek["OK"], True, peek['Message'] if 'Message' in peek else 'OK')

    peek = peek["Value"]
    for op in peek:
      opId = op.OperationID

    getFTS = db.getScheduledRequest(opId)
    self.assertEqual(getFTS["OK"], True, "getScheduled failed")
    self.assertEqual(getFTS["Value"].RequestName, "FTSTest", "wrong request selected")

    delete = db.deleteRequest(reqID)
    self.assertEqual(delete["OK"], True, delete['Message'] if 'Message' in delete else 'OK')
Exemplo n.º 8
0
  def test06Dirty( self ):
    """ dirty records """
    db = RequestDB()

    r = Request()
    r.RequestName = "dirty"

    op1 = Operation( { "Type": "ReplicateAndRegister", "TargetSE": "CERN-USER"} )
    op1 += File( {"LFN": "/a/b/c/1", "Status": "Scheduled", "Checksum": "123456", "ChecksumType": "ADLER32" } )

    op2 = Operation( { "Type": "ReplicateAndRegister", "TargetSE": "CERN-USER"} )
    op2 += File( {"LFN": "/a/b/c/2", "Status": "Scheduled", "Checksum": "123456", "ChecksumType": "ADLER32" } )

    op3 = Operation( { "Type": "ReplicateAndRegister", "TargetSE": "CERN-USER"} )
    op3 += File( {"LFN": "/a/b/c/3", "Status": "Scheduled", "Checksum": "123456", "ChecksumType": "ADLER32" } )

    r += op1
    r += op2
    r += op3

    put = db.putRequest( r )
    self.assertEqual( put["OK"], True, "1. putRequest failed: %s" % put.get( "Message", "" ) )
    reqID = put['Value']

    r = db.getRequest( reqID )
    self.assertEqual( r["OK"], True, "1. getRequest failed: %s" % r.get( "Message", "" ) )
    r = r["Value"]

    del r[0]
    self.assertEqual( len( r ), 2, "1. len wrong" )

    put = db.putRequest( r )
    self.assertEqual( put["OK"], True, "2. putRequest failed: %s" % put.get( "Message", "" ) )
    reqID = put['Value']

    r = db.getRequest( reqID )
    self.assertEqual( r["OK"], True, "2. getRequest failed: %s" % r.get( "Message", "" ) )

    r = r["Value"]
    self.assertEqual( len( r ), 2, "2. len wrong" )

    op4 = Operation( { "Type": "ReplicateAndRegister", "TargetSE": "CERN-USER"} )
    op4 += File( {"LFN": "/a/b/c/4", "Status": "Scheduled", "Checksum": "123456", "ChecksumType": "ADLER32" } )

    r[0] = op4
    put = db.putRequest( r )
    self.assertEqual( put["OK"], True, "3. putRequest failed: %s" % put.get( "Message", "" ) )
    reqID = put['Value']

    r = db.getRequest( reqID )
    self.assertEqual( r["OK"], True, "3. getRequest failed: %s" % r.get( "Message", "" ) )
    r = r["Value"]

    self.assertEqual( len( r ), 2, "3. len wrong" )

    delete = db.deleteRequest( reqID )
    self.assertEqual( delete["OK"], True, delete['Message'] if 'Message' in delete else 'OK' )
Exemplo n.º 9
0
 def initializeHandler(cls, serviceInfoDict):
     """ initialize handler """
     try:
         cls.__requestDB = RequestDB()
     except RuntimeError, error:
         gLogger.exception(error)
         return S_ERROR(error)
Exemplo n.º 10
0
  def test_db( self ):

    # # empty DB at that stage
    ret = RequestDB().getDBSummary()
    self.assertEqual( ret,
                      { 'OK': True,
                        'Value': { 'Operation': {}, 'Request': {}, 'File': {} } } )
Exemplo n.º 11
0
  def test06Dirty( self ):
    """ dirty records """
    db = RequestDB()

    r = Request()
    r.RequestName = "dirty"

    op1 = Operation( { "Type": "ReplicateAndRegister", "TargetSE": "CERN-USER"} )
    op1 += File( {"LFN": "/a/b/c/1", "Status": "Scheduled", "Checksum": "123456", "ChecksumType": "ADLER32" } )

    op2 = Operation( { "Type": "ReplicateAndRegister", "TargetSE": "CERN-USER"} )
    op2 += File( {"LFN": "/a/b/c/2", "Status": "Scheduled", "Checksum": "123456", "ChecksumType": "ADLER32" } )

    op3 = Operation( { "Type": "ReplicateAndRegister", "TargetSE": "CERN-USER"} )
    op3 += File( {"LFN": "/a/b/c/3", "Status": "Scheduled", "Checksum": "123456", "ChecksumType": "ADLER32" } )

    r += op1
    r += op2
    r += op3

    put = db.putRequest( r )
    self.assertEqual( put["OK"], True, "1. putRequest failed: %s" % put.get( "Message", "" ) )
    reqID = put['Value']

    r = db.getRequest( reqID )
    self.assertEqual( r["OK"], True, "1. getRequest failed: %s" % r.get( "Message", "" ) )
    r = r["Value"]

    del r[0]
    self.assertEqual( len( r ), 2, "1. len wrong" )

    put = db.putRequest( r )
    self.assertEqual( put["OK"], True, "2. putRequest failed: %s" % put.get( "Message", "" ) )
    reqID = put['Value']

    r = db.getRequest( reqID )
    self.assertEqual( r["OK"], True, "2. getRequest failed: %s" % r.get( "Message", "" ) )

    r = r["Value"]
    self.assertEqual( len( r ), 2, "2. len wrong" )

    op4 = Operation( { "Type": "ReplicateAndRegister", "TargetSE": "CERN-USER"} )
    op4 += File( {"LFN": "/a/b/c/4", "Status": "Scheduled", "Checksum": "123456", "ChecksumType": "ADLER32" } )

    r[0] = op4
    put = db.putRequest( r )
    self.assertEqual( put["OK"], True, "3. putRequest failed: %s" % put.get( "Message", "" ) )
    reqID = put['Value']

    r = db.getRequest( reqID )
    self.assertEqual( r["OK"], True, "3. getRequest failed: %s" % r.get( "Message", "" ) )
    r = r["Value"]

    self.assertEqual( len( r ), 2, "3. len wrong" )

    delete = db.deleteRequest( reqID )
    self.assertEqual( delete["OK"], True, delete['Message'] if 'Message' in delete else 'OK' )
Exemplo n.º 12
0
 def test01TableDesc(self):
     """ table description """
     tableDict = RequestDB.getTableMeta()
     self.assertEqual("Request" in tableDict, True)
     self.assertEqual("Operation" in tableDict, True)
     self.assertEqual("File" in tableDict, True)
     self.assertEqual(tableDict["Request"], Request.tableDesc())
     self.assertEqual(tableDict["Operation"], Operation.tableDesc())
     self.assertEqual(tableDict["File"], File.tableDesc())
Exemplo n.º 13
0
 def test01TableDesc(self):
     """ table description """
     tableDict = RequestDB.getTableMeta()
     self.assertEqual("Request" in tableDict, True)
     self.assertEqual("Operation" in tableDict, True)
     self.assertEqual("File" in tableDict, True)
     self.assertEqual(tableDict["Request"], Request.tableDesc())
     self.assertEqual(tableDict["Operation"], Operation.tableDesc())
     self.assertEqual(tableDict["File"], File.tableDesc())
Exemplo n.º 14
0
    def test01StressBulk(self):
        """ stress test bulk """

        db = RequestDB()

        reqIDs = []
        for i in xrange(self.stressRequests):
            request = Request({"RequestName": "test-%d" % i})
            op = Operation({"Type": "RemoveReplica", "TargetSE": "CERN-USER"})
            op += File({"LFN": "/lhcb/user/c/cibak/foo"})
            request += op
            put = db.putRequest(request)
            self.assertEqual(put["OK"], True)
            reqIDs.append(put['Value'])

        loops = self.stressRequests // self.bulkRequest + \
            (1 if (self.stressRequests % self.bulkRequest) else 0)
        totalSuccessful = 0

        time.sleep(1)
        startTime = time.time()

        for i in xrange(loops):
            get = db.getBulkRequests(self.bulkRequest, True)
            if "Message" in get:
                print(get["Message"])
            self.assertEqual(get["OK"], True, "get failed")

            totalSuccessful += len(get["Value"])

        endTime = time.time()

        print("getRequests duration %s " % (endTime - startTime))

        self.assertEqual(
            totalSuccessful, self.stressRequests,
            "Did not retrieve all the requests: %s instead of %s" %
            (totalSuccessful, self.stressRequests))

        for reqID in reqIDs:
            delete = db.deleteRequest(reqID)
            self.assertEqual(
                delete["OK"], True,
                delete['Message'] if 'Message' in delete else 'OK')
Exemplo n.º 15
0
    def test_db(self):
        """ table description """
        tableDict = RequestDB.getTableMeta()
        self.assertEqual("Request" in tableDict, True)
        self.assertEqual("Operation" in tableDict, True)
        self.assertEqual("File" in tableDict, True)
        self.assertEqual(tableDict["Request"], Request.tableDesc())
        self.assertEqual(tableDict["Operation"], Operation.tableDesc())
        self.assertEqual(tableDict["File"], File.tableDesc())

        # # empty DB at that stage
        ret = RequestDB().getDBSummary()
        self.assertEqual(ret, {
            'OK': True,
            'Value': {
                'Operation': {},
                'Request': {},
                'File': {}
            }
        })
Exemplo n.º 16
0
  def initializeHandler(cls, serviceInfoDict):
    """ initialize handler """

    try:
      cls.__requestDB = RequestDB()
    except RuntimeError as error:
      gLogger.exception(error)
      return S_ERROR(error)

    # If there is a constant delay to be applied to each request
    cls.constantRequestDelay = getServiceOption(serviceInfoDict, 'ConstantRequestDelay', 0)

    # # create tables for empty db
    return cls.__requestDB.createTables()
Exemplo n.º 17
0
  def test_db( self ):

    """ table description """
    tableDict = RequestDB.getTableMeta()
    self.assertEqual( "Request" in tableDict, True )
    self.assertEqual( "Operation" in tableDict, True )
    self.assertEqual( "File" in tableDict, True )
    self.assertEqual( tableDict["Request"], Request.tableDesc() )
    self.assertEqual( tableDict["Operation"], Operation.tableDesc() )
    self.assertEqual( tableDict["File"], File.tableDesc() )

    # # empty DB at that stage
    ret = RequestDB().getDBSummary()
    self.assertEqual( ret,
                      { 'OK': True,
                        'Value': { 'Operation': {}, 'Request': {}, 'File': {} } } )
Exemplo n.º 18
0
    def test02Scheduled(self):
        """ scheduled request r/w """

        db = RequestDB()

        req = Request({"RequestName": "FTSTest"})
        op = Operation({
            "Type": "ReplicateAndRegister",
            "TargetSE": "CERN-USER"
        })
        op += File({
            "LFN": "/a/b/c",
            "Status": "Scheduled",
            "Checksum": "123456",
            "ChecksumType": "ADLER32"
        })
        req += op

        put = db.putRequest(req)
        self.assertEqual(put["OK"], True,
                         put['Message'] if 'Message' in put else 'OK')
        reqID = put['Value']

        peek = db.peekRequest(reqID)
        self.assertEqual(peek["OK"], True,
                         peek['Message'] if 'Message' in peek else 'OK')

        peek = peek["Value"]
        for op in peek:
            opId = op.OperationID

        getFTS = db.getScheduledRequest(opId)
        self.assertEqual(getFTS["OK"], True, "getScheduled failed")
        self.assertEqual(getFTS["Value"].RequestName, "FTSTest",
                         "wrong request selected")

        delete = db.deleteRequest(reqID)
        self.assertEqual(delete["OK"], True,
                         delete['Message'] if 'Message' in delete else 'OK')
Exemplo n.º 19
0
  def test01fullChain( self ):
    put = self.requestClient.putRequest( self.request )
    self.assert_( put['OK'] )

    self.assertEqual( type( put['Value'] ), long )
    reqID = put['Value']

    # # summary
    ret = RequestDB().getDBSummary()
    self.assertEqual( ret,
                      { 'OK': True,
                        'Value': { 'Operation': { 'ReplicateAndRegister': { 'Waiting': 1L } },
                                   'Request': { 'Waiting': 1L },
                                   'File': { 'Waiting': 2L} } } )

    get = self.requestClient.getRequest( reqID )
    self.assert_( get['OK'] )
    self.assertEqual( isinstance( get['Value'], Request ), True )
    # # summary - the request became "Assigned"
    res = RequestDB().getDBSummary()
    self.assertEqual( res,
                      { 'OK': True,
                        'Value': { 'Operation': { 'ReplicateAndRegister': { 'Waiting': 1L } },
                                   'Request': { 'Assigned': 1L },
                                   'File': { 'Waiting': 2L} } } )


    res = self.requestClient.getRequestInfo( reqID )
    self.assertEqual( res['OK'], True, res['Message'] if 'Message' in res else 'OK' )

    res = self.requestClient.getRequestFileStatus( reqID, self.file.LFN )
    self.assertEqual( res['OK'], True, res['Message'] if 'Message' in res else 'OK' )

    res = self.requestClient.getRequestFileStatus( reqID, [self.file.LFN] )
    self.assertEqual( res['OK'], True, res['Message'] if 'Message' in res else 'OK' )

    res = self.requestClient.getDigest( reqID )
    self.assertEqual( res['OK'], True, res['Message'] if 'Message' in res else 'OK' )

    res = self.requestClient.readRequestsForJobs( [123] )
    self.assertEqual( res['OK'], True, res['Message'] if 'Message' in res else 'OK' )
    self.assert_( isinstance( res['Value']['Successful'][123], Request ) )

    # Adding new request
    request2 = Request()
    request2.RequestName = "RequestManagerHandlerTests-2"
    request2.OwnerDN = "/DC=ch/DC=cern/OU=Organic Units/OU=Users/CN=cibak/CN=605919/CN=Krzysztof Ciba"
    request2.OwnerGroup = "dirac_user"
    request2.JobID = 456
    request2.addOperation( self.operation )

    # # update
    res = self.requestClient.putRequest( request2 )
    self.assertEqual( res['OK'], True, res['Message'] if 'Message' in res else 'OK' )
    reqID2 = res['Value']

    # # get summary again
    ret = RequestDB().getDBSummary()
    self.assertEqual( ret,
                      { 'OK': True,
                        'Value': { 'Operation': { 'ReplicateAndRegister': {'Waiting': 2L } },
                                   'Request': { 'Waiting': 1L, 'Assigned': 1L },
                                   'File': { 'Waiting': 4L} } } )
Exemplo n.º 20
0
        self.assert_(isinstance(res['Value']['Successful'][123], Request))

        # Adding new request
        request2 = Request()
        request2.RequestName = "RequestManagerHandlerTests-2"
        request2.OwnerDN = "/DC=ch/DC=cern/OU=Organic Units/OU=Users/CN=cibak/CN=605919/CN=Krzysztof Ciba"
        request2.OwnerGroup = "dirac_user"
        request2.JobID = 456
        request2.addOperation(self.operation)

        # # update
        res = self.requestClient.putRequest(request2)
        self.assert_(res['OK'])

        # # get summary again
        ret = RequestDB().getDBSummary()
        self.assertEqual(
            ret, {
                'OK': True,
                'Value': {
                    'Operation': {
                        'ReplicateAndRegister': {
                            'Waiting': 2L
                        }
                    },
                    'Request': {
                        'Waiting': 1L,
                        'Assigned': 1L
                    },
                    'File': {
                        'Waiting': 4L
Exemplo n.º 21
0
 def setUp(self):
     self.TransferDB = TransferDB()
     self.RequestDB = RequestDB('mysql')
Exemplo n.º 22
0
    def test_fullChain(self):
        put = self.requestClient.putRequest(self.request)
        self.assert_(put['OK'])

        # # summary
        ret = RequestDB().getDBSummary()
        self.assertEqual(
            ret, {
                'OK': True,
                'Value': {
                    'Operation': {
                        'ReplicateAndRegister': {
                            'Waiting': 1L
                        }
                    },
                    'Request': {
                        'Waiting': 1L
                    },
                    'File': {
                        'Waiting': 2L
                    }
                }
            })

        get = self.requestClient.getRequest(self.request.RequestName)
        self.assert_(get['OK'])
        self.assertEqual(isinstance(get['Value'], Request), True)
        # # summary - the request became "Assigned"
        res = RequestDB().getDBSummary()
        self.assertEqual(
            res, {
                'OK': True,
                'Value': {
                    'Operation': {
                        'ReplicateAndRegister': {
                            'Waiting': 1L
                        }
                    },
                    'Request': {
                        'Assigned': 1L
                    },
                    'File': {
                        'Waiting': 2L
                    }
                }
            })

        res = self.requestClient.getRequestInfo(self.request.RequestName)
        self.assert_(res['OK'])
        res = self.requestClient.getRequestName(res['Value'][0])
        self.assert_(res['OK'])
        self.assertEqual(res['Value'], self.request.RequestName)

        res = self.requestClient.getRequestFileStatus(self.request.RequestName,
                                                      self.file.LFN)
        self.assert_(res['OK'])

        res = self.requestClient.getRequestFileStatus(self.request.RequestName,
                                                      [self.file.LFN])
        self.assert_(res['OK'])

        res = self.requestClient.getDigest(self.request.RequestName)
        self.assert_(res['OK'])

        res = self.requestClient.getRequestNamesForJobs([123])
        self.assert_(res['OK'])
        self.assertEqual(res['Value'], {
            'Successful': {
                123L: self.request.RequestName
            },
            'Failed': {}
        })
Exemplo n.º 23
0
def reqDB(request):
    """This fixture just instanciate the RequestDB"""
    yield RequestDB()
Exemplo n.º 24
0
    def test03RequestRW(self):
        """ db r/w requests """
        db = RequestDB()
        db._checkTables(True)

        # # empty DB at that stage
        ret = db.getDBSummary()
        self.assertEqual(ret, {
            'OK': True,
            'Value': {
                'Operation': {},
                'Request': {},
                'File': {}
            }
        })

        # # insert
        ret = db.putRequest(self.request)
        self.assertEqual(ret, {'OK': True, 'Value': ''})

        # # get digest -> JSON
        ret = db.getDigest(self.request.RequestName)
        self.assertEqual(ret["OK"], True)
        self.assertEqual(bool(ret["Value"]), True)

        # # db summary
        ret = db.getDBSummary()
        self.assertEqual(
            ret, {
                'OK': True,
                'Value': {
                    'Operation': {
                        'RemoveFile': {
                            'Queued': 1L
                        },
                        'ReplicateAndRegister': {
                            'Waiting': 1L
                        }
                    },
                    'Request': {
                        'Waiting': 1L
                    },
                    'File': {
                        'Waiting': 2L
                    }
                }
            })

        # # get request for jobs
        ret = db.getRequestNamesForJobs([1])
        self.assertEqual(ret["OK"], True)
        self.assertEqual(ret["Value"], {1: 'test1'})

        # # read requests
        ret = db.readRequestsForJobs([1])
        self.assertEqual(ret["OK"], True)
        self.assertEqual(ret["Value"][1]["OK"], True)

        # # select
        ret = db.getRequest()
        self.assertEqual(ret["OK"], True)
        request = ret["Value"]
        self.assertEqual(isinstance(request, Request), True)

        # # summary
        ret = db.getDBSummary()
        self.assertEqual(
            ret, {
                'OK': True,
                'Value': {
                    'Operation': {
                        'RemoveFile': {
                            'Queued': 1L
                        },
                        'ReplicateAndRegister': {
                            'Waiting': 1L
                        }
                    },
                    'Request': {
                        'Assigned': 1L
                    },
                    'File': {
                        'Waiting': 2L
                    }
                }
            })
        # # update
        ret = db.putRequest(request)
        self.assertEqual(ret, {'OK': True, 'Value': ''})

        # # get summary again
        ret = db.getDBSummary()
        self.assertEqual(
            ret, {
                'OK': True,
                'Value': {
                    'Operation': {
                        'RemoveFile': {
                            'Queued': 1L
                        },
                        'ReplicateAndRegister': {
                            'Waiting': 1L
                        }
                    },
                    'Request': {
                        'Waiting': 1L
                    },
                    'File': {
                        'Waiting': 2L
                    }
                }
            })

        # # delete
        ret = db.deleteRequest(self.request.RequestName)
        self.assertEqual(ret, {'OK': True, 'Value': ''})

        # # should be empty now
        ret = db.getDBSummary()
        self.assertEqual(ret, {
            'OK': True,
            'Value': {
                'Operation': {},
                'Request': {},
                'File': {}
            }
        })
Exemplo n.º 25
0
 def setUp(self):
     self.requestDB = RequestDB('mysql')
     self.requestName = 'test-%s' % time.strftime('%Y-%m-%d %H:%M:%S')
Exemplo n.º 26
0
    def test03RequestRW(self):
        """ db r/w requests """
        db = RequestDB()
        db._checkTables(True)

        # # empty DB at that stage
        ret = db.getDBSummary()
        self.assertEqual(ret, {"OK": True, "Value": {"Operation": {}, "Request": {}, "File": {}}})

        # # insert
        ret = db.putRequest(self.request)
        self.assertEqual(ret, {"OK": True, "Value": ""})

        # # get digest -> JSON
        ret = db.getDigest(self.request.RequestName)
        self.assertEqual(ret["OK"], True)
        self.assertEqual(bool(ret["Value"]), True)

        # # db summary
        ret = db.getDBSummary()
        self.assertEqual(
            ret,
            {
                "OK": True,
                "Value": {
                    "Operation": {"RemoveFile": {"Queued": 1L}, "ReplicateAndRegister": {"Waiting": 1L}},
                    "Request": {"Waiting": 1L},
                    "File": {"Waiting": 2L},
                },
            },
        )

        # # get request for jobs
        ret = db.getRequestNamesForJobs([1])
        self.assertEqual(ret["OK"], True)
        self.assertEqual(ret["Value"], {1: "test1"})

        # # read requests
        ret = db.readRequestsForJobs([1])
        self.assertEqual(ret["OK"], True)
        self.assertEqual(ret["Value"][1]["OK"], True)

        # # select
        ret = db.getRequest()
        self.assertEqual(ret["OK"], True)
        request = ret["Value"]
        self.assertEqual(isinstance(request, Request), True)

        # # summary
        ret = db.getDBSummary()
        self.assertEqual(
            ret,
            {
                "OK": True,
                "Value": {
                    "Operation": {"RemoveFile": {"Queued": 1L}, "ReplicateAndRegister": {"Waiting": 1L}},
                    "Request": {"Assigned": 1L},
                    "File": {"Waiting": 2L},
                },
            },
        )
        # # update
        ret = db.putRequest(request)
        self.assertEqual(ret, {"OK": True, "Value": ""})

        # # get summary again
        ret = db.getDBSummary()
        self.assertEqual(
            ret,
            {
                "OK": True,
                "Value": {
                    "Operation": {"RemoveFile": {"Queued": 1L}, "ReplicateAndRegister": {"Waiting": 1L}},
                    "Request": {"Waiting": 1L},
                    "File": {"Waiting": 2L},
                },
            },
        )

        # # delete
        ret = db.deleteRequest(self.request.RequestName)
        self.assertEqual(ret, {"OK": True, "Value": ""})

        # # should be empty now
        ret = db.getDBSummary()
        self.assertEqual(ret, {"OK": True, "Value": {"Operation": {}, "Request": {}, "File": {}}})
Exemplo n.º 27
0
    def test01fullChain(self):
        put = self.requestClient.putRequest(self.request)
        self.assertTrue(put['OK'], put)

        self.assertEqual(type(put['Value']), long)
        reqID = put['Value']

        # # summary
        ret = RequestDB().getDBSummary()
        self.assertEqual(
            ret, {
                'OK': True,
                'Value': {
                    'Operation': {
                        'ReplicateAndRegister': {
                            'Waiting': 1
                        }
                    },
                    'Request': {
                        'Waiting': 1
                    },
                    'File': {
                        'Waiting': 2
                    }
                }
            })

        get = self.requestClient.getRequest(reqID)
        self.assertTrue(get['OK'])
        self.assertEqual(isinstance(get['Value'], Request), True)
        # # summary - the request became "Assigned"
        res = RequestDB().getDBSummary()
        self.assertEqual(
            res, {
                'OK': True,
                'Value': {
                    'Operation': {
                        'ReplicateAndRegister': {
                            'Waiting': 1
                        }
                    },
                    'Request': {
                        'Assigned': 1
                    },
                    'File': {
                        'Waiting': 2
                    }
                }
            })

        res = self.requestClient.getRequestInfo(reqID)
        self.assertEqual(res['OK'], True,
                         res['Message'] if 'Message' in res else 'OK')

        res = self.requestClient.getRequestFileStatus(reqID, self.file.LFN)
        self.assertEqual(res['OK'], True,
                         res['Message'] if 'Message' in res else 'OK')

        res = self.requestClient.getRequestFileStatus(reqID, [self.file.LFN])
        self.assertEqual(res['OK'], True,
                         res['Message'] if 'Message' in res else 'OK')

        res = self.requestClient.getDigest(reqID)
        self.assertEqual(res['OK'], True,
                         res['Message'] if 'Message' in res else 'OK')

        res = self.requestClient.readRequestsForJobs([123])
        self.assertEqual(res['OK'], True,
                         res['Message'] if 'Message' in res else 'OK')
        self.assertTrue(isinstance(res['Value']['Successful'][123], Request))

        proxyInfo = getProxyInfo()['Value']
        # Adding new request
        request2 = Request()
        request2.RequestName = "RequestManagerHandlerTests-2"
        self.request.OwnerDN = proxyInfo['identity']
        self.request.OwnerGroup = proxyInfo['group']
        request2.JobID = 456
        request2.addOperation(self.operation)

        # # update
        res = self.requestClient.putRequest(request2)
        self.assertEqual(res['OK'], True,
                         res['Message'] if 'Message' in res else 'OK')
        reqID2 = res['Value']

        # # get summary again
        ret = RequestDB().getDBSummary()
        self.assertEqual(
            ret, {
                'OK': True,
                'Value': {
                    'Operation': {
                        'ReplicateAndRegister': {
                            'Waiting': 2
                        }
                    },
                    'Request': {
                        'Waiting': 1,
                        'Assigned': 1
                    },
                    'File': {
                        'Waiting': 4
                    }
                }
            })

        delete = self.requestClient.deleteRequest(reqID)
        self.assertEqual(delete['OK'], True,
                         delete['Message'] if 'Message' in delete else 'OK')
        delete = self.requestClient.deleteRequest(reqID2)
        self.assertEqual(delete['OK'], True,
                         delete['Message'] if 'Message' in delete else 'OK')

        # # should be empty now
        ret = RequestDB().getDBSummary()
        self.assertEqual(ret, {
            'OK': True,
            'Value': {
                'Operation': {},
                'Request': {},
                'File': {}
            }
        })