本文整理汇总了Python中WMCore.Credential.Proxy.Proxy.create方法的典型用法代码示例。如果您正苦于以下问题:Python Proxy.create方法的具体用法?Python Proxy.create怎么用?Python Proxy.create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WMCore.Credential.Proxy.Proxy
的用法示例。
在下文中一共展示了Proxy.create方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testMyProxyEnvironment
# 需要导入模块: from WMCore.Credential.Proxy import Proxy [as 别名]
# 或者: from WMCore.Credential.Proxy.Proxy import create [as 别名]
def testMyProxyEnvironment(self):
"""
Test the myProxyEnvironment context manager
In this test a new Proxy and MyProxy are initialized
"""
myProxy = Proxy(self.dict)
# Create the proxy
myProxy.create()
proxyPath = myProxy.getProxyFilename()
userDN = myProxy.getSubject()
self.assertTrue(os.path.exists(proxyPath))
# Delegate and check the proxy
myProxy.delegate(credential=proxyPath, serverRenewer=True)
valid = myProxy.checkMyProxy()
self.assertTrue(valid)
# Make sure X509_USER_PROXY exists only in the context manager and corresponds to a file
if 'X509_USER_PROXY' in os.environ:
del os.environ['X509_USER_PROXY']
self.assertFalse('X509_USER_PROXY' in os.environ)
with myProxyEnvironment(userDN=userDN, serverCert=serverCert, serverKey=serverKey,
myproxySrv='myproxy.cern.ch', proxyDir='/tmp/', logger=self.logger):
self.assertTrue('X509_USER_PROXY' in os.environ)
self.assertTrue(os.path.exists(os.environ['X509_USER_PROXY']))
self.assertFalse('X509_USER_PROXY' in os.environ)
return
示例2: Proxy
# 需要导入模块: from WMCore.Credential.Proxy import Proxy [as 别名]
# 或者: from WMCore.Credential.Proxy.Proxy import create [as 别名]
class Proxy(object):
'''
CMS uses proxies constantly. This class is a wrapper function around WMCore
proxy handling, to allow the user to update/check/delete their proxy in
myproxy and update/check the local proxy
'''
def __init__(self):
'''
Constructor
'''
self.helper = WMCoreProxy({'logger' : logging})
def getProxyFilename(self):
return self.helper.getProxyFilename()
def initProxy(self):
self.helper.create()
def deleteProxy(self):
self.helper.destroy()
def uploadToMyproxy(self, allowedDN):
self.helper.serverDN = allowedDN
self.helper.delegate( None, True )
示例3: createNewVomsProxy
# 需要导入模块: from WMCore.Credential.Proxy import Proxy [as 别名]
# 或者: from WMCore.Credential.Proxy.Proxy import create [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()
示例4: ProxyTest
# 需要导入模块: from WMCore.Credential.Proxy import Proxy [as 别名]
# 或者: from WMCore.Credential.Proxy.Proxy import create [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)
#.........这里部分代码省略.........
示例5: MyProxyTest
# 需要导入模块: from WMCore.Credential.Proxy import Proxy [as 别名]
# 或者: from WMCore.Credential.Proxy.Proxy import create [as 别名]
class MyProxyTest(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, 'serverDN' : serverDN}
self.proxyPath = None
self.proxy = Proxy( self.dict )
self.serverDN = self.dict['serverDN']
def tearDown(self):
"""
_tearDown_
"""
return
@attr("integration")
def testAAACreateMyProxy( self ):
"""
Test if delegate method create correctly the MyProxy.
"""
self.proxy.create()
self.proxy.delegate( credential = self.proxyPath )
valid = self.proxy.checkMyProxy( )
self.assertTrue(valid, 'Could not create MyProxy')
@attr("integration")
def testDelegateServer( self ):
"""
Test if delegate method create MyProxy and delegate
the retrieval to the server correctly.
"""
self.proxy.delegate( credential = self.proxyPath, serverRenewer = True )
valid = self.proxy.checkMyProxy( checkRenewer = True )
self.assertTrue(valid)
@attr("integration")
def testCheckMyProxy( self ):
"""
Test if checkMyProxy checks correctly the MyProxy validity.
"""
valid = self.proxy.checkMyProxy( )
self.assertTrue(valid)
@attr("integration")
def testRenewMyProxy( self ):
"""
Test if renewMyProxy method renews correctly the MyProxy.
"""
self.proxy.renewMyProxy( proxy = self.proxyPath )
time.sleep( 5 )
timeLeft = self.proxy.getMyProxyTimeLeft( proxy = self.proxyPath )
self.assertEqual(int(timeLeft) / 3600, 167)
@attr("integration")
def testRenewMyProxyForServer( self ):
"""
Renew MyProxy which the retrieval is delegated to a server.
"""
time.sleep( 70 )
self.proxy.renewMyProxy( proxy = self.proxyPath, serverRenewer = True )
time.sleep( 5 )
timeLeft = self.proxy.getMyProxyTimeLeft( proxy = self.proxyPath, serverRenewer = True )
self.assertEqual(int(timeLeft) / 3600, 167)
@attr("integration")
def testMyProxyEnvironment(self):
"""
Test the myProxyEnvironment context manager
In this test a new Proxy and MyProxy are initialized
"""
myProxy = Proxy(self.dict)
# Create the proxy
myProxy.create()
proxyPath = myProxy.getProxyFilename()
userDN = myProxy.getSubject()
self.assertTrue(os.path.exists(proxyPath))
# Delegate and check the proxy
myProxy.delegate(credential=proxyPath, serverRenewer=True)
valid = myProxy.checkMyProxy()
self.assertTrue(valid)
# Make sure X509_USER_PROXY exists only in the context manager and corresponds to a file
if 'X509_USER_PROXY' in os.environ:
del os.environ['X509_USER_PROXY']
self.assertFalse('X509_USER_PROXY' in os.environ)
with myProxyEnvironment(userDN=userDN, serverCert=serverCert, serverKey=serverKey,
#.........这里部分代码省略.........
示例6: ProxyTest
# 需要导入模块: from WMCore.Credential.Proxy import Proxy [as 别名]
# 或者: from WMCore.Credential.Proxy.Proxy import create [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")
#.........这里部分代码省略.........