From 040f1acf02dc379e3fe577d900b96b47a38a714a Mon Sep 17 00:00:00 2001 From: Felix Bechstein Date: Wed, 27 Jan 2016 08:18:12 +0100 Subject: Shortcut for creating unit files / tmpfiles This change allows creating unit files and reloading systemd with just a single resource. It's fully compatible with the manual behavior. --- spec/defines/tmpfile_spec.rb | 48 ++++++++++++++++++++++++++++++++++++++++++ spec/defines/unit_file_spec.rb | 48 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 96 insertions(+) create mode 100644 spec/defines/tmpfile_spec.rb create mode 100644 spec/defines/unit_file_spec.rb (limited to 'spec/defines') diff --git a/spec/defines/tmpfile_spec.rb b/spec/defines/tmpfile_spec.rb new file mode 100644 index 0000000..4eb22ac --- /dev/null +++ b/spec/defines/tmpfile_spec.rb @@ -0,0 +1,48 @@ +require 'spec_helper' + +describe 'systemd::tmpfile' do + + let(:facts) { { + :path => '/usr/bin', + } } + + context 'default params' do + + let(:title) { 'fancy.conf' } + + it 'creates the tmpfile' do + should contain_file('/etc/tmpfiles.d/fancy.conf').with({ + 'ensure' => 'file', + 'owner' => 'root', + 'group' => 'root', + 'mode' => '0444', + }) + end + + it 'triggers systemd daemon-reload' do + should contain_class('systemd') + should contain_file('/etc/tmpfiles.d/fancy.conf').with_notify("Exec[systemd-tmpfiles-create]") + end + end + + context 'with params' do + let(:title) { 'fancy.conf' } + + let(:params) { { + :ensure => 'absent', + :path => '/etc/tmpfiles.d/foo', + :content => 'some-content', + :source => 'some-source', + } } + + it 'creates the unit file' do + should contain_file('/etc/tmpfiles.d/foo/fancy.conf').with({ + 'ensure' => 'absent', + 'content' => 'some-content', + 'source' => 'some-source', + }) + end + + end + +end diff --git a/spec/defines/unit_file_spec.rb b/spec/defines/unit_file_spec.rb new file mode 100644 index 0000000..0eebbd3 --- /dev/null +++ b/spec/defines/unit_file_spec.rb @@ -0,0 +1,48 @@ +require 'spec_helper' + +describe 'systemd::unit_file' do + + let(:facts) { { + :path => '/usr/bin', + } } + + context 'default params' do + + let(:title) { 'fancy.service' } + + it 'creates the unit file' do + should contain_file('/etc/systemd/system/fancy.service').with({ + 'ensure' => 'file', + 'owner' => 'root', + 'group' => 'root', + 'mode' => '0444', + }) + end + + it 'triggers systemd daemon-reload' do + should contain_class('systemd') + should contain_file('/etc/systemd/system/fancy.service').with_notify("Exec[systemctl-daemon-reload]") + end + end + + context 'with params' do + let(:title) { 'fancy.service' } + + let(:params) { { + :ensure => 'absent', + :path => '/usr/lib/systemd/system', + :content => 'some-content', + :source => 'some-source', + } } + + it 'creates the unit file' do + should contain_file('/usr/lib/systemd/system/fancy.service').with({ + 'ensure' => 'absent', + 'content' => 'some-content', + 'source' => 'some-source', + }) + end + + end + +end -- cgit v1.2.3 From 57283b23aafb47608501ae0ac68c1defa7f4065c Mon Sep 17 00:00:00 2001 From: Theo Chatzimichos Date: Tue, 16 Aug 2016 17:05:47 +0200 Subject: Add target param for the unit file (#10) This is useful in case the Unit file is a symlink to another one --- spec/defines/unit_file_spec.rb | 2 ++ 1 file changed, 2 insertions(+) (limited to 'spec/defines') diff --git a/spec/defines/unit_file_spec.rb b/spec/defines/unit_file_spec.rb index 0eebbd3..88a0122 100644 --- a/spec/defines/unit_file_spec.rb +++ b/spec/defines/unit_file_spec.rb @@ -33,6 +33,7 @@ describe 'systemd::unit_file' do :path => '/usr/lib/systemd/system', :content => 'some-content', :source => 'some-source', + :target => 'some-target', } } it 'creates the unit file' do @@ -40,6 +41,7 @@ describe 'systemd::unit_file' do 'ensure' => 'absent', 'content' => 'some-content', 'source' => 'some-source', + 'target' => 'some-target', }) end -- cgit v1.2.3