Skip to content

Commit

Permalink
Merge 2488f2d into d9bb715
Browse files Browse the repository at this point in the history
  • Loading branch information
remram44 committed Jun 30, 2016
2 parents d9bb715 + 2488f2d commit e9a8a0e
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 7 deletions.
45 changes: 39 additions & 6 deletions reprounzip-vagrant/reprounzip/unpackers/vagrant/__init__.py
Expand Up @@ -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
Expand All @@ -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']
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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')

Expand All @@ -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.
Expand All @@ -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:
Expand Down
11 changes: 10 additions & 1 deletion reprounzip/reprounzip/unpackers/common/x11.py
Expand Up @@ -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
Expand All @@ -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,
Expand Down

0 comments on commit e9a8a0e

Please sign in to comment.