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

Support Python 3 #2761

Merged
merged 1 commit into from
Dec 16, 2018
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
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ jobs:
- stage: test
env: CHECK=cacti PYTHON3=true
- stage: test
env: CHECK=cassandra_nodetool
env: CHECK=cassandra_nodetool PYTHON3=true
- stage: test
env: CHECK=ceph
- stage: test
Expand Down
2 changes: 1 addition & 1 deletion cassandra_nodetool/tests/compose/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ services:
expose:
- ${CONTAINER_PORT}
volumes:
- ./jmxremote.password:/etc/cassandra/jmxremote.password
- ${JMX_PASS_FILE}:/etc/cassandra/jmxremote.password

dd-test-cassandra2:
image: cassandra:${CASSANDRA_VERSION}
Expand Down
84 changes: 41 additions & 43 deletions cassandra_nodetool/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
import pytest
import time

import common
from . import common
from datadog_checks.dev import TempDir
from datadog_checks.dev.utils import copy_path

log = logging.getLogger(__file__)

Expand All @@ -23,7 +25,7 @@ def wait_on_docker_logs(container_name, max_wait, sentences):
log.info("Waiting for {} to come up".format(container_name))
for _ in range(max_wait):
out = subprocess.check_output(args)
if any(s in out for s in sentences):
if any(str.encode(s) in out for s in sentences):
log.info('{} is up!'.format(container_name))
return True
time.sleep(1)
Expand Down Expand Up @@ -53,46 +55,42 @@ def cassandra_cluster():
env['CONTAINER_PORT'] = common.PORT

# We need to restrict permission on the password file
os.chmod(os.path.join(common.HERE, 'compose', 'jmxremote.password'), stat.S_IRUSR)

docker_compose_args = [
"docker-compose",
"-f", os.path.join(common.HERE, 'compose', 'docker-compose.yaml')
]
subprocess.check_call(docker_compose_args + ["up", "-d", common.CASSANDRA_CONTAINER_NAME])

# wait for the cluster to be up before yielding
if not wait_on_docker_logs(
common.CASSANDRA_CONTAINER_NAME,
20,
['Listening for thrift clients', "Created default superuser role 'cassandra'"]
):
raise Exception("Cassandra cluster dd-test-cassandra boot timed out!")

cassandra_seed = get_container_ip("{}".format(common.CASSANDRA_CONTAINER_NAME))
env['CASSANDRA_SEEDS'] = cassandra_seed
subprocess.check_call(docker_compose_args + ["up", "-d", common.CASSANDRA_CONTAINER_NAME_2])

if not wait_on_docker_logs(
common.CASSANDRA_CONTAINER_NAME_2,
50,
['Listening for thrift clients', 'Not starting RPC server as requested']
):
raise Exception("Cassandra cluster {} boot timed out!".format(common.CASSANDRA_CONTAINER_NAME_2))

subprocess.check_call([
"docker",
"exec", common.CASSANDRA_CONTAINER_NAME,
"cqlsh",
"-e", "CREATE KEYSPACE test WITH REPLICATION={'class':'SimpleStrategy', 'replication_factor':2}"
])
yield
# Create a temporary file so if we have to run tests more than once on a machine
# the original file's perms aren't modified
with TempDir() as tmpdir:
jmx_pass_file = os.path.join(common.HERE, "compose", 'jmxremote.password')
copy_path(jmx_pass_file, tmpdir)
temp_jmx_file = os.path.join(tmpdir, 'jmxremote.password')
env['JMX_PASS_FILE'] = temp_jmx_file
os.chmod(temp_jmx_file, stat.S_IRWXU)
docker_compose_args = [
"docker-compose",
"-f", os.path.join(common.HERE, 'compose', 'docker-compose.yaml')
]
subprocess.check_call(docker_compose_args + ["up", "-d", common.CASSANDRA_CONTAINER_NAME])
# wait for the cluster to be up before yielding
if not wait_on_docker_logs(
common.CASSANDRA_CONTAINER_NAME,
20,
['Listening for thrift clients', "Created default superuser role 'cassandra'"]
):
raise Exception("Cassandra cluster dd-test-cassandra boot timed out!")
cassandra_seed = get_container_ip("{}".format(common.CASSANDRA_CONTAINER_NAME))
env['CASSANDRA_SEEDS'] = cassandra_seed.decode('utf-8')
subprocess.check_call(docker_compose_args + ["up", "-d", common.CASSANDRA_CONTAINER_NAME_2])
if not wait_on_docker_logs(
common.CASSANDRA_CONTAINER_NAME_2,
50,
['Listening for thrift clients', 'Not starting RPC server as requested']
):
raise Exception("Cassandra cluster {} boot timed out!".format(common.CASSANDRA_CONTAINER_NAME_2))
subprocess.check_call([
"docker",
"exec", common.CASSANDRA_CONTAINER_NAME,
"cqlsh",
"-e",
"CREATE KEYSPACE IF NOT EXISTS test WITH REPLICATION={'class':'SimpleStrategy', 'replication_factor':2}"
])
yield
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please clean all this up using our docker utils


subprocess.check_call(docker_compose_args + ["down"])


@pytest.fixture
def aggregator():
from datadog_checks.stubs import aggregator
aggregator.reset()
return aggregator
2 changes: 1 addition & 1 deletion cassandra_nodetool/tests/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import pytest

import common
from . import common
from datadog_checks.cassandra_nodetool import CassandraNodetoolCheck


Expand Down
2 changes: 1 addition & 1 deletion cassandra_nodetool/tests/test_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from mock import patch
from os import path
import common
from . import common
from datadog_checks.cassandra_nodetool import CassandraNodetoolCheck


Expand Down
21 changes: 10 additions & 11 deletions cassandra_nodetool/tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,36 @@
minversion = 2.0
basepython = py27
envlist =
{py27,py36}
unit
integration
flake8

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

[testenv:unit]
deps =
-e../datadog_checks_base[deps]
-rrequirements-dev.txt
setenv =
CASSANDRA_VERSION=2.1.14
CONTAINER_PORT=7199
passenv =
DOCKER*
COMPOSE*
JMX_*
commands =
pip install --require-hashes -r requirements.txt
pytest -m"not integration" -v
pytest -m"integration" -v

[testenv:integration]
[testenv:unit]
deps =
-e../datadog_checks_base[deps]
-rrequirements-dev.txt
setenv =
CASSANDRA_VERSION=2.1.14
CONTAINER_PORT=7199
passenv =
DOCKER*
COMPOSE*
commands =
pip install --require-hashes -r requirements.txt
pytest -m"integration" -v
pytest -m"not integration" -v

[testenv:flake8]
skip_install = true
Expand All @@ -41,4 +40,4 @@ commands = flake8 .

[flake8]
exclude = .eggs,.tox
max-line-length = 120
max-line-length = 120