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

Tests: Update test_rucio_bin to use fixtures, #6529 #6561

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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 .github/workflows/integration_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ jobs:
docker exec -t dev_rucio_1 cp etc/rse-accounts.cfg.template etc/rse-accounts.cfg
docker exec -t dev_rucio_1 tools/run_tests.sh -ir
- name: File Upload/Download Test
run: docker exec -t dev_rucio_1 tools/pytest.sh -v --tb=short tests/test_rucio_server.py
run: docker exec -t dev_rucio_1 tools/pytest.sh -v --tb=short tests/test_server_upload_download.py
- name: UploadClient Test
run: docker exec -t dev_rucio_1 tools/pytest.sh -v --tb=short tests/test_upload.py
- name: File Upload/Download Test using 'impl' parameter
Expand Down
2 changes: 1 addition & 1 deletion bin/rucio
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ from rucio.common.exception import (
UnsupportedOperation,
)
from rucio.common.extra import import_extras
from rucio.common.test_rucio_server import TestRucioServer
from rucio.common.rucio_server_tests import TestRucioServer
from rucio.common.utils import Color, StoreAndDeprecateWarningAction, chunks, detect_client_location, extract_scope, parse_did_filter_from_string, parse_did_filter_from_string_fe, setup_logger, sizefmt

EXTRA_MODULES = import_extras(['argcomplete'])
Expand Down
30 changes: 29 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

def pytest_configure(config):
config.addinivalue_line('markers', 'dirty: marks test as dirty, i.e. tests are leaving structures behind')
config.addinivalue_line('markers', 'noparallel(reason, groups): marks test being unable to run in parallel to other tests' )
config.addinivalue_line('markers', 'noparallel(reason, groups): marks test being unable to run in parallel to other tests')

if config.pluginmanager.hasplugin("xdist"):
from .ruciopytest import xdist_noparallel_scheduler
Expand Down Expand Up @@ -586,3 +586,31 @@ def metrics_mock():
mock.patch('rucio.core.monitor.TIMINGS', new={}), \
mock.patch('prometheus_client.values.ValueClass', new=values.MutexValue):
yield registry


@pytest.fixture
def account_name_generator():
from rucio.common.utils import generate_uuid
return lambda: 'jdoe-' + str(generate_uuid()).lower()[:16]


@pytest.fixture
def scope_name_generator():
from rucio.common.utils import generate_uuid
return lambda: 'mock_' + str(generate_uuid()).lower()[:16]


@pytest.fixture
def rse_name_generator():
def generator(size=10):
return 'MOCK-' + ''.join(choice(ascii_uppercase) for _ in range(size))
return generator


@pytest.fixture
def client_rse_factory(rucio_client, vo, function_scope_prefix):
""" Makes an rse factory that does not require a new db session"""
from .temp_factories import ClientMockRSEFactory

with ClientMockRSEFactory(db_session=rucio_client.session, vo=vo, name_prefix=function_scope_prefix) as factory:
yield factory
56 changes: 55 additions & 1 deletion tests/temp_factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,6 @@ def upload_client(self):
def cleanup(self, session=None):
if not self.created_dids:
return

self._cleanup_db_deps(session=session or self.db_session)

@transactional_session
Expand Down Expand Up @@ -365,3 +364,58 @@ def cleanup(self):
for fp in self.non_basedir_files:
if os.path.isfile(fp):
os.remove(fp)


class ClientMockRSEFactory(TemporaryRSEFactory):
def __init__(self, vo, name_prefix, db_session=None, **kwargs):
super().__init__(vo, name_prefix, db_session, **kwargs)

@staticmethod
def make_posix_rse(rse_client, rse_name_generator):
rse_name = rse_name_generator()
rse_client.add_rse(rse_name)
def_rse_id = rse_client.get_rse(rse=rse_name)['id']

protocol_parameters = {
'scheme': "file",
'hostname': '%s.cern.ch' % def_rse_id,
'port': 0,
'prefix': '/test_%s/' % def_rse_id,
'impl': 'rucio.rse.protocols.posix.Default',
'domains': {
'wan': {
'read': 1,
'write': 1,
'delete': 1,
'third_party_copy_read': 1,
'third_party_copy_write': 1,
},
'lan': {
'read': 1,
'write': 1,
'delete': 1,
}
}
}
rse_client.add_protocol(rse_name, protocol_parameters)
return rse_name, def_rse_id

def cleanup(self, session=None):
if not self.created_rses:
return

self._cleanup_db_deps(session=session or self.db_session)

@transactional_session
def _cleanup_db_deps(self, *, session=None):
cleanup_db_deps(
model=models.RSE,
select_rows_stmt=models.RSE.id.in_(self.created_rses),
session=session,
)

def _cleanup_rses(self):
for rse_id in self.created_rses:
# Only archive RSE instead of deleting. Account handling code doesn't expect RSEs to ever be deleted.
# So running test in parallel results in some tests failing on foreign key errors.
rse_core.del_rse(rse_id)
Loading
Loading