Esempio n. 1
0
    def setUp(self):
        # Create a mock of DB class
        self.mock_DB = Mock()

        # Setting mock return value
        self.mock_DB._query.return_value = {'OK': True, 'Value': ''}
        self.mock_DB._update.return_value = {'OK': True, 'Value': ''}

        sys.modules["DIRAC"] = DIRAC.ResourceStatusSystem.test.fake_Logger
        sys.modules[
            "DIRAC.ResourceStatusSystem.Utilities.CS"] = DIRAC.ResourceStatusSystem.test.fake_Logger
        sys.modules[
            "DIRAC.Core.Utilities.SiteCEMapping"] = DIRAC.ResourceStatusSystem.test.fake_Logger
        sys.modules[
            "DIRAC.Core.Utilities.SiteSEMapping"] = DIRAC.ResourceStatusSystem.test.fake_Logger
        sys.modules[
            "DIRAC.Core.Utilities.SitesDIRACGOCDBmapping"] = DIRAC.ResourceStatusSystem.test.fake_Logger

        from LHCbDIRAC.ResourceStatusSystem.Policy import Configurations
        from DIRAC.ResourceStatusSystem.DB.ResourceManagementDB import ResourceManagementDB

        # setting mock interface
        self.rmDB = ResourceManagementDB(DBin=self.mock_DB)

        self.mock_DB_1 = Mock()
        self.mock_DB_1._query.return_value = {
            'OK': True,
            'Value': (('VOMS', ), )
        }

        self.rmDB_1 = ResourceManagementDB(DBin=self.mock_DB_1)
Esempio n. 2
0
    def setUp(self):

        sys.modules["DIRAC"] = DIRAC.ResourceStatusSystem.test.fake_Logger
        sys.modules[
            "DIRAC.ResourceStatusSystem.Utilities.CS"] = DIRAC.ResourceStatusSystem.test.fake_Logger
        sys.modules[
            "DIRAC.Core.Utilities.SiteCEMapping"] = DIRAC.ResourceStatusSystem.test.fake_Logger
        sys.modules[
            "DIRAC.Core.Utilities.SiteSEMapping"] = DIRAC.ResourceStatusSystem.test.fake_Logger
        sys.modules[
            "DIRAC.Core.Utilities.SitesDIRACGOCDBmapping"] = DIRAC.ResourceStatusSystem.test.fake_Logger
        sys.modules[
            "DIRAC.ResourceStatusSystem.DB.ResourceStatusDB"] = DIRAC.ResourceStatusSystem.test.fake_rsDB
        sys.modules[
            "DIRAC.FrameworkSystem.Client.NotificationClient"] = DIRAC.ResourceStatusSystem.test.fake_NotificationClient

        from DIRAC import gConfig

        from DIRAC.ResourceStatusSystem.Utilities.Publisher import Publisher
        from DIRAC.ResourceStatusSystem.Utilities.Synchronizer import Synchronizer

        #    from DIRAC.ResourceStatusSystem.test.fake_rsDB import ResourceStatusDB
        #    self.rsDB = ResourceStatusDB()

        self.VO = gConfig.getValue("DIRAC/Extensions")

        self.mockCC = Mock()
        self.mockIG = Mock()
        self.mockWMSA = Mock()

        self.mockCC.commandInvocation.return_value = 'INFO_GOT_MOCK'
        self.mockWMSA.getSiteMaskLogging.return_value = {
            'OK': True,
            'Value': {
                'LCG.CERN.ch':
                [('Active', '2009-11-25 17:36:14', 'atsareg', 'test')]
            }
        }

        self.p = Publisher(self.VO,
                           rsDBIn=None,
                           commandCallerIn=self.mockCC,
                           infoGetterIn=self.mockIG,
                           WMSAdminIn=self.mockWMSA)

        self.configModule = __import__(
            self.VO + "DIRAC.ResourceStatusSystem.Policy.Configurations",
            globals(), locals(), ['*'])

        self.syncC = Synchronizer()
    def setUp(self):
        import sys
        sys.modules[
            "DIRAC.Core.DISET.RequestHandler"] = DIRAC.ResourceStatusSystem.test.fake_RequestHandler
        sys.modules[
            "DIRAC.ResourceStatusSystem.DB.ResourceStatusDB"] = DIRAC.ResourceStatusSystem.test.fake_rsDB
        sys.modules["DIRAC"] = DIRAC.ResourceStatusSystem.test.fake_Logger
        from DIRAC.ResourceStatusSystem.Service.ResourceStatusHandler import ResourceStatusHandler, initializeResourceStatusHandler

        a = Mock()
        initializeResourceStatusHandler(a)
        self.rsh = ResourceStatusHandler('', '', '')

        self.mock_command = Mock()
Esempio n. 4
0
  def test_policyInvocation(self):
    cc = Mock()

    policies_modules = {'Site':['DT_Policy', 'GGUSTickets_Policy'],
                        'Service': ['PilotsEfficiency_Simple_Policy', 'JobsEfficiency_Simple_Policy'],
                        'Resource':['SAMResults_Policy', 'DT_Policy'],
                        'StorageElement':['SEOccupancy_Policy', 'TransferQuality_Policy']
                        }

    for g in ValidRes:
      for status in ValidStatus:
        self.mock_p.evaluate.return_value = {'Status':status,
                                             'Reason':'testReason',
                                             'PolicyName': 'test_P'}
        pc = PolicyCaller(commandCallerIn = cc)

        for pol_mod in policies_modules[g]:
          res = pc.policyInvocation(self.VO, g, 'XX', status, self.mock_p,
                                    (g, 'XX'), None, pol_mod)
          self.assertEqual(res['Status'], status)

          res = pc.policyInvocation(self.VO, g, 'XX', status, self.mock_p,
                                    None, None, pol_mod)
          self.assertEqual(res['Status'], status)

          for extraArgs in ((g, 'XX'), [(g, 'XX'), (g, 'XX')]):
            res = pc.policyInvocation(self.VO, g, 'XX', status, self.mock_p,
                                      None, None, pol_mod, extraArgs)
            self.assertEqual(res['Status'], status)
Esempio n. 5
0
  def setUp( self ):

    self.mockRSS = Mock()

    self.RSCli = ResourceStatusClient( serviceIn = self.mockRSS )
    self.RMCli = ResourceManagementClient( serviceIn = self.mockRSS )
    self.PilotsCli = PilotsClient()
    self.JobsCli = JobsClient()
Esempio n. 6
0
    def setUp(self):
        sys.modules["DIRAC"] = DIRAC.ResourceStatusSystem.test.fake_Logger
        sys.modules[
            "DIRAC.ResourceStatusSystem.Utilities.CS"] = DIRAC.ResourceStatusSystem.test.fake_Logger
        sys.modules[
            "DIRAC.Core.Utilities.SiteCEMapping"] = DIRAC.ResourceStatusSystem.test.fake_Logger
        sys.modules[
            "DIRAC.Core.Utilities.SiteSEMapping"] = DIRAC.ResourceStatusSystem.test.fake_Logger
        sys.modules[
            "DIRAC.Core.Utilities.SitesDIRACGOCDBmapping"] = DIRAC.ResourceStatusSystem.test.fake_Logger
        sys.modules[
            "DIRAC.Interfaces.API.DiracAdmin"] = DIRAC.ResourceStatusSystem.test.fake_Admin
        sys.modules[
            "DIRAC.FrameworkSystem.Client.NotificationClient"] = DIRAC.ResourceStatusSystem.test.fake_NotificationClient

        from DIRAC.ResourceStatusSystem.Utilities.InfoGetter import InfoGetter
        from DIRAC.ResourceStatusSystem.PolicySystem.PolicyBase import PolicyBase
        from DIRAC.ResourceStatusSystem.PolicySystem.PolicyInvoker import PolicyInvoker

        from DIRAC import gConfig
        self.VO = gConfig.getValue("DIRAC/Extensions")
        if 'LHCb' in self.VO:
            self.VO = 'LHCb'

        self.mock_command = Mock()
        self.mock_policy = Mock()
        self.mock_p = Mock()
        self.mock_args = Mock()
        self.pb = PolicyBase()
        self.pi = PolicyInvoker()
        self.mock_pdp = Mock()
        self.mock_rsDB = Mock()
        self.mock_rmDB = Mock()
        self.mock_nc = Mock()
        self.mock_da = Mock()
        self.mock_da.getBannedSites.return_value = {
            'OK': True,
            'Value': ['LCG.APC.fr', 'LCG.Bari.it', 'LCG.Catania.it']
        }
        self.mock_da.addSiteInMask.return_value = {'OK': True, 'Value': ''}
        self.mock_da.banSiteFromMask.return_value = {'OK': True, 'Value': ''}
        self.mock_da.sendMail.return_value = {'OK': True, 'Value': ''}
        self.mock_csAPI = Mock()
        self.mock_csAPI.setOption.return_value = {'OK': True, 'Value': ''}
        self.mock_csAPI.commit.return_value = {'OK': True, 'Value': ''}
        self.ig = InfoGetter(self.VO)
Esempio n. 7
0
    def setUp(self):

        from DIRAC.Core.Base.Script import parseCommandLine
        parseCommandLine()

        self.mockRSS = Mock()

        self.GOCCli = GOCDBClient()
        self.SLSCli = SLSClient()
        self.SAMCli = SAMResultsClient()
        self.GGUSCli = GGUSTicketsClient()
    def setUp(self):
        #    from DIRAC.Core.Base import Script
        #    Script.parseCommandLine()
        import sys
        sys.modules[
            "DIRAC.Core.DISET.RequestHandler"] = DIRAC.ResourceStatusSystem.test.fake_RequestHandler
        sys.modules[
            "DIRAC.ResourceStatusSystem.DB.ResourceStatusDB"] = DIRAC.ResourceStatusSystem.test.fake_rsDB
        sys.modules[
            "DIRAC.ResourceStatusSystem.DB.ResourceManagementDB"] = DIRAC.ResourceStatusSystem.test.fake_rmDB
        sys.modules["DIRAC"] = DIRAC.ResourceStatusSystem.test.fake_Logger
        sys.modules[
            "DIRAC.ResourceStatusSystem.Utilities.CS"] = DIRAC.ResourceStatusSystem.test.fake_Logger
        from DIRAC.ResourceStatusSystem.Service.ResourceManagementHandler import ResourceManagementHandler, initializeResourceManagementHandler

        a = Mock()
        initializeResourceManagementHandler(a)
        self.rmh = ResourceManagementHandler('', '', '')

        self.mock_command = Mock()
Esempio n. 9
0
 def test_getJobsSimpleEff( self ):
   WMS_Mock = Mock()
   WMS_Mock.getSiteSummaryWeb.return_value = {'OK': True,
                                              'rpcStub': ( ( 'WorkloadManagement/WMSAdministrator',
                                                           {'skipCACheck': True,
                                                            'delegatedGroup': 'diracAdmin',
                                                            'delegatedDN': '/DC=ch/DC=cern/OU=Organic Units/OU=Users/CN=fstagni/CN=693025/CN=Federico Stagni', 'timeout': 600} ),
                                                            'getSiteSummaryWeb', ( {'Site': 'LCG.CERN.ch'}, [], 0, 500 ) ),
                                                            'Value': {'TotalRecords': 1,
                                                                      'ParameterNames': ['Site', 'GridType', 'Country', 'Tier', 'MaskStatus', 'Received', 'Checking', 'Staging', 'Waiting', 'Matched', 'Running', 'Stalled', 'Done', 'Completed', 'Failed', 'Efficiency', 'Status'],
                                                                      'Extras': {'ru': {'Received': 0, 'Staging': 0, 'Checking': 0, 'Completed': 0, 'Waiting': 0, 'Failed': 0, 'Running': 0, 'Done': 0, 'Stalled': 0, 'Matched': 0}, 'fr': {'Received': 0, 'Staging': 0, 'Checking': 0, 'Completed': 0, 'Waiting': 12L, 'Failed': 0, 'Running': 0, 'Done': 0, 'Stalled': 0, 'Matched': 0}, 'ch': {'Received': 0, 'Staging': 0, 'Checking': 0, 'Completed': 0, 'Waiting': 4L, 'Failed': 0, 'Running': 0, 'Done': 0, 'Stalled': 0, 'Matched': 1L}, 'nl': {'Received': 0, 'Staging': 0, 'Checking': 0, 'Completed': 0, 'Waiting': 0, 'Failed': 0, 'Running': 0, 'Done': 0, 'Stalled': 0, 'Matched': 0}, 'uk': {'Received': 0, 'Staging': 0, 'Checking': 0, 'Completed': 0, 'Waiting': 0, 'Failed': 0, 'Running': 0, 'Done': 0, 'Stalled': 0, 'Matched': 0}, 'Unknown': {'Received': 0, 'Staging': 0, 'Checking': 0, 'Completed': 0, 'Waiting': 0, 'Failed': 0, 'Running': 0, 'Done': 0, 'Stalled': 0, 'Matched': 0}, 'de': {'Received': 0, 'Staging': 0, 'Checking': 0, 'Completed': 0, 'Waiting': 1L, 'Failed': 0, 'Running': 0, 'Done': 0, 'Stalled': 0, 'Matched': 0}, 'it': {'Received': 0, 'Staging': 0, 'Checking': 1L, 'Completed': 0, 'Waiting': 2L, 'Failed': 0, 'Running': 0, 'Done': 0, 'Stalled': 0, 'Matched': 0}, 'hu': {'Received': 0, 'Staging': 0, 'Checking': 0, 'Completed': 0, 'Waiting': 0, 'Failed': 0, 'Running': 0, 'Done': 0, 'Stalled': 0, 'Matched': 0}, 'cy': {'Received': 0, 'Staging': 0, 'Checking': 0, 'Completed': 0, 'Waiting': 0, 'Failed': 0, 'Running': 0, 'Done': 0, 'Stalled': 0, 'Matched': 0}, 'bg': {'Received': 0, 'Staging': 0, 'Checking': 0, 'Completed': 0, 'Waiting': 0, 'Failed': 0, 'Running': 0, 'Done': 0, 'Stalled': 0, 'Matched': 0}, 'au': {'Received': 0, 'Staging': 0, 'Checking': 0, 'Completed': 0, 'Waiting': 10L, 'Failed': 0, 'Running': 0, 'Done': 0, 'Stalled': 0, 'Matched': 0}, 'il': {'Received': 0, 'Staging': 0, 'Checking': 0, 'Completed': 0, 'Waiting': 0, 'Failed': 0, 'Running': 0, 'Done': 0, 'Stalled': 0, 'Matched': 0}, 'br': {'Received': 0, 'Staging': 0, 'Checking': 0, 'Completed': 0, 'Waiting': 0, 'Failed': 0, 'Running': 0, 'Done': 0, 'Stalled': 0, 'Matched': 0}, 'ie': {'Received': 0, 'Staging': 0, 'Checking': 0, 'Completed': 0, 'Waiting': 0, 'Failed': 0, 'Running': 0, 'Done': 0, 'Stalled': 0, 'Matched': 0}, 'pl': {'Received': 0, 'Staging': 0, 'Checking': 0, 'Completed': 0, 'Waiting': 0, 'Failed': 0, 'Running': 0, 'Done': 0, 'Stalled': 0, 'Matched': 0}, 'es': {'Received': 0, 'Staging': 0, 'Checking': 0, 'Completed': 0, 'Waiting': 0, 'Failed': 0, 'Running': 0, 'Done': 2L, 'Stalled': 0, 'Matched': 0}},
                                                                      'Records': [['LCG.CERN.ch', 'LCG', 'ch', 'Tier-1', 'Active', 0, 0, 0, 4L, 1L, 0, 0, 0, 0, 0, '0.0', 'Idle']]}}
   res = self.JobsCli.getJobsSimpleEff( 'XX', RPCWMSAdmin = WMS_Mock )
   self.assertEqual( res, {'LCG.CERN.ch': 'Idle'} )
Esempio n. 10
0
  def test_getPilotsSimpleEff( self ):
    #self.mockRSS.getPilotsSimpleEff.return_value = {'OK':True, 'Value':{'Records': [['', '', 0, 3L, 0, 0, 0, 283L, 66L, 0, 0, 352L, '1.00', '81.25', 'Fair', 'Yes']]}}

    WMS_Mock = Mock()
    WMS_Mock.getPilotSummaryWeb.return_value = {'OK': True,
                                                'rpcStub': ( ( 'WorkloadManagement/WMSAdministrator',
                                                             {'skipCACheck': True,
                                                              'delegatedGroup': 'diracAdmin',
                                                              'delegatedDN': '/DC=ch/DC=cern/OU=Organic Units/OU=Users/CN=fstagni/CN=693025/CN=Federico Stagni', 'timeout': 600} ),
                                                              'getPilotSummaryWeb', ( {'GridSite': 'LCG.Ferrara.it'}, [], 0, 500 ) ),
                                                              'Value': {
                                                                        'TotalRecords': 0,
                                                                        'ParameterNames': ['Site', 'CE', 'Submitted', 'Ready', 'Scheduled', 'Waiting', 'Running', 'Done', 'Aborted', 'Done_Empty', 'Aborted_Hour', 'Total', 'PilotsPerJob', 'PilotJobEff', 'Status', 'InMask'],
                                                                        'Extras': {'Scheduled': 0, 'Status': 'Poor', 'Aborted_Hour': 20L, 'Waiting': 59L, 'Submitted': 6L, 'PilotsPerJob': '1.03', 'Ready': 0, 'Running': 0, 'PilotJobEff': '39.34', 'Done': 328L, 'Aborted': 606L, 'Done_Empty': 9L, 'Total': 999L},
                                                                        'Records': []}}
Esempio n. 11
0
 def __init__(self, *args, **kwargs):
     self.db = Mock()
     self.db._update.return_value = {'OK': True, 'Value': []}
     self.db._query.return_value = {'OK': True, 'Value': ()}
     pass