-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
51 lines (35 loc) · 1.12 KB
/
test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import xrootdpyfs
import pdb
from subprocess import call, PIPE
import os
from fs.opener import opener
def connect_test():
"""Do some test connecting awww yeahhhh"""
kdestroy()
# `klist` is empty (returns 0 when not empty)
with open(os.devnull, 'wb') as discard:
call(['klist'], stdout=discard,
stderr=discard)
# pdb.set_trace()
kinit_via_tab('cern.butts', 'otrondru')
xrdfs, path = connect()
assert xrdfs
def connect():
"""Connect to the EOS server thingy."""
remote_root = "root://eosuser.cern.ch"
remote_dir = "//eos/user/o/otrondru/"
return opener.parse(remote_root + remote_dir)
def kinit_via_tab(keytab, principal):
"""Get a kerberos ticket via a keytab."""
cmd = ['kinit', '-t', keytab, principal]
call_discard(cmd)
def kdestroy():
"""Destroy kerberos tickets on system."""
call_discard(['kdestroy'])
def call_discard(cmd):
"""Call `cmd` and discard the stderr and -out."""
with open(os.devnull, 'wb') as discard:
call(cmd, stdout=discard,
stderr=discard)
if __name__ == '__main__':
connect_test()