From d7f6001513631449703cfdc924b9738111b9b5ea Mon Sep 17 00:00:00 2001 From: Ilia Kurenkov Date: Thu, 19 Sep 2024 15:20:09 +0200 Subject: [PATCH] Remove last batch of easy 'six' dependencies --- .../datadog_checks/citrix_hypervisor/check.py | 6 +++--- citrix_hypervisor/tests/test_citrix_hypervisor.py | 4 ++-- citrix_hypervisor/tests/test_metadata.py | 2 +- .../datadog_test_libs/win/pdh_mocks.py | 13 +++---------- gearmand/datadog_checks/gearmand/gearmand.py | 10 +--------- network/datadog_checks/network/ethtool.py | 4 +--- .../datadog_checks/postgres/statement_samples.py | 3 +-- 7 files changed, 12 insertions(+), 30 deletions(-) diff --git a/citrix_hypervisor/datadog_checks/citrix_hypervisor/check.py b/citrix_hypervisor/datadog_checks/citrix_hypervisor/check.py index 5323b270bad13..02c96fcf00676 100644 --- a/citrix_hypervisor/datadog_checks/citrix_hypervisor/check.py +++ b/citrix_hypervisor/datadog_checks/citrix_hypervisor/check.py @@ -2,9 +2,9 @@ # All rights reserved # Licensed under a 3-clause BSD style license (see LICENSE) from typing import Any, Dict, List # noqa: F401 +from xmlrpc.client import ServerProxy import yaml -from six.moves import xmlrpc_client as xmlrpclib from datadog_checks.base import AgentCheck, ConfigurationError from datadog_checks.base.ddyaml import yaml_load_force_loader @@ -94,7 +94,7 @@ def _get_master_session(self, session): master_address = session['ErrorDescription'][1] if not master_address.startswith('http://'): master_address = 'http://' + master_address - master_xenserver = xmlrpclib.Server(master_address) + master_xenserver = ServerProxy(master_address) # Master credentials can be different, we could specify new `master_username` and # `master_password` options later if requested @@ -109,7 +109,7 @@ def _get_master_session(self, session): def open_session(self): # type: () -> Dict[str, str] try: - self.xenserver = xmlrpclib.Server(self._base_url) + self.xenserver = ServerProxy(self._base_url) except Exception as e: self.log.warning(str(e)) return {} diff --git a/citrix_hypervisor/tests/test_citrix_hypervisor.py b/citrix_hypervisor/tests/test_citrix_hypervisor.py index 50ba95bc68430..a0b9271b72a01 100644 --- a/citrix_hypervisor/tests/test_citrix_hypervisor.py +++ b/citrix_hypervisor/tests/test_citrix_hypervisor.py @@ -27,7 +27,7 @@ ], ) def test_open_session(instance, side_effect, expected_session, tag): - with mock.patch('six.moves.xmlrpc_client.Server', side_effect=side_effect): + with mock.patch('datadog_checks.citrix_hypervisor.check.ServerProxy', side_effect=side_effect): check = CitrixHypervisorCheck('citrix_hypervisor', {}, [instance]) session = check.open_session() @@ -38,7 +38,7 @@ def test_open_session(instance, side_effect, expected_session, tag): @pytest.mark.usefixtures('mock_responses') @pytest.mark.parametrize('server_type', [pytest.param('master'), pytest.param('slave')]) def test_check(aggregator, dd_run_check, instance, server_type): - with mock.patch('six.moves.xmlrpc_client.Server', return_value=mocked_xenserver(server_type)): + with mock.patch('datadog_checks.citrix_hypervisor.check.ServerProxy', return_value=mocked_xenserver(server_type)): check = CitrixHypervisorCheck('citrix_hypervisor', {}, [instance]) dd_run_check(check) diff --git a/citrix_hypervisor/tests/test_metadata.py b/citrix_hypervisor/tests/test_metadata.py index 490710a1c10e3..f4160301e424e 100644 --- a/citrix_hypervisor/tests/test_metadata.py +++ b/citrix_hypervisor/tests/test_metadata.py @@ -31,7 +31,7 @@ def test_collect_metadata(datadog_agent, instance): xenserver.session.get_this_host.return_value = {'Status': 'Success', 'Value': 'hostref'} xenserver.host.get_software_version.return_value = content - with mock.patch('six.moves.xmlrpc_client.Server', return_value=xenserver): + with mock.patch('datadog_checks.citrix_hypervisor.check.ServerProxy', return_value=xenserver): check.check(None) datadog_agent.assert_metadata('test:123', version_metadata) datadog_agent.assert_metadata_count(len(version_metadata)) diff --git a/datadog_checks_tests_helper/datadog_test_libs/win/pdh_mocks.py b/datadog_checks_tests_helper/datadog_test_libs/win/pdh_mocks.py index 7b1d1cf4d0ad9..1b1d6d990c34e 100644 --- a/datadog_checks_tests_helper/datadog_test_libs/win/pdh_mocks.py +++ b/datadog_checks_tests_helper/datadog_test_libs/win/pdh_mocks.py @@ -2,12 +2,11 @@ # All rights reserved # Licensed under a 3-clause BSD style license (see LICENSE) import os +import winreg from collections import defaultdict import mock import pytest -from six import PY3 -from six.moves import winreg HERE = os.path.abspath(os.path.dirname(__file__)) @@ -19,10 +18,7 @@ @pytest.fixture def pdh_mocks_fixture(): - if PY3: - regqueryvalueex = mock.patch('winreg.QueryValueEx', mock_QueryValueEx) - else: - regqueryvalueex = mock.patch('_winreg.QueryValueEx', mock_QueryValueEx) + regqueryvalueex = mock.patch('winreg.QueryValueEx', mock_QueryValueEx) pdhlookupbyindex = mock.patch('win32pdh.LookupPerfNameByIndex', mock_LookupPerfNameByIndex) pdhenumobjectitems = mock.patch('win32pdh.EnumObjectItems', mock_EnumObjectItems) @@ -46,10 +42,7 @@ def pdh_mocks_fixture(): @pytest.fixture def pdh_mocks_fixture_bad_perf_strings(): - if PY3: - regqueryvalueex = mock.patch('winreg.QueryValueEx', mock_QueryValueExWithRaise) - else: - regqueryvalueex = mock.patch('_winreg.QueryValueEx', mock_QueryValueExWithRaise) + regqueryvalueex = mock.patch('winreg.QueryValueEx', mock_QueryValueExWithRaise) pdhlookupbyindex = mock.patch('win32pdh.LookupPerfNameByIndex', mock_LookupPerfNameByIndex) pdhenumobjectitems = mock.patch('win32pdh.EnumObjectItems', mock_EnumObjectItems) diff --git a/gearmand/datadog_checks/gearmand/gearmand.py b/gearmand/datadog_checks/gearmand/gearmand.py index 20768e418324b..299c955bc6378 100644 --- a/gearmand/datadog_checks/gearmand/gearmand.py +++ b/gearmand/datadog_checks/gearmand/gearmand.py @@ -3,18 +3,10 @@ # All rights reserved # Licensed under Simplified BSD License (see LICENSE) -from six import PY2 +import python3_gearman as gearman from datadog_checks.base import AgentCheck -# Python 3 compatibility is a different library -# It's a drop in replacement but has a different name -# This will enable the check to use the new library -if PY2: - import gearman -else: - import python3_gearman as gearman - MAX_NUM_TASKS = 200 diff --git a/network/datadog_checks/network/ethtool.py b/network/datadog_checks/network/ethtool.py index 35ba342bdab60..55e9dc935c780 100644 --- a/network/datadog_checks/network/ethtool.py +++ b/network/datadog_checks/network/ethtool.py @@ -11,8 +11,6 @@ import struct from collections import defaultdict -from six import PY3 - from .const import ( ENA_METRIC_NAMES, ENA_METRIC_PREFIX, @@ -41,7 +39,7 @@ def _byte_array_to_string(s): Convert a byte array to string b'hv_netvsc\x00\x00\x00\x00' -> 'hv_netvsc' """ - s = s.tobytes() if PY3 else s.tostring() + s = s.tobytes() s = s.partition(b'\x00')[0].decode('utf-8') return s diff --git a/postgres/datadog_checks/postgres/statement_samples.py b/postgres/datadog_checks/postgres/statement_samples.py index eb89ecaac7b07..0a93cad3b5616 100644 --- a/postgres/datadog_checks/postgres/statement_samples.py +++ b/postgres/datadog_checks/postgres/statement_samples.py @@ -10,7 +10,6 @@ import psycopg2 from cachetools import TTLCache -from six import PY2 from datadog_checks.postgres.cursor import CommenterCursor, CommenterDictCursor @@ -884,6 +883,6 @@ def _get_truncation_state(track_activity_query_size, statement): # multi-byte characters that fall on the limit are left out. One caveat is that if a statement's length # happens to be greater or equal to the threshold below but isn't actually truncated, this # would falsely report it as a truncated statement - statement_bytes = bytes(statement) if PY2 else bytes(statement, "utf-8") + statement_bytes = bytes(statement, "utf-8") truncated = len(statement_bytes) >= track_activity_query_size - (MAX_CHARACTER_SIZE_IN_BYTES + 1) return StatementTruncationState.truncated if truncated else StatementTruncationState.not_truncated