Previously, we required a host-only interface with a static IP for NFS to work in VirtualBox, because we needed access to the guest's IP in order to properly configure mount commands. After boot, VirtualBox exposes the IP addresses of a guest's network adapters via the "guestproperty" interface. This adds support for reading VirtualBox guest properties to the VirtualBox driver and utilizes that support to prepare NFS settings, which removes the necessity for a static IP for NFS to work. In this commit we also start building out scaffolding for unit testing vbox actions and drivers. Test plan: - Prepare a Vagrantfile with the following: * private network with type: :dhcp * synced folder with nfs: true - Boot a VM from this Vagrantfile using the virtualbox provider - Machine should boot successfully with working synced folder
31 lines
1.3 KiB
Ruby
31 lines
1.3 KiB
Ruby
shared_context "virtualbox" do
|
|
let(:vbox_context) { true }
|
|
let(:uuid) { "1234-abcd-5678-efgh" }
|
|
let(:vbox_version) { "4.3.4" }
|
|
let(:subprocess) { double("Vagrant::Util::Subprocess") }
|
|
|
|
# this is a helper that returns a duck type suitable from a system command
|
|
# execution; allows setting exit_code, stdout, and stderr in stubs.
|
|
def subprocess_result(options={})
|
|
defaults = {exit_code: 0, stdout: "", stderr: ""}
|
|
double("subprocess_result", defaults.merge(options))
|
|
end
|
|
|
|
before do
|
|
# we don't want unit tests to ever run commands on the system; so we wire
|
|
# in a double to ensure any unexpected messages raise exceptions
|
|
stub_const("Vagrant::Util::Subprocess", subprocess)
|
|
|
|
# drivers will blow up on instantiation if they cannot determine the
|
|
# virtualbox version, so wire this stub in automatically
|
|
subprocess.stub(:execute).
|
|
with("VBoxManage", "--version", an_instance_of(Hash)).
|
|
and_return(subprocess_result(stdout: vbox_version))
|
|
|
|
# drivers also call vm_exists? during init;
|
|
subprocess.stub(:execute).
|
|
with("VBoxManage", "showvminfo", kind_of(String), kind_of(Hash)).
|
|
and_return(subprocess_result(exit_code: 0))
|
|
end
|
|
end
|