forked from rucio/rucio
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_conveyor.py
1704 lines (1426 loc) · 91.1 KB
/
test_conveyor.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# -*- coding: utf-8 -*-
# Copyright European Organization for Nuclear Research (CERN) since 2012
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import logging
import threading
import time
from datetime import datetime, timedelta
from tempfile import TemporaryDirectory
from unittest.mock import patch
from urllib.parse import urlencode, urlparse, parse_qsl, urlunparse
from sqlalchemy import update
import pytest
import rucio.daemons.reaper.reaper
from rucio.common.utils import generate_uuid, adler32
from rucio.common.exception import ReplicaNotFound, RequestNotFound
from rucio.core import config as core_config
from rucio.core import did as did_core
from rucio.core import distance as distance_core
from rucio.core import lock as lock_core
from rucio.core import message as message_core
from rucio.core import replica as replica_core
from rucio.core import request as request_core
from rucio.core import rse as rse_core
from rucio.core import rule as rule_core
from rucio.core.account_limit import set_local_account_limit
from rucio.daemons.conveyor.finisher import finisher
from rucio.daemons.conveyor.poller import poller
from rucio.daemons.conveyor.preparer import preparer
from rucio.daemons.conveyor.submitter import submitter
from rucio.daemons.conveyor.stager import stager
from rucio.daemons.conveyor.throttler import throttler
from rucio.daemons.conveyor.receiver import receiver, GRACEFUL_STOP as receiver_graceful_stop, Receiver
from rucio.daemons.reaper.reaper import reaper
from rucio.db.sqla import models
from rucio.db.sqla.constants import LockState, RequestState, RequestType, ReplicaState, RSEType, RuleState
from rucio.db.sqla.session import read_session, transactional_session
from rucio.tests.common import skip_rse_tests_with_accounts
from rucio.transfertool.fts3 import FTS3Transfertool
from tests.ruciopytest import NoParallelGroups
from tests.mocks.mock_http_server import MockServer
MAX_POLL_WAIT_SECONDS = 100
TEST_FTS_HOST = 'https://fts:8446'
@transactional_session
def __update_request(request_id, *, session=None, **kwargs):
session.query(models.Request).filter_by(id=request_id).update(kwargs, synchronize_session=False)
def __wait_for_replica_transfer(dst_rse_id, scope, name, max_wait_seconds=MAX_POLL_WAIT_SECONDS, transfertool=None):
"""
Wait for the replica to become AVAILABLE on the given RSE as a result of a pending transfer
"""
replica = {}
for _ in range(max_wait_seconds):
poller(once=True, older_than=0, partition_wait_time=0, transfertool=transfertool)
finisher(once=True, partition_wait_time=0)
replica = replica_core.get_replica(rse_id=dst_rse_id, scope=scope, name=name)
if replica['state'] != ReplicaState.COPYING:
break
time.sleep(1)
return replica
def __wait_for_state_transition(dst_rse_id, scope, name, max_wait_seconds=MAX_POLL_WAIT_SECONDS, run_poller=True, transfertool=None):
"""
Wait for the request state to be updated to the given expected state as a result of a pending transfer
"""
request = {}
for _ in range(max_wait_seconds):
if run_poller:
poller(once=True, older_than=0, partition_wait_time=0, transfertool=transfertool)
request = request_core.get_request_by_did(rse_id=dst_rse_id, scope=scope, name=name)
if request['state'] != RequestState.SUBMITTED:
break
time.sleep(1)
return request
def __wait_for_fts_state(request, expected_state, max_wait_seconds=MAX_POLL_WAIT_SECONDS):
job_state = ''
for _ in range(max_wait_seconds):
fts_response = FTS3Transfertool(external_host=TEST_FTS_HOST).bulk_query({request['external_id']: {request['id']: request}})
job_state = fts_response[request['external_id']][request['id']].job_response['job_state']
if job_state == expected_state:
break
time.sleep(1)
return job_state
def set_query_parameters(url, params):
"""
Set a query parameter in an url which may, or may not, have other existing query parameters
"""
url_parts = list(urlparse(url))
query = dict(parse_qsl(url_parts[4]))
query.update(params)
url_parts[4] = urlencode(query)
return urlunparse(url_parts)
@read_session
def __get_source(request_id, src_rse_id, scope, name, *, session=None):
return session.query(models.Source) \
.filter(models.Source.request_id == request_id) \
.filter(models.Source.scope == scope) \
.filter(models.Source.name == name) \
.filter(models.Source.rse_id == src_rse_id) \
.first()
@pytest.fixture
def scitags_mock(core_config_mock):
"""Run a mock http server which always returns the content of scitags.json from test/inputs"""
from tests.inputs import SCITAGS_JSON
from pathlib import Path
class _SendScitagsJson(MockServer.Handler):
def do_GET(self):
file_content = Path(SCITAGS_JSON).read_text()
self.send_code_and_message(200, {'Content-Type': 'application/json'}, file_content)
with MockServer(_SendScitagsJson) as mock_server:
core_config.set('packet-marking', 'enabled', True)
core_config.set('packet-marking', 'fetch_url', mock_server.base_url)
core_config.set('packet-marking', 'exp_name', 'atlas')
yield mock_server
@skip_rse_tests_with_accounts
@pytest.mark.dirty(reason="leaves files in XRD containers")
@pytest.mark.noparallel(groups=[NoParallelGroups.XRD, NoParallelGroups.SUBMITTER, NoParallelGroups.POLLER, NoParallelGroups.FINISHER])
@pytest.mark.parametrize("core_config_mock", [{"table_content": [
('transfers', 'multihop_tombstone_delay', -1), # Set OBSOLETE tombstone for intermediate replicas
]}], indirect=True)
@pytest.mark.parametrize("caches_mock", [{"caches_to_mock": [
'rucio.core.rse_expression_parser.REGION', # The list of multihop RSEs is retrieved by rse expression
'rucio.core.config.REGION',
'rucio.daemons.reaper.reaper.REGION',
]}], indirect=True)
def test_multihop_intermediate_replica_lifecycle(vo, did_factory, root_account, core_config_mock, caches_mock, metrics_mock):
"""
Ensure that intermediate replicas created by the submitter are protected from deletion even if their tombstone is
set to epoch.
After successful transfers, intermediate replicas with default (epoch) tombstone must be removed. The others must
be left intact.
"""
src_rse1_name = 'XRD1'
src_rse1_id = rse_core.get_rse_id(rse=src_rse1_name, vo=vo)
src_rse2_name = 'XRD2'
src_rse2_id = rse_core.get_rse_id(rse=src_rse2_name, vo=vo)
jump_rse_name = 'XRD3'
jump_rse_id = rse_core.get_rse_id(rse=jump_rse_name, vo=vo)
dst_rse_name = 'XRD4'
dst_rse_id = rse_core.get_rse_id(rse=dst_rse_name, vo=vo)
all_rses = [src_rse1_id, src_rse2_id, jump_rse_id, dst_rse_id]
did = did_factory.upload_test_file(src_rse1_name)
# Copy replica to a second source. To avoid the special case of having a unique last replica, which could be handled in a special (more careful) way
rule_core.add_rule(dids=[did], account=root_account, copies=1, rse_expression=src_rse2_name, grouping='ALL', weight=None, lifetime=3600, locked=False, subscription_id=None)
submitter(once=True, rses=[{'id': rse_id} for rse_id in all_rses], partition_wait_time=0, transfertype='single', filter_transfertool=None)
replica = __wait_for_replica_transfer(dst_rse_id=src_rse2_id, **did)
assert replica['state'] == ReplicaState.AVAILABLE
rse_core.set_rse_limits(rse_id=jump_rse_id, name='MinFreeSpace', value=1)
rse_core.set_rse_usage(rse_id=jump_rse_id, source='storage', used=1, free=0)
try:
rule_core.add_rule(dids=[did], account=root_account, copies=1, rse_expression=dst_rse_name, grouping='ALL', weight=None, lifetime=3600, locked=False, subscription_id=None)
# Submit transfers to FTS
# Ensure a replica was created on the intermediary host with epoch tombstone
submitter(once=True, rses=[{'id': rse_id} for rse_id in all_rses], partition_wait_time=0, transfertype='single', filter_transfertool=None)
request = request_core.get_request_by_did(rse_id=jump_rse_id, **did)
assert request['state'] == RequestState.SUBMITTED
replica = replica_core.get_replica(rse_id=jump_rse_id, **did)
assert replica['tombstone'] == datetime(year=1970, month=1, day=1)
assert replica['state'] == ReplicaState.COPYING
request = request_core.get_request_by_did(rse_id=dst_rse_id, **did)
# Fake an existing unused source with raking of 0 for the second source.
# The ranking of this source should remain at 0 till the end.
@transactional_session
def __fake_source_ranking(*, session=None):
models.Source(request_id=request['id'],
scope=request['scope'],
name=request['name'],
rse_id=src_rse2_id,
dest_rse_id=request['dest_rse_id'],
ranking=0,
bytes=request['bytes'],
url=None,
is_using=False). \
save(session=session, flush=False)
__fake_source_ranking()
# The intermediate replica is protected by its state (Copying)
rucio.daemons.reaper.reaper.REGION.invalidate()
reaper(once=True, rses=[], include_rses=jump_rse_name, exclude_rses=None)
replica = replica_core.get_replica(rse_id=jump_rse_id, **did)
assert replica['state'] == ReplicaState.COPYING
# Wait for the intermediate replica to become ready
replica = __wait_for_replica_transfer(dst_rse_id=jump_rse_id, **did)
assert replica['state'] == ReplicaState.AVAILABLE
# ensure tha the ranking was correct for all sources and intermediate rses
assert __get_source(request_id=request['id'], src_rse_id=src_rse1_id, **did).ranking == 0
assert __get_source(request_id=request['id'], src_rse_id=jump_rse_id, **did).ranking == 0
assert __get_source(request_id=request['id'], src_rse_id=src_rse2_id, **did).ranking == 0
# Only group_bulk=1 part of the path was submitted.
# run submitter again to copy from jump rse to destination rse
__update_request(request_core.get_request_by_did(rse_id=dst_rse_id, **did)['id'], last_processed_by=None)
submitter(once=True, rses=[{'id': rse_id} for rse_id in all_rses], partition_wait_time=0, transfertype='single', filter_transfertool=None)
# Wait for the destination replica to become ready
replica = __wait_for_replica_transfer(dst_rse_id=dst_rse_id, **did)
assert replica['state'] == ReplicaState.AVAILABLE
rucio.daemons.reaper.reaper.REGION.invalidate()
reaper(once=True, rses=[], include_rses='test_container_xrd=True', exclude_rses=None)
with pytest.raises(ReplicaNotFound):
replica_core.get_replica(rse_id=jump_rse_id, **did)
# 3 request: copy to second source + 2 hops (each separately)
# Use inequalities, because there can be left-overs from other tests
assert metrics_mock.get_sample_value('rucio_daemons_conveyor_poller_update_request_state_total', labels={'updated': 'True'}) >= 3
assert metrics_mock.get_sample_value('rucio_daemons_conveyor_common_submit_transfer_total') >= 3
# at least the failed hop
assert metrics_mock.get_sample_value('rucio_daemons_conveyor_finisher_handle_requests_total') > 0
finally:
@transactional_session
def _cleanup_all_usage_and_limits(rse_id, *, session=None):
session.query(models.RSELimit).filter_by(rse_id=rse_id).delete()
session.query(models.RSEUsage).filter_by(rse_id=rse_id, source='storage').delete()
_cleanup_all_usage_and_limits(rse_id=jump_rse_id)
@skip_rse_tests_with_accounts
@pytest.mark.noparallel(groups=[NoParallelGroups.XRD, NoParallelGroups.SUBMITTER, NoParallelGroups.POLLER, NoParallelGroups.FINISHER])
@pytest.mark.parametrize("caches_mock", [{"caches_to_mock": [
'rucio.core.rse_expression_parser.REGION', # The list of multihop RSEs is retrieved by rse expression
]}], indirect=True)
def test_fts_non_recoverable_failures_handled_on_multihop(vo, did_factory, root_account, replica_client, caches_mock, metrics_mock):
"""
Verify that the poller correctly handles non-recoverable FTS job failures
"""
src_rse = 'XRD1'
src_rse_id = rse_core.get_rse_id(rse=src_rse, vo=vo)
jump_rse = 'XRD3'
jump_rse_id = rse_core.get_rse_id(rse=jump_rse, vo=vo)
dst_rse = 'XRD4'
dst_rse_id = rse_core.get_rse_id(rse=dst_rse, vo=vo)
all_rses = [src_rse_id, jump_rse_id, dst_rse_id]
# Register a did which doesn't exist. It will trigger an non-recoverable error during the FTS transfer.
did = did_factory.random_file_did()
replica_client.add_replicas(rse=src_rse, files=[{'scope': did['scope'].external, 'name': did['name'], 'bytes': 1, 'adler32': 'aaaaaaaa'}])
rule_core.add_rule(dids=[did], account=root_account, copies=1, rse_expression=dst_rse, grouping='ALL', weight=None, lifetime=None, locked=False, subscription_id=None)
submitter(once=True, rses=[{'id': rse_id} for rse_id in all_rses], group_bulk=2, partition_wait_time=0, transfertype='single', filter_transfertool=None)
request = __wait_for_state_transition(dst_rse_id=dst_rse_id, **did)
assert 'Unused hop in multi-hop' in request['err_msg']
assert request['state'] == RequestState.FAILED
request = request_core.get_request_by_did(rse_id=jump_rse_id, **did)
assert request['state'] == RequestState.FAILED
assert request['attributes']['source_replica_expression'] == src_rse
# Each hop is a separate transfer, which will be handled by the poller and marked as failed
assert metrics_mock.get_sample_value('rucio_daemons_conveyor_poller_update_request_state_total', labels={'updated': 'True'}) >= 2
# Finisher will handle transfers of the same multihop one hop at a time
finisher(once=True, partition_wait_time=0)
finisher(once=True, partition_wait_time=0)
# The intermediate request must not be re-scheduled by finisher
with pytest.raises(RequestNotFound):
request_core.get_request_by_did(rse_id=jump_rse_id, **did)
request = request_core.get_request_by_did(rse_id=dst_rse_id, **did)
# ensure tha the ranking was correctly decreased for the whole path
assert __get_source(request_id=request['id'], src_rse_id=jump_rse_id, **did).ranking == -1
assert __get_source(request_id=request['id'], src_rse_id=src_rse_id, **did).ranking == -1
assert request['state'] == RequestState.QUEUED
@skip_rse_tests_with_accounts
@pytest.mark.dirty(reason="leaves files in XRD containers")
@pytest.mark.noparallel(groups=[NoParallelGroups.XRD, NoParallelGroups.SUBMITTER, NoParallelGroups.POLLER, NoParallelGroups.FINISHER])
@pytest.mark.parametrize("caches_mock", [{"caches_to_mock": [
'rucio.core.rse_expression_parser.REGION', # The list of multihop RSEs is retrieved by rse expression
]}], indirect=True)
def test_fts_recoverable_failures_handled_on_multihop(vo, did_factory, root_account, replica_client, file_factory, caches_mock, metrics_mock):
"""
Verify that the poller correctly handles recoverable FTS job failures
"""
src_rse = 'XRD1'
src_rse_id = rse_core.get_rse_id(rse=src_rse, vo=vo)
jump_rse = 'XRD3'
jump_rse_id = rse_core.get_rse_id(rse=jump_rse, vo=vo)
dst_rse = 'XRD4'
dst_rse_id = rse_core.get_rse_id(rse=dst_rse, vo=vo)
all_rses = [src_rse_id, jump_rse_id, dst_rse_id]
# Create and upload a real file, but register it with wrong checksum. This will trigger
# a FTS "Recoverable" failure on checksum validation
local_file = file_factory.file_generator()
did = did_factory.random_file_did()
did_factory.upload_client.upload(
[
{
'path': local_file,
'rse': src_rse,
'did_scope': did['scope'].external,
'did_name': did['name'],
'no_register': True,
}
]
)
replica_client.add_replicas(rse=src_rse, files=[{'scope': did['scope'].external, 'name': did['name'], 'bytes': 1, 'adler32': 'aaaaaaaa'}])
rule_core.add_rule(dids=[did], account=root_account, copies=1, rse_expression=dst_rse, grouping='ALL', weight=None, lifetime=None, locked=False, subscription_id=None)
submitter(once=True, rses=[{'id': rse_id} for rse_id in all_rses], group_bulk=2, partition_wait_time=0, transfertype='single', filter_transfertool=None)
request = __wait_for_state_transition(dst_rse_id=dst_rse_id, **did)
assert request['state'] == RequestState.FAILED
request = request_core.get_request_by_did(rse_id=jump_rse_id, **did)
assert request['state'] == RequestState.FAILED
# Each hop is a separate transfer, which will be handled by the poller and marked as failed
assert metrics_mock.get_sample_value('rucio_daemons_conveyor_poller_update_request_state_total', labels={'updated': 'True'}) >= 2
@skip_rse_tests_with_accounts
@pytest.mark.dirty(reason="leaves files in XRD containers")
@pytest.mark.noparallel(groups=[NoParallelGroups.XRD, NoParallelGroups.SUBMITTER, NoParallelGroups.POLLER, NoParallelGroups.FINISHER])
@pytest.mark.parametrize("caches_mock", [{"caches_to_mock": [
'rucio.core.rse_expression_parser.REGION', # The list of multihop RSEs is retrieved by rse expression
]}], indirect=True)
def test_multisource(vo, did_factory, root_account, replica_client, caches_mock, metrics_mock):
src_rse1 = 'XRD4'
src_rse1_id = rse_core.get_rse_id(rse=src_rse1, vo=vo)
src_rse2 = 'XRD1'
src_rse2_id = rse_core.get_rse_id(rse=src_rse2, vo=vo)
dst_rse = 'XRD3'
dst_rse_id = rse_core.get_rse_id(rse=dst_rse, vo=vo)
all_rses = [src_rse1_id, src_rse2_id, dst_rse_id]
# Add a good replica on the RSE which has a higher distance ranking
did = did_factory.upload_test_file(src_rse1)
# Add non-existing replica which will fail during multisource transfers on the RSE with lower cost (will be the preferred source)
replica_client.add_replicas(rse=src_rse2, files=[{'scope': did['scope'].external, 'name': did['name'], 'bytes': 1, 'adler32': 'aaaaaaaa'}])
# Submit indirectly, via a container, to test this case
dataset = did_factory.make_dataset()
did_core.attach_dids(dids=[did], account=root_account, **dataset)
container = did_factory.make_container()
did_core.attach_dids(dids=[dataset], account=root_account, **container)
rule_core.add_rule(dids=[container], account=root_account, copies=1, rse_expression=dst_rse, grouping='ALL', weight=None, lifetime=None, locked=False, subscription_id=None)
submitter(once=True, rses=[{'id': rse_id} for rse_id in all_rses], group_bulk=2, partition_wait_time=0, transfertype='single', filter_transfertool=None)
@read_session
def __source_exists(src_rse_id, scope, name, *, session=None):
return session.query(models.Source) \
.filter(models.Source.rse_id == src_rse_id) \
.filter(models.Source.scope == scope) \
.filter(models.Source.name == name) \
.count() != 0
# Entries in the source table must be created for both sources of the multi-source transfer
assert __source_exists(src_rse_id=src_rse1_id, **did)
assert __source_exists(src_rse_id=src_rse2_id, **did)
# After submission, the source rse is the one which will fail
request = request_core.get_request_by_did(rse_id=dst_rse_id, **did)
assert request['source_rse'] == src_rse2
assert request['source_rse_id'] == src_rse2_id
# The source_rse must be updated to the correct one
request = __wait_for_state_transition(dst_rse_id=dst_rse_id, **did)
assert request['source_rse'] == src_rse1
assert request['source_rse_id'] == src_rse1_id
replica = __wait_for_replica_transfer(dst_rse_id=dst_rse_id, **did)
assert replica['state'] == ReplicaState.AVAILABLE
# Both entries in source table must be removed after completion
assert not __source_exists(src_rse_id=src_rse1_id, **did)
assert not __source_exists(src_rse_id=src_rse2_id, **did)
# Only one request was handled; doesn't matter that it's multisource
assert metrics_mock.get_sample_value('rucio_daemons_conveyor_finisher_handle_requests_total') >= 1
assert metrics_mock.get_sample_value('rucio_daemons_conveyor_poller_update_request_state_total', labels={'updated': 'True'}) >= 1
assert metrics_mock.get_sample_value(
'rucio_core_request_get_next_requests_total',
labels={
'request_type': 'TRANSFER.STAGEIN.STAGEOUT',
'state': 'DONE.FAILED.LOST.SUBMISSION_FAILED.NO_SOURCES.ONLY_TAPE_SOURCES.MISMATCH_SCHEME'}
)
@skip_rse_tests_with_accounts
@pytest.mark.dirty(reason="leaves files in XRD containers")
@pytest.mark.noparallel(groups=[NoParallelGroups.XRD, NoParallelGroups.SUBMITTER, NoParallelGroups.RECEIVER])
def test_multisource_receiver(vo, did_factory, replica_client, root_account, metrics_mock, message_mock):
"""
Run receiver as a background thread to automatically handle fts notifications.
Ensure that a multi-source job in which the first source fails is correctly handled by receiver.
"""
receiver_thread = threading.Thread(target=receiver, kwargs={'id_': 0, 'all_vos': True, 'total_threads': 1})
receiver_thread.start()
try:
src_rse1 = 'XRD4'
src_rse1_id = rse_core.get_rse_id(rse=src_rse1, vo=vo)
src_rse2 = 'XRD1'
src_rse2_id = rse_core.get_rse_id(rse=src_rse2, vo=vo)
dst_rse = 'XRD3'
dst_rse_id = rse_core.get_rse_id(rse=dst_rse, vo=vo)
all_rses = [src_rse1_id, src_rse2_id, dst_rse_id]
# Add a good replica on the RSE which has a higher distance ranking
did = did_factory.upload_test_file(src_rse1)
# Add non-existing replica which will fail during multisource transfers on the RSE with lower cost (will be the preferred source)
replica_client.add_replicas(rse=src_rse2, files=[{'scope': did['scope'].external, 'name': did['name'], 'bytes': 1, 'adler32': 'aaaaaaaa'}])
# submit using indirectly via a dataset to test this case
dataset = did_factory.make_dataset()
did_core.attach_dids(dids=[did], account=root_account, **dataset)
did_core.set_metadata(did['scope'], did['name'], 'datatype', 'RAW')
rule_core.add_rule(dids=[dataset], account=root_account, copies=1, rse_expression=dst_rse, grouping='ALL', weight=None, lifetime=None, locked=False, subscription_id=None)
submitter(once=True, rses=[{'id': rse_id} for rse_id in all_rses], group_bulk=2, partition_wait_time=0, transfertype='single', filter_transfertool=None)
# After submission, the source rse is the one which will fail
request = request_core.get_request_by_did(rse_id=dst_rse_id, **did)
assert request['source_rse'] == src_rse2
assert request['source_rse_id'] == src_rse2_id
request = {}
for _ in range(MAX_POLL_WAIT_SECONDS):
request = request_core.get_request_by_did(rse_id=dst_rse_id, **did)
# The request must not be marked as failed. Not even temporarily. It is a multi-source transfer and the
# the first, failed, source must not change the replica state. We must wait for all sources to be tried.
assert request['state'] != RequestState.FAILED
if request['state'] == RequestState.DONE:
break
time.sleep(1)
assert request['state'] == RequestState.DONE
assert metrics_mock.get_sample_value('rucio_daemons_conveyor_receiver_update_request_state_total', labels={'updated': 'True'}) >= 1
# The source was updated to the good one
assert request['source_rse'] == src_rse1
assert request['source_rse_id'] == src_rse1_id
# Test the content of generated messages
msgs = message_core.retrieve_messages()
msg_submitted = next(msg for msg in msgs if msg['event_type'] == 'transfer-submitted')
assert msg_submitted['payload']['request-id'] == request['id']
assert msg_submitted['payload']['datatype'] == 'RAW'
assert msg_submitted['payload']['datasetScope'] == dataset['scope'].external
assert msg_submitted['payload']['dataset'] == dataset['name']
msg_done = next(msg for msg in msgs if msg['event_type'] == 'transfer-done')
assert msg_done['payload']['request-id'] == request['id']
assert msg_done['payload']['datatype'] == 'RAW'
assert msg_done['payload']['datasetScope'] == dataset['scope'].external
assert msg_done['payload']['dataset'] == dataset['name']
assert msg_done['payload']['transfer_link'].startswith('https://fts:8449/')
finally:
receiver_graceful_stop.set()
receiver_thread.join(timeout=5)
receiver_graceful_stop.clear()
@skip_rse_tests_with_accounts
@pytest.mark.noparallel(groups=[NoParallelGroups.XRD, NoParallelGroups.SUBMITTER, NoParallelGroups.RECEIVER])
@pytest.mark.parametrize("caches_mock", [{"caches_to_mock": [
'rucio.core.rse_expression_parser.REGION', # The list of multihop RSEs is retrieved by rse expression
]}], indirect=True)
def test_multihop_receiver_on_failure(vo, did_factory, replica_client, root_account, caches_mock, metrics_mock):
"""
Verify that the receiver correctly handles multihop jobs which fail
"""
receiver_thread = threading.Thread(target=receiver, kwargs={'id_': 0, 'all_vos': True, 'total_threads': 1})
receiver_thread.start()
try:
src_rse = 'XRD1'
src_rse_id = rse_core.get_rse_id(rse=src_rse, vo=vo)
jump_rse = 'XRD3'
jump_rse_id = rse_core.get_rse_id(rse=jump_rse, vo=vo)
dst_rse = 'XRD4'
dst_rse_id = rse_core.get_rse_id(rse=dst_rse, vo=vo)
all_rses = [src_rse_id, jump_rse_id, dst_rse_id]
# Register a did which doesn't exist. It will trigger a failure error during the FTS transfer.
did = did_factory.random_file_did()
replica_client.add_replicas(rse=src_rse, files=[{'scope': did['scope'].external, 'name': did['name'], 'bytes': 1, 'adler32': 'aaaaaaaa'}])
rule_core.add_rule(dids=[did], account=root_account, copies=1, rse_expression=dst_rse, grouping='ALL', weight=None, lifetime=None, locked=False, subscription_id=None)
submitter(once=True, rses=[{'id': rse_id} for rse_id in all_rses], group_bulk=2, partition_wait_time=0, transfertype='single', filter_transfertool=None)
request = __wait_for_state_transition(dst_rse_id=jump_rse_id, run_poller=False, **did)
assert request['state'] == RequestState.FAILED
request = __wait_for_state_transition(dst_rse_id=dst_rse_id, run_poller=False, **did)
assert request['state'] == RequestState.FAILED
assert 'Unused hop in multi-hop' in request['err_msg']
assert metrics_mock.get_sample_value('rucio_daemons_conveyor_receiver_update_request_state_total', labels={'updated': 'True'}) >= 1
# Finisher will handle transfers of the same multihop one hop at a time
finisher(once=True, partition_wait_time=0)
finisher(once=True, partition_wait_time=0)
# The intermediate request must not be re-scheduled by finisher
with pytest.raises(RequestNotFound):
request_core.get_request_by_did(rse_id=jump_rse_id, **did)
request = request_core.get_request_by_did(rse_id=dst_rse_id, **did)
# ensure tha the ranking was correctly decreased for the whole path
assert __get_source(request_id=request['id'], src_rse_id=jump_rse_id, **did).ranking == -1
assert __get_source(request_id=request['id'], src_rse_id=src_rse_id, **did).ranking == -1
assert request['state'] == RequestState.QUEUED
finally:
receiver_graceful_stop.set()
receiver_thread.join(timeout=5)
receiver_graceful_stop.clear()
@skip_rse_tests_with_accounts
@pytest.mark.noparallel(groups=[NoParallelGroups.XRD, NoParallelGroups.SUBMITTER, NoParallelGroups.RECEIVER])
@pytest.mark.parametrize("caches_mock", [{"caches_to_mock": [
'rucio.core.rse_expression_parser.REGION', # The list of multihop RSEs is retrieved by rse expression
]}], indirect=True)
def test_multihop_receiver_on_success(vo, did_factory, root_account, caches_mock, metrics_mock):
"""
Verify that the receiver correctly handles successful multihop jobs
"""
receiver_thread = threading.Thread(target=receiver, kwargs={'id_': 0, 'all_vos': True, 'total_threads': 1})
receiver_thread.start()
try:
src_rse = 'XRD1'
src_rse_id = rse_core.get_rse_id(rse=src_rse, vo=vo)
jump_rse = 'XRD3'
jump_rse_id = rse_core.get_rse_id(rse=jump_rse, vo=vo)
dst_rse = 'XRD4'
dst_rse_id = rse_core.get_rse_id(rse=dst_rse, vo=vo)
all_rses = [src_rse_id, jump_rse_id, dst_rse_id]
did = did_factory.upload_test_file(src_rse)
rule_priority = 5
rule_core.add_rule(dids=[did], account=root_account, copies=1, rse_expression=dst_rse, grouping='ALL', weight=None, lifetime=3600, locked=False, subscription_id=None, priority=rule_priority)
submitter(once=True, rses=[{'id': rse_id} for rse_id in all_rses], group_bulk=2, partition_wait_time=0, transfertype='single', filter_transfertool=None)
request = __wait_for_state_transition(dst_rse_id=jump_rse_id, run_poller=False, **did)
assert request['state'] == RequestState.DONE
request = __wait_for_state_transition(dst_rse_id=dst_rse_id, run_poller=False, **did)
assert request['state'] == RequestState.DONE
fts_response = FTS3Transfertool(external_host=TEST_FTS_HOST).bulk_query({request['external_id']: {request['id']: request}})
fts_response = fts_response[request['external_id']][request['id']]
assert fts_response.job_response['priority'] == rule_priority
# Two hops; both handled by receiver
assert metrics_mock.get_sample_value('rucio_daemons_conveyor_receiver_update_request_state_total', labels={'updated': 'True'}) >= 2
finally:
receiver_graceful_stop.set()
receiver_thread.join(timeout=5)
receiver_graceful_stop.clear()
@skip_rse_tests_with_accounts
@pytest.mark.dirty(reason="leaves files in XRD containers")
@pytest.mark.noparallel(groups=[NoParallelGroups.XRD, NoParallelGroups.SUBMITTER, NoParallelGroups.RECEIVER, NoParallelGroups.POLLER])
@pytest.mark.parametrize("caches_mock", [{"caches_to_mock": [
'rucio.core.rse.REGION',
'rucio.core.rse_expression_parser.REGION',
'rucio.rse.rsemanager.RSE_REGION', # for RSE info
]}], indirect=True)
def test_receiver_archiving(vo, did_factory, root_account, caches_mock, scitags_mock):
"""
Ensure that receiver doesn't mark archiving requests as DONE
"""
src_rse = 'XRD3'
src_rse_id = rse_core.get_rse_id(rse=src_rse, vo=vo)
dst_rse = 'XRD4'
dst_rse_id = rse_core.get_rse_id(rse=dst_rse, vo=vo)
all_rses = [src_rse_id, dst_rse_id]
received_messages = {}
class ReceiverWrapper(Receiver):
"""
Wrap receiver to record the last handled message for each given request_id
"""
def _perform_request_update(self, msg, *, session=None, logger=logging.log):
ret = super()._perform_request_update(msg, session=session, logger=logger)
received_messages[msg['file_metadata']['request_id']] = msg
return ret
with patch('rucio.daemons.conveyor.receiver.Receiver', ReceiverWrapper):
receiver_thread = threading.Thread(target=receiver, kwargs={'id_': 0, 'all_vos': True, 'total_threads': 1})
receiver_thread.start()
# Fake that destination RSE is a tape
rse_core.update_rse(rse_id=dst_rse_id, parameters={'rse_type': RSEType.TAPE})
try:
rse_core.add_rse_attribute(dst_rse_id, 'archive_timeout', 60)
did = did_factory.upload_test_file(src_rse)
rule_core.add_rule(dids=[did], account=root_account, copies=1, rse_expression=dst_rse, grouping='ALL', weight=None, lifetime=None, locked=False, subscription_id=None, activity='test')
submitter(once=True, rses=[{'id': rse_id} for rse_id in all_rses], group_bulk=2, partition_wait_time=0, transfertype='single', filter_transfertool=None)
# Wait for the reception of the FTS Completion message for the submitted request
request = request_core.get_request_by_did(rse_id=dst_rse_id, **did)
for i in range(MAX_POLL_WAIT_SECONDS):
if request['id'] in received_messages:
break
if i == MAX_POLL_WAIT_SECONDS - 1:
assert False # Waited too long; fail the test
time.sleep(1)
assert __wait_for_fts_state(request, expected_state='ARCHIVING') == 'ARCHIVING'
# Receiver must not mark "ARCHIVING" requests as "DONE"
request = request_core.get_request_by_did(rse_id=dst_rse_id, **did)
assert received_messages[request['id']].get('scitag') == 2 << 6 | 18 # 'atlas' experiment: 2; 'test' activity: 18
assert request['state'] == RequestState.SUBMITTED
# Poller should also correctly handle "ARCHIVING" transfers and not mark them as DONE
poller(once=True, older_than=0, partition_wait_time=0)
request = request_core.get_request_by_did(rse_id=dst_rse_id, **did)
assert request['state'] == RequestState.SUBMITTED
finally:
rse_core.update_rse(rse_id=dst_rse_id, parameters={'rse_type': RSEType.DISK})
rse_core.del_rse_attribute(dst_rse_id, 'archive_timeout')
receiver_graceful_stop.set()
receiver_thread.join(timeout=5)
receiver_graceful_stop.clear()
@skip_rse_tests_with_accounts
@pytest.mark.noparallel(groups=[NoParallelGroups.PREPARER, NoParallelGroups.THROTTLER, NoParallelGroups.SUBMITTER, NoParallelGroups.POLLER])
@pytest.mark.parametrize("file_config_mock", [{
"overrides": [('conveyor', 'use_preparer', 'true')]
}], indirect=True)
def test_preparer_throttler_submitter(rse_factory, did_factory, root_account, file_config_mock, metrics_mock):
"""
Integration test of the preparer/throttler workflow.
"""
src_rse, src_rse_id = rse_factory.make_rse(scheme='mock', protocol_impl='rucio.rse.protocols.posix.Default')
dst_rse1, dst_rse_id1 = rse_factory.make_rse(scheme='mock', protocol_impl='rucio.rse.protocols.posix.Default')
dst_rse2, dst_rse_id2 = rse_factory.make_rse(scheme='mock', protocol_impl='rucio.rse.protocols.posix.Default')
all_rses = [src_rse_id, dst_rse_id1, dst_rse_id2]
for rse_id in all_rses:
rse_core.add_rse_attribute(rse_id, 'fts', TEST_FTS_HOST)
distance_core.add_distance(src_rse_id, dst_rse_id1, distance=10)
distance_core.add_distance(src_rse_id, dst_rse_id2, distance=10)
# Set limits only for one of the RSEs
request_core.set_transfer_limit(dst_rse1, max_transfers=1, activity='all_activities', strategy='fifo')
did1 = did_factory.upload_test_file(src_rse)
did2 = did_factory.upload_test_file(src_rse)
rule_core.add_rule(dids=[did1], account=root_account, copies=1, rse_expression=dst_rse1, grouping='ALL', weight=None, lifetime=3600, locked=False, subscription_id=None)
rule_core.add_rule(dids=[did2], account=root_account, copies=1, rse_expression=dst_rse1, grouping='ALL', weight=None, lifetime=3600, locked=False, subscription_id=None)
rule_core.add_rule(dids=[did1], account=root_account, copies=1, rse_expression=dst_rse2, grouping='ALL', weight=None, lifetime=None, locked=False, subscription_id=None)
request = request_core.get_request_by_did(rse_id=dst_rse_id1, **did1)
assert request['state'] == RequestState.PREPARING
request = request_core.get_request_by_did(rse_id=dst_rse_id1, **did2)
assert request['state'] == RequestState.PREPARING
request = request_core.get_request_by_did(rse_id=dst_rse_id2, **did1)
assert request['state'] == RequestState.PREPARING
# submitter must not work on PREPARING replicas
submitter(once=True, rses=[{'id': rse_id} for rse_id in all_rses], group_bulk=2, partition_wait_time=0, transfertype='single', filter_transfertool=None)
# One RSE has limits set: the requests will be moved to WAITING status; the other RSE has no limits: go directly to queued
preparer(once=True, sleep_time=1, bulk=100, partition_wait_time=0, ignore_availability=False)
request = request_core.get_request_by_did(rse_id=dst_rse_id1, **did1)
assert request['state'] == RequestState.WAITING
request = request_core.get_request_by_did(rse_id=dst_rse_id1, **did2)
assert request['state'] == RequestState.WAITING
request = request_core.get_request_by_did(rse_id=dst_rse_id2, **did1)
assert request['state'] == RequestState.QUEUED
# submitter must not work on WAITING replicas
submitter(once=True, rses=[{'id': rse_id} for rse_id in all_rses], group_bulk=2, partition_wait_time=0, transfertype='single', filter_transfertool=None)
# One of the waiting requests will be queued, the second will remain in waiting state
throttler(once=True, partition_wait_time=0)
# Check metrics.
# This gauge values are recorded at the beginning of the execution. Hence 2 waiting and 0 transfers
gauge_name = 'rucio_daemons_conveyor_throttler_rse_transfer_limits'
assert metrics_mock.get_sample_value(gauge_name, labels={'activity': 'all_activities', 'rse': dst_rse1, 'limit_attr': 'residual_capacity'}) == 1
assert metrics_mock.get_sample_value(gauge_name, labels={'activity': 'all_activities', 'rse': dst_rse1, 'limit_attr': 'max_transfers'}) == 1
assert metrics_mock.get_sample_value(gauge_name, labels={'activity': 'all_activities', 'rse': dst_rse1, 'limit_attr': 'active'}) == 0
assert metrics_mock.get_sample_value(gauge_name, labels={'activity': 'all_activities', 'rse': dst_rse1, 'limit_attr': 'waiting'}) == 2
request1 = request_core.get_request_by_did(rse_id=dst_rse_id1, **did1)
request2 = request_core.get_request_by_did(rse_id=dst_rse_id1, **did2)
# one request WAITING and other QUEUED
assert (request1['state'] == RequestState.WAITING and request2['state'] == RequestState.QUEUED
or request1['state'] == RequestState.QUEUED and request2['state'] == RequestState.WAITING)
waiting_did = did1 if request1['state'] == RequestState.WAITING else did2
queued_did = did1 if request1['state'] == RequestState.QUEUED else did2
submitter(once=True, rses=[{'id': rse_id} for rse_id in all_rses], group_bulk=2, partition_wait_time=0, transfertype='single', filter_transfertool=None)
# Calling the throttler again will not schedule the waiting request, because there is a submitted one
throttler(once=True, partition_wait_time=0)
# This gauge values are recorded at the beginning of the execution. Hence 1 waiting and one transfer
assert metrics_mock.get_sample_value(gauge_name, labels={'activity': 'all_activities', 'rse': dst_rse1, 'limit_attr': 'residual_capacity'}) == 0
assert metrics_mock.get_sample_value(gauge_name, labels={'activity': 'all_activities', 'rse': dst_rse1, 'limit_attr': 'max_transfers'}) == 1
assert metrics_mock.get_sample_value(gauge_name, labels={'activity': 'all_activities', 'rse': dst_rse1, 'limit_attr': 'active'}) == 1
assert metrics_mock.get_sample_value(gauge_name, labels={'activity': 'all_activities', 'rse': dst_rse1, 'limit_attr': 'waiting'}) == 1
request = request_core.get_request_by_did(rse_id=dst_rse_id1, **waiting_did)
assert request['state'] == RequestState.WAITING
request = __wait_for_state_transition(dst_rse_id=dst_rse_id1, **queued_did)
assert request['state'] == RequestState.DONE
request = __wait_for_state_transition(dst_rse_id=dst_rse_id2, **did1)
assert request['state'] == RequestState.DONE
# Now that the submitted transfers are finished, the WAITING one can be queued
throttler(once=True, partition_wait_time=0)
request = request_core.get_request_by_did(rse_id=dst_rse_id1, **waiting_did)
assert request['state'] == RequestState.QUEUED
# Check that resetting stale waiting requests works properly
request_core.set_transfer_limit(dst_rse2, max_transfers=1, activity='all_activities', strategy='fifo')
did3 = did_factory.upload_test_file(src_rse)
did4 = did_factory.upload_test_file(src_rse)
rule_core.add_rule(dids=[did3], account=root_account, copies=1, rse_expression=dst_rse2, grouping='ALL',
weight=None, lifetime=3600, locked=False, subscription_id=None)
rule_core.add_rule(dids=[did4], account=root_account, copies=1, rse_expression=dst_rse2, grouping='ALL',
weight=None, lifetime=3600, locked=False, subscription_id=None)
request3 = request_core.get_request_by_did(rse_id=dst_rse_id2, **did3)
request4 = request_core.get_request_by_did(rse_id=dst_rse_id2, **did4)
assert request3['state'] == RequestState.PREPARING
assert request4['state'] == RequestState.PREPARING
# Run the preparer so requests are in waiting state
preparer(once=True, sleep_time=1, bulk=100, partition_wait_time=0, ignore_availability=False)
request3 = request_core.get_request_by_did(rse_id=dst_rse_id2, **did3)
request4 = request_core.get_request_by_did(rse_id=dst_rse_id2, **did4)
assert request3['state'] == RequestState.WAITING
assert request4['state'] == RequestState.WAITING
# Artificially set both requests' last_processed_at timestamp as >1 day old
@transactional_session
def __set_process_timestamp(request_ids, timestamp, *, session=None):
stmt = update(
models.Request
).where(
models.Request.id.in_(request_ids)
).values(
{
models.Request.last_processed_at: timestamp
}
)
session.execute(stmt)
__set_process_timestamp([request['id'] for request in [request3, request4]], datetime.utcnow() - timedelta(days=2))
# Run throttler: one request reset to PREPARING state and Null source_rse_id, and one request QUEUED
throttler(once=True, partition_wait_time=0)
request3 = request_core.get_request_by_did(rse_id=dst_rse_id2, **did3)
request4 = request_core.get_request_by_did(rse_id=dst_rse_id2, **did4)
assert ((request3['source_rse_id'] is None and request3['state'] == RequestState.PREPARING and request4['state'] == RequestState.QUEUED)
or (request4['source_rse_id'] is None and request4['state'] == RequestState.PREPARING and request3['state'] == RequestState.QUEUED))
@skip_rse_tests_with_accounts
@pytest.mark.dirty(reason="leaves files in XRD containers")
@pytest.mark.noparallel(groups=[NoParallelGroups.XRD, NoParallelGroups.SUBMITTER, NoParallelGroups.POLLER, NoParallelGroups.FINISHER])
@pytest.mark.parametrize("caches_mock", [{"caches_to_mock": [
'rucio.core.rse.REGION',
'rucio.rse.rsemanager.RSE_REGION', # for RSE info
]}], indirect=True)
def test_non_deterministic_dst(did_factory, did_client, root_account, vo, caches_mock):
"""
Test a transfer towards a non-deterministic RSE
"""
src_rse = 'XRD3'
src_rse_id = rse_core.get_rse_id(rse=src_rse, vo=vo)
dst_rse = 'XRD4'
dst_rse_id = rse_core.get_rse_id(rse=dst_rse, vo=vo)
all_rses = [src_rse_id, dst_rse_id]
did = did_factory.upload_test_file(src_rse)
# Dataset name is part of the non-deterministic path
dataset = did_factory.make_dataset()
did_client.add_files_to_dataset(files=[{'scope': did['scope'].external, 'name': did['name']}], scope=dataset['scope'].external, name=dataset['name'])
rse_core.update_rse(rse_id=dst_rse_id, parameters={'deterministic': False})
try:
rule_core.add_rule(dids=[did], account=root_account, copies=1, rse_expression=dst_rse, grouping='ALL', weight=None, lifetime=None, locked=False, subscription_id=None)
submitter(once=True, rses=[{'id': rse_id} for rse_id in all_rses], group_bulk=2, partition_wait_time=0, transfertype='single', filter_transfertool=None)
replica = __wait_for_replica_transfer(dst_rse_id=dst_rse_id, **did)
assert replica['state'] == ReplicaState.AVAILABLE
finally:
rse_core.update_rse(rse_id=dst_rse_id, parameters={'deterministic': True})
@skip_rse_tests_with_accounts
@pytest.mark.noparallel(groups=[NoParallelGroups.STAGER, NoParallelGroups.POLLER, NoParallelGroups.FINISHER])
def test_stager(rse_factory, did_factory, root_account, replica_client):
"""
Submit a real transfer to FTS and rely on the gfal "mock" plugin to report a simulated "success"
https://gitlab.cern.ch/dmc/gfal2/-/blob/master/src/plugins/mock/README_PLUGIN_MOCK
"""
src_rse, src_rse_id = rse_factory.make_rse(scheme='mock', protocol_impl='rucio.rse.protocols.posix.Default', rse_type=RSEType.TAPE)
dst_rse, dst_rse_id = rse_factory.make_rse(scheme='mock', protocol_impl='rucio.rse.protocols.posix.Default')
all_rses = [src_rse_id, dst_rse_id]
distance_core.add_distance(src_rse_id, dst_rse_id, distance=10)
rse_core.add_rse_attribute(src_rse_id, 'staging_buffer', dst_rse)
for rse_id in all_rses:
rse_core.add_rse_attribute(rse_id, 'fts', TEST_FTS_HOST)
did = did_factory.upload_test_file(src_rse)
replica = replica_core.get_replica(rse_id=src_rse_id, **did)
replica_client.add_replicas(rse=dst_rse, files=[{'scope': did['scope'].external, 'name': did['name'], 'state': 'C',
'bytes': replica['bytes'], 'adler32': replica['adler32'], 'md5': replica['md5']}])
request_core.queue_requests(requests=[{'dest_rse_id': dst_rse_id,
'scope': did['scope'],
'name': did['name'],
'rule_id': '00000000000000000000000000000000',
'attributes': {
'source_replica_expression': src_rse,
'activity': 'Some Activity',
'bytes': replica['bytes'],
'adler32': replica['adler32'],
'md5': replica['md5'],
},
'request_type': RequestType.STAGEIN,
'retry_count': 0,
'account': root_account,
'requested_at': datetime.utcnow()}])
stager(once=True, rses=[{'id': rse_id} for rse_id in all_rses])
replica = __wait_for_replica_transfer(dst_rse_id=dst_rse_id, max_wait_seconds=2 * MAX_POLL_WAIT_SECONDS, **did)
assert replica['state'] == ReplicaState.AVAILABLE
@pytest.mark.noparallel(groups=[NoParallelGroups.SUBMITTER, NoParallelGroups.FINISHER])
def test_transfer_to_mas_existing_replica(rse_factory, did_factory, root_account, jdoe_account):
"""
Test qos: transfer from tape to disk
Assert rse maximum_pin_lifetime is passed to transfer tool in the transfer request
Test rule and lock state transitions
"""
src_rse, src_rse_id = rse_factory.make_rse(scheme='mock', protocol_impl='rucio.rse.protocols.posix.Default', rse_type=RSEType.TAPE)
dst_rse, dst_rse_id = rse_factory.make_rse(scheme='mock', protocol_impl='rucio.rse.protocols.posix.Default', rse_type=RSEType.DISK)
all_rses = [src_rse_id, dst_rse_id]
maximum_pin_lifetime = 86400
distance_core.add_distance(src_rse_id, dst_rse_id, distance=10)
rse_core.add_rse_attribute(dst_rse_id, 'staging_required', True)
rse_core.add_rse_attribute(dst_rse_id, 'maximum_pin_lifetime', maximum_pin_lifetime)
did = did_factory.upload_test_file(rse_name=src_rse)
rule1_id = rule_core.add_rule(dids=[did], account=root_account, copies=1, rse_expression=dst_rse, grouping='ALL', weight=None, lifetime=-1, locked=False, subscription_id=None)[0]
request = request_core.get_request_by_did(rse_id=dst_rse_id, **did)
assert request['request_type'] == RequestType.TRANSFER
submitter(once=True, rses=[{'id': dst_rse_id}], partition_wait_time=0, transfertools=['mock'], transfertype='single', filter_transfertool=None)
assert lock_core.get_replica_locks_for_rule_id(rule_id=rule1_id)[0]['state'] == LockState.REPLICATING
assert rule_core.get_rule(rule1_id)['state'] == RuleState.REPLICATING
replica = __wait_for_replica_transfer(dst_rse_id=dst_rse_id, transfertool='mock', **did)
assert replica['state'] == ReplicaState.AVAILABLE
assert rule_core.get_rule(rule1_id)['state'] == RuleState.OK
# assert all replicas available
for rse_id in all_rses:
assert replica_core.get_replica(rse_id=rse_id, **did)['state'] == ReplicaState.AVAILABLE
# now test a second rule, different account
set_local_account_limit(jdoe_account, dst_rse_id, bytes_=-1)
rule2_id = rule_core.add_rule(dids=[did], account=jdoe_account, copies=1, rse_expression=dst_rse, grouping='ALL', weight=None, lifetime=-1, locked=False, subscription_id=None, source_replica_expression=dst_rse)[0]
request = request_core.get_request_by_did(rse_id=dst_rse_id, **did)
assert request['request_type'] == RequestType.STAGEIN
stager(once=True, rses=[{'id': dst_rse_id}])
assert request['attributes']['lifetime'] == str(maximum_pin_lifetime)
assert lock_core.get_replica_locks_for_rule_id(rule_id=rule2_id)[0]['state'] == LockState.REPLICATING
assert rule_core.get_rule(rule2_id)['state'] == RuleState.REPLICATING
# mock a successful stagein
request = request_core.get_request(request_id=request['id'])
request_core.transition_request_state(request_id=request['id'], state=RequestState.DONE, external_id=request['external_id'])
finisher(once=True, partition_wait_time=0)
assert lock_core.get_replica_locks_for_rule_id(rule_id=rule1_id)[0]['state'] == LockState.OK
assert rule_core.get_rule(rule1_id)['state'] == RuleState.OK
assert lock_core.get_replica_locks_for_rule_id(rule_id=rule2_id)[0]['state'] == LockState.OK
assert rule_core.get_rule(rule2_id)['state'] == RuleState.OK
@pytest.mark.noparallel(groups=[NoParallelGroups.SUBMITTER, NoParallelGroups.POLLER, NoParallelGroups.FINISHER])
def test_failed_transfers_to_mas_existing_replica(rse_factory, did_factory, root_account, jdoe_account):
"""
Test qos: transfer from tape to disk
Assert rse maximum_pin_lifetime is passed to transfer tool in the transfer request
Test rule and lock state transitions
"""
src_rse, src_rse_id = rse_factory.make_rse(scheme='mock', protocol_impl='rucio.rse.protocols.posix.Default', rse_type=RSEType.TAPE)
dst_rse, dst_rse_id = rse_factory.make_rse(scheme='mock', protocol_impl='rucio.rse.protocols.posix.Default', rse_type=RSEType.DISK)
maximum_pin_lifetime = 86400
distance_core.add_distance(src_rse_id, dst_rse_id, distance=10)
rse_core.add_rse_attribute(dst_rse_id, 'staging_required', True)
rse_core.add_rse_attribute(dst_rse_id, 'maximum_pin_lifetime', maximum_pin_lifetime)
did = did_factory.upload_test_file(rse_name=src_rse)
rule1_id = rule_core.add_rule(dids=[did], account=root_account, copies=1, rse_expression=dst_rse, grouping='ALL', weight=None, lifetime=-1, locked=False, subscription_id=None)[0]
request = request_core.get_request_by_did(rse_id=dst_rse_id, **did)
assert request['request_type'] == RequestType.TRANSFER
submitter(once=True, rses=[{'id': dst_rse_id}], partition_wait_time=0, transfertools=['mock'], transfertype='single', filter_transfertool=None)
assert lock_core.get_replica_locks_for_rule_id(rule_id=rule1_id)[0]['state'] == LockState.REPLICATING
assert rule_core.get_rule(rule1_id)['state'] == RuleState.REPLICATING
# mock a failed transfer
request = request_core.get_request(request_id=request['id'])
request_core.transition_request_state(request_id=request['id'], state=RequestState.FAILED, external_id=request['external_id'])
finisher(once=True, partition_wait_time=0)
lock_core.failed_transfer(scope=did['scope'], name=did['name'], rse_id=dst_rse_id)
assert rule_core.get_rule(rule1_id)['state'] == RuleState.STUCK
assert lock_core.get_replica_locks_for_rule_id(rule_id=rule1_id)[0]['state'] == LockState.STUCK
# now test a second rule, different account
set_local_account_limit(jdoe_account, dst_rse_id, bytes_=-1)
rule2_id = rule_core.add_rule(dids=[did], account=jdoe_account, copies=1, rse_expression=dst_rse, grouping='ALL', weight=None, lifetime=-1, locked=False, subscription_id=None, source_replica_expression=dst_rse)[0]
request = request_core.get_request_by_did(rse_id=dst_rse_id, **did)
# since the first rule is STUCK assert a transfer not stagein
assert request['request_type'] == RequestType.TRANSFER
submitter(once=True, rses=[{'id': dst_rse_id}], partition_wait_time=0, transfertools=['mock'], transfertype='single', filter_transfertool=None)
assert request['attributes']['lifetime'] is None
assert lock_core.get_replica_locks_for_rule_id(rule_id=rule2_id)[0]['state'] == LockState.REPLICATING
assert rule_core.get_rule(rule2_id)['state'] == RuleState.REPLICATING
# mock a failed transfer for the second rule
request = request_core.get_request(request_id=request['id'])
request_core.transition_request_state(request_id=request['id'], state=RequestState.FAILED, external_id=request['external_id'])
finisher(once=True, partition_wait_time=0)
lock_core.failed_transfer(scope=did['scope'], name=did['name'], rse_id=dst_rse_id)
assert lock_core.get_replica_locks_for_rule_id(rule_id=rule1_id)[0]['state'] == LockState.STUCK
assert rule_core.get_rule(rule1_id)['state'] == RuleState.STUCK
assert lock_core.get_replica_locks_for_rule_id(rule_id=rule2_id)[0]['state'] == LockState.STUCK
assert rule_core.get_rule(rule2_id)['state'] == RuleState.STUCK
@skip_rse_tests_with_accounts
@pytest.mark.noparallel(groups=[NoParallelGroups.SUBMITTER, NoParallelGroups.POLLER, NoParallelGroups.FINISHER])
def test_lost_transfers(rse_factory, did_factory, root_account):