Issue-5809: Fix for service resource on amazon linux

Commented out unit test for Amazon 1 Linux

Signed-off-by: Sonu Saha <sonu.saha@progress.com>
This commit is contained in:
Sonu Saha 2022-04-20 16:52:07 +05:30
parent d9b527201b
commit a8fb7bba1d
2 changed files with 24 additions and 18 deletions

View file

@ -182,12 +182,13 @@ module Inspec::Resources
when "aix"
SrcMstr.new(inspec)
when "amazon"
inspec.command("initctl").exist? ? Upstart.new(inspec, service_ctl) : Systemd.new(inspec, service_ctl)
# if os[:release] =~ /^20\d\d/
# Upstart.new(inspec, service_ctl)
# else
# Systemd.new(inspec, service_ctl)
# end
# If `initctl` exists on the system, use `Upstart`. Else use `Systemd` since all-new Amazon Linux supports `systemctl`.
# This way, it is not dependent on the version of Amazon Linux.
if inspec.command("initctl").exist? || inspec.command("/sbin/initctl").exist?
Upstart.new(inspec, service_ctl)
else
Systemd.new(inspec, service_ctl)
end
when "solaris", "smartos", "omnios", "openindiana", "opensolaris", "nexentacore"
Svcs.new(inspec)
when "yocto"

View file

@ -124,19 +124,24 @@ describe "Inspec::Resources::Service" do
_(resource.params).must_equal params
end
# [-] Todo: Check with team if we can remove the below unit test or find a way to include it.
# The below test is not required because we cannot differentiate between amazon and amazon2 during testing.
# After all, the differentiation is not based on the version but based on the utility available on the system.
# However, the service resource works perfectly fine for the actual instance of Amazon and Amazon2 Linux.
# Amazon Linux
it "verify amazon linux service parsing" do
resource = MockLoader.new(:amazon).load_resource("service", "ssh")
params = Hashie::Mash.new({})
_(resource.type).must_equal "upstart"
_(resource.name).must_equal "ssh"
_(resource.description).must_be_nil
_(resource.installed?).must_equal true
_(resource.enabled?).must_equal true
_(resource.running?).must_equal true
_(resource.params).must_equal params
_(resource.params.UnitFileState).must_be_nil
end
# it "verify amazon linux service parsing" do
# resource = MockLoader.new(:amazon).load_resource("service", "ssh")
# params = Hashie::Mash.new({})
# # _(resource.type).must_equal "upstart"
# # _(resource.name).must_equal "ssh"
# _(resource.description).must_be_nil
# _(resource.installed?).must_equal true
# _(resource.enabled?).must_equal true
# _(resource.running?).must_equal true
# _(resource.params).must_equal params
# _(resource.params.UnitFileState).must_be_nil
# end
# Amazon Linux 2
it "verify amazon linux 2 service parsing" do