diff --git a/reprounzip-vagrant/reprounzip/unpackers/vagrant/__init__.py b/reprounzip-vagrant/reprounzip/unpackers/vagrant/__init__.py index b47b7188a..1bccdcd2b 100644 --- a/reprounzip-vagrant/reprounzip/unpackers/vagrant/__init__.py +++ b/reprounzip-vagrant/reprounzip/unpackers/vagrant/__init__.py @@ -32,7 +32,7 @@ FileUploader, FileDownloader, get_runs, add_environment_options, \ fixup_environment, metadata_read, metadata_write, \ metadata_initial_iofiles, metadata_update_run -from reprounzip.unpackers.common.x11 import X11Handler +from reprounzip.unpackers.common.x11 import BaseX11Handler from reprounzip.unpackers.vagrant.run_command import IgnoreMissingKey, \ run_interactive from reprounzip.utils import unicode_, iteritems, stderr, download_file @@ -41,6 +41,8 @@ def select_box(runs): """Selects a box for the experiment, with the correct distribution. """ + return ('debian', 'remram/debian-8-amd64-xfce') + distribution, version = runs[0]['distribution'] distribution = distribution.lower() architecture = runs[0]['architecture'] @@ -162,6 +164,18 @@ def machine_setup(target, use_chroot): if chan.recv_exit_status() != 0: logging.critical("Couldn't mount directories in chroot") sys.exit(1) + # Mount X11 socket + chan = ssh.get_transport().open_session() + chan.exec_command( + '/usr/bin/sudo /bin/sh -c %s' % shell_escape( + 'if [ -d /tmp/.X11-unix ]; then ' + '[ -d /experimentroot/tmp/.X11-unix ] || ' + 'mkdir /experimentroot/tmp/.X11-unix; ' + 'mount -o bind /tmp/.X11-unix /experimentroot/tmp/.X11-unix; ' + 'fi; exit 0')) + if chan.recv_exit_status() != 0: + logging.critical("Couldn't mount X11 sockets in chroot") + sys.exit(1) ssh.close() return info @@ -353,11 +367,16 @@ def vagrant_setup_create(args): # Run the setup script on the virtual machine fp.write(' config.vm.provision "shell", path: "setup.sh"\n') + gui = True + # Memory size - if memory is not None: - fp.write(' config.vm.provider "virtualbox" do |v|\n' - ' v.memory = %d\n' - ' end\n' % memory) + if memory is not None or gui: + fp.write(' config.vm.provider "virtualbox" do |v|\n') + if memory is not None: + fp.write(' v.memory = %d\n' % memory) + if gui: + fp.write(' v.gui = true\n') + fp.write(' end\n') fp.write('end\n') @@ -384,6 +403,20 @@ def vagrant_setup_start(args): machine_setup(target, use_chroot) +class LocalX11Handler(BaseX11Handler): + port_forward = [] + init_cmds = [] + + @staticmethod + def fix_env(env): + """Sets ``$XAUTHORITY`` and ``$DISPLAY`` in the environment. + """ + new_env = dict(env) + new_env.pop('XAUTHORITY', None) + new_env['DISPLAY'] = ':0' + return new_env + + @target_must_exist def vagrant_run(args): """Runs the experiment in the virtual machine. @@ -404,7 +437,7 @@ def vagrant_run(args): hostname = runs[selected_runs[0]].get('hostname', 'reprounzip') # X11 handler - x11 = X11Handler(args.x11, ('local', hostname), args.x11_display) + x11 = LocalX11Handler() cmds = [] for run_number in selected_runs: diff --git a/reprounzip/reprounzip/unpackers/common/x11.py b/reprounzip/reprounzip/unpackers/common/x11.py index 03bb0ffb8..57cc653c3 100644 --- a/reprounzip/reprounzip/unpackers/common/x11.py +++ b/reprounzip/reprounzip/unpackers/common/x11.py @@ -89,7 +89,7 @@ def as_bytes(self): ascii(self.data)) -class X11Handler(object): +class BaseX11Handler(object): """X11 handler. This selects a way to connect to the local X server and an authentication @@ -98,6 +98,15 @@ class X11Handler(object): commands, and `port_forward` which describes the reverse port tunnels from the experiment to the local X server. """ + + +class X11Handler(BaseX11Handler): + """X11 handler that will connect to a server outside on the host. + + This connects out of the created environment using the network. It is used + by Vagrant (through SSH) and Docker (TCP connection), and may have + significant latency. + """ DISPLAY_NUMBER = 15 SOCK2X = {socket.AF_INET: Xauth.FAMILY_INTERNET,