#NEWLINE# @ when ( 'deploy_service with bounce strategy "{bounce_method}" and drain method "{drain_method}" is initiated' ) #NEWLINE# def when_deploy_service_initiated( context , bounce_method , drain_method ) : #NEWLINE# #INDENT# with contextlib . nested ( mock . patch ( 'paasta_tools.bounce_lib.get_happy_tasks' , autospec = True , side_effect = ( lambda app , _ , __ , ___ , **kwargs : get_happy_tasks ( app , context . service , 'fake_nerve_ns' , context . system_paasta_config ) [ : context . max_tasks ] ) ) , mock . patch ( 'paasta_tools.bounce_lib.bounce_lock_zookeeper' , autospec = True ) , mock . patch ( 'paasta_tools.bounce_lib.create_app_lock' , autospec = True ) , mock . patch ( 'paasta_tools.bounce_lib.time.sleep' , autospec = True ) , mock . patch ( 'paasta_tools.setup_marathon_job.load_system_paasta_config' , autospec = True ) , mock . patch ( 'paasta_tools.setup_marathon_job._log' , autospec = True ) ) as ( _ , _ , _ , _ , mock_load_system_paasta_config , _ ) : #NEWLINE# #INDENT# mock_load_system_paasta_config . return_value . get_cluster = mock . Mock ( return_value = context . cluster ) #NEWLINE# for _ in xrange ( 120 ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# setup_marathon_job . deploy_service ( service = context . service , instance = mock_load_system_paasta_config . instance , marathon_jobid = context . new_config [ 'id' ] , config = context . new_config , client = context . marathon_client , bounce_method = bounce_method , drain_method_name = drain_method , drain_method_params = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } , nerve_ns = context . instance , bounce_health_params = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } , soa_dir = None ) #NEWLINE# return #NEWLINE# #UNINDENT# except MarathonHttpError : #NEWLINE# #INDENT# time . sleep ( 0.5 ) #NEWLINE# #UNINDENT# #UNINDENT# raise Exception ( 'Unable to qcuiqre app lock for setup_marathon_job.deploy_service' )