当前位置: 首页>>代码示例>>Python>>正文


Python Proxy.getTimeLeft方法代码示例

本文整理汇总了Python中WMCore.Credential.Proxy.Proxy.getTimeLeft方法的典型用法代码示例。如果您正苦于以下问题:Python Proxy.getTimeLeft方法的具体用法?Python Proxy.getTimeLeft怎么用?Python Proxy.getTimeLeft使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在WMCore.Credential.Proxy.Proxy的用法示例。


在下文中一共展示了Proxy.getTimeLeft方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: Proxy

# 需要导入模块: from WMCore.Credential.Proxy import Proxy [as 别名]
# 或者: from WMCore.Credential.Proxy.Proxy import getTimeLeft [as 别名]
class Proxy(Configurable):

    """
    Wrapper around CMS credentials.

    Parameters
    ----------
        renew : bool
            Whether to renew proxy.  Defaults to `True`.
    """

    _mutable = {}

    def __init__(self, renew=True):
        self.renew = renew
        self.__proxy = WMProxy({'logger': logging.getLogger("WMCore"), 'proxyValidity': '192:00'})
        self.__setup()

    def __setup(self):
        if self.check() and self.__proxy.getTimeLeft() > 4 * 3600:
            if 'X509_USER_PROXY' not in os.environ:
                os.environ['X509_USER_PROXY'] = self.__proxy.getProxyFilename()
        elif self.renew:
            self.__proxy.renew()
            if self.__proxy.getTimeLeft() < 4 * 3600:
                raise AttributeError("could not renew proxy")
            os.environ['X509_USER_PROXY'] = self.__proxy.getProxyFilename()
        else:
            raise AttributeError("please renew or disable your proxy")

    def __getstate__(self):
        state = dict(self.__dict__)
        del state['_Proxy__proxy']
        return state

    def __setstate__(self, state):
        self.__dict__.update(state)
        with PartiallyMutable.unlock():
            self.__proxy = WMProxy({'logger': logging.getLogger("WMCore"), 'proxyValidity': '192:00'})
            self.__setup()

    def check(self):
        left = self.__proxy.getTimeLeft()
        if left == 0:
            return False
        elif left < 4 * 3600:
            logger.warn("only {0}:{1:02} left in proxy lifetime!".format(left / 3600, left / 60))
        return True

    def expires(self):
        return int(time.time()) + self.__proxy.getTimeLeft()

    def time_left(self):
        return self.__proxy.getTimeLeft()
开发者ID:khurtado,项目名称:lobster,代码行数:56,代码来源:proxy.py

示例2: getProxy

# 需要导入模块: from WMCore.Credential.Proxy import Proxy [as 别名]
# 或者: from WMCore.Credential.Proxy.Proxy import getTimeLeft [as 别名]
def getProxy(userdn, group, role, defaultDelegation, logger):
    """
    _getProxy_
    """
    log.debug("Retrieving proxy for %s" % userdn)
    proxy = Proxy(defaultDelegation)
    proxyPath = proxy.getProxyFilename( True )
    timeleft = proxy.getTimeLeft( proxyPath )
    if timeleft is not None and timeleft > 3600:
        return (True, proxyPath)
    proxyPath = proxy.logonRenewMyProxy()
    timeleft = proxy.getTimeLeft( proxyPath )
    if timeleft is not None and timeleft > 0:
        return (True, proxyPath)
    return (False, None)
开发者ID:TonyWildish,项目名称:ASO-monitor,代码行数:17,代码来源:__init__.py

示例3: get_proxy

# 需要导入模块: from WMCore.Credential.Proxy import Proxy [as 别名]
# 或者: from WMCore.Credential.Proxy.Proxy import getTimeLeft [as 别名]
 def get_proxy(self, ad):
     result = None
     vo = 'cms'
     group = ''
     role = ''
     if 'CRAB_UserVO' in ad and ad['CRAB_UserVO']:
         vo = ad['CRAB_UserVO']
     if 'CRAB_UserGroup' in ad and ad['CRAB_UserGroup'] and ad['CRAB_UserGroup'] != classad.Value.Undefined:
         group = ad['CRAB_UserGroup']
     if 'CRAB_UserRole' in ad and ad['CRAB_UserRole'] and ad['CRAB_UserRole'] != classad.Value.Undefined:
         role = ad['CRAB_UserRole']
     proxycfg = {'vo': vo,
                 'logger': self.logger,
                 'myProxySvr': self.config.Services.MyProxy,
                 'myproxyAccount': self.config.TaskWorker.resturl,
                 'proxyValidity' : '144:0',
                 'min_time_left' : MINPROXYLENGTH, ## do we need this ? or should we use self.myproxylen? 
                 'userDN' : ad['CRAB_UserDN'],
                 'group' : group,
                 'role' : role,
                 'server_key': self.config.MyProxy.serverhostkey,
                 'server_cert': self.config.MyProxy.serverhostcert,
                 'serverDN': self.config.MyProxy.serverdn,
                 'uisource': getattr(self.config.MyProxy, 'uisource', ''),
                 'credServerPath': self.config.MyProxy.credpath,
                 'cleanEnvironment' : getattr(self.config.MyProxy, 'cleanEnvironment', False)}
     proxy = Proxy(proxycfg)
     userproxy = proxy.getProxyFilename(serverRenewer=True)
     proxy.logonRenewMyProxy()
     timeleft = proxy.getTimeLeft(userproxy)
     if timeleft is None or timeleft <= 0:
         self.logger.error("Impossible to retrieve proxy from %s for %s." %(proxycfg['myProxySvr'], proxycfg['userDN']))
         raise Exception("Failed to retrieve proxy.")
     return userproxy
开发者ID:belforte,项目名称:CRABServer,代码行数:36,代码来源:RenewRemoteProxies.py

示例4: execute

# 需要导入模块: from WMCore.Credential.Proxy import Proxy [as 别名]
# 或者: from WMCore.Credential.Proxy.Proxy import getTimeLeft [as 别名]
 def execute(self, *args, **kwargs):
     result = None
     proxycfg = {'vo': kwargs['task']['tm_user_vo'],
                 'logger': self.logger,
                 'myProxySvr': self.config.Services.MyProxy,
                 'proxyValidity' : '144:0',
                 'min_time_left' : 36000, ## do we need this ? or should we use self.myproxylen? 
                 'userDN' : kwargs['task']['tm_user_dn'],
                 'group' : kwargs['task']['tm_user_group'] if kwargs['task']['tm_user_group'] else '',
                 'role' : kwargs['task']['tm_user_role'] if kwargs['task']['tm_user_role'] else '',
                 'server_key': self.config.MyProxy.serverhostkey,
                 'server_cert': self.config.MyProxy.serverhostcert,
                 'serverDN': self.config.MyProxy.serverdn,
                 'uisource': getattr(self.config.MyProxy, 'uisource', ''),
                 'credServerPath': self.config.MyProxy.credpath,
                 'myproxyAccount' : self.server['host'],
                 'cleanEnvironment' : getattr(self.config.MyProxy, 'cleanEnvironment', False)
                }
     proxy = Proxy(proxycfg)
     userproxy = proxy.getProxyFilename(serverRenewer=True)
     proxy.logonRenewMyProxy()
     timeleft = proxy.getTimeLeft(userproxy)
     if timeleft is None or timeleft <= 0:
         msg = "Impossible to retrieve proxy from %s for %s." % (proxycfg['myProxySvr'], proxycfg['userDN'])
         raise TaskWorkerException(msg)
     else:
         kwargs['task']['user_proxy'] = userproxy
         result = Result(task=kwargs['task'], result='OK')
     return result
开发者ID:HassenRiahi,项目名称:CRABServer,代码行数:31,代码来源:MyProxyLogon.py

示例5: execute

# 需要导入模块: from WMCore.Credential.Proxy import Proxy [as 别名]
# 或者: from WMCore.Credential.Proxy.Proxy import getTimeLeft [as 别名]
 def execute(self, *args, **kwargs):
     result = None
     proxycfg = {'vo': kwargs['task']['tm_user_vo'],
                 'logger': self.logger,
                 'myProxySvr': self.config.Services.MyProxy,
                 'proxyValidity' : '144:0',
                 'min_time_left' : 36000, ## do we need this ? or should we use self.myproxylen? 
                 'userDN' : kwargs['task']['tm_user_dn'],
                 'group' : kwargs['task']['tm_user_group'] if kwargs['task']['tm_user_group'] else '',
                 'role' : kwargs['task']['tm_user_role'] if kwargs['task']['tm_user_role'] else '',
                 'server_key': self.config.MyProxy.serverhostkey,
                 'server_cert': self.config.MyProxy.serverhostcert,
                 'serverDN': self.config.MyProxy.serverdn,
                 'uisource': getattr(self.config.MyProxy, 'uisource', ''),
                 'credServerPath': self.config.MyProxy.credpath,
                 'myproxyAccount' : self.server['host'],
                 'cleanEnvironment' : getattr(self.config.MyProxy, 'cleanEnvironment', False)
                }
     # WMCore proxy methods are awfully verbode, reduce logging level when using them
     with tempSetLogLevel(logger=self.logger, level=logging.ERROR):
         proxy = Proxy(proxycfg)
         userproxy = proxy.getProxyFilename(serverRenewer=True)
         proxy.logonRenewMyProxy()
         timeleft = proxy.getTimeLeft(userproxy)
         usergroups = set(proxy.getAllUserGroups(userproxy))
     if timeleft is None or timeleft <= 0:
         msg = "Impossible to retrieve proxy from %s for %s." % (proxycfg['myProxySvr'], proxycfg['userDN'])
         self.logger.error(msg)
         self.logger.error("\n Will try again in verbose mode")
         self.logger.error("===========PROXY ERROR START ==========================")
         with tempSetLogLevel(logger=self.logger, level=logging.DEBUG):
             userproxy = proxy.getProxyFilename(serverRenewer=True)
             proxy.logonRenewMyProxy()
             timeleft = proxy.getTimeLeft(userproxy)
             usergroups = set(proxy.getAllUserGroups(userproxy))
         self.logger.error("===========PROXY ERROR END   ==========================")
         raise TaskWorkerException(msg)
     else:
         kwargs['task']['user_proxy'] = userproxy
         kwargs['task']['user_groups'] = usergroups
         self.logger.debug("Valid proxy for %s now in %s", proxycfg['userDN'], userproxy)
         result = Result(task=kwargs['task'], result='OK')
     return result
开发者ID:belforte,项目名称:CRABServer,代码行数:45,代码来源:MyProxyLogon.py

示例6: getProxy

# 需要导入模块: from WMCore.Credential.Proxy import Proxy [as 别名]
# 或者: from WMCore.Credential.Proxy.Proxy import getTimeLeft [as 别名]
def getProxy(config, userdn, group, role):
    """
    _getProxy_
    """
    defaultDelegation = getDefaultDelegation(config, "cms", "myproxy.cern.ch", threading.currentThread().logger)
    defaultDelegation['userDN'] = userdn
    defaultDelegation['group'] = group
    defaultDelegation['role'] = role

    logging.debug("Retrieving proxy for %s" % userdn)
    proxy = Proxy(defaultDelegation)
    proxyPath = proxy.getProxyFilename( True )
    timeleft = proxy.getTimeLeft( proxyPath )
    if timeleft is not None and timeleft > 3600:
        return (True, proxyPath)
    proxyPath = proxy.logonRenewMyProxy()
    timeleft = proxy.getTimeLeft( proxyPath )
    if timeleft is not None and timeleft > 0:
        return (True, proxyPath)
    return (False, None)
开发者ID:stuartw,项目名称:WMCore,代码行数:22,代码来源:TaskArchiverPoller.py

示例7: createNewVomsProxy

# 需要导入模块: from WMCore.Credential.Proxy import Proxy [as 别名]
# 或者: from WMCore.Credential.Proxy.Proxy import getTimeLeft [as 别名]
    def createNewVomsProxy(self, timeleftthreshold=0):
        """
        Handles the proxy creation:
           - checks if a valid proxy still exists
           - performs the creation if it is expired
        """
        ## TODO add the change to have user-cert/key defined in the config.
        userproxy = Proxy( self.defaultDelegation )
        userproxy.userDN = userproxy.getSubject()

        proxytimeleft = 0
        self.logger.debug("Getting proxy life time left")
        # does it return an integer that indicates?
        proxytimeleft = userproxy.getTimeLeft()
        self.logger.debug("Proxy is valid: %i" % proxytimeleft)

        #if it is not expired I check if role and/or group are changed
        if not proxytimeleft < timeleftthreshold and self.defaultDelegation['role']!=None and  self.defaultDelegation['group']!=None:
            group , role = userproxy.getUserGroupAndRoleFromProxy( userproxy.getProxyFilename())
            if group != self.defaultDelegation['group'] or role != self.defaultDelegation['role']:
                self.proxyChanged = True

        #if the proxy is expired, or we changed role and/or group, we need to create a new one
        if proxytimeleft < timeleftthreshold or self.proxyChanged:
            # creating the proxy
            self.logger.debug("Creating a proxy for %s hours" % self.defaultDelegation['proxyValidity'] )
            userproxy.create()
            proxytimeleft = userproxy.getTimeLeft()
            group , role = userproxy.getUserGroupAndRoleFromProxy( userproxy.getProxyFilename())

            if proxytimeleft > 0 and group == self.defaultDelegation['group'] and role == self.defaultDelegation['role']:
                self.logger.debug("Proxy created.")
            else:
                raise ProxyCreationException("Problems creating proxy.")

        return userproxy.getSubject( ), userproxy.getProxyFilename()
开发者ID:bbockelm,项目名称:CRABClient,代码行数:38,代码来源:CredentialInteractions.py

示例8: get_proxy

# 需要导入模块: from WMCore.Credential.Proxy import Proxy [as 别名]
# 或者: from WMCore.Credential.Proxy.Proxy import getTimeLeft [as 别名]
 def get_proxy(self, ad):
     result = None
     vo = "cms"
     group = ""
     role = ""
     if "CRAB_UserVO" in ad and ad["CRAB_UserVO"]:
         vo = ad["CRAB_UserVO"]
     if "CRAB_UserGroup" in ad and ad["CRAB_UserGroup"] and ad["CRAB_UserGroup"] != classad.Value.Undefined:
         group = ad["CRAB_UserGroup"]
     if "CRAB_UserRole" in ad and ad["CRAB_UserRole"] and ad["CRAB_UserRole"] != classad.Value.Undefined:
         role = ad["CRAB_UserRole"]
     print vo, group, role
     proxycfg = {
         "vo": vo,
         "logger": self.logger,
         "myProxySvr": self.config.Services.MyProxy,
         "myproxyAccount": self.config.TaskWorker.resturl,
         "proxyValidity": "144:0",
         "min_time_left": MINPROXYLENGTH,  ## do we need this ? or should we use self.myproxylen?
         "userDN": ad["CRAB_UserDN"],
         "group": group,
         "role": role,
         "server_key": self.config.MyProxy.serverhostkey,
         "server_cert": self.config.MyProxy.serverhostcert,
         "serverDN": self.config.MyProxy.serverdn,
         "uisource": getattr(self.config.MyProxy, "uisource", ""),
         "credServerPath": self.config.MyProxy.credpath,
         "cleanEnvironment": getattr(self.config.MyProxy, "cleanEnvironment", False),
     }
     proxy = Proxy(proxycfg)
     userproxy = proxy.getProxyFilename(serverRenewer=True)
     proxy.logonRenewMyProxy()
     timeleft = proxy.getTimeLeft(userproxy)
     if timeleft is None or timeleft <= 0:
         self.logger.error(
             "Impossible to retrieve proxy from %s for %s." % (proxycfg["myProxySvr"], proxycfg["userDN"])
         )
         raise Exception("Failed to retrieve proxy.")
     return userproxy
开发者ID:nizamyusli,项目名称:CRABServer,代码行数:41,代码来源:RenewRemoteProxies.py

示例9: execute

# 需要导入模块: from WMCore.Credential.Proxy import Proxy [as 别名]
# 或者: from WMCore.Credential.Proxy.Proxy import getTimeLeft [as 别名]
 def execute(self, *args, **kwargs):
     result = None
     proxycfg = {
         "vo": kwargs["task"]["tm_user_vo"],
         "logger": self.logger,
         "myProxySvr": self.config.Services.MyProxy,
         "proxyValidity": "24:0",
         "min_time_left": 36000,  ## do we need this ? or should we use self.myproxylen?
         "userDN": kwargs["task"]["tm_user_dn"],
         "group": kwargs["task"]["tm_user_group"] if kwargs["task"]["tm_user_group"] else "",
         "role": kwargs["task"]["tm_user_role"] if kwargs["task"]["tm_user_role"] else "",
         "server_key": self.config.MyProxy.serverhostkey,
         "server_cert": self.config.MyProxy.serverhostcert,
         "serverDN": self.config.MyProxy.serverdn,
         "uisource": self.config.MyProxy.uisource,
         "credServerPath": self.config.MyProxy.credpath,
     }
     proxy = Proxy(proxycfg)
     userproxy = proxy.getProxyFilename(serverRenewer=True)
     proxy.logonRenewMyProxy()
     timeleft = proxy.getTimeLeft(userproxy)
     if timeleft is None or timeleft <= 0:
         msg = "Impossible to retrieve proxy from %s for %s." % (proxycfg["myProxySvr"], proxycfg["userDN"])
         self.logger.error("Setting %s as failed" % str(kwargs["task"]["tm_taskname"]))
         configreq = {
             "workflow": kwargs["task"]["tm_taskname"],
             "status": "FAILED",
             "subresource": "failure",
             "failure": b64encode(msg),
         }
         self.logger.error(str(configreq))
         self.server.post(self.resturl, data=urllib.urlencode(configreq))
         raise StopHandler(msg)
     else:
         kwargs["task"]["user_proxy"] = userproxy
         result = Result(task=kwargs["task"], result="OK")
     return result
开发者ID:bbockelm,项目名称:CAFTaskWorker,代码行数:39,代码来源:MyProxyLogon.py

示例10: execute

# 需要导入模块: from WMCore.Credential.Proxy import Proxy [as 别名]
# 或者: from WMCore.Credential.Proxy.Proxy import getTimeLeft [as 别名]
 def execute(self, *args, **kwargs):
     result = None
     proxycfg = {'vo': kwargs['task']['tm_user_vo'],
                 'logger': self.logger,
                 'myProxySvr': self.config.Services.MyProxy,
                 'proxyValidity' : '144:0',
                 'min_time_left' : 36000, ## do we need this ? or should we use self.myproxylen? 
                 'userDN' : kwargs['task']['tm_user_dn'],
                 'group' : kwargs['task']['tm_user_group'] if kwargs['task']['tm_user_group'] else '',
                 'role' : kwargs['task']['tm_user_role'] if kwargs['task']['tm_user_role'] else '',
                 'server_key': self.config.MyProxy.serverhostkey,
                 'server_cert': self.config.MyProxy.serverhostcert,
                 'serverDN': self.config.MyProxy.serverdn,
                 'uisource': getattr(self.config.MyProxy, 'uisource', ''),
                 'credServerPath': self.config.MyProxy.credpath,
                 'myproxyAccount' : self.server['host'],
                 'cleanEnvironment' : getattr(self.config.MyProxy, 'cleanEnvironment', False)
                }
     proxy = Proxy(proxycfg)
     userproxy = proxy.getProxyFilename(serverRenewer=True)
     proxy.logonRenewMyProxy()
     timeleft = proxy.getTimeLeft(userproxy)
     if timeleft is None or timeleft <= 0:
         msg = "Impossible to retrieve proxy from %s for %s." %(proxycfg['myProxySvr'], proxycfg['userDN'])
         self.logger.error("Setting %s as failed" % str(kwargs['task']['tm_taskname']))
         configreq = {'workflow': kwargs['task']['tm_taskname'],
                      'status': "FAILED",
                      'subresource': 'failure',
                      'failure': b64encode(msg)}
         self.logger.error(str(configreq))
         self.server.post(self.resturi, data = urllib.urlencode(configreq))
         raise StopHandler(msg)
     else:
         kwargs['task']['user_proxy'] = userproxy
         result = Result(task=kwargs['task'], result='OK')
     return result
开发者ID:khurtado,项目名称:CRABServer,代码行数:38,代码来源:MyProxyLogon.py

示例11: AgentStatusPoller

# 需要导入模块: from WMCore.Credential.Proxy import Proxy [as 别名]
# 或者: from WMCore.Credential.Proxy.Proxy import getTimeLeft [as 别名]

#.........这里部分代码省略.........
        else:
            agentInfo['drain_mode'] = False

        couchInfo = self.collectCouchDBInfo()
        if couchInfo['status'] != 'ok':
            agentInfo['down_components'].append(couchInfo['name'])
            agentInfo['status'] = couchInfo['status']
            agentInfo['down_component_detail'].append(couchInfo)

        # Couch process warning
        couchProc = numberCouchProcess()
        logging.info("CouchDB is running with %d processes", couchProc)
        couchProcessThreshold = self.config.AnalyticsDataCollector.couchProcessThreshold
        if couchProc >= couchProcessThreshold:
            agentInfo['couch_process_warning'] = couchProc
        else:
            agentInfo['couch_process_warning'] = 0

        # This adds the last time and message when data was updated to agentInfo
        lastDataUpload = DataUploadTime.getInfo()
        if lastDataUpload['data_last_update']:
            agentInfo['data_last_update'] = lastDataUpload['data_last_update']
        if lastDataUpload['data_error']:
            agentInfo['data_error'] = lastDataUpload['data_error']

        # Change status if there is data_error, couch process maxed out or disk full problems.
        if agentInfo['status'] == 'ok' and (agentInfo['drain_mode'] or agentInfo['disk_warning']):
            agentInfo['status'] = "warning"

        if agentInfo['status'] == 'ok' or agentInfo['status'] == 'warning':
            if agentInfo.get('data_error', 'ok') != 'ok' or agentInfo.get('couch_process_warning', 0):
                agentInfo['status'] = "error"

        logging.info("List of agent components down: %s", agentInfo['down_components'])

        return agentInfo

    def uploadAgentInfoToCentralWMStats(self, agentInfo, uploadTime):
        # direct data upload to the remote to prevent data conflict when agent is cleaned up and redeployed
        agentDocs = convertToAgentCouchDoc(agentInfo, self.config.ACDC, uploadTime)
        self.centralWMStatsCouchDB.updateAgentInfo(agentDocs)

    @timeFunction
    def collectWMBSInfo(self):
        """
        Fetches WMBS job information.
        In addition to WMBS, also collects RunJob info from BossAir
        :return: dict with the number of jobs in each status
        """
        logging.info("Getting wmbs job info ...")
        results = {}

        # first retrieve the site thresholds
        results['thresholds'] = self.wmagentDB.getJobSlotInfo()
        logging.debug("Running and pending site thresholds: %s", results['thresholds'])

        # now fetch the amount of jobs in each state and the amount of created
        # jobs grouped by task
        results.update(self.wmagentDB.getAgentMonitoring())

        logging.debug("Total number of jobs in WMBS sorted by status: %s", results['wmbsCountByState'])
        logging.debug("Total number of 'created' jobs in WMBS sorted by type: %s", results['wmbsCreatedTypeCount'])
        logging.debug("Total number of 'executing' jobs in WMBS sorted by type: %s", results['wmbsExecutingTypeCount'])

        logging.debug("Total number of active jobs in BossAir sorted by status: %s", results['activeRunJobByStatus'])
        logging.debug("Total number of complete jobs in BossAir sorted by status: %s",
                      results['completeRunJobByStatus'])

        logging.debug("Available slots thresholds to pull work from GQ to LQ: %s", results['thresholdsGQ2LQ'])
        logging.debug("List of jobs pending for each site, sorted by priority: %s", results['sitePendCountByPrio'])

        return results

    def checkProxyLifetime(self, agInfo):
        """
        Check the proxy lifetime (usually X509_USER_CERT) and raise either
        a warning or an error if the proxy validity is about to expire.
        :param agInfo: dictionary with plenty of agent monitoring information in place.
        :return: same dictionary object plus additional keys/values if needed.
        """
        secsLeft = self.proxy.getTimeLeft(proxy=self.proxyFile)
        logging.debug("Proxy '%s' lifetime is %d secs", self.proxyFile, secsLeft)


        if secsLeft <= 86400 * 3:  # 3 days
            proxyWarning = True
            agInfo['status'] = "error"
        elif secsLeft <= 86400 * 5:  # 5 days
            proxyWarning = True
            if agInfo['status'] == "ok":
                agInfo['status'] = "warning"
        else:
            proxyWarning = False

        if proxyWarning:
            warnMsg = "Agent proxy '%s' must be renewed ASAP. " % self.proxyFile
            warnMsg += "Its time left is: %.2f hours." % (secsLeft / 3600.)
            agInfo['proxy_warning'] = warnMsg

        return
开发者ID:alexanderrichards,项目名称:WMCore,代码行数:104,代码来源:AgentStatusPoller.py

示例12: ProxyTest

# 需要导入模块: from WMCore.Credential.Proxy import Proxy [as 别名]
# 或者: from WMCore.Credential.Proxy.Proxy import getTimeLeft [as 别名]
class ProxyTest(unittest.TestCase):
    def setUp(self):
        """
        Setup for unit tests
        """
        logging.basicConfig(
            level=logging.DEBUG,
            format="%(asctime)s %(name)-12s %(levelname)-8s %(message)s",
            datefmt="%m-%d %H:%M",
            filename="proxy_unittests.log",
            filemode="w",
        )

        logger_name = "ProxyTest"

        self.logger = logging.getLogger(logger_name)
        self.dict = {
            "logger": self.logger,
            "vo": "cms",
            "group": group,
            "role": role,
            "myProxySvr": myProxySvr,
            "proxyValidity": "192:00",
            "min_time_left": 36000,
            "uisource": uiPath,
        }

        self.proxyPath = None
        self.proxy = Proxy(self.dict)

    def tearDown(self):
        """
        _tearDown_

        Tear down the proxy.
        """
        return

    def getUserIdentity(self):
        """
        _getUserIdentity_
        Retrieve the user's subject from the voms-proxy-info call.
        """
        vomsProxyInfoCall = subprocess.Popen(
            ["voms-proxy-info", "-identity"], stdout=subprocess.PIPE, stderr=subprocess.PIPE
        )
        if vomsProxyInfoCall.wait() != 0:
            return None

        (stdout, stderr) = vomsProxyInfoCall.communicate()
        return stdout[0:-1]

    def getUserAttributes(self):
        """
        _getUserAttributes_
        Retrieve the user's attributes from the voms-proxy-info call.
        """
        vomsProxyInfoCall = subprocess.Popen(
            ["voms-proxy-info", "-fqan"], stdout=subprocess.PIPE, stderr=subprocess.PIPE
        )
        if vomsProxyInfoCall.wait() != 0:
            return None

        (stdout, stderr) = vomsProxyInfoCall.communicate()
        return stdout[0:-1]

    @attr("integration")
    def testGetUserCertEnddate(self):
        """
        Test if getTimeLeft method returns correctly the proxy time left.
        """
        daysleft = self.proxy.getUserCertEnddate()
        self.assertEqual(daysleft, 29)  # set this as the number of days left in .globus/usercert.pem

    @attr("integration")
    def testAAACreateProxy(self):
        """
        Test if create method creates correctly the proxy.
        This is sort of bad form to require that this test run first, but the alternative is
        entering a password for every single invocation
        """
        self.proxy.create()
        time.sleep(5)
        proxyPath = self.proxy.getProxyFilename()
        self.assertTrue(os.path.exists(proxyPath))

    @attr("integration")
    def testCheckProxyTimeLeft(self):
        """
        Test if getTimeLeft method returns correctly the proxy time left.
        """
        timeLeft = self.proxy.getTimeLeft()
        self.assertEqual(int(timeLeft) / 3600, 191)

    @attr("integration")
    def testRenewProxy(self):
        """
        Test if the renew method renews correctly the user proxy.
        """
        time.sleep(70)
#.........这里部分代码省略.........
开发者ID:vlimant,项目名称:WMCore,代码行数:103,代码来源:Proxy_t.py

示例13: AgentStatusPoller

# 需要导入模块: from WMCore.Credential.Proxy import Proxy [as 别名]
# 或者: from WMCore.Credential.Proxy.Proxy import getTimeLeft [as 别名]

#.........这里部分代码省略.........
        results = {}

        # first retrieve the site thresholds
        results['thresholds'] = self.wmagentDB.getJobSlotInfo()
        logging.debug("Running and pending site thresholds: %s", results['thresholds'])

        # now fetch the amount of jobs in each state and the amount of created
        # jobs grouped by task
        results.update(self.wmagentDB.getAgentMonitoring())

        logging.debug("Total number of jobs in WMBS sorted by status: %s", results['wmbsCountByState'])
        logging.debug("Total number of 'created' jobs in WMBS sorted by type: %s", results['wmbsCreatedTypeCount'])
        logging.debug("Total number of 'executing' jobs in WMBS sorted by type: %s", results['wmbsExecutingTypeCount'])

        logging.debug("Total number of active jobs in BossAir sorted by status: %s", results['activeRunJobByStatus'])
        logging.debug("Total number of complete jobs in BossAir sorted by status: %s",
                      results['completeRunJobByStatus'])

        logging.debug("Available slots thresholds to pull work from GQ to LQ: %s", results['thresholdsGQ2LQ'])
        logging.debug("List of jobs pending for each site, sorted by priority: %s", results['sitePendCountByPrio'])

        return results

    def checkCredLifetime(self, agInfo, credType):
        """
        Check the credential lifetime. Usually X509_USER_PROXY or X509_USER_CERT
        and raise either a warning or an error if the proxy validity is about to expire.
        :param agInfo: dictionary with plenty of agent monitoring information in place.
        :param credType: credential type, can be: "proxy" or "certificate"
        :return: same dictionary object plus additional keys/values if needed.
        """
        if credType == "proxy":
            credFile = self.proxyFile
            secsLeft = self.proxy.getTimeLeft(proxy=credFile)
        elif credType == "certificate":
            credFile = self.userCertFile
            secsLeft = self.proxy.getUserCertTimeLeft(openSSL=True)
        else:
            logging.error("Unknown credential type. Available options are: [proxy, certificate]")
            return

        logging.debug("%s '%s' lifetime is %d seconds", credType, credFile, secsLeft)

        daysLeft = secsLeft / (60. * 60 * 24)

        if daysLeft <= self.credThresholds[credType]['error']:
            credWarning = True
            agInfo['status'] = "error"
        elif daysLeft <= self.credThresholds[credType]['warning']:
            credWarning = True
            if agInfo['status'] == "ok":
                agInfo['status'] = "warning"
        else:
            credWarning = False

        if credWarning:
            warnMsg = "Agent %s '%s' must be renewed ASAP. " % (credType, credFile)
            warnMsg += "Its time left is: %.2f hours;" % (secsLeft / 3600.)
            agInfo['proxy_warning'] = agInfo.get('proxy_warning', "") + warnMsg
            logging.warning(warnMsg)

        return

    def buildMonITDocs(self, dataStats):
        """
        Convert agent statistics into MonIT-friendly documents to be posted
开发者ID:dmwm,项目名称:WMCore,代码行数:70,代码来源:AgentStatusPoller.py

示例14: ProxyTest

# 需要导入模块: from WMCore.Credential.Proxy import Proxy [as 别名]
# 或者: from WMCore.Credential.Proxy.Proxy import getTimeLeft [as 别名]
class ProxyTest(unittest.TestCase):

    def setUp(self):
        """
        Setup for unit tests
        """
        logging.basicConfig(level=logging.DEBUG,
                    format='%(asctime)s %(name)-12s %(levelname)-8s %(message)s',
                    datefmt='%m-%d %H:%M',
                    filename='proxy_unittests.log',
                    filemode='w')

        logger_name = 'ProxyTest'

        self.logger = logging.getLogger(logger_name)
        self.dict = {'logger': self.logger,
                     'vo': 'cms', 'group': group, 'role': role, 'myProxySvr': myProxySvr,
                     'proxyValidity' : '192:00', 'min_time_left' : 36000}

        self.proxyPath = None
        self.proxy = Proxy( self.dict )

    def tearDown(self):
        """
        _tearDown_

        Tear down the proxy.
        """
        return

    def getUserIdentity(self):
        """
        _getUserIdentity_
        Retrieve the user's subject from the voms-proxy-info call.
        """
        vomsProxyInfoCall = subprocess.Popen(["voms-proxy-info", "-identity"],
                                             stdout = subprocess.PIPE,
                                             stderr = subprocess.PIPE)
        if vomsProxyInfoCall.wait() != 0:
            return None

        (stdout, stderr) = vomsProxyInfoCall.communicate()
        return stdout[0:-1]

    def getUserAttributes(self):
        """
        _getUserAttributes_
        Retrieve the user's attributes from the voms-proxy-info call.
        """
        vomsProxyInfoCall = subprocess.Popen(["voms-proxy-info", "-fqan"],
                                             stdout = subprocess.PIPE,
                                             stderr = subprocess.PIPE)
        if vomsProxyInfoCall.wait() != 0:
            return None

        (stdout, stderr) = vomsProxyInfoCall.communicate()
        return stdout[0:-1]

    @attr("integration")
    def testGetUserCertEnddate( self ):
        """
        Test if getTimeLeft method returns correctly the proxy time left.
        """
        daysleft = self.proxy.getUserCertEnddate()
        self.assertEqual(daysleft, 58) #set this as the number of days left in .globus/usercert.pem
        daysleft = self.proxy.getUserCertEnddate(openSSL=False)
        self.assertEqual(daysleft, 58) #set this as the number of days left in .globus/usercert.pem

    @attr("integration")
    def testAAACreateProxy( self ):
        """
        Test if create method creates correctly the proxy.
        This is sort of bad form to require that this test run first, but the alternative is
        entering a password for every single invocation
        """
        self.proxy.create()
        time.sleep( 5 )
        proxyPath = self.proxy.getProxyFilename()
        self.assertTrue(os.path.exists(proxyPath))

    @attr("integration")
    def testCheckProxyTimeLeft( self ):
        """
        Test if getTimeLeft method returns correctly the proxy time left.
        """
        timeLeft = self.proxy.getTimeLeft()
        self.assertEqual(int(timeLeft) / 3600, 191)

    @attr("integration")
    def testRenewProxy( self ):
        """
        Test if the renew method renews correctly the user proxy.
        """
        time.sleep( 70 )
        self.proxy.renew()
        time.sleep( 10 )
        timeLeft = self.proxy.getTimeLeft()
        self.assertEqual(int(timeLeft) / 3600, 191)

    @attr("integration")
#.........这里部分代码省略.........
开发者ID:AndresTanasijczuk,项目名称:WMCore,代码行数:103,代码来源:Proxy_t.py


注:本文中的WMCore.Credential.Proxy.Proxy.getTimeLeft方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。