Skip to content

Commit

Permalink
upload: move dirac upload test to belle ii. rucio#6475
Browse files Browse the repository at this point in the history
  • Loading branch information
panta-123 committed Feb 6, 2024
1 parent bdf2a9f commit f71ccf1
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 59 deletions.
82 changes: 81 additions & 1 deletion tests/test_belleii.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

from rucio.common.exception import InvalidObject
from rucio.common.schema.belleii import validate_schema
from rucio.common.utils import generate_uuid, extract_scope
from rucio.common.utils import generate_uuid, extract_scope, adler32
from rucio.core.config import set as config_set
from rucio.tests.common import did_name_generator, skip_non_belleii

Expand Down Expand Up @@ -127,3 +127,83 @@ def test_belle2_schema(rse_factory, did_factory, root_account, did_client):
scope, name = extract_scope(path, [])
with pytest.raises(InvalidObject):
validate_schema('did', {'name': name, 'scope': scope, 'type': 'CONTAINER'})

@skip_non_belleii
def test_upload_file_with_dirac(rse, scope, upload_client, download_client, did_client, file_factory):
"Upload with dirac (CLIENT): Test the functionality of the upload method"
config_set('dirac', 'lifetime', '{"user.*": 2592400}')
local_file1 = file_factory.file_generator(use_basedir=True)
local_file2 = file_factory.file_generator(use_basedir=True)
download_dir = file_factory.base_dir
fn1 = did_name_generator('file', name_prefix='user')
fn2 = did_name_generator('file', name_prefix='user')

items = [
{
'path': local_file1,
'rse': rse,
'did_scope': scope,
'did_name': fn1,
'guid': generate_uuid()
},
{
'path': local_file2,
'rse': rse,
'did_scope': scope,
'did_name': fn2,
'guid': generate_uuid()
}
]

status = upload_client.upload(items)
assert status == 0
# download the files
did1 = f"{scope}:{fn1}"
did2 = f"{scope}:{fn2}"
download_client.download_dids([
{'did': did1, 'base_dir': download_dir},
{'did': did2, 'base_dir': download_dir}
])

# match checksums
downloaded_file1 = f"{download_dir}/{fn1}"
assert adler32(local_file1) == adler32(downloaded_file1)

downloaded_file2 = f"{download_dir}/{fn2}"
assert adler32(local_file2) == adler32(downloaded_file2)

# extra check for heriarchy
# Check the existence of all parents from the files
for lfn in [fn1, fn2]:
directories = lfn['lfn'].split('/')
for cnt, directory in enumerate(directories):
parent = "/".join(directories[0:cnt])
child = "/".join(directories[0:cnt + 1])
if parent != '':
parent_scope, parent_name = extract_scope(parent, [])
children = [did['name'] for did in did_client.list_content(parent_scope, parent_name)]
assert child in children

# test with dataset name
fn3 = did_name_generator('file', name_prefix='user')
directories = fn3['lfn'].split('/')
dataset_name = "/".join(directories[0:-1])
local_file3 = file_factory.file_generator()
items = [
{
'path': local_file3,
'rse': rse,
'dataset_scope': scope,
'dataset_name': dataset_name,
'guid': generate_uuid()
}]

status = upload_client.upload(items)
assert status == 0

# Check for filename existence (dataset+local_file3)
created_file_name = "/".join([dataset_name, local_file3])
did = did_client.get_did(scope, created_file_name)
assert did['scope'] == scope
assert did['name'] == created_file_name

58 changes: 0 additions & 58 deletions tests/test_upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -398,61 +398,3 @@ def test_upload_file_ignore_availability(rse_factory, scope, upload_client, file

status = upload_client.upload(item, ignore_availability=True)
assert status == 0

@skip_non_belleii
def test_upload_file_with_dirac(rse, scope, upload_client, download_client, did_client, file_factory):
config_set('dirac', 'lifetime', '{"user.*": 2592400}')
local_file1 = file_factory.file_generator(use_basedir=True)
local_file2 = file_factory.file_generator(use_basedir=True)
download_dir = file_factory.base_dir
fn1 = did_name_generator('file')
fn2 = did_name_generator('file')

items = [
{
'path': local_file1,
'rse': rse,
'did_scope': scope,
'did_name': fn1,
'guid': generate_uuid()
},
{
'path': local_file2,
'rse': rse,
'did_scope': scope,
'did_name': fn2,
'guid': generate_uuid()
}
]

status = upload_client.upload(items)
assert status == 0
# download the files
did1 = f"{scope}:{fn1}"
did2 = f"{scope}:{fn2}"
download_client.download_dids([
{'did': did1, 'base_dir': download_dir},
{'did': did2, 'base_dir': download_dir}
])

# match checksums
downloaded_file1 = f"{download_dir}/{scope}/{fn1}"
assert adler32(local_file1) == adler32(downloaded_file1)

downloaded_file2 = f"{download_dir}/{scope}/{fn2}"
assert adler32(local_file2) == adler32(downloaded_file2)

# extra check for heriarchy
# Check the existence of all parents from the files
for lfn in [fn1, fn2]:
directories = lfn['lfn'].split('/')
for cnt, directory in enumerate(directories):
parent = "/".join(directories[0:cnt])
child = "/".join(directories[0:cnt + 1])
if parent != '':
parent_scope, parent_name = extract_scope(parent, [])
children = [did['name'] for did in did_client.list_content(parent_scope, parent_name)]
assert child in children

# failed test for dirac and recursive.

0 comments on commit f71ccf1

Please sign in to comment.