e030a93f768a14b1a3baba9cd038e3bea7e75c9d
[mirror/dsa-puppet.git] / 3rdparty / modules / systemd / spec / defines / service_limits_spec.rb
1 require 'spec_helper'
2
3 describe 'systemd::service_limits' do
4   context 'supported operating systems' do
5     on_supported_os.each do |os, facts|
6       context "on #{os}" do
7         let(:facts) { facts }
8
9         let(:title) { 'test.service' }
10
11         describe 'with limits and present' do
12           let(:params) {{
13             :limits => {
14               'LimitCPU'    => '10m',
15               'LimitFSIZE'  => 'infinity',
16               'LimitDATA'   => '10K',
17               'LimitNOFILE' => '20:infinity',
18               'LimitNICE'   => '-10',
19               'LimitRTPRIO' => 50,
20               'IODeviceWeight' => [
21                 {'/dev/weight' => 10},
22                 {'/dev/weight2' => 20}
23               ],
24               'IOReadBandwidthMax' => [
25                 {'/bw/max' => '10K'}
26               ]
27             }
28           }}
29
30           it { is_expected.to compile.with_all_deps }
31           it { is_expected.to create_file("/etc/systemd/system/#{title}.d/90-limits.conf").with(
32             :ensure  => 'file',
33               :content => /LimitCPU=10m/,
34               :mode    => '0444'
35           ) }
36           it { is_expected.to create_file("/etc/systemd/system/#{title}.d/90-limits.conf").with(
37             :content => /LimitFSIZE=infinity/
38           ) }
39           it { is_expected.to create_file("/etc/systemd/system/#{title}.d/90-limits.conf").with(
40             :content => /LimitDATA=10K/
41           ) }
42           it { is_expected.to create_file("/etc/systemd/system/#{title}.d/90-limits.conf").with(
43             :content => /LimitNOFILE=20:infinity/
44           ) }
45           it { is_expected.to create_file("/etc/systemd/system/#{title}.d/90-limits.conf").with(
46             :content => /LimitNICE=-10/
47           ) }
48           it { is_expected.to create_file("/etc/systemd/system/#{title}.d/90-limits.conf").with(
49             :content => /LimitRTPRIO=50/
50           ) }
51           it { is_expected.to create_file("/etc/systemd/system/#{title}.d/90-limits.conf").with(
52             :content => %r(IODeviceWeight=/dev/weight 10)
53           ) }
54           it { is_expected.to create_file("/etc/systemd/system/#{title}.d/90-limits.conf").with(
55             :content => %r(IODeviceWeight=/dev/weight2 20)
56           ) }
57           it { is_expected.to create_file("/etc/systemd/system/#{title}.d/90-limits.conf").with(
58             :content => %r(IOReadBandwidthMax=/bw/max 10K)
59           ) }
60           it { is_expected.to create_exec("restart #{title} because limits").with(
61             :command => "systemctl restart #{title}",
62             :refreshonly => true
63           ) }
64         end
65
66         describe 'ensured absent' do
67           let(:params) {{
68             :ensure => 'absent',
69           }}
70
71           it { is_expected.to compile.with_all_deps }
72           it do
73             is_expected.to create_file("/etc/systemd/system/#{title}.d/90-limits.conf")
74               .with_ensure('absent')
75               .that_notifies("Exec[restart #{title} because limits]")
76           end
77           it do
78             is_expected.to create_exec("restart #{title} because limits")
79               .with_command("systemctl restart #{title}")
80               .with_refreshonly(true)
81           end
82         end
83       end
84     end
85   end
86 end