Skip to content

Commit

Permalink
Merge pull request mizzy#738 from shogo82148/support-amazonlinux2022
Browse files Browse the repository at this point in the history
Support Amazon Linux 2022
  • Loading branch information
mizzy authored Dec 29, 2022
2 parents dacd644 + d11e977 commit d77e338
Show file tree
Hide file tree
Showing 10 changed files with 145 additions and 0 deletions.
7 changes: 7 additions & 0 deletions lib/specinfra/command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,13 @@ module Command
require 'specinfra/command/amazon/v2/service'
require 'specinfra/command/amazon/v2/port'

# Amazon Linux V2022 (inherit RedHat)
require 'specinfra/command/amazon/v2022'
require 'specinfra/command/amazon/v2022/package'
require 'specinfra/command/amazon/v2022/port'
require 'specinfra/command/amazon/v2022/service'
require 'specinfra/command/amazon/v2022/yumrepo'

# AIX (inherit Base)
require 'specinfra/command/aix'
require 'specinfra/command/aix/base'
Expand Down
2 changes: 2 additions & 0 deletions lib/specinfra/command/amazon/v2022.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class Specinfra::Command::Amazon::V2022 < Specinfra::Command::Redhat::Base
end
31 changes: 31 additions & 0 deletions lib/specinfra/command/amazon/v2022/package.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
class Specinfra::Command::Amazon::V2022::Package < Specinfra::Command::Linux::Base::Package
class << self
def check_is_installed(package, version=nil)
cmd = "rpm -q #{escape(package)}"
if version
full_package = "#{package}-#{version}"
cmd = "#{cmd} | grep -w -- #{Regexp.escape(full_package)}"
end
cmd
end

alias :check_is_installed_by_rpm :check_is_installed

def get_version(package, opts=nil)
"rpm -q --qf '%{VERSION}-%{RELEASE}' #{package}"
end

def install(package, version=nil, option='')
if version
full_package = "#{package}-#{version}"
else
full_package = package
end
cmd = "dnf -y #{option} install #{escape(full_package)}"
end

def remove(package, option='')
"dnf -y #{option} remove #{package}"
end
end
end
5 changes: 5 additions & 0 deletions lib/specinfra/command/amazon/v2022/port.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class Specinfra::Command::Amazon::V2022::Port < Specinfra::Command::Amazon::Base::Port
class << self
include Specinfra::Command::Module::Ss
end
end
5 changes: 5 additions & 0 deletions lib/specinfra/command/amazon/v2022/service.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class Specinfra::Command::Amazon::V2022::Service < Specinfra::Command::Amazon::Base::Service
class << self
include Specinfra::Command::Module::Systemd
end
end
11 changes: 11 additions & 0 deletions lib/specinfra/command/amazon/v2022/yumrepo.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class Specinfra::Command::Amazon::V2022::Yumrepo < Specinfra::Command::Redhat::Base::Yumrepo
class << self
def check_exists(repository)
"dnf repolist all | grep -qsE \"^[\\!\\*]?#{escape(repository)}\(\\s\|$\|\\/)\""
end

def check_is_enabled(repository)
"dnf repolist enabled | grep -qs \"^[\\!\\*]\\?#{escape(repository)}\""
end
end
end
32 changes: 32 additions & 0 deletions spec/command/amazon2022/package_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
require 'spec_helper'

property[:os] = nil
set :os, :family => 'amazon', :release => '2022'

describe get_command(:check_package_is_installed, 'telnet') do
it { should eq 'rpm -q telnet' }
end

describe get_command(:check_package_is_installed, 'telnet', '0.17-48.el6.x86_64') do
it { should eq 'rpm -q telnet | grep -w -- telnet\\-0\\.17\\-48\\.el6\\.x86_64' }
end

describe get_command(:check_package_is_installed, 'linux-headers-$(uname -r)') do
it 'should be escaped (that is, command substitution should not work' do
should eq 'rpm -q linux-headers-\\$\\(uname\\ -r\\)'
end
end

describe get_command(:install_package, 'telnet') do
it { should eq "dnf -y install telnet" }
end

describe get_command(:install_package, 'telnet', '0.17-48.el6.x86_64') do
it { should eq "dnf -y install telnet-0.17-48.el6.x86_64" }
end

describe get_command(:install_package, 'linux-headers-$(uname -r)') do
it 'should be escaped (that is, command substitution should no work)' do
should eq "dnf -y install linux-headers-\\$\\(uname\\ -r\\)"
end
end
8 changes: 8 additions & 0 deletions spec/command/amazon2022/port_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
require 'spec_helper'

property[:os] = nil
set :os, :family => 'amazon', :release => '2022'

describe get_command(:check_port_is_listening, '80') do
it { should eq 'ss -tunl | grep -E -- :80\ ' }
end
32 changes: 32 additions & 0 deletions spec/command/amazon2022/service_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
require 'spec_helper'

property[:os] = nil
set :os, :family => 'amazon', :release => '2022'

describe get_command(:enable_service, 'httpd') do
it { should eq 'systemctl enable httpd' }
end

describe get_command(:disable_service, 'httpd') do
it { should eq 'systemctl disable httpd' }
end

describe get_command(:start_service, 'httpd') do
it { should eq 'systemctl start httpd' }
end

describe get_command(:stop_service, 'httpd') do
it { should eq 'systemctl stop httpd' }
end

describe get_command(:restart_service, 'httpd') do
it { should eq 'systemctl restart httpd' }
end

describe get_command(:reload_service, 'httpd') do
it { should eq 'systemctl reload httpd' }
end

describe get_command(:enable_service, 'sshd.socket') do
it { should eq 'systemctl enable sshd.socket' }
end
12 changes: 12 additions & 0 deletions spec/command/amazon2022/yumrepo_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
require 'spec_helper'

property[:os] = nil
set :os, :family => 'amazon', :release => '2022'

describe get_command(:check_yumrepo_exists, 'epel') do
it { should eq "dnf repolist all | grep -qsE \"^[\\!\\*]?epel\(\\s\|$\|\\/)\"" }
end

describe get_command(:check_yumrepo_is_enabled, 'epel') do
it { should eq "dnf repolist enabled | grep -qs \"^[\\!\\*]\\?epel\"" }
end

0 comments on commit d77e338

Please sign in to comment.