Add CentOS guest plugin

This commit is contained in:
sophia 2020-04-06 10:53:22 -04:00
parent 311fb035e6
commit 5104d075bd
6 changed files with 94 additions and 10 deletions

View File

@ -0,0 +1,24 @@
module VagrantPlugins
module GuestCentos
module Cap
class Flavor
def self.flavor(machine)
# Read the version file
output = ""
machine.communicate.sudo("cat /etc/centos-release") do |_, data|
output = data
end
# Detect various flavors we care about
if output =~ /(CentOS)( .+)? 7/i
return :centos_7
elsif output =~ /(CentOS)( .+)? 8/i
return :centos_8
else
return :centos
end
end
end
end
end
end

View File

@ -0,0 +1,9 @@
module VagrantPlugins
module GuestCentos
class Guest < Vagrant.plugin("2", :guest)
def detect?(machine)
machine.communicate.test("cat /etc/centos-release")
end
end
end
end

View File

@ -0,0 +1,20 @@
require "vagrant"
module VagrantPlugins
module GuestCentos
class Plugin < Vagrant.plugin("2")
name "CentOS guest"
description "CentOS guest support."
guest(:centos, :redhat) do
require_relative "guest"
Guest
end
guest_capability(:centos, :flavor) do
require_relative "cap/flavor"
Cap::Flavor
end
end
end
end

View File

@ -10,13 +10,7 @@ module VagrantPlugins
end
# Detect various flavors we care about
if output =~ /(CentOS)( .+)? 7/i
return :centos_7
elsif output =~ /(CentOS)( .+)? 8/i
return :centos_8
elsif output =~ /(CentOS)( .+)?/i
return :centos
elsif output =~ /(Red Hat Enterprise|Scientific|Cloud|Virtuozzo)\s*Linux( .+)? release 7/i
if output =~ /(Red Hat Enterprise|Scientific|Cloud|Virtuozzo)\s*Linux( .+)? release 7/i
return :rhel_7
elsif output =~ /(Red Hat Enterprise|Scientific|Cloud|Virtuozzo)\s*Linux( .+)? release 8/i
return :rhel_8

View File

@ -0,0 +1,37 @@
require_relative "../../../../base"
describe "VagrantPlugins::GuestCentos::Cap::Flavor" do
let(:caps) do
VagrantPlugins::GuestCentos::Plugin
.components
.guest_capabilities[:centos]
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 ".flavor" do
let(:cap) { caps.get(:flavor) }
{
"CentOS Linux 2.4 release 7" => :centos_7,
"CentOS Linux release 8.1.1911 (Core)" => :centos_8,
"CentOS" => :centos,
"banana" => :centos,
}.each do |str, expected|
it "returns #{expected} for #{str}" do
comm.stub_command("cat /etc/centos-release", stdout: str)
expect(cap.flavor(machine)).to be(expected)
end
end
end
end

View File

@ -22,15 +22,15 @@ describe "VagrantPlugins::GuestRedHat::Cap::Flavor" do
let(:cap) { caps.get(:flavor) }
{
"CentOS Linux 2.4 release 7" => :centos_7,
"Red Hat Enterprise Linux 2.4 release 7" => :rhel_7,
"Red Hat Enterprise Linux release 7" => :rhel_7,
"Scientific Linux release 7" => :rhel_7,
"CloudLinux release 7.2 (Valeri Kubasov)" => :rhel_7,
"CentOS Linux release 8.1.1911 (Core)" => :centos_8,
"CloudLinux release 8.1.1911 (Valeri Kubasov)" => :rhel_8,
"Red Hat Enterprise Linux release 8" => :rhel_8,
"CentOS" => :centos,
"Red Hat Enterprise Linux" => :rhel,
"RHEL 6" => :rhel,
"banana" => :rhel,
}.each do |str, expected|