Skip to content

Commit

Permalink
Remove last batch of easy 'six' dependencies (#18624)
Browse files Browse the repository at this point in the history
  • Loading branch information
iliakur committed Sep 19, 2024
1 parent ddf0510 commit 8da9ca8
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 30 deletions.
6 changes: 3 additions & 3 deletions citrix_hypervisor/datadog_checks/citrix_hypervisor/check.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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 {}
Expand Down
4 changes: 2 additions & 2 deletions citrix_hypervisor/tests/test_citrix_hypervisor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion citrix_hypervisor/tests/test_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
13 changes: 3 additions & 10 deletions datadog_checks_tests_helper/datadog_test_libs/win/pdh_mocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__))

Expand All @@ -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)
Expand All @@ -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)
Expand Down
10 changes: 1 addition & 9 deletions gearmand/datadog_checks/gearmand/gearmand.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
4 changes: 1 addition & 3 deletions network/datadog_checks/network/ethtool.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
import struct
from collections import defaultdict

from six import PY3

from .const import (
ENA_METRIC_NAMES,
ENA_METRIC_PREFIX,
Expand Down Expand Up @@ -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

Expand Down
3 changes: 1 addition & 2 deletions postgres/datadog_checks/postgres/statement_samples.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

import psycopg2
from cachetools import TTLCache
from six import PY2

from datadog_checks.postgres.cursor import CommenterCursor, CommenterDictCursor

Expand Down Expand Up @@ -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

0 comments on commit 8da9ca8

Please sign in to comment.