From c518b9edc2875e40ca623be1337683da6c590507 Mon Sep 17 00:00:00 2001 From: Alex Pop Date: Fri, 6 May 2016 12:22:56 +0100 Subject: [PATCH] expose systemd service properties via .info --- lib/resources/service.rb | 1 + test/unit/resources/service_test.rb | 14 +++++++------- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/lib/resources/service.rb b/lib/resources/service.rb index e71836b50..aaf1438a3 100644 --- a/lib/resources/service.rb +++ b/lib/resources/service.rb @@ -229,6 +229,7 @@ module Inspec::Resources running: running, enabled: enabled, type: 'systemd', + properties: params, } end end diff --git a/test/unit/resources/service_test.rb b/test/unit/resources/service_test.rb index 89d3eb2e4..5afbcc72a 100644 --- a/test/unit/resources/service_test.rb +++ b/test/unit/resources/service_test.rb @@ -40,7 +40,7 @@ describe 'Inspec::Resources::Service' do # ubuntu 15.04 with systemd it 'verify ubuntu package parsing' do resource = MockLoader.new(:ubuntu1504).load_resource('service', 'sshd') - srv = { name: 'sshd.service', description: 'OpenSSH server daemon', installed: true, running: true, enabled: true, type: 'systemd' } + srv = { name: 'sshd.service', description: 'OpenSSH server daemon', installed: true, running: true, enabled: true, type: 'systemd', :properties=>{"Id"=>"sshd.service", "Names"=>"sshd.service", "Description"=>"OpenSSH server daemon", "LoadState"=>"loaded", "UnitFileState"=>"enabled", "SubState"=>"running"} } _(resource.info).must_equal srv _(resource.installed?).must_equal true _(resource.enabled?).must_equal true @@ -49,7 +49,7 @@ describe 'Inspec::Resources::Service' do it 'verify ubuntu package parsing with default systemd_service' do resource = MockLoader.new(:ubuntu1504).load_resource('systemd_service', 'sshd') - srv = { name: 'sshd.service', description: 'OpenSSH server daemon', installed: true, running: true, enabled: true, type: 'systemd' } + srv = { name: 'sshd.service', description: 'OpenSSH server daemon', installed: true, running: true, enabled: true, type: 'systemd', :properties=>{"Id"=>"sshd.service", "Names"=>"sshd.service", "Description"=>"OpenSSH server daemon", "LoadState"=>"loaded", "UnitFileState"=>"enabled", "SubState"=>"running"} } _(resource.info).must_equal srv _(resource.installed?).must_equal true _(resource.enabled?).must_equal true @@ -78,7 +78,7 @@ describe 'Inspec::Resources::Service' do # centos 7 with systemd it 'verify centos 7 package parsing' do resource = MockLoader.new(:centos7).load_resource('service', 'sshd') - srv = { name: 'sshd.service', description: 'OpenSSH server daemon', installed: true, running: true, enabled: true, type: 'systemd' } + srv = { name: 'sshd.service', description: 'OpenSSH server daemon', installed: true, running: true, enabled: true, type: 'systemd', :properties=>{"Id"=>"sshd.service", "Names"=>"sshd.service", "Description"=>"OpenSSH server daemon", "LoadState"=>"loaded", "UnitFileState"=>"enabled", "SubState"=>"running"} } _(resource.info).must_equal srv _(resource.installed?).must_equal true _(resource.enabled?).must_equal true @@ -87,7 +87,7 @@ describe 'Inspec::Resources::Service' do it 'verify centos 7 package parsing with systemd_service and service_ctl override' do resource = MockLoader.new(:centos7).load_resource('systemd_service', 'sshd', '/path/to/systemctl') - srv = { name: 'sshd.service', description: 'OpenSSH server daemon', installed: true, running: true, enabled: true, type: 'systemd' } + srv = { name: 'sshd.service', description: 'OpenSSH server daemon', installed: true, running: true, enabled: true, type: 'systemd', :properties=>{"Id"=>"sshd.service", "Names"=>"sshd.service", "Description"=>"OpenSSH server daemon", "LoadState"=>"loaded", "UnitFileState"=>"enabled", "SubState"=>"running"} } _(resource.info).must_equal srv _(resource.installed?).must_equal true _(resource.enabled?).must_equal true @@ -96,7 +96,7 @@ describe 'Inspec::Resources::Service' do it 'verify centos 7 package parsing with static loaded service' do resource = MockLoader.new(:centos7).load_resource('service', 'dbus') - srv = { name: 'dbus.service', description: 'D-Bus System Message Bus', installed: true, running: true, enabled: true, type: 'systemd' } + srv = { name: 'dbus.service', description: 'D-Bus System Message Bus', installed: true, running: true, enabled: true, type: 'systemd', :properties=>{"Id"=>"dbus.service", "Names"=>"messagebus.service dbus.service", "Description"=>"D-Bus System Message Bus", "LoadState"=>"loaded", "UnitFileState"=>"static", "SubState"=>"running"} } _(resource.info).must_equal srv _(resource.installed?).must_equal true _(resource.enabled?).must_equal true @@ -125,7 +125,7 @@ describe 'Inspec::Resources::Service' do # arch linux with systemd it 'verify arch linux package parsing' do resource = MockLoader.new(:arch).load_resource('service', 'sshd') - srv = { name: 'sshd.service', description: 'OpenSSH server daemon', installed: true, running: true, enabled: true, type: 'systemd' } + srv = { name: 'sshd.service', description: 'OpenSSH server daemon', installed: true, running: true, enabled: true, type: 'systemd', :properties=>{"Id"=>"sshd.service", "Names"=>"sshd.service", "Description"=>"OpenSSH server daemon", "LoadState"=>"loaded", "UnitFileState"=>"enabled", "SubState"=>"running"} } _(resource.info).must_equal srv _(resource.installed?).must_equal true _(resource.enabled?).must_equal true @@ -145,7 +145,7 @@ describe 'Inspec::Resources::Service' do # debian 8 with systemd it 'verify debian 8 package parsing' do resource = MockLoader.new(:debian8).load_resource('service', 'sshd') - srv = { name: 'sshd.service', description: 'OpenSSH server daemon', installed: true, running: true, enabled: true, type: 'systemd' } + srv = { name: 'sshd.service', description: 'OpenSSH server daemon', installed: true, running: true, enabled: true, type: 'systemd', :properties=>{"Id"=>"sshd.service", "Names"=>"sshd.service", "Description"=>"OpenSSH server daemon", "LoadState"=>"loaded", "UnitFileState"=>"enabled", "SubState"=>"running"} } _(resource.info).must_equal srv _(resource.installed?).must_equal true _(resource.enabled?).must_equal true