@@ -87,6 +87,7 @@ def aggregator():
8787 aggregator .reset ()
8888 return aggregator
8989
90+
9091@pytest .fixture (scope = "module" )
9192def psutil_mocks ():
9293 p1 = mock .patch ('psutil.disk_partitions' , return_value = [MockPart ()],
@@ -104,6 +105,7 @@ def psutil_mocks():
104105 p3 .stop ()
105106 p4 .stop ()
106107
108+
107109def test_bad_config ():
108110 """
109111 Check creation will fail if more than one `instance` is passed to the
@@ -112,6 +114,7 @@ def test_bad_config():
112114 with pytest .raises (Exception ):
113115 Disk ('disk' , None , {}, [{}, {}])
114116
117+
115118def test_default_options ():
116119 check = Disk ('disk' , None , {}, [{}])
117120
@@ -124,6 +127,7 @@ def test_default_options():
124127 assert check ._device_tag_re == []
125128 assert check ._service_check_rw is False
126129
130+
127131def test_disk_check (aggregator ):
128132 """
129133 Basic check to see if all metrics are there
@@ -135,6 +139,7 @@ def test_disk_check(aggregator):
135139
136140 assert aggregator .metrics_asserted_pct == 100.0
137141
142+
138143def test__exclude_disk_psutil ():
139144 """
140145 Test exclusion logic
@@ -177,6 +182,7 @@ def test__exclude_disk_psutil():
177182 assert c ._exclude_disk_psutil (MockPart (device = 'sdz' , mountpoint = '/run' )) is True
178183 assert c ._exclude_disk_psutil (MockPart (device = 'sdz' , mountpoint = '/run/shm' )) is False
179184
185+
180186def test_device_exclusion_logic_no_name ():
181187 """
182188 Same as above but with default configuration values and device='' to expose a bug in #2359
@@ -191,6 +197,7 @@ def test_device_exclusion_logic_no_name():
191197 assert c ._exclude_disk_psutil (MockPart (device = '' , mountpoint = '/run' )) is True
192198 assert c ._exclude_disk_psutil (MockPart (device = '' , mountpoint = '/run/shm' )) is False
193199
200+
194201def test_psutil (aggregator , psutil_mocks ):
195202 """
196203 Mock psutil and run the check
@@ -210,6 +217,7 @@ def test_psutil(aggregator, psutil_mocks):
210217
211218 assert aggregator .metrics_asserted_pct == 100.0
212219
220+
213221def test_use_mount (aggregator , psutil_mocks ):
214222 """
215223 Same as above, using mount to tag
@@ -226,6 +234,7 @@ def test_use_mount(aggregator, psutil_mocks):
226234
227235 assert aggregator .metrics_asserted_pct == 100.0
228236
237+
229238def test_psutil_rw (aggregator , psutil_mocks ):
230239 """
231240 Check for 'ro' option in the mounts
@@ -236,6 +245,7 @@ def test_psutil_rw(aggregator, psutil_mocks):
236245
237246 aggregator .assert_service_check ('disk.read_write' , status = Disk .CRITICAL )
238247
248+
239249def mock_df_output (fname ):
240250 """
241251 Load fixtures from tests/fixtures/ folder and return a tuple matching the
@@ -244,6 +254,7 @@ def mock_df_output(fname):
244254 with open (os .path .join (HERE , 'fixtures' , fname )) as f :
245255 return f .read (), '' , ''
246256
257+
247258def test_no_psutil_debian (aggregator ):
248259 p1 = mock .patch ('os.statvfs' , return_value = MockInodesMetrics (), __name__ = "statvfs" )
249260 p2 = mock .patch ('datadog_checks.disk.disk.get_subprocess_output' ,
@@ -262,6 +273,7 @@ def test_no_psutil_debian(aggregator):
262273 aggregator .assert_metric (name , tags = ['device:udev' ])
263274 assert aggregator .metrics_asserted_pct == 100.0
264275
276+
265277def test_no_psutil_freebsd (aggregator ):
266278 p1 = mock .patch ('os.statvfs' , return_value = MockInodesMetrics (), __name__ = "statvfs" )
267279 p2 = mock .patch ('datadog_checks.disk.disk.get_subprocess_output' ,
@@ -278,6 +290,7 @@ def test_no_psutil_freebsd(aggregator):
278290 aggregator .assert_metric (name , value = value , tags = ['device:zroot' ])
279291 assert aggregator .metrics_asserted_pct == 100.0
280292
293+
281294def test_no_psutil_centos (aggregator ):
282295 p1 = mock .patch ('os.statvfs' , return_value = MockInodesMetrics (), __name__ = "statvfs" )
283296 p2 = mock .patch ('datadog_checks.disk.disk.get_subprocess_output' ,
@@ -295,6 +308,7 @@ def test_no_psutil_centos(aggregator):
295308 aggregator .assert_metric (name , tags = ['device:{}' .format (device )])
296309 assert aggregator .metrics_asserted_pct == 100.0
297310
311+
298312def test_legacy_option ():
299313 """
300314 Ensure check option overrides datadog.conf
@@ -305,6 +319,7 @@ def test_legacy_option():
305319 c = Disk ('disk' , None , {'use_mount' : 'yes' }, [{'use_mount' : 'no' }])
306320 assert c ._use_mount is False
307321
322+
308323def test_ignore_empty_regex ():
309324 """
310325 Ignore empty regex as they match all strings
@@ -313,8 +328,9 @@ def test_ignore_empty_regex():
313328 check = Disk ('disk' , None , {'device_blacklist_re' : '' }, [{}])
314329 assert check ._excluded_disk_re == re .compile ('^$' )
315330
331+
316332def test_device_tagging (aggregator , psutil_mocks ):
317- instances = [{'use_mount' : 'no' , 'device_tag_re' : {"/dev/sda.*" : "type:dev,tag:two" }, 'tags' :["optional:tags1" ]}]
333+ instances = [{'use_mount' : 'no' , 'device_tag_re' : {"/dev/sda.*" : "type:dev,tag:two" }, 'tags' : ["optional:tags1" ]}]
318334 c = Disk ('disk' , None , {}, instances )
319335 c .check (instances [0 ])
320336
0 commit comments