Skip to content

Commit

Permalink
Support Python 3 (#2857)
Browse files Browse the repository at this point in the history
  • Loading branch information
gmmeyer authored Jan 3, 2019
1 parent 5326ac9 commit c15d569
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 23 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ jobs:
- stage: test
env: CHECK=hdfs_datanode
- stage: test
env: CHECK=hdfs_namenode
env: CHECK=hdfs_namenode PYTHON3=true
- stage: test
env: CHECK=http_check PYTHON3=true
- stage: test
Expand Down
12 changes: 6 additions & 6 deletions hdfs_namenode/datadog_checks/hdfs_namenode/hdfs_namenode.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@
hdfs.namenode.corrupt_blocks Number of corrupt blocks
"""

# stdlib
from urlparse import urljoin
from __future__ import division

from six.moves.urllib.parse import urljoin
from six import iteritems

# 3rd party
import requests
from requests.exceptions import Timeout, HTTPError, InvalidURL, ConnectionError
from simplejson import JSONDecodeError

# Project
from datadog_checks.checks import AgentCheck


Expand Down Expand Up @@ -151,7 +151,7 @@ def _hdfs_namenode_metrics(self, beans, metrics, tags):
if bean_name != bean_name:
raise Exception("Unexpected bean name {}".format(bean_name))

for metric, (metric_name, metric_type) in metrics.iteritems():
for metric, (metric_name, metric_type) in iteritems(metrics):
metric_value = bean.get(metric)

if metric_value is not None:
Expand Down Expand Up @@ -186,7 +186,7 @@ def _rest_request_to_json(self, address, auth, disable_ssl_validation, object_pa

# Add query_params as arguments
if query_params:
query = '&'.join(['{}={}'.format(key, value) for key, value in query_params.iteritems()])
query = '&'.join(['{}={}'.format(key, value) for key, value in iteritems(query_params)])
url = urljoin(url, '?' + query)

self.log.debug('Attempting to connect to "{}"'.format(url))
Expand Down
8 changes: 5 additions & 3 deletions hdfs_namenode/tests/test_hdfs_namenode.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

from datadog_checks.hdfs_namenode import HDFSNameNode

from six import iteritems

from .common import (
HDFS_NAMENODE_CONFIG, HDFS_NAMENODE_AUTH_CONFIG, CUSTOM_TAGS, HDFS_NAMESYSTEM_METRIC_TAGS,
HDFS_NAMESYSTEM_METRICS_VALUES, HDFS_NAMESYSTEM_STATE_METRICS_VALUES, HDFS_NAMESYSTEM_MUTUAL_METRICS_VALUES
Expand All @@ -20,13 +22,13 @@ def test_check(aggregator, mocked_request):
HDFSNameNode.JMX_SERVICE_CHECK, HDFSNameNode.OK, tags=HDFS_NAMESYSTEM_METRIC_TAGS + CUSTOM_TAGS, count=1
)

for metric, value in HDFS_NAMESYSTEM_STATE_METRICS_VALUES.iteritems():
for metric, value in iteritems(HDFS_NAMESYSTEM_STATE_METRICS_VALUES):
aggregator.assert_metric(metric, value=value, tags=HDFS_NAMESYSTEM_METRIC_TAGS + CUSTOM_TAGS, count=1)

for metric, value in HDFS_NAMESYSTEM_METRICS_VALUES.iteritems():
for metric, value in iteritems(HDFS_NAMESYSTEM_METRICS_VALUES):
aggregator.assert_metric(metric, value=value, tags=HDFS_NAMESYSTEM_METRIC_TAGS + CUSTOM_TAGS, count=1)

for metric, value in HDFS_NAMESYSTEM_MUTUAL_METRICS_VALUES.iteritems():
for metric, value in iteritems(HDFS_NAMESYSTEM_MUTUAL_METRICS_VALUES):
aggregator.assert_metric(metric, value=value, tags=HDFS_NAMESYSTEM_METRIC_TAGS + CUSTOM_TAGS, count=2)

aggregator.assert_all_metrics_covered()
Expand Down
23 changes: 10 additions & 13 deletions hdfs_namenode/tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,22 @@
minversion = 2.0
basepython = py27
envlist =
hdfs_namenode
flake8
{py27,py36}-unit
{py27,py36}-flake8

[testenv]
usedevelop = true
platform = linux|darwin|win32

[testenv:hdfs_namenode]
skip_install =
flake8: true
deps =
-e../datadog_checks_base[deps]
-rrequirements-dev.txt
unit: -e../datadog_checks_base[deps]
unit: -rrequirements-dev.txt
flake8: flake8
commands =
pip install -r requirements.in
pytest -v

[testenv:flake8]
skip_install = true
deps = flake8
commands = flake8 .
unit: pip install -r requirements.in
unit: pytest -v
flake8: flake8 .

[flake8]
exclude = .eggs,.tox
Expand Down

0 comments on commit c15d569

Please sign in to comment.