From 98f70d4d7aa504dda5d3d10f8bdc4e92a74d81f0 Mon Sep 17 00:00:00 2001 From: Aloz1 Date: Thu, 12 Jul 2018 08:40:33 +1000 Subject: [PATCH 1/4] Add void linux host support --- plugins/hosts/void/cap/nfs.rb | 19 +++++++++++++++++++ plugins/hosts/void/host.rb | 22 ++++++++++++++++++++++ plugins/hosts/void/plugin.rb | 30 ++++++++++++++++++++++++++++++ 3 files changed, 71 insertions(+) create mode 100644 plugins/hosts/void/cap/nfs.rb create mode 100644 plugins/hosts/void/host.rb create mode 100644 plugins/hosts/void/plugin.rb diff --git a/plugins/hosts/void/cap/nfs.rb b/plugins/hosts/void/cap/nfs.rb new file mode 100644 index 000000000..a0d0fac91 --- /dev/null +++ b/plugins/hosts/void/cap/nfs.rb @@ -0,0 +1,19 @@ +module VagrantPlugins + module HostVoid + module Cap + class NFS + def self.nfs_check_command(env) + "/usr/bin/sv status nfs-server" + end + + def self.nfs_start_command(env) + "/usr/bin/sv up nfs-server " + end + + def self.nfs_installed(env) + Kernel.system("/usr/bin/xbps-query nfs-utils", [:out, :err] => "/dev/null") + end + end + end + end +end diff --git a/plugins/hosts/void/host.rb b/plugins/hosts/void/host.rb new file mode 100644 index 000000000..ea22c9b6a --- /dev/null +++ b/plugins/hosts/void/host.rb @@ -0,0 +1,22 @@ +require 'pathname' + +require 'vagrant' + +module VagrantPlugins + module HostVoid + class Host < Vagrant.plugin("2", :host) + def detect?(env) + os_file = Pathname.new("/etc/os-release") + + if os_file.exist? + file = os_file.open + while (line = file.gets) do + return true if line =~ /^ID="void"/ + end + end + + false + end + end + end +end diff --git a/plugins/hosts/void/plugin.rb b/plugins/hosts/void/plugin.rb new file mode 100644 index 000000000..4b297ab73 --- /dev/null +++ b/plugins/hosts/void/plugin.rb @@ -0,0 +1,30 @@ +require "vagrant" + +module VagrantPlugins + module HostVoid + class Plugin < Vagrant.plugin("2") + name "Void host" + description "Void linux host support." + + host("void", "linux") do + require_relative "host" + Host + end + + host_capability("void", "nfs_installed") do + require_relative "cap/nfs" + Cap::NFS + end + + host_capability("void", "nfs_check_command") do + require_relative "cap/nfs" + Cap::NFS + end + + host_capability("void", "nfs_start_command") do + require_relative "cap/nfs" + Cap::NFS + end + end + end +end From 5e258cbc7c8026373c44411496daa3c4062224d7 Mon Sep 17 00:00:00 2001 From: Aloz1 Date: Fri, 13 Jul 2018 08:08:05 +1000 Subject: [PATCH 2/4] Fixed nfs_start_command. NFS now starts. --- plugins/hosts/void/cap/nfs.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/plugins/hosts/void/cap/nfs.rb b/plugins/hosts/void/cap/nfs.rb index a0d0fac91..259fc776b 100644 --- a/plugins/hosts/void/cap/nfs.rb +++ b/plugins/hosts/void/cap/nfs.rb @@ -7,7 +7,11 @@ module VagrantPlugins end def self.nfs_start_command(env) - "/usr/bin/sv up nfs-server " + <<-EOF + /usr/bin/ln -s /etc/sv/statd /var/service/ && \ + /usr/bin/ln -s /etc/sv/rpcbind /var/service/ && \ + /usr/bin/ln -s /etc/sv/nfs-server /var/service/ + EOF end def self.nfs_installed(env) From b9b9eeac852d5ec92a19a7dab86af309734926df Mon Sep 17 00:00:00 2001 From: Aloz1 Date: Sat, 14 Jul 2018 15:53:13 +1000 Subject: [PATCH 3/4] Void requires root access to check service status Service status check was failing because it was not being run as root. This resulted in vagrant thinking the service was not running, hence it would always try to start nfs rather than updating exports. --- plugins/hosts/void/cap/nfs.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/hosts/void/cap/nfs.rb b/plugins/hosts/void/cap/nfs.rb index 259fc776b..1a5c4999c 100644 --- a/plugins/hosts/void/cap/nfs.rb +++ b/plugins/hosts/void/cap/nfs.rb @@ -3,7 +3,7 @@ module VagrantPlugins module Cap class NFS def self.nfs_check_command(env) - "/usr/bin/sv status nfs-server" + "sudo /usr/bin/sv status nfs-server" end def self.nfs_start_command(env) From ac5b45445a30488b8cb7a401c3a47159ec4770f8 Mon Sep 17 00:00:00 2001 From: Chris Roberts Date: Wed, 19 Dec 2018 09:44:05 -0800 Subject: [PATCH 4/4] Remove use of `system`. Add test coverage. --- plugins/hosts/void/cap/nfs.rb | 3 +- test/unit/plugins/hosts/void/cap/nfs_test.rb | 62 ++++++++++++++++++++ 2 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 test/unit/plugins/hosts/void/cap/nfs_test.rb diff --git a/plugins/hosts/void/cap/nfs.rb b/plugins/hosts/void/cap/nfs.rb index 1a5c4999c..2e4ce9fb3 100644 --- a/plugins/hosts/void/cap/nfs.rb +++ b/plugins/hosts/void/cap/nfs.rb @@ -15,7 +15,8 @@ module VagrantPlugins end def self.nfs_installed(env) - Kernel.system("/usr/bin/xbps-query nfs-utils", [:out, :err] => "/dev/null") + result = Vagrant::Util::Subprocess.execute("/usr/bin/xbps-query nfs-utils") + result.exit_code == 0 end end end diff --git a/test/unit/plugins/hosts/void/cap/nfs_test.rb b/test/unit/plugins/hosts/void/cap/nfs_test.rb new file mode 100644 index 000000000..72aac8713 --- /dev/null +++ b/test/unit/plugins/hosts/void/cap/nfs_test.rb @@ -0,0 +1,62 @@ +require_relative "../../../../base" +require_relative "../../../../../../plugins/hosts/void/cap/nfs" +require_relative "../../../../../../lib/vagrant/util" + +describe VagrantPlugins::HostVoid::Cap::NFS do + + include_context "unit" + + let(:caps) do + VagrantPlugins::HostVoid::Plugin + .components + .host_capabilities[:void] + end + + let(:env) { double("env") } + + context ".nfs_check_command" do + it "should provide nfs_check_command capability" do + expect(caps.get(:nfs_check_command)).to eq(described_class) + end + + it "should return command to execute" do + expect(caps.get(:nfs_check_command).nfs_check_command(env)).to be_a(String) + end + end + + context ".nfs_start_command" do + it "should provide nfs_start_command capability" do + expect(caps.get(:nfs_start_command)).to eq(described_class) + end + + it "should return command to execute" do + expect(caps.get(:nfs_start_command).nfs_start_command(env)).to be_a(String) + end + end + + context ".nfs_installed" do + let(:exit_code) { 0 } + let(:result) { Vagrant::Util::Subprocess::Result.new(exit_code, "", "") } + + before { allow(Vagrant::Util::Subprocess).to receive(:execute). + with(/xbps-query nfs-utils/).and_return(result) } + + it "should provide nfs_installed capability" do + expect(caps.get(:nfs_installed)).to eq(described_class) + end + + context "when installed" do + it "should return true" do + expect(caps.get(:nfs_installed).nfs_installed(env)).to be_truthy + end + end + + context "when not installed" do + let(:exit_code) { 1 } + + it "should return false" do + expect(caps.get(:nfs_installed).nfs_installed(env)).to be_falsey + end + end + end +end