From 666d5e639131c765f41dd1b08da97e9f7a4728fe Mon Sep 17 00:00:00 2001 From: Chris Roberts Date: Wed, 10 Aug 2016 08:42:56 -0700 Subject: [PATCH 1/3] guests/bsd: remove darwin matching --- plugins/guests/bsd/guest.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/guests/bsd/guest.rb b/plugins/guests/bsd/guest.rb index 1a5586586..e1391601c 100644 --- a/plugins/guests/bsd/guest.rb +++ b/plugins/guests/bsd/guest.rb @@ -2,7 +2,7 @@ module VagrantPlugins module GuestBSD class Guest < Vagrant.plugin("2", :guest) def detect?(machine) - machine.communicate.test("uname -s | grep -i 'Darwin|BSD'") + machine.communicate.test("uname -s | grep -i 'BSD'") end end end From 571659a5d10547ba5a6d6567aa7d1f4aee07b0f5 Mon Sep 17 00:00:00 2001 From: Chris Roberts Date: Wed, 10 Aug 2016 08:47:11 -0700 Subject: [PATCH 2/3] guests/openbsd: include -h option on shutdown For OpenBSD versions prior to 5.7 the `-h` option _must_ be provided to the `shutdown` command when `-p` is used. Later versions no longer require the `-h` option but still allow it for compatibility. http://cvsweb.openbsd.org/cgi-bin/cvsweb/src/sbin/shutdown/shutdown.8?rev=1.40&content-type=text/x-cvsweb-markup http://cvsweb.openbsd.org/cgi-bin/cvsweb/src/sbin/shutdown/shutdown.c?rev=1.40&content-type=text/x-cvsweb-markup --- plugins/guests/openbsd/cap/halt.rb | 19 ++++++++ plugins/guests/openbsd/plugin.rb | 5 +++ .../plugins/guests/openbsd/cap/halt_test.rb | 43 +++++++++++++++++++ 3 files changed, 67 insertions(+) create mode 100644 plugins/guests/openbsd/cap/halt.rb create mode 100644 test/unit/plugins/guests/openbsd/cap/halt_test.rb diff --git a/plugins/guests/openbsd/cap/halt.rb b/plugins/guests/openbsd/cap/halt.rb new file mode 100644 index 000000000..654e6153b --- /dev/null +++ b/plugins/guests/openbsd/cap/halt.rb @@ -0,0 +1,19 @@ +module VagrantPlugins + module GuestOpenBSD + module Cap + class Halt + def self.halt(machine) + begin + # Versions of OpenBSD prior to 5.7 require the -h option to be + # provided with the -p option. Later options allow the -h to + # be optional. + machine.communicate.sudo("/sbin/shutdown -p -h now", shell: "sh") + rescue IOError, Vagrant::Errors::SSHDisconnected + # Do nothing, because it probably means the machine shut down + # and SSH connection was lost. + end + end + end + end + end +end diff --git a/plugins/guests/openbsd/plugin.rb b/plugins/guests/openbsd/plugin.rb index 94881feda..821c99195 100644 --- a/plugins/guests/openbsd/plugin.rb +++ b/plugins/guests/openbsd/plugin.rb @@ -21,6 +21,11 @@ module VagrantPlugins Cap::ConfigureNetworks end + guest_capability(:openbsd, :halt) do + require_relative "cap/halt" + Cap::Halt + end + guest_capability(:openbsd, :rsync_install) do require_relative "cap/rsync" Cap::RSync diff --git a/test/unit/plugins/guests/openbsd/cap/halt_test.rb b/test/unit/plugins/guests/openbsd/cap/halt_test.rb new file mode 100644 index 000000000..17ec5c913 --- /dev/null +++ b/test/unit/plugins/guests/openbsd/cap/halt_test.rb @@ -0,0 +1,43 @@ +require_relative "../../../../base" + +describe "VagrantPlugins::GuestOpenBSD::Cap::Halt" do + let(:caps) do + VagrantPlugins::GuestOpenBSD::Plugin + .components + .guest_capabilities[:openbsd] + end + + let(:machine) { double("machine") } + let(:comm) { VagrantTests::DummyCommunicator::Communicator.new(machine) } + + before do + allow(machine).to receive(:communicate).and_return(comm) + end + + after do + comm.verify_expectations! + end + + describe ".halt" do + let(:cap) { caps.get(:halt) } + + it "runs the shutdown command" do + comm.expect_command("/sbin/shutdown -p -h now") + cap.halt(machine) + end + + it "ignores an IOError" do + comm.stub_command("/sbin/shutdown -p -h now", raise: IOError) + expect { + cap.halt(machine) + }.to_not raise_error + end + + it "ignores an Vagrant::Errors::SSHDisconnected" do + comm.stub_command("/sbin/shutdown -p -h now", raise: Vagrant::Errors::SSHDisconnected) + expect { + cap.halt(machine) + }.to_not raise_error + end + end +end From 6cdab917deac0a56560fc94ccc624e4128a14716 Mon Sep 17 00:00:00 2001 From: Chris Roberts Date: Wed, 10 Aug 2016 08:54:56 -0700 Subject: [PATCH 3/3] guests/dragonflybsd: add detection for DragonFly BSD --- plugins/guests/dragonflybsd/guest.rb | 9 +++++++++ plugins/guests/dragonflybsd/plugin.rb | 15 +++++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 plugins/guests/dragonflybsd/guest.rb create mode 100644 plugins/guests/dragonflybsd/plugin.rb diff --git a/plugins/guests/dragonflybsd/guest.rb b/plugins/guests/dragonflybsd/guest.rb new file mode 100644 index 000000000..94b6ea137 --- /dev/null +++ b/plugins/guests/dragonflybsd/guest.rb @@ -0,0 +1,9 @@ +module VagrantPlugins + module GuestDragonFlyBSD + class Guest < Vagrant.plugin("2", :guest) + def detect?(machine) + machine.communicate.test("uname -s | grep -i 'DragonFly'") + end + end + end +end diff --git a/plugins/guests/dragonflybsd/plugin.rb b/plugins/guests/dragonflybsd/plugin.rb new file mode 100644 index 000000000..31caa06df --- /dev/null +++ b/plugins/guests/dragonflybsd/plugin.rb @@ -0,0 +1,15 @@ +require "vagrant" + +module VagrantPlugins + module GuestDragonFlyBSD + class Plugin < Vagrant.plugin("2") + name "DragonFly BSD guest" + description "DragonFly BSD guest support." + + guest(:dragonflybsd, :bsd) do + require_relative "guest" + Guest + end + end + end +end