#NEWLINE# @ mock . patch ( 'swift.obj.replicator.random.shuffle' , side_effect = ( lambda l : l ) ) #NEWLINE# def test_collect_jobs_multi_disk_servers_per_port( self , mock_shuffle ) : #NEWLINE# #INDENT# devs = [ { #NEWLINE# #INDENT# 'id' : 0 , #NEWLINE# 'device' : 'sda' , #NEWLINE# 'zone' : 0 , #NEWLINE# 'region' : 1 , #NEWLINE# 'ip' : '1.1.1.1' , #NEWLINE# 'port' : 1111 , #NEWLINE# 'replication_ip' : '127.0.0.0' , #NEWLINE# 'replication_port' : 6200 , #NEWLINE# #UNINDENT# } , { #NEWLINE# #INDENT# 'id' : 1 , #NEWLINE# 'device' : 'sdb' , #NEWLINE# 'zone' : 1 , #NEWLINE# 'region' : 1 , #NEWLINE# 'ip' : '1.1.1.1' , #NEWLINE# 'port' : 1111 , #NEWLINE# 'replication_ip' : '127.0.0.0' , #NEWLINE# 'replication_port' : 6200 , #NEWLINE# #UNINDENT# } , { #NEWLINE# #INDENT# 'id' : 2 , #NEWLINE# 'device' : 'sdc' , #NEWLINE# 'zone' : 2 , #NEWLINE# 'region' : 2 , #NEWLINE# 'ip' : '1.1.1.2' , #NEWLINE# 'port' : 1112 , #NEWLINE# 'replication_ip' : '127.0.0.1' , #NEWLINE# 'replication_port' : 6200 , #NEWLINE# #UNINDENT# } , { #NEWLINE# #INDENT# 'id' : 3 , #NEWLINE# 'device' : 'sdd' , #NEWLINE# 'zone' : 4 , #NEWLINE# 'region' : 2 , #NEWLINE# 'ip' : '1.1.1.2' , #NEWLINE# 'port' : 1112 , #NEWLINE# 'replication_ip' : '127.0.0.1' , #NEWLINE# 'replication_port' : 6201 , #NEWLINE# #UNINDENT# } ] #NEWLINE# ( objects_sdb , objects_1_sdb , _ , _ ) = self . _write_disk_data ( 'sdb' ) #NEWLINE# ( objects_sdc , objects_1_sdc , _ , _ ) = self . _write_disk_data ( 'sdc' ) #NEWLINE# ( objects_sdd , objects_1_sdd , _ , _ ) = self . _write_disk_data ( 'sdd' ) #NEWLINE# _create_test_rings ( self . testdir , devs ) #NEWLINE# self . conf [ 'bind_ip' ] = '127.0.0.1' #NEWLINE# self . conf [ 'servers_per_port' ] = 1 #NEWLINE# self . _create_replicator ( ) #NEWLINE# jobs = self . replicator . collect_jobs ( ) #NEWLINE# self . assertEqual ( [ mock . call ( jobs ) ] , devs . mock_calls ) #NEWLINE# jobs_to_delete = [ j for j in jobs if j [ 'delete' ] ] #NEWLINE# self . assertEqual ( len ( jobs_to_delete ) , 4 ) #NEWLINE# self . assertEqual ( [ '3' , '0' , '3' , '0' ] , [ j [ 'partition' ] for j in jobs_to_delete ] ) #NEWLINE# jobs_by_pol_part_dev = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# for job in jobs : #NEWLINE# #INDENT# self . assertTrue ( ( job [ 'device' ] in ( 'sdc' , 'sdd' ) ) ) #NEWLINE# jobs_by_pol_part_dev [ ( ( str ( int ( job [ 'policy' ] ) ) + job [ 'partition' ] ) + job [ 'device' ] ) ] = job #NEWLINE# #UNINDENT# self . assertEqual ( [ node [ 'id' ] for node in jobs_by_pol_part_dev [ '00sdc' ] [ 'nodes' ] ] , [ 0 , 1 ] ) #NEWLINE# self . assertEqual ( [ node [ 'id' ] for node in jobs_by_pol_part_dev [ '00sdd' ] [ 'nodes' ] ] , [ 0 , 1 , 2 ] ) #NEWLINE# self . assertEqual ( [ node [ 'id' ] for node in jobs_by_pol_part_dev [ '01sdc' ] [ 'nodes' ] ] , [ 1 , 3 ] ) #NEWLINE# self . assertEqual ( [ node [ 'id' ] for node in jobs_by_pol_part_dev [ '01sdd' ] [ 'nodes' ] ] , [ 1 , 2 ] ) #NEWLINE# self . assertEqual ( [ node [ 'id' ] for node in jobs_by_pol_part_dev [ '02sdc' ] [ 'nodes' ] ] , [ 3 , 0 ] ) #NEWLINE# self . assertEqual ( [ node [ 'id' ] for node in jobs_by_pol_part_dev [ '02sdd' ] [ 'nodes' ] ] , [ 2 , 0 ] ) #NEWLINE# self . assertEqual ( [ node [ 'id' ] for node in jobs_by_pol_part_dev [ '03sdc' ] [ 'nodes' ] ] , [ 3 , 0 , 1 ] ) #NEWLINE# self . assertEqual ( [ node [ 'id' ] for node in jobs_by_pol_part_dev [ '03sdd' ] [ 'nodes' ] ] , [ 0 , 1 ] ) #NEWLINE# self . assertEqual ( [ node [ 'id' ] for node in jobs_by_pol_part_dev [ '10sdc' ] [ 'nodes' ] ] , [ 0 , 1 ] ) #NEWLINE# self . assertEqual ( [ node [ 'id' ] for node in jobs_by_pol_part_dev [ '10sdd' ] [ 'nodes' ] ] , [ 0 , 1 , 2 ] ) #NEWLINE# self . assertEqual ( [ node [ 'id' ] for node in jobs_by_pol_part_dev [ '11sdc' ] [ 'nodes' ] ] , [ 1 , 3 ] ) #NEWLINE# self . assertEqual ( [ node [ 'id' ] for node in jobs_by_pol_part_dev [ '11sdd' ] [ 'nodes' ] ] , [ 1 , 2 ] ) #NEWLINE# self . assertEqual ( [ node [ 'id' ] for node in jobs_by_pol_part_dev [ '12sdc' ] [ 'nodes' ] ] , [ 3 , 0 ] ) #NEWLINE# self . assertEqual ( [ node [ 'id' ] for node in jobs_by_pol_part_dev [ '12sdd' ] [ 'nodes' ] ] , [ 2 , 0 ] ) #NEWLINE# self . assertEqual ( [ node [ 'id' ] for node in jobs_by_pol_part_dev [ '13sdc' ] [ 'nodes' ] ] , [ 3 , 0 , 1 ] ) #NEWLINE# self . assertEqual ( [ node [ 'id' ] for node in jobs_by_pol_part_dev [ '13sdd' ] [ 'nodes' ] ] , [ 0 , 1 ] ) #NEWLINE# for part in [ '00' , '01' , '02' , '03' ] : #NEWLINE# #INDENT# self . assertEqual ( jobs_by_pol_part_dev [ ( part + 'sdc' ) ] [ 'path' ] , os . path . join ( objects_sdc , part [ 1 : ] ) ) #NEWLINE# self . assertEqual ( jobs_by_pol_part_dev [ ( part + 'sdd' ) ] [ 'path' ] , os . path . join ( objects_sdd , part [ 1 : ] ) ) #NEWLINE# #UNINDENT# for part in [ '10' , '11' , '12' , '13' ] : #NEWLINE# #INDENT# self . assertEqual ( jobs_by_pol_part_dev [ ( part + 'sdc' ) ] [ 'path' ] , os . path . join ( objects_1_sdc , part [ 1 : ] ) ) #NEWLINE# self . assertEqual ( jobs_by_pol_part_dev [ ( part + 'sdd' ) ] [ 'path' ] , os . path . join ( objects_1_sdd , part [ 1 : ] ) )