|
1 | 1 | """CoffeaCasaCluster class |
2 | 2 | """ |
3 | 3 | import os |
4 | | -import sys |
5 | 4 | from pathlib import Path |
| 5 | +import sys |
6 | 6 | import dask |
7 | 7 | from dask_jobqueue.htcondor import HTCondorCluster, HTCondorJob |
8 | 8 | from distributed.security import Security |
|
30 | 30 | else: |
31 | 31 | CONDA_ENV = HOME_DIR / "environment.yml" |
32 | 32 |
|
33 | | -# helper functions from htcondor/htcondor-ce/htcondorce/tools.py |
34 | | -def x509_user_proxy_path(): |
35 | | - """Return the path to the user's X.509 proxy or raise FileNotFoundError if it doesn't exist on disk |
36 | | - """ |
37 | | - try: |
38 | | - path = os.environ['X509_USER_PROXY'] |
39 | | - except KeyError: |
40 | | - path = f'/tmp/x509up_u{os.geteuid()}' |
41 | | - if open(path): |
42 | | - return path |
43 | | - return None # we shouldn't get here; failure to open should raise OSError |
| 33 | +import os |
| 34 | +from pathlib import Path |
44 | 35 |
|
45 | | -# helper functions from htcondor/htcondor-ce/htcondorce/tools.py |
46 | 36 | def bearer_token_path(): |
47 | | - """Return the path to the user's X.509 proxy or raise FileNotFoundError if it doesn't exist on disk |
48 | | - """ |
| 37 | + """Return the path to the user's X.509 proxy or None if not found""" |
| 38 | + |
49 | 39 | def check_token_path(path, suffix=''): |
50 | 40 | token_path = f'{path}{suffix}' |
51 | | - if open(token_path): |
| 41 | + if Path(token_path).is_file(): |
52 | 42 | return token_path |
53 | | - return None # we shouldn't get here, failure to open should raise OSError |
| 43 | + return None |
54 | 44 |
|
| 45 | + # 1. Check BEARER_TOKEN_FILE env variable |
55 | 46 | try: |
56 | | - # 2. BEARER_TOKEN_PATH containing the path to the token |
57 | 47 | path = check_token_path(os.environ['BEARER_TOKEN_FILE']) |
58 | | - except (KeyError, FileNotFoundError): |
59 | | - try: |
60 | | - # 3. XDG_RUNTIME_DIR containing the path to the folder containing the token at bt_u$UID |
61 | | - path = check_token_path(os.environ['XDG_RUNTIME_DIR'], suffix=f'/bt_u{os.geteuid()}') |
62 | | - except (KeyError, FileNotFoundError): |
63 | | - # 4. Otherwise, the token is expected at /tmp/bt_u$UID |
64 | | - # Raise FileExceptionError if it doesn't exist |
65 | | - path = check_token_path(f'/tmp/bt_u{os.geteuid()}') |
| 48 | + if path: |
| 49 | + return path |
| 50 | + except KeyError: |
| 51 | + pass |
| 52 | + |
| 53 | + # 2. Check XDG_RUNTIME_DIR + /bt_u$UID |
| 54 | + try: |
| 55 | + xdg_runtime_dir = os.environ['XDG_RUNTIME_DIR'] |
| 56 | + path = check_token_path(xdg_runtime_dir, suffix=f'/bt_u{os.geteuid()}') |
| 57 | + if path: |
| 58 | + return path |
| 59 | + except KeyError: |
| 60 | + pass |
| 61 | + |
| 62 | + # 3. Check /tmp/bt_u$UID |
| 63 | + try: |
| 64 | + path = check_token_path(f'/tmp/bt_u{os.geteuid()}') |
| 65 | + if path: |
| 66 | + return path |
| 67 | + except KeyError: |
| 68 | + pass |
66 | 69 |
|
67 | | - return path |
| 70 | + return None |
68 | 71 |
|
69 | 72 |
|
70 | 73 | def merge_dicts(*dict_args): |
@@ -176,12 +179,11 @@ def _modify_job_kwargs(cls, |
176 | 179 | job_config["protocol"] = "tls://" |
177 | 180 | job_config["security"] = cls.security() |
178 | 181 | input_files += [CA_FILE, CERT_FILE] |
179 | | - if opendata is None: |
180 | | - XCACHE_SCITOKEN_FILE = bearer_token_path() |
181 | | - if XCACHE_SCITOKEN_FILE: |
182 | | - input_files += [XCACHE_SCITOKEN_FILE] |
183 | | - else: |
184 | | - raise KeyError("Please check with system administarator why you do not have a certificate.") |
| 182 | + XCACHE_SCITOKEN_FILE = bearer_token_path() |
| 183 | + if XCACHE_SCITOKEN_FILE: |
| 184 | + input_files += [XCACHE_SCITOKEN_FILE] |
| 185 | + else: |
| 186 | + print("Warning: No bearer token found — proceeding without it.") |
185 | 187 | files = ", ".join(str(path) for path in input_files) |
186 | 188 | ## Networking settings |
187 | 189 | try: |
|
0 commit comments