2
2
3
3
describe 'puppet_metrics_collector::system' do
4
4
context 'with default parameters' do
5
- it { is_expected . not_to contain_package ( 'sysstat' ) }
6
- it { is_expected . not_to contain_package ( 'open-vm-tools' ) }
5
+ it {
6
+ is_expected . not_to contain_package ( 'sysstat' )
7
+ is_expected . not_to contain_package ( 'open-vm-tools' )
8
+ }
7
9
end
8
10
9
11
context 'with sysstat' do
10
12
context 'already installed' do
11
13
let ( :pre_condition ) { 'package{"sysstat": }' }
12
14
let ( :facts ) { { puppet_metrics_collector : { have_sysstat : true , have_systemd : true } } }
13
15
14
- it { is_expected . to contain_class ( 'puppet_metrics_collector::system::cpu' ) }
15
- it { is_expected . to contain_class ( 'puppet_metrics_collector::system::memory' ) }
16
- it { is_expected . to contain_class ( 'puppet_metrics_collector::system::processes' ) }
16
+ it {
17
+ is_expected . not_to contain_class ( 'puppet_metrics_collector::system::cpu' )
18
+ is_expected . not_to contain_class ( 'puppet_metrics_collector::system::memory' )
19
+ is_expected . to contain_class ( 'puppet_metrics_collector::system::sar' )
20
+ is_expected . to contain_class ( 'puppet_metrics_collector::system::processes' )
21
+ is_expected . to contain_file ( '/opt/puppetlabs/puppet-metrics-collector/scripts/system_metrics' )
22
+
23
+ legacy_crons = [
24
+ 'system_cpu_metrics_collection' ,
25
+ 'system_cpu_metrics_tidy' ,
26
+ 'system_processes_metrics_collection' ,
27
+ 'system_processes_metrics_tidy' ,
28
+ 'system_memory_metrics_collection' ,
29
+ 'system_memory_metrics_tidy' ,
30
+ ]
31
+ legacy_crons . each { |cron | is_expected . to contain_cron ( cron ) . with_ensure ( 'absent' ) }
32
+
33
+ [ 'system_cpu' , 'system_processes' ] . each do |service |
34
+ is_expected . to contain_puppet_metrics_collector__collect ( service )
35
+ is_expected . to contain_puppet_metrics_collector__sar_metric ( service )
36
+
37
+ is_expected . to contain_file ( "/opt/puppetlabs/puppet-metrics-collector/#{ service } " )
38
+
39
+ is_expected . to contain_file ( "/etc/systemd/system/puppet_#{ service } -tidy.service" )
40
+ is_expected . to contain_file ( "/etc/systemd/system/puppet_#{ service } -tidy.timer" )
41
+ is_expected . to contain_file ( "/etc/systemd/system/puppet_#{ service } -metrics.service" )
42
+ is_expected . to contain_file ( "/etc/systemd/system/puppet_#{ service } -metrics.timer" )
43
+
44
+ is_expected . to contain_service ( "puppet_#{ service } -metrics.service" )
45
+ is_expected . to contain_service ( "puppet_#{ service } -metrics.timer" )
46
+ is_expected . to contain_service ( "puppet_#{ service } -tidy.service" )
47
+ is_expected . to contain_service ( "puppet_#{ service } -tidy.timer" )
48
+ end
49
+
50
+ legacy_files = [
51
+ '/opt/puppetlabs/puppet-metrics-collector/scripts/system_processes_metrics_tidy' ,
52
+ '/opt/puppetlabs/puppet-metrics-collector/scripts/system_memory_metrics_tidy' ,
53
+ '/opt/puppetlabs/puppet-metrics-collector/scripts/system_cpu_metrics_tidy' ,
54
+ '/opt/puppetlabs/puppet-metrics-collector/scripts/generate_system_metrics' ,
55
+ ]
56
+ legacy_files . each { |file | is_expected . to contain_file ( file ) . with_ensure ( 'absent' ) }
57
+
58
+ [ 'system_memory' ] . each do |service |
59
+ is_expected . to contain_puppet_metrics_collector__sar_metric ( service ) . with_metric_ensure ( 'absent' )
60
+ is_expected . to contain_puppet_metrics_collector__collect ( service ) . with_ensure ( 'absent' )
61
+
62
+ is_expected . to contain_file ( "/etc/systemd/system/puppet_#{ service } -tidy.service" ) . with_ensure ( 'absent' )
63
+ is_expected . to contain_file ( "/etc/systemd/system/puppet_#{ service } -tidy.timer" ) . with_ensure ( 'absent' )
64
+ is_expected . to contain_file ( "/etc/systemd/system/puppet_#{ service } -metrics.service" ) . with_ensure ( 'absent' )
65
+ is_expected . to contain_file ( "/etc/systemd/system/puppet_#{ service } -metrics.timer" ) . with_ensure ( 'absent' )
66
+ is_expected . to contain_file ( "/opt/puppetlabs/puppet-metrics-collector/#{ service } " ) . with_ensure ( 'absent' )
67
+
68
+ is_expected . to contain_service ( "puppet_#{ service } -metrics.service" ) . with_ensure ( 'stopped' )
69
+ is_expected . to contain_service ( "puppet_#{ service } -metrics.timer" ) . with_ensure ( 'stopped' )
70
+ is_expected . to contain_service ( "puppet_#{ service } -tidy.service" ) . with_ensure ( 'stopped' )
71
+ is_expected . to contain_service ( "puppet_#{ service } -tidy.timer" ) . with_ensure ( 'stopped' )
72
+ end
73
+ }
17
74
end
18
75
19
76
context 'not installed and managed' do
20
77
let ( :params ) { { manage_sysstat : true } }
21
78
let ( :facts ) { { puppet_metrics_collector : { have_sysstat : false , have_systemd : true } } }
22
79
23
80
it { is_expected . to contain_package ( 'sysstat' ) }
24
- it { is_expected . to contain_class ( 'puppet_metrics_collector::system::cpu' ) }
25
- it { is_expected . to contain_class ( 'puppet_metrics_collector::system::memory' ) }
81
+ it { is_expected . not_to contain_class ( 'puppet_metrics_collector::system::cpu' ) }
82
+ it { is_expected . not_to contain_class ( 'puppet_metrics_collector::system::memory' ) }
83
+ it { is_expected . to contain_class ( 'puppet_metrics_collector::system::sar' ) }
26
84
it { is_expected . to contain_class ( 'puppet_metrics_collector::system::processes' ) }
27
85
end
28
86
29
87
context 'not installed and not managed' do
30
88
it { is_expected . not_to contain_package ( 'sysstat' ) }
31
89
it { is_expected . not_to contain_class ( 'puppet_metrics_collector::system::cpu' ) }
32
90
it { is_expected . not_to contain_class ( 'puppet_metrics_collector::system::memory' ) }
91
+ it { is_expected . not_to contain_class ( 'puppet_metrics_collector::system::sar' ) }
33
92
it { is_expected . not_to contain_class ( 'puppet_metrics_collector::system::processes' ) }
34
93
end
35
94
end
42
101
context 'when the virtual fact reports vmware' do
43
102
let ( :facts ) { { virtual : 'vmware' } }
44
103
45
- it { is_expected . to contain_class ( 'puppet_metrics_collector::system::vmware' ) }
46
- it { is_expected . not_to contain_package ( 'open-vm-tools' ) }
104
+ it {
105
+ is_expected . to contain_class ( 'puppet_metrics_collector::system::vmware' )
106
+ is_expected . not_to contain_package ( 'open-vm-tools' )
107
+
108
+ is_expected . to contain_exec ( 'puppet_metrics_collector_system_daemon_reload' )
109
+
110
+ legacy_crons = [
111
+ 'vmware_metrics_collection' ,
112
+ 'vmware_metrics_tidy' ,
113
+ ]
114
+ legacy_crons . each { |cron | is_expected . to contain_cron ( cron ) . with_ensure ( 'absent' ) }
115
+
116
+ is_expected . to contain_puppet_metrics_collector__collect ( 'vmware' )
117
+
118
+ is_expected . to contain_file ( '/opt/puppetlabs/puppet-metrics-collector/vmware' )
119
+ is_expected . to contain_file ( '/opt/puppetlabs/puppet-metrics-collector/scripts/vmware_metrics' )
120
+
121
+ is_expected . to contain_file ( '/etc/systemd/system/puppet_vmware-tidy.service' )
122
+ is_expected . to contain_file ( '/etc/systemd/system/puppet_vmware-tidy.timer' )
123
+ is_expected . to contain_file ( '/etc/systemd/system/puppet_vmware-metrics.service' )
124
+ is_expected . to contain_file ( '/etc/systemd/system/puppet_vmware-metrics.timer' )
125
+
126
+ is_expected . to contain_service ( 'puppet_vmware-metrics.service' )
127
+ is_expected . to contain_service ( 'puppet_vmware-metrics.timer' )
128
+ is_expected . to contain_service ( 'puppet_vmware-tidy.service' )
129
+ is_expected . to contain_service ( 'puppet_vmware-tidy.timer' )
130
+ }
47
131
48
132
context 'when management of VMware Tools is enabled' do
49
133
let ( :params ) { { manage_vmware_tools : true , vmware_tools_pkg : 'foo-tools' } }
67
151
context 'when /opt/puppetlabs/server/bin/psql is present' do
68
152
let ( :facts ) { { puppet_metrics_collector : { have_pe_psql : true , have_systemd : true } } }
69
153
70
- it { is_expected . to contain_service ( 'puppet_postgres-metrics.timer' ) . with_ensure ( 'running' ) }
154
+ it {
155
+ is_expected . to contain_class ( 'puppet_metrics_collector::system::postgres' )
156
+ is_expected . to contain_puppet_metrics_collector__collect ( 'postgres' )
157
+
158
+ is_expected . to contain_file ( '/opt/puppetlabs/puppet-metrics-collector/postgres' )
159
+ is_expected . to contain_file ( '/opt/puppetlabs/puppet-metrics-collector/scripts/psql_metrics' )
160
+
161
+ is_expected . to contain_file ( '/etc/systemd/system/puppet_postgres-tidy.service' )
162
+ is_expected . to contain_file ( '/etc/systemd/system/puppet_postgres-tidy.timer' )
163
+ is_expected . to contain_file ( '/etc/systemd/system/puppet_postgres-metrics.service' )
164
+ is_expected . to contain_file ( '/etc/systemd/system/puppet_postgres-metrics.timer' )
165
+
166
+ is_expected . to contain_service ( 'puppet_postgres-metrics.service' )
167
+ is_expected . to contain_service ( 'puppet_postgres-metrics.timer' )
168
+ is_expected . to contain_service ( 'puppet_postgres-tidy.service' )
169
+ is_expected . to contain_service ( 'puppet_postgres-tidy.timer' )
170
+
171
+ legacy_crons = [
172
+ 'postgres_metrics_collection' ,
173
+ 'postgres_metrics_tidy' ,
174
+ ]
175
+ legacy_crons . each { |cron | is_expected . to contain_cron ( cron ) . with_ensure ( 'absent' ) }
176
+ }
71
177
end
72
178
73
179
context 'when /opt/puppetlabs/server/bin/psql is absent' do
@@ -113,7 +219,7 @@ class {'puppet_metrics_collector':
113
219
end
114
220
let ( :facts ) { { puppet_metrics_collector : { have_sysstat : true , have_systemd : true } } }
115
221
116
- it { is_expected . not_to contain_puppet_metrics_collector__collect ( 'system_cpu ' ) . with_metrics_command ( %r{--influx-db\s +puppet_metrics} ) }
222
+ it { is_expected . not_to contain_puppet_metrics_collector__collect ( 'sar ' ) . with_metrics_command ( %r{--influx-db\s +puppet_metrics} ) }
117
223
end
118
224
119
225
context 'when customizing the collection frequency' do
@@ -123,7 +229,7 @@ class {'puppet_metrics_collector':
123
229
end
124
230
let ( :params ) { { collection_frequency : 10 } }
125
231
126
- [ 'system_cpu' , 'system_memory' , ' system_processes', 'postgres' , 'vmware' ] . each do |service |
232
+ [ 'system_cpu' , 'system_processes' , 'postgres' , 'vmware' ] . each do |service |
127
233
it { is_expected . to contain_file ( "/etc/systemd/system/puppet_#{ service } -metrics.timer" ) . with_content ( %r{OnCalendar=.*0\/ 10} ) }
128
234
end
129
235
end
0 commit comments