Merge pull request #4233 from jaredledvina/patch-1

Debian service detection for Buster
This commit is contained in:
Miah Johnson 2019-07-01 23:39:01 -07:00 committed by GitHub
commit 825751bdb9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 2 deletions

View file

@ -127,10 +127,14 @@ module Inspec::Resources
Systemd.new(inspec, service_ctl)
end
elsif %w{debian}.include?(platform)
if os[:release] == "buster/sid"
version = 10
else
version = os[:release].to_i
end
if version > 7
Systemd.new(inspec, service_ctl)
else
elsif version > 0
SysV.new(inspec, service_ctl || "/usr/sbin/service")
end
elsif %w{redhat fedora centos oracle cloudlinux}.include?(platform)

View file

@ -13,6 +13,7 @@ class MockLoader
debian6: { name: "debian", family: "debian", release: "6", arch: "x86_64" },
debian7: { name: "debian", family: "debian", release: "7", arch: "x86_64" },
debian8: { name: "debian", family: "debian", release: "8", arch: "x86_64" },
debian10: { name: "debian", family: "debian", release: "buster/sid", arch: "x86_64" },
freebsd9: { name: "freebsd", family: "freebsd", release: "9", arch: "amd64" },
freebsd10: { name: "freebsd", family: "freebsd", release: "10", arch: "amd64" },
osx104: { name: "mac_os_x", family: "darwin", release: "10.10.4", arch: nil },

View file

@ -330,6 +330,19 @@ describe "Inspec::Resources::Service" do
_(resource.params).must_equal params
end
# debian 10 with systemd
it "verify debian 10 service parsing" do
resource = MockLoader.new(:debian10).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
# debian 8 with systemd but no service file
it "gets the correct service info when the `.service` file is missing" do
resource = MockLoader.new(:debian8).load_resource("service", "apache2")