#NEWLINE# @ target_must_exist #NEWLINE# def vagrant_run( args ) : #NEWLINE# #INDENT# 'Runs the experiment in the virtual machine.\n    ' #NEWLINE# target = Path ( args . target [ 0 ] ) #NEWLINE# unpacked_info = read_dict ( target ) #NEWLINE# use_chroot = unpacked_info [ 'use_chroot' ] #NEWLINE# cmdline = args . cmdline #NEWLINE# check_vagrant_version ( ) #NEWLINE# config = load_config ( ( target / 'config.yml' ) , True ) #NEWLINE# runs = config . runs #NEWLINE# selected_runs = get_runs ( runs , args . run , cmdline ) #NEWLINE# hostname = runs [ selected_runs [ 0 ] ] . get ( 'hostname' , 'reprounzip' ) #NEWLINE# x11 = X11Handler ( args . x11 , ( 'local' , hostname ) , args . x11_display ) #NEWLINE# cmds = [ ] #NEWLINE# for run_number in selected_runs : #NEWLINE# #INDENT# run = runs [ run_number ] #NEWLINE# cmd = ( 'cd %s && ' % shell_escape ( run [ 'workingdir' ] ) ) #NEWLINE# if use_chroot : #NEWLINE# #INDENT# cmd += '/busybox env -i ' #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# cmd += '/usr/bin/env -i ' #NEWLINE# #UNINDENT# environ = x11 . fix_env ( run [ 'environ' ] ) #NEWLINE# environ = fixup_environment ( environ , args ) #NEWLINE# cmd += ' ' . join ( ( ( '%s=%s' % ( shell_escape ( k ) , shell_escape ( v ) ) ) for ( k , v ) in iteritems ( environ ) ) ) #NEWLINE# cmd += ' ' #NEWLINE# if ( cmdline is None ) : #NEWLINE# #INDENT# argv = ( [ run [ 'binary' ] ] + run [ 'argv' ] [ 1 : ] ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# argv = cmdline #NEWLINE# #UNINDENT# cmd += ' ' . join ( ( shell_escape ( a ) for a in argv ) ) #NEWLINE# uid = run . get ( 'uid' , 1000 ) #NEWLINE# gid = run . get ( 'gid' , 1000 ) #NEWLINE# if use_chroot : #NEWLINE# #INDENT# userspec = ( '%s:%s' % ( uid , gid ) ) #NEWLINE# cmd = ( 'chroot --userspec=%s /experimentroot /bin/sh -c %s' % ( target , shell_escape ( cmd ) ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# cmd = ( "sudo -u '#%d' sh -c %s" % ( uid , shell_escape ( cmd ) ) ) #NEWLINE# #UNINDENT# cmds . append ( cmd ) #NEWLINE# #UNINDENT# if use_chroot : #NEWLINE# #INDENT# cmds = ( [ ( 'chroot /experimentroot /bin/sh -c %s' % shell_escape ( c ) ) for c in x11 . init_cmds ] + cmds ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# cmds = ( x11 . init_cmds + cmds ) #NEWLINE# #UNINDENT# cmds = ' && ' . join ( cmds ) #NEWLINE# cmds = ( ( ( 'OLD_HOSTNAME=$(/bin/hostname); /bin/hostname %s; ' % hostname ) + cmds ) + '; RES=$?; /bin/hostname "$OLD_HOSTNAME"; exit $RES' ) #NEWLINE# cmds = ( '/usr/bin/sudo /bin/sh -c %s' % shell_escape ( cmds ) ) #NEWLINE# info = machine_setup ( target , unpacked_info [ 'use_chroot' ] ) #NEWLINE# signals . pre_run ( target = target ) #NEWLINE# interactive = ( not ( args . no_stdin or os . environ . get ( 'REPROUNZIP_NON_INTERACTIVE' ) ) ) #NEWLINE# retcode = run_interactive ( info , interactive , cmds , ( not args . no_pty ) , x11 . port_forward ) #NEWLINE# stderr . write ( ( '\r\n*** Command finished, status: %d\r\n' % retcode ) ) #NEWLINE# metadata_update_run ( config , unpacked_info , selected_runs ) #NEWLINE# write_dict ( target , unpacked_info ) #NEWLINE# signals . post_run ( target = target , retcode = retcode )