在Travis-CI内部启动Vagrant VM

时间:2016-05-18 18:05:29

标签: vagrant virtual-machine virtualbox travis-ci

如何在Travis-CI内使用Vagrant启动Virtualbox VM?

我知道有时不支持在VM中启动VM,但是reported successes有这种特定配置。

我试图设置一个持续集成服务器来运行我的sysadmin tool的单元测试,以便在不同的操作系统和Python版本中进行测试。它使用Tox来处理初始化各种Python虚拟环境,使用Pytest来运行测试并包装Vagrant以设置和拆除Virtualbox VM。它在我的Ubuntu 14 localhost上正常运行,但在Travis中,Vagrant超时尝试启动Virtualbox VM:

==> default: Importing base box 'ubuntu/trusty64'...
==> default: Matching MAC address for NAT networking...
==> default: Checking if box 'ubuntu/trusty64' is up to date...
==> default: Setting the name of the VM: functional_tests_default_1463515960654_71459
==> default: Clearing any previously set forwarded ports...
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
    default: Adapter 1: nat
==> default: Forwarding ports...
    default: 22 => 2222 (adapter 1)
==> default: Running 'pre-boot' VM customizations...
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
    default: SSH address: 127.0.0.1:2222
    default: SSH username: vagrant
    default: SSH auth method: private key
    default: Warning: Connection timeout. Retrying...
    default: Warning: Connection timeout. Retrying...
    default: Warning: Connection timeout. Retrying...
    default: Warning: Connection timeout. Retrying...
    default: Warning: Connection timeout. Retrying...
    default: Warning: Connection timeout. Retrying...
    default: Warning: Connection timeout. Retrying...
    ...
    The job exceeded the maximum time limit for jobs, and has been terminated.

由于它没有给我任何细节,我不确定如何诊断问题。我尝试使用export VAGRANT_LOG=DEBUG;启用更多输出,但是没有显示任何有用的内容并且超出了Travis的最大日志大小。我也试过增加超时,并将内存分配到1GB,但都没有帮助。

我发现的唯一奇怪的事情是,我无法解释,这是来自sudo apt-get -y install -q virtualbox-ose-dkms virtualbox --fix-missing的消息:

Module build for the currently running kernel was skipped since the
kernel source for this kernel does not seem to be installed.

但是,在此之前,安装内核源代码的命令成功:

sudo apt-get -y --force-yes install linux-headers-`uname -r`

如何在Travis-CI中启动Vagrant / Virtualbox VM?

2 个答案:

答案 0 :(得分:8)

可悲的是,Travis-CI不支持这一点,并且没有计划在不久的将来这样做。检查以下票证:https://github.com/travis-ci/travis-ci/issues/6060

由于Travis在虚拟化容器(OpenVZ)中运行您的构建,您可以尝试使用32位VM。这可行,但我没有测试过。

答案 1 :(得分:7)

From the end of 2019可以在TravisCI上运行Vagrant!,您要做的就是切换到libvirtKVM提供商而不是{{ 1}}在Travis上-see this so answer,获取完整的HowTo以及GitHub上的此完全可理解的示例项目:https://github.com/jonashackt/vagrant-travisci-libvrt

请参见this TravisCI build for example

successful vagrant installation and execution on Travis

如果您不想在本地使用virtualbox提供程序,则只需使用generic Vagrant Box images from Vagrant Cloud之一,因为它们同时支持libvirt(本地)和{{1} }(在TravisCI上)。