1 |
|
from Actor import * |
2 |
|
from crab_util import * |
3 |
|
import common |
4 |
+ |
import traceback |
5 |
|
from ProdCommon.Credential.CredentialAPI import CredentialAPI |
6 |
+ |
from SubmitterServer import SubmitterServer |
7 |
+ |
|
8 |
|
|
9 |
|
class CredentialRenew(Actor): |
10 |
|
|
11 |
|
def __init__(self, cfg_params): |
12 |
< |
|
12 |
> |
self.cfg_params=cfg_params |
13 |
|
self.credentialType = 'Proxy' |
14 |
|
if common.scheduler.name().upper() in ['LSF', 'CAF']: |
15 |
|
self.credentialType = 'Token' |
16 |
+ |
|
17 |
+ |
# init client server params... |
18 |
+ |
CliServerParams(self) |
19 |
|
|
20 |
|
def run(self): |
21 |
|
""" |
22 |
|
""" |
17 |
– |
common.logger.debug(5, "CredentialRenew::run() called") |
18 |
– |
self.renewer() |
19 |
– |
common.logger.message("Credential successfully delegated to the server.\n") |
20 |
– |
return |
23 |
|
|
24 |
< |
def renewer(self): |
25 |
< |
""" |
26 |
< |
""" |
27 |
< |
myproxyserver = self.cfg_params.get('EDG.proxy_server', 'myproxy.cern.ch') |
24 |
> |
common.logger.debug("CredentialRenew::run() called") |
25 |
> |
|
26 |
> |
# FIXME With MyProxy delegation this part is completely overlapped with the method manageDelegation |
27 |
> |
# in SubmitServer. We should to maintain just one version of the method in a common part |
28 |
> |
|
29 |
> |
try: |
30 |
> |
myproxyserver = Downloader("http://cmsdoc.cern.ch/cms/LCG/crab/config/").config("myproxy_server.conf") |
31 |
> |
if myproxyserver is None: |
32 |
> |
raise CrabException("myproxy_server.conf retrieved but empty") |
33 |
> |
except Exception, e: |
34 |
> |
common.logger.info("Problem setting myproxy server endpoint: using myproxy.cern.ch") |
35 |
> |
common.logger.debug(e) |
36 |
> |
myproxyserver = 'myproxy.cern.ch' |
37 |
> |
|
38 |
|
configAPI = {'credential' : self.credentialType, \ |
39 |
|
'myProxySvr' : myproxyserver,\ |
40 |
|
'serverDN' : self.server_dn,\ |
41 |
|
'shareDir' : common.work_space.shareDir() ,\ |
42 |
< |
'userName' : UnixUserName(),\ |
43 |
< |
'serverName' : self.server_name \ |
42 |
> |
'userName' : getUserName(),\ |
43 |
> |
'serverName' : self.server_name, \ |
44 |
> |
'logger' : common.logger() \ |
45 |
|
} |
46 |
|
try: |
47 |
< |
CredAPI = CredentialAPI( configAPI ) |
48 |
< |
except Exception, err : |
49 |
< |
common.logger.debug(3, "Configuring Credential API: " +str(traceback.format_exc())) |
47 |
> |
CredAPI = CredentialAPI( configAPI ) |
48 |
> |
except Exception, err : |
49 |
> |
common.logger.debug( "Configuring Credential API: " +str(traceback.format_exc())) |
50 |
|
raise CrabException("ERROR: Unable to configure Credential Client API %s\n"%str(err)) |
51 |
< |
if not CredAPI.checkCredential(Time=100) : |
52 |
< |
common.logger.message("Please renew your %s :\n"%self.credentialType) |
53 |
< |
try: |
54 |
< |
CredAPI.ManualRenewCredential() |
55 |
< |
except Exception, ex: |
56 |
< |
raise CrabException(str(ex)) |
57 |
< |
try: |
58 |
< |
dict = CredAPI.registerCredential(sub) |
59 |
< |
except Exception, err: |
60 |
< |
common.logger.debug(3, "Registering Credentials : " +str(traceback.format_exc())) |
61 |
< |
raise CrabException("ERROR: Unable to register %s delegating server: %s\n"%(self.credentialType,self.server_name )) |
51 |
> |
|
52 |
> |
if self.credentialType == 'Proxy': |
53 |
> |
# Proxy delegation through MyProxy, 4 days lifetime minimum |
54 |
> |
if not CredAPI.checkMyProxy(Time=4, checkRetrieverRenewer=True) : |
55 |
> |
common.logger.info("Please renew MyProxy delegated proxy:\n") |
56 |
> |
try: |
57 |
> |
CredAPI.credObj.serverDN = self.server_dn |
58 |
> |
CredAPI.ManualRenewMyProxy() |
59 |
> |
except Exception, ex: |
60 |
> |
common.logger.debug("Delegating Credentials to MyProxy : " +str(traceback.format_exc())) |
61 |
> |
raise CrabException(str(ex)) |
62 |
> |
else: |
63 |
> |
self.renewer() |
64 |
> |
if not CredAPI.checkCredential(Time=100) : |
65 |
> |
common.logger.info("Please renew your %s :\n"%self.credentialType) |
66 |
> |
try: |
67 |
> |
CredAPI.ManualRenewCredential() |
68 |
> |
except Exception, ex: |
69 |
> |
raise CrabException(str(ex)) |
70 |
> |
try: |
71 |
> |
dict = CredAPI.registerCredential() |
72 |
> |
except Exception, err: |
73 |
> |
common.logger.debug( "Registering Credentials : " +str(traceback.format_exc())) |
74 |
> |
raise CrabException("ERROR: Unable to register %s delegating server: %s\n"%\ |
75 |
> |
(self.credentialType,self.server_name )) |
76 |
> |
|
77 |
> |
common.logger.info("Credential successfully delegated to the server.\n") |
78 |
> |
return |