Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parse USERDISK base on hostname in RunDB #1384

Merged
merged 4 commits into from
May 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion straxen/storage/mongo_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,8 +260,8 @@ def __init__(self, store_files_at=None, *args, **kwargs):
# either specified by the user or we use these defaults:
if store_files_at is None:
store_files_at = (
"/tmp/straxen_resource_cache/",
"./resource_cache",
"/tmp/straxen_resource_cache",
)
elif not isinstance(store_files_at, (tuple, str, list)):
raise ValueError(f"{store_files_at} should be tuple of paths!")
Expand Down
29 changes: 19 additions & 10 deletions straxen/storage/rundb.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,14 @@ class RunDB(strax.StorageFrontend):

storage_type = strax.StorageType.LOCAL
# Dict of alias used in rundb: regex on hostname
hosts = {"dali": r"^dali.*rcc.*|^midway2.*rcc.*|^midway.*rcc.*|fried.rice.edu"}
hosts = {
"dali": r"^dali.*rcc.*|fried.rice.edu",
"midway": r"^midway2.*rcc.*|^midway.*rcc.*",
}
userdisks = {
"UC_DALI_USERDISK": r"^dali.*rcc.*|fried.rice.edu",
"UC_MIDWAY_USERDISK": r"^midway2.*rcc.*|^midway.*rcc.*",
}

provide_run_metadata = True
progress_bar = False
Expand Down Expand Up @@ -126,18 +133,20 @@ def __init__(
if re.match(regex, self.hostname):
self.available_query.append({"host": host_alias})

# When querying for rucio, add that it should be dali-userdisk (when on dali)
# When querying for rucio, add that it should be sparsed by the hostname
if self.rucio_path is not None and any(
re.match(regex, self.hostname) for regex in self.hosts.values()
):
self.backends.append(RucioLocalBackend(self.rucio_path))
self.available_query.append(
{
"host": "rucio-catalogue",
"location": "UC_DALI_USERDISK",
"status": "transferred",
}
)
for host_alias, regex in self.userdisks.items():
if re.match(regex, self.hostname):
self.backends.append(RucioLocalBackend(self.rucio_path))
self.available_query.append(
{
"host": "rucio-catalogue",
"location": host_alias,
"status": "transferred",
}
)

def _data_query(self, key):
"""Return MongoDB query for data field matching key."""
Expand Down
5 changes: 5 additions & 0 deletions straxen/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ def _is_on_pytest():
return "PYTEST_CURRENT_TEST" in os_environ


@export
def mongo_uri_not_set():
return "TEST_MONGO_URI" not in os.environ


def _get_fake_daq_reader():
class DAQReader(straxen.DAQReader):
"""Dummy version of the DAQ reader to make sure that all the testing data produced here will
Expand Down
9 changes: 3 additions & 6 deletions tests/storage/test_database_frontends.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,7 @@
import pymongo
import datetime
import socket
from straxen import RunDB


def mongo_uri_not_set():
return "TEST_MONGO_URI" not in os.environ
from straxen import RunDB, mongo_uri_not_set


@unittest.skipIf(mongo_uri_not_set(), "No access to test database")
Expand Down Expand Up @@ -66,6 +62,7 @@ class RunDBTestLocal(RunDB):
"""Change class to mathc current host too."""

hosts = {"bla": f"{socket.getfqdn()}"}
userdisks = {"BLA_USERDISK": f"{socket.getfqdn()}"}

cls.rundb_sf_with_current_host = RunDBTestLocal(
readonly=False,
Expand Down Expand Up @@ -199,7 +196,7 @@ def test_rucio_format(self):
rd["data"] = [
{
"host": "rucio-catalogue",
"location": "UC_DALI_USERDISK",
"location": "BLA_USERDISK",
"status": "transferred",
"did": did,
"number": int(rucio_id),
Expand Down
5 changes: 1 addition & 4 deletions tests/storage/test_mongo_downloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@
import straxen
import os
import pymongo


def mongo_uri_not_set():
return "TEST_MONGO_URI" not in os.environ
from straxen import mongo_uri_not_set


@unittest.skipIf(mongo_uri_not_set(), "No access to test database")
Expand Down