Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove more esoteric uses of 'six' #18638

Merged
merged 1 commit into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
397 changes: 204 additions & 193 deletions cisco_aci/datadog_checks/cisco_aci/models.py

Large diffs are not rendered by default.

5 changes: 1 addition & 4 deletions cisco_aci/tests/fixtures/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@
# All rights reserved
# Licensed under a 3-clause BSD style license (see LICENSE)

import six

if six.PY3:
from datadog_checks.cisco_aci.models import DeviceMetadataList, InterfaceMetadata, NetworkDevicesMetadata
from datadog_checks.cisco_aci.models import DeviceMetadataList, InterfaceMetadata, NetworkDevicesMetadata

DEVICE_METADATA = [
{
Expand Down
71 changes: 32 additions & 39 deletions cisco_aci/tests/test_fabric.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,17 @@
# All rights reserved
# Licensed under Simplified BSD License (see LICENSE)

import six
from freezegun import freeze_time

from datadog_checks.base.utils.containers import hash_mutable
from datadog_checks.cisco_aci import CiscoACICheck
from datadog_checks.cisco_aci.api import Api

if six.PY3:
from .fixtures.metadata import (
EXPECTED_INTERFACE_METADATA,
EXPECTED_METADATA_EVENTS,
)

from freezegun import freeze_time

from . import common
from .fixtures.metadata import (
EXPECTED_INTERFACE_METADATA,
EXPECTED_METADATA_EVENTS,
)


def test_fabric_mocked(aggregator):
Expand Down Expand Up @@ -86,38 +82,35 @@ def test_fabric_mocked(aggregator):
with freeze_time("2012-01-14 03:21:34"):
check.check({})

if six.PY3:
ndm_metadata = aggregator.get_event_platform_events("network-devices-metadata")
expected_metadata = [event.model_dump(mode="json", exclude_none=True) for event in EXPECTED_METADATA_EVENTS]
assert ndm_metadata == expected_metadata
ndm_metadata = aggregator.get_event_platform_events("network-devices-metadata")
expected_metadata = [event.model_dump(mode="json", exclude_none=True) for event in EXPECTED_METADATA_EVENTS]
assert ndm_metadata == expected_metadata

interface_tag_mapping = {
'default:10.0.200.0': (device_hn101, hn101),
'default:10.0.200.1': (device_hn102, hn102),
'default:10.0.200.5': (device_hn201, hn201),
'default:10.0.200.2': (device_hn202, hn202),
}
interface_tag_mapping = {
'default:10.0.200.0': (device_hn101, hn101),
'default:10.0.200.1': (device_hn102, hn102),
'default:10.0.200.5': (device_hn201, hn201),
'default:10.0.200.2': (device_hn202, hn202),
}

for interface in EXPECTED_INTERFACE_METADATA:
device_hn, hn = interface_tag_mapping.get(interface.device_id)
device_namespace, device_ip = interface.device_id.split(':')
interface_tags = [
'port:{}'.format(interface.name),
'medium:broadcast',
'snmpTrapSt:enable',
'node_id:{}'.format(hn.split('-')[-1]),
'fabric_pod_id:1',
'device_ip:{}'.format(device_ip),
'device_namespace:{}'.format(device_namespace),
'device_hostname:{}'.format(device_hn),
'device_id:{}'.format(interface.device_id),
'port.status:{}'.format(interface.status),
'dd.internal.resource:ndm_device_user_tags:{}'.format(interface.device_id),
'dd.internal.resource:ndm_interface_user_tags:{}:{}'.format(interface.device_id, interface.index),
]
aggregator.assert_metric(
'cisco_aci.fabric.port.status', value=1.0, tags=interface_tags, hostname=device_hn
)
for interface in EXPECTED_INTERFACE_METADATA:
device_hn, hn = interface_tag_mapping.get(interface.device_id)
device_namespace, device_ip = interface.device_id.split(':')
interface_tags = [
'port:{}'.format(interface.name),
'medium:broadcast',
'snmpTrapSt:enable',
'node_id:{}'.format(hn.split('-')[-1]),
'fabric_pod_id:1',
'device_ip:{}'.format(device_ip),
'device_namespace:{}'.format(device_namespace),
'device_hostname:{}'.format(device_hn),
'device_id:{}'.format(interface.device_id),
'port.status:{}'.format(interface.status),
'dd.internal.resource:ndm_device_user_tags:{}'.format(interface.device_id),
'dd.internal.resource:ndm_interface_user_tags:{}:{}'.format(interface.device_id, interface.index),
]
aggregator.assert_metric('cisco_aci.fabric.port.status', value=1.0, tags=interface_tags, hostname=device_hn)

metric_name = 'cisco_aci.fabric.port.ingr_total.bytes.cum'
aggregator.assert_metric(
Expand Down
14 changes: 0 additions & 14 deletions datadog_checks_dev/datadog_checks/dev/compat.py

This file was deleted.

5 changes: 1 addition & 4 deletions datadog_checks_dev/datadog_checks/dev/structures.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,11 @@
from shutil import rmtree
from tempfile import mkdtemp

import six

from ._env import e2e_active, get_env_vars, remove_env_vars, set_env_vars, tear_down_env
from .warn import warning


@six.add_metaclass(abc.ABCMeta)
class LazyFunction(object):
class LazyFunction(abc.ABC):
"""Abstract base class for lazy function calls."""

@abc.abstractmethod
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
import os
from typing import Dict # noqa: F401

import six

from ...datastructures import JSONDict
from ...git import git_show_file
from ...utils import get_metadata_file, has_logs, is_metric_in_metadata_file, read_metadata_rows
Expand All @@ -29,8 +27,7 @@ def __repr__(self):
return str(self)


@six.add_metaclass(abc.ABCMeta)
class BaseManifestValidator(object):
class BaseManifestValidator(abc.ABC):
def __init__(
self,
is_extras=False,
Expand Down Expand Up @@ -64,6 +61,7 @@ def should_validate(self):
return True
return False

@abc.abstractmethod
def validate(self, check_name, manifest, should_fix):
# type: (str, Dict, bool) -> None
"""Validates the decoded manifest. Will perform inline changes if fix is true"""
Expand Down
20 changes: 1 addition & 19 deletions directory/datadog_checks/directory/traverse.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
# (C) Datadog, Inc. 2018-present
# All rights reserved
# Licensed under a 3-clause BSD style license (see LICENSE)
import platform
import sys

import six

try:
from os import scandir
except ImportError:
from scandir import scandir


def _walk(top, onerror=None, followlinks=False):
def walk(top, onerror=None, followlinks=False):
"""A simplified and modified version of stdlib's `os.walk` that yields the
`os.DirEntry` objects that `scandir` produces during traversal instead of paths as
strings.
Expand Down Expand Up @@ -72,16 +67,3 @@ def _walk(top, onerror=None, followlinks=False):
for dir_entry in dirs:
for entry in walk(dir_entry.path, onerror, followlinks):
yield entry


if six.PY3 or platform.system() != 'Windows':
walk = _walk
else:
# Fix for broken unicode handling on Windows on Python 2.x, see:
# https://github.com/benhoyt/scandir/issues/54
file_system_encoding = sys.getfilesystemencoding()

def walk(top, onerror, followlinks):
if isinstance(top, bytes):
top = top.decode(file_system_encoding)
return _walk(top, onerror, followlinks)
27 changes: 5 additions & 22 deletions iis/tests/test_e2e.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,8 @@
# All rights reserved
# Licensed under Simplified BSD License (see LICENSE)

import socket

import pytest
import six

from datadog_checks.base import AgentCheck
from datadog_checks.dev.subprocess import run_command
from datadog_checks.dev.utils import get_active_env
from datadog_checks.iis import IIS
Expand All @@ -22,31 +18,18 @@ def test_e2e(dd_agent_check, aggregator, instance):
Check should run without error if IIS is installed
"""
aggregator = dd_agent_check(instance)
if six.PY3:
aggregator.assert_service_check('iis.windows.perf.health', IIS.OK)
aggregator.assert_service_check('iis.windows.perf.health', IIS.OK)


@pytest.fixture
def iis_host(aggregator):
if six.PY2:
# the python2 version of the check uses the configured hostname,
# which is the hostnane of the docker host.
return 'iis_host:{}'.format(socket.gethostname())
else:
# the python3 version of the check uses the perf counter server field,
# which is the hostname of the container.
result = run_container_command(['hostname'])
hostname = result.stdout.strip()
return 'iis_host:{}'.format(hostname)
result = run_container_command(['hostname'])
hostname = result.stdout.strip()
return 'iis_host:{}'.format(hostname)


def normalize_tags(tags):
if six.PY2:
# The python2 version of the check calls self.normalize_tag
a = AgentCheck()
return [a.normalize_tag(tag) for tag in tags]
else:
return tags
return tags


def run_container_command(command):
Expand Down
4 changes: 1 addition & 3 deletions snmp/datadog_checks/snmp/parsing/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
from logging import Logger # noqa: F401
from typing import Dict, List, NamedTuple, Optional, Pattern, Sequence, TypedDict, Union, cast

import six

from datadog_checks.base import ConfigurationError

from ..models import OID
Expand Down Expand Up @@ -558,7 +556,7 @@ def _parse_index_slices(metric_tag):
if not isinstance(rule, dict) or set(rule) != {'start', 'end'}:
raise ConfigurationError('Transform rule must contain start and end. Invalid rule: {}'.format(rule))
start, end = rule['start'], rule['end']
if not isinstance(start, six.integer_types) or not isinstance(end, six.integer_types):
if not isinstance(start, int) or not isinstance(end, int):
raise ConfigurationError('Transform rule start and end must be integers. Invalid rule: {}'.format(rule))
if start > end:
raise ConfigurationError(
Expand Down
3 changes: 1 addition & 2 deletions sqlserver/datadog_checks/sqlserver/sqlserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import time
from collections import defaultdict

import six
from cachetools import TTLCache

from datadog_checks.base import AgentCheck
Expand Down Expand Up @@ -905,7 +904,7 @@ def collect_metrics(self):
instance_results = {}
engine_edition = self.static_info_cache.get(STATIC_INFO_ENGINE_EDITION, "")
# Execute the `fetch_all` operations first to minimize the database calls
for cls, metric_names in six.iteritems(self.instance_per_type_metrics):
for cls, metric_names in self.instance_per_type_metrics.items():
if not metric_names:
instance_results[cls] = None, None
else:
Expand Down
Loading