From aa725fe2dfec1303eaf06a466674472d218cb372 Mon Sep 17 00:00:00 2001 From: Artem Sidorenko Date: Sat, 8 Oct 2016 23:03:59 +0200 Subject: [PATCH] Linux Mint support for service resource --- lib/resources/service.rb | 7 ++++ test/helper.rb | 2 ++ test/unit/resources/service_test.rb | 52 +++++++++++++++++++++++++++++ 3 files changed, 61 insertions(+) diff --git a/lib/resources/service.rb b/lib/resources/service.rb index 58c3be55f..83ae1940a 100644 --- a/lib/resources/service.rb +++ b/lib/resources/service.rb @@ -120,6 +120,13 @@ module Inspec::Resources else Systemd.new(inspec, service_ctl) end + elsif %w{linuxmint}.include?(platform) + version = os[:release].to_f + if version < 18 + Upstart.new(inspec, service_ctl) + else + Systemd.new(inspec, service_ctl) + end elsif %w{debian}.include?(platform) version = os[:release].to_i if version > 7 diff --git a/test/helper.rb b/test/helper.rb index 47b50f4f4..dcbd267bc 100644 --- a/test/helper.rb +++ b/test/helper.rb @@ -49,6 +49,8 @@ class MockLoader ubuntu1204: { name: 'ubuntu', family: 'debian', release: '12.04', arch: 'x86_64' }, ubuntu1404: { name: 'ubuntu', family: 'debian', release: '14.04', arch: 'x86_64' }, ubuntu1504: { name: 'ubuntu', family: 'debian', release: '15.04', arch: 'x86_64' }, + mint17: { name: 'linuxmint', family: 'debian', release: '17.3', arch: 'x86_64' }, + mint18: { name: 'linuxmint', family: 'debian', release: '18', arch: 'x86_64' }, windows: { name: 'windows', family: 'windows', release: '6.2.9200', arch: 'x86_64' }, wrlinux: { name: 'wrlinux', family: 'redhat', release: '7.0(3)I2(2)', arch: 'x86_64' }, solaris11: { name: "solaris", family: 'solaris', release: '11', arch: 'i386'}, diff --git a/test/unit/resources/service_test.rb b/test/unit/resources/service_test.rb index 3f80fd936..0bf7d9f7f 100644 --- a/test/unit/resources/service_test.rb +++ b/test/unit/resources/service_test.rb @@ -75,6 +75,58 @@ describe 'Inspec::Resources::Service' do _(resource.params).must_equal params end + # linux mint 17 with upstart + it 'verify mint package parsing' do + resource = MockLoader.new(:mint17).load_resource('service', 'ssh') + params = Hashie::Mash.new({}) + _(resource.type).must_equal 'upstart' + _(resource.name).must_equal 'ssh' + _(resource.description).must_equal nil + _(resource.installed?).must_equal true + _(resource.enabled?).must_equal true + _(resource.running?).must_equal true + _(resource.params).must_equal params + end + + it 'verify mint package parsing with default upstart_service' do + resource = MockLoader.new(:mint17).load_resource('upstart_service', 'ssh') + params = Hashie::Mash.new({}) + _(resource.type).must_equal 'upstart' + _(resource.name).must_equal 'ssh' + _(resource.description).must_equal 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_equal nil + end + + # mint 18 with systemd + it 'verify mint package parsing' do + resource = MockLoader.new(:mint18).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 + _(resource.params.SubState).must_equal 'running' + end + + it 'verify mint package parsing with default systemd_service' do + resource = MockLoader.new(:mint18).load_resource('systemd_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 + # centos 6 with sysv it 'verify centos 6 package parsing' do resource = MockLoader.new(:centos6).load_resource('service', 'sshd')