Merge pull request #12785 from dustymabe/dusty-el9
Enhancements for EL guests capabilities
This commit is contained in:
commit
aee8d7b96e
23
plugins/guests/alma/cap/flavor.rb
Normal file
23
plugins/guests/alma/cap/flavor.rb
Normal 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
|
||||||
10
plugins/guests/alma/guest.rb
Normal file
10
plugins/guests/alma/guest.rb
Normal 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
|
||||||
20
plugins/guests/alma/plugin.rb
Normal file
20
plugins/guests/alma/plugin.rb
Normal 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
|
||||||
@ -3,19 +3,24 @@ module VagrantPlugins
|
|||||||
module Cap
|
module Cap
|
||||||
class Flavor
|
class Flavor
|
||||||
def self.flavor(machine)
|
def self.flavor(machine)
|
||||||
# Read the version file
|
# Pick up version info from `/etc/os-release`. This file started to exist
|
||||||
output = ""
|
# in CentOS 7. For versions before that (i.e. CentOS 6) just plain `:centos`
|
||||||
machine.communicate.sudo("cat /etc/centos-release") do |_, data|
|
# should do.
|
||||||
output = data
|
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
|
end
|
||||||
|
if version.nil? || version < 1
|
||||||
# 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
|
return :centos
|
||||||
|
else
|
||||||
|
return "centos_#{version}".to_sym
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -1,9 +1,11 @@
|
|||||||
|
require "vagrant"
|
||||||
|
require_relative '../linux/guest'
|
||||||
|
|
||||||
module VagrantPlugins
|
module VagrantPlugins
|
||||||
module GuestCentos
|
module GuestCentos
|
||||||
class Guest < Vagrant.plugin("2", :guest)
|
class Guest < VagrantPlugins::GuestLinux::Guest
|
||||||
def detect?(machine)
|
# Name used for guest detection
|
||||||
machine.communicate.test("cat /etc/centos-release")
|
GUEST_DETECTION_NAME = "centos".freeze
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -3,19 +3,24 @@ module VagrantPlugins
|
|||||||
module Cap
|
module Cap
|
||||||
class Flavor
|
class Flavor
|
||||||
def self.flavor(machine)
|
def self.flavor(machine)
|
||||||
# Read the version file
|
# Pick up version info from `/etc/os-release`. This file started to exist
|
||||||
output = ""
|
# in RHEL 7. For versions before that (i.e. RHEL 6) just plain `:rhel`
|
||||||
machine.communicate.sudo("cat /etc/redhat-release") do |_, data|
|
# should do.
|
||||||
output = data
|
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
|
end
|
||||||
|
if version.nil? || version < 1
|
||||||
# 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
|
|
||||||
return :rhel
|
return :rhel
|
||||||
|
else
|
||||||
|
return "rhel_#{version}".to_sym
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
36
test/unit/plugins/guests/alma/cap/flavor_test.rb
Normal file
36
test/unit/plugins/guests/alma/cap/flavor_test.rb
Normal 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
|
||||||
@ -21,16 +21,31 @@ describe "VagrantPlugins::GuestCentos::Cap::Flavor" do
|
|||||||
describe ".flavor" do
|
describe ".flavor" do
|
||||||
let(:cap) { caps.get(:flavor) }
|
let(:cap) { caps.get(:flavor) }
|
||||||
|
|
||||||
{
|
# /etc/os-release was added in EL7+
|
||||||
"CentOS Linux 2.4 release 7" => :centos_7,
|
context "without /etc/os-release file" do
|
||||||
"CentOS Linux release 8.1.1911 (Core)" => :centos_8,
|
{
|
||||||
|
"" => :centos
|
||||||
"CentOS" => :centos,
|
}.each do |str, expected|
|
||||||
"banana" => :centos,
|
it "returns #{expected} for #{str}" do
|
||||||
}.each do |str, expected|
|
comm.stub_command("test -f /etc/os-release", exit_code: 1)
|
||||||
it "returns #{expected} for #{str}" do
|
expect(cap.flavor(machine)).to be(expected)
|
||||||
comm.stub_command("cat /etc/centos-release", stdout: str)
|
end
|
||||||
expect(cap.flavor(machine)).to be(expected)
|
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
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -21,22 +21,31 @@ describe "VagrantPlugins::GuestRedHat::Cap::Flavor" do
|
|||||||
describe ".flavor" do
|
describe ".flavor" do
|
||||||
let(:cap) { caps.get(:flavor) }
|
let(:cap) { caps.get(:flavor) }
|
||||||
|
|
||||||
{
|
# /etc/os-release was added in EL7+
|
||||||
"Red Hat Enterprise Linux 2.4 release 7" => :rhel_7,
|
context "without /etc/os-release file" do
|
||||||
"Red Hat Enterprise Linux release 7" => :rhel_7,
|
{
|
||||||
"Scientific Linux release 7" => :rhel_7,
|
"" => :rhel
|
||||||
"CloudLinux release 7.2 (Valeri Kubasov)" => :rhel_7,
|
}.each do |str, expected|
|
||||||
|
it "returns #{expected} for #{str}" do
|
||||||
"CloudLinux release 8.1.1911 (Valeri Kubasov)" => :rhel_8,
|
comm.stub_command("test -f /etc/os-release", exit_code: 1)
|
||||||
"Red Hat Enterprise Linux release 8" => :rhel_8,
|
expect(cap.flavor(machine)).to be(expected)
|
||||||
|
end
|
||||||
"Red Hat Enterprise Linux" => :rhel,
|
end
|
||||||
"RHEL 6" => :rhel,
|
end
|
||||||
"banana" => :rhel,
|
context "with /etc/os-release file" do
|
||||||
}.each do |str, expected|
|
{
|
||||||
it "returns #{expected} for #{str}" do
|
"7" => :rhel_7,
|
||||||
comm.stub_command("cat /etc/redhat-release", stdout: str)
|
"8" => :rhel_8,
|
||||||
expect(cap.flavor(machine)).to be(expected)
|
"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
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user