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


Python Proxy.renew方法代码示例

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


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

示例1: Proxy

# 需要导入模块: from WMCore.Credential.Proxy import Proxy [as 别名]
# 或者: from WMCore.Credential.Proxy.Proxy import renew [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: ProxyTest

# 需要导入模块: from WMCore.Credential.Proxy import Proxy [as 别名]
# 或者: from WMCore.Credential.Proxy.Proxy import renew [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

示例3: ProxyTest

# 需要导入模块: from WMCore.Credential.Proxy import Proxy [as 别名]
# 或者: from WMCore.Credential.Proxy.Proxy import renew [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.renew方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。