Merge pull request #12785 from dustymabe/dusty-el9

Enhancements for EL guests capabilities
This commit is contained in:
Sophia Castellarin 2022-08-01 12:10:40 -05:00 committed by GitHub
commit aee8d7b96e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 177 additions and 52 deletions

View File

@ -0,0 +1,23 @@
module VagrantPlugins
module GuestAlma
module Cap
class Flavor
def self.flavor(machine)
# Read the version file
version = ""
machine.communicate.sudo("source /etc/os-release && printf $VERSION_ID") do |type, data|
if type == :stdout
version = data.split(".").first.to_i
end
end
if version.nil? || version < 1
:alma
else
"alma_#{version}".to_sym
end
end
end
end
end
end

View File

@ -0,0 +1,10 @@
require_relative "../linux/guest"
module VagrantPlugins
module GuestAlma
class Guest < VagrantPlugins::GuestLinux::Guest
# Name used for guest detection
GUEST_DETECTION_NAME = "almalinux".freeze
end
end
end

View File

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

View File

@ -3,19 +3,24 @@ module VagrantPlugins
module Cap
class Flavor
def self.flavor(machine)
# Read the version file
output = ""
machine.communicate.sudo("cat /etc/centos-release") do |_, data|
output = data
# Pick up version info from `/etc/os-release`. This file started to exist
# in CentOS 7. For versions before that (i.e. CentOS 6) just plain `:centos`
# should do.
version = nil
if machine.communicate.test("test -f /etc/os-release")
begin
machine.communicate.execute("source /etc/os-release && printf $VERSION_ID") do |type, data|
if type == :stdout
version = data.split(".").first.to_i
end
end
rescue
end
end
# Detect various flavors we care about
if output =~ /(CentOS)( .+)? 7/i
return :centos_7
elsif output =~ /(CentOS)( .+)? 8/i
return :centos_8
else
if version.nil? || version < 1
return :centos
else
return "centos_#{version}".to_sym
end
end
end

View File

@ -1,9 +1,11 @@
require "vagrant"
require_relative '../linux/guest'
module VagrantPlugins
module GuestCentos
class Guest < Vagrant.plugin("2", :guest)
def detect?(machine)
machine.communicate.test("cat /etc/centos-release")
end
class Guest < VagrantPlugins::GuestLinux::Guest
# Name used for guest detection
GUEST_DETECTION_NAME = "centos".freeze
end
end
end

View File

@ -3,19 +3,24 @@ module VagrantPlugins
module Cap
class Flavor
def self.flavor(machine)
# Read the version file
output = ""
machine.communicate.sudo("cat /etc/redhat-release") do |_, data|
output = data
# Pick up version info from `/etc/os-release`. This file started to exist
# in RHEL 7. For versions before that (i.e. RHEL 6) just plain `:rhel`
# should do.
version = nil
if machine.communicate.test("test -f /etc/os-release")
begin
machine.communicate.execute("source /etc/os-release && printf $VERSION_ID") do |type, data|
if type == :stdout
version = data.split(".").first.to_i
end
end
rescue
end
end
# Detect various flavors we care about
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
else
if version.nil? || version < 1
return :rhel
else
return "rhel_#{version}".to_sym
end
end
end

View File

@ -0,0 +1,36 @@
require_relative "../../../../base"
describe "VagrantPlugins::GuestAlma::Cap::Flavor" do
let(:caps) do
VagrantPlugins::GuestAlma::Plugin
.components
.guest_capabilities[:alma]
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) }
{
"" => :alma,
"8.2" => :alma_8,
"9" => :alma_9,
"invalid" => :alma
}.each do |str, expected|
it "returns #{expected} for #{str}" do
comm.stub_command("source /etc/os-release && printf $VERSION_ID", stdout: str)
expect(cap.flavor(machine)).to be(expected)
end
end
end
end

View File

@ -21,16 +21,31 @@ describe "VagrantPlugins::GuestCentos::Cap::Flavor" do
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)
# /etc/os-release was added in EL7+
context "without /etc/os-release file" do
{
"" => :centos
}.each do |str, expected|
it "returns #{expected} for #{str}" do
comm.stub_command("test -f /etc/os-release", exit_code: 1)
expect(cap.flavor(machine)).to be(expected)
end
end
end
context "with /etc/os-release file" do
{
"7" => :centos_7,
"8" => :centos_8,
"9.0" => :centos_9,
"9.1" => :centos_9,
"" => :centos,
"banana" => :centos,
}.each do |str, expected|
it "returns #{expected} for #{str}" do
comm.stub_command("test -f /etc/os-release", exit_code: 0)
comm.stub_command("source /etc/os-release && printf $VERSION_ID", stdout: str)
expect(cap.flavor(machine)).to be(expected)
end
end
end
end

View File

@ -21,22 +21,31 @@ describe "VagrantPlugins::GuestRedHat::Cap::Flavor" do
describe ".flavor" do
let(:cap) { caps.get(:flavor) }
{
"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,
"CloudLinux release 8.1.1911 (Valeri Kubasov)" => :rhel_8,
"Red Hat Enterprise Linux release 8" => :rhel_8,
"Red Hat Enterprise Linux" => :rhel,
"RHEL 6" => :rhel,
"banana" => :rhel,
}.each do |str, expected|
it "returns #{expected} for #{str}" do
comm.stub_command("cat /etc/redhat-release", stdout: str)
expect(cap.flavor(machine)).to be(expected)
# /etc/os-release was added in EL7+
context "without /etc/os-release file" do
{
"" => :rhel
}.each do |str, expected|
it "returns #{expected} for #{str}" do
comm.stub_command("test -f /etc/os-release", exit_code: 1)
expect(cap.flavor(machine)).to be(expected)
end
end
end
context "with /etc/os-release file" do
{
"7" => :rhel_7,
"8" => :rhel_8,
"9.0" => :rhel_9,
"9.1" => :rhel_9,
"" => :rhel,
"banana" => :rhel,
}.each do |str, expected|
it "returns #{expected} for #{str}" do
comm.stub_command("test -f /etc/os-release", exit_code: 0)
comm.stub_command("source /etc/os-release && printf $VERSION_ID", stdout: str)
expect(cap.flavor(machine)).to be(expected)
end
end
end
end