Example #1
0
    def setUp(self):
        """ set up

    :param self: self reference
    """
        self.log = gLogger.getSubLogger(self.__class__.__name__)
        self.requestDB = RequestDBFile()
        setRequest = self.requestDB.setRequest("testRequest", reqStr)
class RequestDBFileTests(unittest.TestCase):
  """
  .. class:: RequestDBFileTests
  
  """

  def setUp( self ):
    """ set up

    :param self: self reference
    """
    self.log = gLogger.getSubLogger( self.__class__.__name__ )
    self.requestDB = RequestDBFile()
    setRequest = self.requestDB.setRequest( "testRequest", reqStr )

  def tearDown( self ):
    #deleteRequest = self.requestDB.deleteRequest( "testRequest" )
    pass
    
  def test_01_getRequestStatus( self ):

    self.assertEqual( self.requestDB.getRequestStatus( "testRequest" ), 
                      {'OK': True, 'Value': {'SubRequestStatus': 'Waiting', 'RequestStatus': 'Waiting'}}) 

    ## get request
    getRemoval =  self.requestDB.getRequest( "removal" )
    oRequest = RequestContainer( getRemoval["Value"]["RequestString"] )

    
    self.assertEqual( self.requestDB.getRequestStatus( "testRequest" ), 
                      {'OK': True, 'Value': {'SubRequestStatus': 'Assigned', 'RequestStatus': 'Waiting'}} )

    ## make removal Done
    oRequest.subRequests["removal"][0]["Attributes"]["Status"] = "Done"
    oRequest.subRequests["removal"][0]["Files"][0]["Status"] = "Done"
   
    update = self.requestDB.updateRequest( getRemoval["Value"]["RequestName"], 
                                           oRequest.toXML()["Value"] )

    ## get status
    self.assertEqual( self.requestDB.getRequestStatus( "testRequest" ), 
                      {'OK': True, 'Value': {'SubRequestStatus': 'Waiting', 'RequestStatus': u'Waiting'}})

    ## make transfer Done
    oRequest.subRequests["transfer"][0]["Attributes"]["Status"] = "Done"
    oRequest.subRequests["transfer"][0]["Files"][0]["Status"] = "Done"
    update = self.requestDB.updateRequest( getRemoval["Value"]["RequestName"], 
                                           oRequest.toXML()["Value"] )
    ## get status
    self.assertEqual( self.requestDB.getRequestStatus( "testRequest" ),
                      {'OK': True, 'Value': {'SubRequestStatus': 'Done', 'RequestStatus': 'Done'}} )

  def test_02_getRequest( self ):
    """ getRequest and JobID """
    getRequest = self.requestDB.getRequest("transfer")
    self.assertEqual( getRequest["OK"], True )
    self.assertEqual( getRequest["Value"]["JobID"], 0 )
Example #3
0
  def setUp( self ):
    """ set up

    :param self: self reference
    """
    self.log = gLogger.getSubLogger( self.__class__.__name__ )
    self.requestDB = RequestDBFile()
    setRequest = self.requestDB.setRequest( "testRequest", reqStr )
Example #4
0
def initializeRequestManagerHandler(serviceInfo):
  global requestDB
  csSection = PathFinder.getServiceSection( "RequestManagement/RequestManager" )
  backend = gConfig.getValue('%s/Backend' % csSection)
  if not backend:
    fatStr = "RequestManager.initializeRequestManagerHandler: Failed to get backed for RequestDB from CS."
    gLogger.fatal(fatStr)
    return S_ERROR(fatStr)
  gLogger.info("RequestManager.initializeRequestManagerHandler: Initialising with backend",backend)
  if backend == 'file':
    from DIRAC.RequestManagementSystem.DB.RequestDBFile import RequestDBFile
    requestDB = RequestDBFile()
  elif backend == 'mysql':
    from DIRAC.RequestManagementSystem.DB.RequestDBMySQL import RequestDBMySQL
    requestDB = RequestDBMySQL()
  else:
    fatStr = "RequestManager.initializeRequestManagerHandler: Supplied backend is not supported."
    gLogger.fatal(fatStr,backend)
    return S_ERROR(fatStr)
  return S_OK()
Example #5
0
class RequestDBFileTests(unittest.TestCase):
    """
  .. class:: RequestDBFileTests
  
  """
    def setUp(self):
        """ set up

    :param self: self reference
    """
        self.log = gLogger.getSubLogger(self.__class__.__name__)
        self.requestDB = RequestDBFile()
        setRequest = self.requestDB.setRequest("testRequest", reqStr)

    def tearDown(self):
        #deleteRequest = self.requestDB.deleteRequest( "testRequest" )
        pass

    def test_01_getRequestStatus(self):

        self.assertEqual(
            self.requestDB.getRequestStatus("testRequest"), {
                'OK': True,
                'Value': {
                    'SubRequestStatus': 'Waiting',
                    'RequestStatus': 'Waiting'
                }
            })

        ## get request
        getRemoval = self.requestDB.getRequest("removal")
        oRequest = RequestContainer(getRemoval["Value"]["RequestString"])

        self.assertEqual(
            self.requestDB.getRequestStatus("testRequest"), {
                'OK': True,
                'Value': {
                    'SubRequestStatus': 'Assigned',
                    'RequestStatus': 'Waiting'
                }
            })

        ## make removal Done
        oRequest.subRequests["removal"][0]["Attributes"]["Status"] = "Done"
        oRequest.subRequests["removal"][0]["Files"][0]["Status"] = "Done"

        update = self.requestDB.updateRequest(
            getRemoval["Value"]["RequestName"],
            oRequest.toXML()["Value"])

        ## get status
        self.assertEqual(
            self.requestDB.getRequestStatus("testRequest"), {
                'OK': True,
                'Value': {
                    'SubRequestStatus': 'Waiting',
                    'RequestStatus': u'Waiting'
                }
            })

        ## make transfer Done
        oRequest.subRequests["transfer"][0]["Attributes"]["Status"] = "Done"
        oRequest.subRequests["transfer"][0]["Files"][0]["Status"] = "Done"
        update = self.requestDB.updateRequest(
            getRemoval["Value"]["RequestName"],
            oRequest.toXML()["Value"])
        ## get status
        self.assertEqual(
            self.requestDB.getRequestStatus("testRequest"), {
                'OK': True,
                'Value': {
                    'SubRequestStatus': 'Done',
                    'RequestStatus': 'Done'
                }
            })

    def test_02_getRequest(self):
        """ getRequest and JobID """
        getRequest = self.requestDB.getRequest("transfer")
        self.assertEqual(getRequest["OK"], True)
        self.assertEqual(getRequest["Value"]["JobID"], 0)