#NEWLINE# def test_handoffs_first_mode_will_abort_if_handoffs_remaining( self ) : #NEWLINE# #INDENT# handoff_suffix_paths = [ ] #NEWLINE# for policy in POLICIES : #NEWLINE# #INDENT# ts = next ( self . ts ) #NEWLINE# df = self . df_mgr . get_diskfile ( 'sda' , '1' , 'a' , 'c' , 'o' , policy ) #NEWLINE# with df . create ( ) as w : #NEWLINE# #INDENT# w . write ( 'asdf' ) #NEWLINE# w . put ( { #NEWLINE# #INDENT# 'X-Timestamp' : ts . internal , #NEWLINE# #UNINDENT# } ) #NEWLINE# w . commit ( remote_path ) #NEWLINE# #UNINDENT# handoff_suffix_paths . append ( os . path . dirname ( df . _datadir ) ) #NEWLINE# #UNINDENT# process_arg_checker = [ ( 0 , '' , [ ] ) , ( 1 , '' , [ ] ) , ( 0 , '' , [ ] ) , ( 0 , '' , [ ] ) , ( 0 , '' , [ ] ) , ( 0 , '' , [ ] ) ] #NEWLINE# stub_body = pickle . dumps ( { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } ) #NEWLINE# with _mock_process ( process_arg_checker ) as rsync_log , mock . patch ( 'swift.obj.replicator.whataremyips' , side_effect = _ips ) , mocked_http_conn ( * ( [ 200 ] * 5 ) , body = stub_body ) as conn_log : #NEWLINE# #INDENT# self . replicator . handoffs_first = True #NEWLINE# self . replicator . replicate ( ) #NEWLINE# #UNINDENT# self . assertEqual ( 1 , self . replicator . handoffs_remaining ) #NEWLINE# self . assertEqual ( 8 , self . replicator . job_count ) #NEWLINE# self . assertLessEqual ( self . replicator . replication_count , ( 2 + self . replicator . concurrency ) ) #NEWLINE# found_rsync_suffix_paths = set ( ) #NEWLINE# expected_replicate_requests = set ( ) #NEWLINE# for subprocess_info in rsync_log : #NEWLINE# #INDENT# ( local_path , remote_path ) = subprocess_info [ 'rsync_args' ] [ ( - 2 ) : ] #NEWLINE# found_rsync_suffix_paths . add ( local_path ) #NEWLINE# if ( subprocess_info [ 'ret_code' ] == 0 ) : #NEWLINE# #INDENT# node_ip = remote_path . split ( ':' , 1 ) [ 0 ] #NEWLINE# expected_replicate_requests . add ( node_ip ) #NEWLINE# #UNINDENT# #UNINDENT# self . assertEqual ( set ( handoff_suffix_paths ) , found_rsync_suffix_paths ) #NEWLINE# found_replicate_requests = set ( ) #NEWLINE# self . assertEqual ( 5 , len ( conn_log . requests ) ) #NEWLINE# for req in conn_log . requests : #NEWLINE# #INDENT# self . assertEqual ( req [ 'method' ] , 'REPLICATE' ) #NEWLINE# found_replicate_requests . add ( req [ 'ip' ] ) #NEWLINE# #UNINDENT# self . assertEqual ( expected_replicate_requests , found_replicate_requests ) #NEWLINE# remaining_policies = [ ] #NEWLINE# for path in handoff_suffix_paths : #NEWLINE# #INDENT# if os . path . exists ( path ) : #NEWLINE# #INDENT# policy = diskfile . extract_policy ( path ) #NEWLINE# remaining_policies . append ( policy ) #NEWLINE# #UNINDENT# #UNINDENT# self . assertEqual ( len ( remaining_policies ) , 1 ) #NEWLINE# remaining_policy = remaining_policies [ 0 ] #NEWLINE# with _mock_process ( process_arg_checker ) as rsync_log , mock . patch ( 'swift.obj.replicator.whataremyips' , side_effect = _ips ) , mocked_http_conn ( * ( [ 200 ] * 14 ) , body = stub_body ) as conn_log : #NEWLINE# #INDENT# self . replicator . handoff_delete = 2 #NEWLINE# self . replicator . replicate ( ) #NEWLINE# #UNINDENT# self . assertEqual ( self . replicator . job_count , self . replicator . replication_count ) #NEWLINE# self . assertFalse ( self . replicator . handoffs_remaining ) #NEWLINE# found_replicate_calls = defaultdict ( int ) #NEWLINE# for req in conn_log . requests : #NEWLINE# #INDENT# self . assertEqual ( req [ 'method' ] , 'REPLICATE' ) #NEWLINE# found_replicate_key = ( int ( req [ 'headers' ] [ 'X-Backend-Storage-Policy-Index' ] ) , req [ 'path' ] ) #NEWLINE# found_replicate_calls [ found_replicate_key ] += 1 #NEWLINE# #UNINDENT# expected_replicate_calls = { #NEWLINE# #INDENT# ( int ( remaining_policy ) , '/sda/1/a83' ) : 2 , #NEWLINE# ( 0 , '/sda/0' ) : 2 , #NEWLINE# ( 1 , '/sda/0' ) : 2 , #NEWLINE# ( 0 , '/sda/2' ) : 2 , #NEWLINE# ( 1 , '/sda/2' ) : 2 , #NEWLINE# ( 0 , '/sda/3' ) : 2 , #NEWLINE# ( 1 , '/sda/3' ) : 2 , #NEWLINE# #UNINDENT# } #NEWLINE# self . assertEqual ( dict ( found_replicate_calls ) , expected_replicate_calls ) #NEWLINE# removed_paths = set ( ) #NEWLINE# for path in handoff_suffix_paths : #NEWLINE# #INDENT# if ( not os . path . exists ( path ) ) : #NEWLINE# #INDENT# removed_paths . add ( path ) #NEWLINE# #UNINDENT# #UNINDENT# self . assertEqual ( removed_paths , set ( handoff_suffix_paths ) )