ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/CRAB/python/check_HN_Name.py
Revision: 1.7
Committed: Mon Jul 29 15:38:08 2013 UTC (11 years, 9 months ago) by belforte
Content type: text/x-python
Branch: MAIN
CVS Tags: CRAB_2_9_1, CRAB_2_9_1_pre2, CRAB_2_9_1_pre1, CRAB_2_9_0, CRAB_2_9_0_pre2, CRAB_2_9_0_pre1, HEAD
Changes since 1.6: +14 -3 lines
Log Message:
use SiteDB V2 API

File Contents

# User Rev Content
1 slacapra 1.1 class check_HN_name:
2     def init(self):
3     pass
4    
5     def stdaloneCheck(self):
6    
7     import urllib
8     from commands import getstatusoutput
9     print 'start standalone check ...\n'
10     status, dn = getstatusoutput('voms-proxy-info -identity')
11     if status == 0:
12     print "my DN is: %s \n"%dn
13     dn = dn.split('\n')[-1]
14     dn = urllib.urlencode({'dn':dn})
15     print 'Using urlencoded DN: \n\t %s '%dn
16 belforte 1.7 try:
17     f = urllib.urlopen("https://cmsweb.cern.ch/sitedb/json/index/dnUserName?%s" % dn)
18     username = str(f.read())
19     f.close()
20     except:
21     print "failed to get username via SiteDB V1 API"
22     username="None"
23    
24     cmd = "curl -s --capath $X509_CERT_DIR --cert $X509_USER_PROXY --key $X509_USER_PROXY 'https://cmsweb.cern.ch/sitedb/data/prod/whoami'|tr ':,' '\n'|grep -A1 login|tail -1"
25     uname = subprocess.check_output(cmd,shell=True)
26    
27    
28     print 'v1: my HN user name is: %s' % username
29     print 'v2: my HN user name is: %s' % uname
30 slacapra 1.1 print '\nend check.....................'
31    
32     def crabCheck(self):
33     from CrabLogger import CrabLogger
34 belforte 1.4 from WorkSpace import WorkSpace, common
35     import tempfile, urllib, os, string
36 slacapra 1.1
37     dname = tempfile.mkdtemp( "", "crab_", '/tmp' )
38     os.system("mkdir %s/log"%dname )
39     os.system("touch %s/crab.log"%dname )
40    
41     cfg_params={'USER.logdir' : dname }
42     common.work_space = WorkSpace(dname, cfg_params)
43     args = string.join(sys.argv,' ')
44     common.debugLevel = 0
45     common.logger = CrabLogger(args)
46    
47     from crab_util import getDN,gethnUserNameFromSiteDB
48     print 'start using CRAB utils ...\n'
49     print "my DN is: %s \n"%getDN()
50     try:
51     print 'my HN user name is: %s \n'%gethnUserNameFromSiteDB()
52     except:
53     print '\nWARNING native crab_utils failed! '
54     dn=urllib.urlencode({'dn':getDN()})
55     print 'trying now using urlencoded DN: \n\t %s '%dn
56     status,hnName = self.gethnName_urlenc(dn)
57     if status == 1:
58     print '\nWARNING: failed also using urlencoded DN '
59     else:
60     print 'my HN user name is: %s \n'%name
61     print 'problems with crab_utils'
62     print '\nend check.....................'
63    
64     os.system("rm -rf %s"%dname )
65    
66     def gethnName_urlenc(self,dn):
67     from WMCore.Services.SiteDB.SiteDB import SiteDBJSON
68     hnUserName = None
69     userdn = dn
70     mySiteDB = SiteDBJSON()
71     status = 0
72     try:
73     hnUserName = mySiteDB.dnUserName(dn=userdn)
74     except:
75     status = 1
76     return status,hnUserName
77    
78    
79     if __name__ == '__main__' :
80     import sys
81 belforte 1.4 import subprocess
82 slacapra 1.1 args = sys.argv[1:]
83 belforte 1.4 check = check_HN_name()
84    
85 belforte 1.6 # print "verify if user DN is mapped in CERN's SSO"
86     # cmd='curl -s --capath $X509_CERT_DIR --cert $X509_USER_PROXY --key $X509_USER_PROXY "https://cmsweb.cern.ch/sitedb/data/dev/people" | grep "`voms-proxy-info -identity`"'
87     # DocUrl = "\nhttps://hypernews.cern.ch/HyperNews/CMS/get/cernCompAnnounce/820.html"
88     # DocUrl += "\nhttps://twiki.cern.ch/twiki/bin/view/CMS/SiteDBForCRAB"
89 belforte 1.4
90 belforte 1.6 # try:
91     # subprocess.check_call(cmd,shell=True)
92     # print "OK. user ready for SiteDB switchover on March 12, 2013\n\n"
93     # except:
94     # print "********** ATTENTION !!!! **************"
95     # print "DN not registered in CERN's SSO"
96     # print "need to follow instructions in %s" % DocUrl
97     # print "or Crab will stop working for you on March 12, 2013"
98     # print "*****************************************"
99     # dummy=raw_input("\nHit Return to acknowlege that you read this message")
100 belforte 1.4
101 slacapra 1.1 if 'crab' in args:
102     check.crabCheck()
103     else:
104     check.stdaloneCheck()
105