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


Python Proxy.getAllUserGroups方法代码示例

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


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

示例1: execute

# 需要导入模块: from WMCore.Credential.Proxy import Proxy [as 别名]
# 或者: from WMCore.Credential.Proxy.Proxy import getAllUserGroups [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)
     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'])
         raise TaskWorkerException(msg)
     else:
         kwargs['task']['user_proxy'] = userproxy
         kwargs['task']['user_groups'] = usergroups
         result = Result(task=kwargs['task'], result='OK')
     return result
开发者ID:dciangot,项目名称:CRABServer,代码行数:33,代码来源:MyProxyLogon.py

示例2: execute

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

示例3: ProxyTest

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

#.........这里部分代码省略.........

    @attr("integration")
    def testCheckAttribute( self ):
        """
        Test if the checkAttribute  method checks correctly the attributes validity.
        """
        valid = self.proxy.checkAttribute( )
        self.assertTrue(valid)

    @attr("integration")
    def testCheckTimeLeft( self ):
        """
        Test if the check method checks correctly the proxy validity.
        """
        valid = self.proxy.check( self.proxyPath )
        self.assertTrue(valid)

    @attr("integration")
    def testVomsRenewal( self ):
        """
        Test if vomsExtensionRenewal method renews correctly the voms-proxy.
        """
        proxyPath = self.proxy.getProxyFilename( )
        time.sleep( 70 )
        attribute = self.proxy.prepareAttForVomsRenewal( self.proxy.getAttributeFromProxy( proxyPath ) )
        self.proxy.vomsExtensionRenewal( proxyPath, attribute )
        vomsTimeLeft = self.proxy.getVomsLife( proxyPath )
        self.assertEqual(int(vomsTimeLeft) / 3600, 191)

    @attr("integration")
    def testElevateAttribute( self ):
        """
        Test if the vomsExtensionRenewal method elevate last attributes given.
        """
        proxyPath = self.proxy.getProxyFilename( )
        attribute = self.proxy.prepareAttForVomsRenewal( '/cms/Role=NULL/Capability=NULL' )
        self.proxy.vomsExtensionRenewal( proxyPath, attribute )
        self.assertEqual(self.proxy.getAttributeFromProxy(proxyPath), '/cms/Role=NULL/Capability=NULL')
        # Restore the original configuration of the proxy
        self.proxy.create()

    @attr("integration")
    def testUserGroupInProxy( self ):
        """
        Test if getUserAttributes method returns correctly the user group.
        """
        self.assertTrue(self.proxy.group, 'No group set. Testing incomplete.')
        self.assertEqual(self.proxy.group, self.getUserAttributes().split('\n')[0].split('/')[2])

    @attr("integration")
    def testUserRoleInProxy( self ):
        """
        Test if getUserAttributes method returns correctly the user role.
        """
        self.assertEqual(self.proxy.role, self.getUserAttributes().split('\n')[0].split('/')[3].split('=')[1])

    @attr("integration")
    def testGetAttributes( self ):
        """
        Test getAttributeFromProxy method.

        Can tested this with:
            voms-proxy-init -voms cms:/cms/integration #or any group of yours
            export PROXY_GROUP=integration
            python test/python/WMCore_t/Credential_t/Proxy_t.py ProxyTest.testGetAttributes
        """
        self.assertTrue(self.proxy.group, 'No group set. Testing incomplete.')
        if not self.dict['role']:
            role = 'NULL'
        else:
            role = self.dict['role']
        proxyPath = self.proxy.getProxyFilename( )
        self.assertEqual(self.proxy.getAttributeFromProxy(proxyPath).split('/')[2], self.dict['group'])
        self.assertEqual(self.proxy.getAttributeFromProxy(proxyPath).split('/')[3].split('=')[1], role)

        #test with the allAttributes flag
        self.assertTrue(self.proxy.getAttributeFromProxy(proxyPath, allAttributes=True)>1)

    @attr("integration")
    def testGetUserGroupAndRole( self ):
        """
        Test GetUserGroupAndRoleFromProxy method.
        """
        if not self.dict['role']:
            role = 'NULL'
        else:
            role = self.dict['role']
        proxyPath = self.proxy.getProxyFilename( )
        if self.dict['group'] and self.dict['role']:
            self.assertEqual(self.proxy.getUserGroupAndRoleFromProxy(proxyPath)[0], self.dict['group'])
            self.assertEqual(self.proxy.getUserGroupAndRoleFromProxy(proxyPath)[1], role)

    @attr("integration")
    def testGetAllUserGroups( self ):
        """
        Test GetAllUserGroups method.
        """
        proxyPath = self.proxy.getProxyFilename( )
        groups = self.proxy.getAllUserGroups(proxyPath)
        print(list(groups))
开发者ID:AndresTanasijczuk,项目名称:WMCore,代码行数:104,代码来源:Proxy_t.py


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