Skip to content

Commit

Permalink
Add CentOS guest plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
soapy1 committed Apr 6, 2020
1 parent 311fb03 commit 5104d07
Show file tree
Hide file tree
Showing 6 changed files with 94 additions and 10 deletions.
24 changes: 24 additions & 0 deletions plugins/guests/centos/cap/flavor.rb
Original file line number Diff line number Diff line change
@@ -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
9 changes: 9 additions & 0 deletions plugins/guests/centos/guest.rb
Original file line number Diff line number Diff line change
@@ -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
20 changes: 20 additions & 0 deletions plugins/guests/centos/plugin.rb
Original file line number Diff line number Diff line change
@@ -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
8 changes: 1 addition & 7 deletions plugins/guests/redhat/cap/flavor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,7 @@ def self.flavor(machine)
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
Expand Down
37 changes: 37 additions & 0 deletions test/unit/plugins/guests/centos/cap/flavor_test.rb
Original file line number Diff line number Diff line change
@@ -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
6 changes: 3 additions & 3 deletions test/unit/plugins/guests/redhat/cap/flavor_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@
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|
Expand Down

0 comments on commit 5104d07

Please sign in to comment.