From edd93eea814d0abf79836c899c120b2b999d86db Mon Sep 17 00:00:00 2001 From: Michael Lihs Date: Sat, 18 Jan 2020 01:24:20 +0100 Subject: [PATCH] Add support for yocto linux in service resource Signed-off-by: Michael Lihs --- lib/inspec/resources/service.rb | 2 ++ test/helpers/mock_loader.rb | 1 + test/unit/resources/service_test.rb | 13 +++++++++++++ 3 files changed, 16 insertions(+) diff --git a/lib/inspec/resources/service.rb b/lib/inspec/resources/service.rb index 77b6053bd..c09e28ffd 100644 --- a/lib/inspec/resources/service.rb +++ b/lib/inspec/resources/service.rb @@ -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 diff --git a/test/helpers/mock_loader.rb b/test/helpers/mock_loader.rb index 04248b165..6a4bcda86 100644 --- a/test/helpers/mock_loader.rb +++ b/test/helpers/mock_loader.rb @@ -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 }, } diff --git a/test/unit/resources/service_test.rb b/test/unit/resources/service_test.rb index 4dfb726af..a2f0b406d 100644 --- a/test/unit/resources/service_test.rb +++ b/test/unit/resources/service_test.rb @@ -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")