#NEWLINE# def test_delete_partition_ssync_with_cleanup_failure( self ) : #NEWLINE# #INDENT# with mock . patch ( 'swift.obj.replicator.http_connect' , mock_http_connect ( 200 ) ) : #NEWLINE# #INDENT# self . replicator . logger = mock_logger = debug_logger ( 'test-replicator' ) #NEWLINE# df = self . df_mgr . get_diskfile ( 'sda' , '1' , 'a' , 'c' , 'o' , policy = POLICIES . legacy ) #NEWLINE# mkdirs ( df . _datadir ) #NEWLINE# ts = normalize_timestamp ( time . time ( ) ) #NEWLINE# f = open ( os . path . join ( df . _datadir , ( ts + '.data' ) ) , 'wb' ) #NEWLINE# f . write ( '0' ) #NEWLINE# f . close ( ) #NEWLINE# ohash = hash_path ( 'a' , 'c' , 'o' ) #NEWLINE# whole_path_from = storage_directory ( self . objects , 1 , ohash ) #NEWLINE# suffix_dir_path = os . path . dirname ( whole_path_from ) #NEWLINE# part_path = os . path . join ( self . objects , '1' ) #NEWLINE# self . assertTrue ( os . access ( part_path , os . F_OK ) ) #NEWLINE# self . call_nums = 0 #NEWLINE# self . conf [ 'sync_method' ] = 'ssync' #NEWLINE# def _fake_ssync( node , job , suffixes , **kwargs ) : #NEWLINE# #INDENT# success = True #NEWLINE# ret_val = { #NEWLINE# #INDENT# ohash : ts , #NEWLINE# #UNINDENT# } #NEWLINE# if ( self . call_nums == 2 ) : #NEWLINE# #INDENT# success = False #NEWLINE# ret_val = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# #UNINDENT# self . call_nums += 1 #NEWLINE# return ( success , ret_val ) #NEWLINE# #UNINDENT# rmdir_func = os . rmdir #NEWLINE# def raise_exception_rmdir( exception_class , error_no ) : #NEWLINE# #INDENT# instance = exception_class ( ) #NEWLINE# instance . errno = error_no #NEWLINE# def func( directory ) : #NEWLINE# #INDENT# if ( directory == suffix_dir_path ) : #NEWLINE# #INDENT# raise instance #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# rmdir_func ( directory ) #NEWLINE# #UNINDENT# #UNINDENT# return func #NEWLINE# #UNINDENT# self . replicator . sync_method = _fake_ssync #NEWLINE# self . replicator . replicate ( ) #NEWLINE# self . assertTrue ( os . access ( whole_path_from , os . F_OK ) ) #NEWLINE# self . assertTrue ( os . access ( suffix_dir_path , os . F_OK ) ) #NEWLINE# self . assertTrue ( os . access ( part_path , os . F_OK ) ) #NEWLINE# with mock . patch ( 'os.rmdir' , raise_exception_rmdir ( OSError , ENOENT ) ) : #NEWLINE# #INDENT# self . replicator . replicate ( ) #NEWLINE# #UNINDENT# self . assertFalse ( mock_logger . get_lines_for_level ( 'error' ) ) #NEWLINE# self . assertFalse ( os . access ( whole_path_from , os . F_OK ) ) #NEWLINE# self . assertTrue ( os . access ( suffix_dir_path , os . F_OK ) ) #NEWLINE# self . assertTrue ( os . access ( part_path , os . F_OK ) ) #NEWLINE# with mock . patch ( 'os.rmdir' , raise_exception_rmdir ( OSError , ENOTEMPTY ) ) : #NEWLINE# #INDENT# self . replicator . replicate ( ) #NEWLINE# #UNINDENT# self . assertFalse ( mock_logger . get_lines_for_level ( 'error' ) ) #NEWLINE# self . assertFalse ( os . access ( whole_path_from , os . F_OK ) ) #NEWLINE# self . assertTrue ( os . access ( suffix_dir_path , os . F_OK ) ) #NEWLINE# self . assertTrue ( os . access ( part_path , os . F_OK ) ) #NEWLINE# with mock . patch ( 'os.rmdir' , raise_exception_rmdir ( OSError , ENOTDIR ) ) : #NEWLINE# #INDENT# self . replicator . replicate ( ) #NEWLINE# #UNINDENT# self . assertEqual ( len ( mock_logger . get_lines_for_level ( 'error' ) ) , 1 ) #NEWLINE# self . assertFalse ( os . access ( whole_path_from , os . F_OK ) ) #NEWLINE# self . assertTrue ( os . access ( suffix_dir_path , os . F_OK ) ) #NEWLINE# self . assertTrue ( os . access ( part_path , os . F_OK ) ) #NEWLINE# self . replicator . replicate ( ) #NEWLINE# self . assertFalse ( os . access ( whole_path_from , os . F_OK ) ) #NEWLINE# self . assertFalse ( os . access ( suffix_dir_path , os . F_OK ) ) #NEWLINE# self . assertTrue ( os . access ( part_path , os . F_OK ) ) #NEWLINE# self . replicator . replicate ( ) #NEWLINE# self . assertFalse ( os . access ( whole_path_from , os . F_OK ) ) #NEWLINE# self . assertFalse ( os . access ( suffix_dir_path , os . F_OK ) ) #NEWLINE# self . assertFalse ( os . access ( part_path , os . F_OK ) )