<s> from behave import given <EOL> from behave import then <EOL> from behave import when <EOL> from docker . errors import APIError <EOL> from paasta_tools . utils import _run <EOL> from paasta_tools . utils import get_docker_client <EOL> @ given ( u'<STR_LIT>' ) <EOL> def docker_is_available ( context ) : <EOL> docker_client = get_docker_client ( ) <EOL> assert docker_client . ping ( ) <EOL> context . docker_client = docker_client <EOL> @ given ( u'<STR_LIT>' ) <EOL> def create_docker_container ( context , task_id , image_name ) : <EOL> container_name = '<STR_LIT>' <EOL> try : <EOL> context . docker_client . remove_container ( container_name , force = True ) <EOL> except APIError : <EOL> pass <EOL> context . docker_client . pull ( image_name ) <EOL> container = context . docker_client . create_container ( <EOL> name = container_name , <EOL> image = image_name , <EOL> command = '<STR_LIT>' , <EOL> environment = { '<STR_LIT>' : task_id } , <EOL> ) <EOL> context . docker_client . start ( container = container . get ( '<STR_LIT>' ) ) <EOL> context . running_container_id = container . get ( '<STR_LIT>' ) <EOL> @ when ( u'<STR_LIT>' ) <EOL> def run_command_in_container ( context , code , task_id ) : <EOL> cmd = '<STR_LIT>' % ( task_id , code ) <EOL> print '<STR_LIT>' % cmd <EOL> exit_code , output = _run ( cmd ) <EOL> print '<STR_LIT>' % ( exit_code , output ) <EOL> context . return_code = exit_code <EOL> @ then ( u'<STR_LIT>' ) <EOL> def paasta_execute_docker_command_result ( context , code ) : <EOL> assert int ( code ) == int ( context . return_code ) <EOL> @ then ( u'<STR_LIT>' ) <EOL> def check_container_exec_instances ( context , num ) : <EOL> """<STR_LIT>""" <EOL> container_info = context . docker_client . inspect_container ( context . running_container_id ) <EOL> if container_info [ '<STR_LIT>' ] is None : <EOL> execs = [ ] <EOL> else : <EOL> execs = container_info [ '<STR_LIT>' ] <EOL> print '<STR_LIT>' % container_info <EOL> assert len ( execs ) <= int ( num ) </s>
