Add support for yocto linux in service resource

Signed-off-by: Michael Lihs <michael.lihs@thoughtworks.com>
This commit is contained in:
Michael Lihs 2020-01-18 01:24:20 +01:00
parent 1f77cb1369
commit edd93eea81
3 changed files with 16 additions and 0 deletions

View file

@ -172,6 +172,8 @@ module Inspec::Resources
end
elsif os.solaris?
Svcs.new(inspec)
elsif %w{yocto}.include?(platform)
Systemd.new(inspec, service_ctl)
end
end

View file

@ -31,6 +31,7 @@ class MockLoader
aix: { name: "aix", family: "aix", release: "7.2", arch: "powerpc" },
amazon: { name: "amazon", family: "redhat", release: "2015.03", arch: "x86_64" },
amazon2: { name: "amazon", family: "redhat", release: "2", arch: "x86_64" },
yocto: { name: "yocto", family: "yocto", release: "0.0.1", arch: "aarch64" },
undefined: { name: nil, family: nil, release: nil, arch: nil },
}

View file

@ -417,6 +417,19 @@ describe "Inspec::Resources::Service" do
_(resource.params).must_equal params
end
# yocto
it "verify yocto service parsing" do
resource = MockLoader.new(:yocto).load_resource("service", "sshd")
params = Hashie::Mash.new({ "ActiveState" => "active", "Description" => "OpenSSH server daemon", "Id" => "sshd.service", "LoadState" => "loaded", "Names" => "sshd.service", "SubState" => "running", "UnitFileState" => "enabled" })
_(resource.type).must_equal "systemd"
_(resource.name).must_equal "sshd.service"
_(resource.description).must_equal "OpenSSH server daemon"
_(resource.installed?).must_equal true
_(resource.enabled?).must_equal true
_(resource.running?).must_equal true
_(resource.params).must_equal params
end
# unknown OS
it "verify service handling on unsupported os" do
resource = MockLoader.new(:undefined).load_resource("service", "dhcp")