Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to support Puppet 4 #18

Merged
merged 11 commits into from
Jul 19, 2017
Prev Previous commit
Next Next commit
Code Review Updates
  • Loading branch information
trevor-vaughan committed Jul 16, 2017
commit 1b706a86f786f06a0fa930ddfa9905e864d18f09
3 changes: 1 addition & 2 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
Boolean $manage_networkd = true,
){

include '::systemd::systemctl::daemon_reload'
include '::systemd::tmpfiles'
contain systemd::systemctl::daemon_reload

if $service_limits {
create_resources('systemd::service_limits', $service_limits)
Expand Down
11 changes: 5 additions & 6 deletions manifests/service_limits.pp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
Optional[String] $source = undef,
Boolean $restart_service = true
) {
include ::systemd

include systemd

if $title !~ Pattern['^.+\.(service|socket|mount|swap)$'] {
fail('$name must match Pattern["^.+\.(service|socket|mount|swap)$"]')
Expand Down Expand Up @@ -70,18 +71,16 @@
owner => 'root',
group => 'root',
mode => '0644',
notify => Class['systemd::systemctl::daemon_reload']
}

File["${path}/${title}.d/90-limits.conf"] ~> Class['systemd::systemctl::daemon_reload']

if $restart_service {
exec { "restart ${title} because limits":
command => "systemctl restart ${title}",
path => $::path,
refreshonly => true,
subscribe => File["${path}/${title}.d/90-limits.conf"],
require => Class['systemd::systemctl::daemon_reload']
}

File["${path}/${title}.d/90-limits.conf"] ~> Exec["restart ${title} because limits"]
Class['systemd::systemctl::daemon_reload'] -> Exec["restart ${title} because limits"]
}
}
6 changes: 3 additions & 3 deletions manifests/tmpfile.pp
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@
Optional[String] $content = undef,
Optional[String] $source = undef,
) {
include ::systemd
include systemd::tmpfiles

if name =~ Pattern['/'] {
if $title =~ Pattern['/'] {
fail('$name may not contain a forward slash "(/)"')
}

Expand All @@ -43,7 +43,7 @@
source => $source,
owner => 'root',
group => 'root',
mode => '0644',
mode => '0444',
notify => Class['systemd::tmpfiles'],
}
}
11 changes: 4 additions & 7 deletions manifests/unit_file.pp
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,13 @@
Optional[String] $source = undef,
Optional[Stdlib::Absolutepath] $target = undef,
) {
include ::systemd
include systemd

if $title !~ Pattern['^.+\.(service|socket|device|mount|automount|swap|target|path|timer|slice|scope)$'] {
fail('$name must match Pattern["^.+\.(service|socket|device|mount|automount|swap|target|path|timer|slice|scope)$"]')
}
assert_type(Systemd::Unit, $title)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would rather assert $name and use a path attribute in the file below, to allow users to choose their resource title as they want.


if $target {
$_ensure = 'link'
}
else {
} else {
$_ensure = $ensure
}

Expand All @@ -54,7 +51,7 @@
target => $target,
owner => 'root',
group => 'root',
mode => '0644',
mode => '0444',
notify => Class['systemd::systemctl::daemon_reload'],
}
}
1 change: 0 additions & 1 deletion spec/classes/init_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
it { is_expected.to compile.with_all_deps }
it { is_expected.to create_class('systemd') }
it { is_expected.to create_class('systemd::systemctl::daemon_reload') }
it { is_expected.to create_class('systemd::tmpfiles') }
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/defines/tmpfile_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
it { is_expected.to create_file("/etc/tmpfiles.d/#{title}").with(
:ensure => 'file',
:content => /#{params[:content]}/,
:mode => '0644'
:mode => '0444'
) }
end
end
Expand Down
14 changes: 13 additions & 1 deletion spec/defines/unit_file_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,24 @@
}}

it { is_expected.to compile.with_all_deps }

it { is_expected.to create_file("/etc/systemd/system/#{title}").with(
:ensure => 'file',
:content => /#{params[:content]}/,
:mode => '0644'
:mode => '0444'
) }

it { is_expected.to create_file("/etc/systemd/system/#{title}").that_notifies('Class[systemd::systemctl::daemon_reload]') }

context 'with a bad unit type' do
let(:title) { 'test.badtype' }

it {
expect{
is_expected.to compile.with_all_deps
}.to raise_error(/expects a match for Systemd::Unit/)
}
end
end
end
end
Expand Down
1 change: 1 addition & 0 deletions types/unit.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
type Systemd::Unit = Pattern['^.+\.(service|socket|device|mount|automount|swap|target|path|timer|slice|scope)$']