Skip to content

Commit 025cde6

Browse files
Slavek Kabrdacoignetp
andauthored
Ensure network check doesn't fail on importing fcntl on Windows (DataDog#8459)
* Ensure network check doesn't fail on importing fcntl on Windows * test * Add network to windows ci * Remove extra blank line * Update test-all-checks * Fix display name * Update network/datadog_checks/network/network.py Co-authored-by: Paul <paul.coignet@datadoghq.com> Co-authored-by: Paul Coignet <paul.coignet@datadoghq.com>
1 parent e96a06f commit 025cde6

File tree

4 files changed

+16
-3
lines changed

4 files changed

+16
-3
lines changed

.azure-pipelines/changes.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ jobs:
2727
- template: './templates/test-single-windows.yml'
2828
parameters:
2929
job_name: Changed
30-
check: '--changed datadog_checks_base datadog_checks_dev active_directory aspdotnet azure_iot_edge disk dns_check dotnetclr exchange_server iis pdh_check sqlserver tcp_check win32_event_log windows_service wmi_check'
30+
check: '--changed datadog_checks_base datadog_checks_dev active_directory aspdotnet azure_iot_edge disk dns_check dotnetclr exchange_server iis network pdh_check sqlserver tcp_check win32_event_log windows_service wmi_check'
3131
display: Windows
3232
pip_cache_config:
3333
key: 'pip | $(Agent.OS) | datadog_checks_base/datadog_checks/base/data/agent_requirements.in'

.azure-pipelines/templates/test-all-checks.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,8 +291,11 @@ jobs:
291291
displayName: Nagios
292292
os: linux
293293
- checkName: network
294-
displayName: Network
294+
displayName: Network (Linux)
295295
os: linux
296+
- checkName: network
297+
displayName: Network (Windows)
298+
os: windows
296299
- checkName: nfsstat
297300
displayName: NFSstat
298301
os: linux

network/datadog_checks/network/network.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
import array
1010
import distutils.spawn
11-
import fcntl
1211
import os
1312
import re
1413
import socket
@@ -28,6 +27,11 @@
2827
except ImportError:
2928
from datadog_checks.base.stubs import datadog_agent
3029

30+
try:
31+
import fcntl
32+
except ImportError:
33+
fcntl = None
34+
3135
if PY3:
3236
long = int
3337

@@ -87,6 +91,8 @@ def check(self, instance):
8791
self._collect_rate_metrics = instance.get('collect_rate_metrics', True)
8892
self._collect_count_metrics = instance.get('collect_count_metrics', False)
8993
self._collect_ena_metrics = instance.get('collect_aws_ena_metrics', False)
94+
if fcntl is None and self._collect_ena_metrics:
95+
raise ConfigurationError("fcntl not importable, collect_aws_ena_metrics should be disabled")
9096

9197
# This decides whether we should split or combine connection states,
9298
# along with a few other things

network/tests/test_network.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,7 @@ def send_ethtool_ioctl_mock(iface, sckt, data):
386386
raise ValueError("Couldn't match any iface/data combination in the test data")
387387

388388

389+
@pytest.mark.skipif(platform.system() == 'Windows', reason="Only runs on Unix systems")
389390
@mock.patch('datadog_checks.network.network.Network._send_ethtool_ioctl')
390391
def test_collect_ena(send_ethtool_ioctl, check):
391392
send_ethtool_ioctl.side_effect = send_ethtool_ioctl_mock
@@ -398,6 +399,7 @@ def test_collect_ena(send_ethtool_ioctl, check):
398399
}
399400

400401

402+
@pytest.mark.skipif(platform.system() == 'Windows', reason="Only runs on Unix systems")
401403
@mock.patch('datadog_checks.network.network.Network._send_ethtool_ioctl')
402404
def test_submit_ena(send_ethtool_ioctl, check, aggregator):
403405
send_ethtool_ioctl.side_effect = send_ethtool_ioctl_mock
@@ -418,12 +420,14 @@ def test_submit_ena(send_ethtool_ioctl, check, aggregator):
418420
aggregator.assert_metric(m, count=1, value=0, tags=['device:eth0'])
419421

420422

423+
@pytest.mark.skipif(platform.system() == 'Windows', reason="Only runs on Unix systems")
421424
@mock.patch('datadog_checks.network.network.Network._send_ethtool_ioctl')
422425
def test_collect_ena_values_not_present(send_ethtool_ioctl, check):
423426
send_ethtool_ioctl.side_effect = send_ethtool_ioctl_mock
424427
assert check._collect_ena('enp0s3') == {}
425428

426429

430+
@pytest.mark.skipif(platform.system() == 'Windows', reason="Only runs on Unix systems")
427431
@mock.patch('fcntl.ioctl')
428432
def test_collect_ena_unsupported_on_iface(ioctl_mock, check, caplog):
429433
caplog.set_level(logging.DEBUG)

0 commit comments

Comments
 (0)