Merge pull request #10012 from Aloz1/add-host-voidlinux

Add void linux host support
This commit is contained in:
Chris Roberts 2018-12-19 16:21:52 -08:00 committed by GitHub
commit f4cb33e954
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 138 additions and 0 deletions

View File

@ -0,0 +1,24 @@
module VagrantPlugins
module HostVoid
module Cap
class NFS
def self.nfs_check_command(env)
"sudo /usr/bin/sv status nfs-server"
end
def self.nfs_start_command(env)
<<-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)
result = Vagrant::Util::Subprocess.execute("/usr/bin/xbps-query nfs-utils")
result.exit_code == 0
end
end
end
end
end

View File

@ -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

View File

@ -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

View File

@ -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