Linux Mint support for service resource

This commit is contained in:
Artem Sidorenko 2016-10-08 23:03:59 +02:00
parent 4ee32ebac4
commit aa725fe2df
3 changed files with 61 additions and 0 deletions

View file

@ -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

View file

@ -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'},

View file

@ -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')