#NEWLINE# def test_status_smartstack_backends_multiple_locations_expected_count( ) : #NEWLINE# #INDENT# service = 'my_service' #NEWLINE# instance = 'my_instance' #NEWLINE# service_instance = compose_job_id ( service , instance ) #NEWLINE# cluster = 'fake_cluster' #NEWLINE# normal_count = 10 #NEWLINE# good_task = mock . Mock ( ) #NEWLINE# other_task = mock . Mock ( ) #NEWLINE# fake_backend = { #NEWLINE# #INDENT# 'status' : 'UP' , #NEWLINE# 'lastchg' : '1' , #NEWLINE# 'last_chk' : 'OK' , #NEWLINE# 'check_code' : '200' , #NEWLINE# 'svname' : 'ipaddress1:1001_hostname1' , #NEWLINE# 'check_status' : 'L7OK' , #NEWLINE# 'check_duration' : 1 , #NEWLINE# #UNINDENT# } #NEWLINE# with contextlib . nested ( mock . patch ( 'paasta_tools.marathon_tools.load_service_namespace_config' , autospec = True ) , mock . patch ( 'paasta_tools.marathon_tools.read_namespace_for_service_instance' ) , mock . patch ( 'paasta_tools.marathon_serviceinit.get_mesos_slaves_grouped_by_attribute' ) , mock . patch ( 'paasta_tools.marathon_serviceinit.get_backends' , autospec = True ) , mock . patch ( 'paasta_tools.marathon_serviceinit.match_backends_and_tasks' , autospec = True ) , mock . patch ( 'paasta_tools.marathon_serviceinit.haproxy_backend_report' , autospec = True ) ) as ( mock_load_service_namespace_config , mock_read_ns , mock_get_mesos_slaves_grouped_by_attribute , mock_get_backends , mock_match_backends_and_tasks , mock_haproxy_backend_report ) : #NEWLINE# #INDENT# mock_load_service_namespace_config . return_value . get_discover . return_value = 'fake_discover' #NEWLINE# mock_read_ns . return_value = instance #NEWLINE# mock_get_backends . return_value = [ fake_backend ] #NEWLINE# mock_match_backends_and_tasks . return_value = [ ( fake_backend , good_task ) ] #NEWLINE# tasks = [ good_task , other_task ] #NEWLINE# mock_get_mesos_slaves_grouped_by_attribute . return_value = { #NEWLINE# #INDENT# 'fake_location1' : [ 'fakehost1' ] , #NEWLINE# 'fake_location2' : [ 'fakehost2' ] , #NEWLINE# #UNINDENT# } #NEWLINE# marathon_serviceinit . status_smartstack_backends ( service = service , instance = instance , cluster = cluster , job_config = fake_marathon_job_config , tasks = tasks , expected_count = normal_count , soa_dir = None , verbose = False , synapse_port = 123456 , synapse_haproxy_url_format = DEFAULT_SYNAPSE_HAPROXY_URL_FORMAT ) #NEWLINE# mock_get_backends . assert_any_call ( service_instance , synapse_host = 'fakehost1' , synapse_port = 123456 , synapse_haproxy_url_format = DEFAULT_SYNAPSE_HAPROXY_URL_FORMAT ) #NEWLINE# mock_get_backends . assert_any_call ( service_instance , synapse_host = 'fakehost2' , synapse_port = 123456 , synapse_haproxy_url_format = DEFAULT_SYNAPSE_HAPROXY_URL_FORMAT ) #NEWLINE# expected_count_per_location = int ( ( normal_count / len ( mock_get_mesos_slaves_grouped_by_attribute . return_value ) ) ) #NEWLINE# mock_haproxy_backend_report . assert_any_call ( expected_count_per_location , 1 )