Skip to content

Commit

Permalink
Add e2e test
Browse files Browse the repository at this point in the history
  • Loading branch information
therve committed Jul 31, 2019
1 parent 73764c5 commit e86580a
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 19 deletions.
16 changes: 5 additions & 11 deletions ceph/datadog_checks/ceph/ceph.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,23 +48,17 @@ def _collect_raw(self, ceph_cmd, ceph_cluster, instance):
test_sudo = os.system('setsid sudo -l < /dev/null')
if test_sudo != 0:
raise Exception('The dd-agent user does not have sudo access')
ceph_args = ['sudo', ceph_cmd]
ceph_args = 'sudo {}'.format(ceph_cmd)
else:
ceph_args = [ceph_cmd]
ceph_args = ceph_cmd

ceph_args += ['--cluster', ceph_cluster]

args = ceph_args + ['version']
try:
output, _, _ = get_subprocess_output(args, self.log)
except Exception as e:
raise Exception('Unable to run cmd=%s: %s' % (' '.join(args), str(e)))
ceph_args = '{} --cluster {}'.format(ceph_args, ceph_cluster)

raw = {}
for cmd in ('mon_status', 'status', 'df detail', 'osd pool stats', 'osd perf', 'health detail'):
try:
args = ceph_args + cmd.split() + ['-fjson']
output, _, _ = get_subprocess_output(args, self.log)
args = '{} {} -fjson'.format(ceph_args, cmd)
output, _, _ = get_subprocess_output(args.split(), self.log)
res = json.loads(output)
except Exception as e:
self.log.warning('Unable to parse data from cmd=%s: %s' % (cmd, str(e)))
Expand Down
6 changes: 3 additions & 3 deletions ceph/tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
HERE = os.path.abspath(os.path.dirname(__file__))
FIXTURE_DIR = os.path.join(HERE, 'fixtures')

BASIC_CONFIG = {'ceph_cmd': os.path.join(FIXTURE_DIR, 'ceph_bin.sh'), 'tags': ['optional:tag1']}
BASIC_CONFIG = {'ceph_cmd': 'docker exec dd-test-ceph ceph', 'tags': ['optional:tag1']}

EXPECTED_METRICS = [
"ceph.commit_latency_ms",
Expand Down Expand Up @@ -61,8 +61,8 @@
]


def mock_data(file):
filepath = os.path.join(FIXTURE_DIR, file)
def mock_data(filename):
filepath = os.path.join(FIXTURE_DIR, filename)
with open(filepath, "r") as f:
data = f.read()
return json.loads(data)
14 changes: 13 additions & 1 deletion ceph/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,18 @@

from datadog_checks.dev import docker_run
from datadog_checks.dev.conditions import CheckDockerLogs
from datadog_checks.dev.subprocess import run_command

from .common import BASIC_CONFIG, HERE

E2E_METADATA = {
'start_commands': [
'apt-get update',
'apt-get install -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" -y docker.io',
],
'docker_volumes': ['/var/run/docker.sock:/var/run/docker.sock'],
}


@pytest.fixture(scope="session")
def dd_environment():
Expand All @@ -22,4 +31,7 @@ def dd_environment():
conditions=[condition],
sleep=5, # Let's wait just a little bit after ceph got spawned to remove flakyness
):
yield BASIC_CONFIG, "local"
run_command(
['docker', 'exec', 'dd-test-ceph', 'ceph', 'tell', 'mon.*', 'injectargs', '--mon_data_avail_warn', '5']
)
yield BASIC_CONFIG, E2E_METADATA
21 changes: 21 additions & 0 deletions ceph/tests/test_e2e.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# (C) Datadog, Inc. 2019
# All rights reserved
# Licensed under a 3-clause BSD style license (see LICENSE)

import pytest

from datadog_checks.ceph import Ceph

from .common import BASIC_CONFIG, EXPECTED_METRICS, EXPECTED_SERVICE_CHECKS, EXPECTED_SERVICE_TAGS


@pytest.mark.e2e
def test_check(dd_agent_check):
aggregator = dd_agent_check(BASIC_CONFIG, rate=True)

for metric in EXPECTED_METRICS:
aggregator.assert_metric(metric, at_least=1)

for sc in EXPECTED_SERVICE_CHECKS:
aggregator.assert_service_check(sc, status=Ceph.OK, tags=EXPECTED_SERVICE_TAGS)
aggregator.assert_service_check('ceph.overall_status', status=Ceph.OK, tags=EXPECTED_SERVICE_TAGS)
9 changes: 5 additions & 4 deletions ceph/tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,22 @@
minversion = 2.0
basepython = py37
envlist =
{py27,py37}-{unit,integration}
{py27,py37}

[testenv]
description =
py{27,37}: e2e ready
dd_check_style = true
usedevelop = true
platform = linux|darwin|win32
deps =
-e../datadog_checks_base[deps]
-rrequirements-dev.txt
setenv =
integration: CEPH_VERSION=v3.2.1-stable-3.2-mimic-centos-7
CEPH_VERSION=v3.2.1-stable-3.2-mimic-centos-7
passenv =
DOCKER*
COMPOSE*
commands =
pip install -r requirements.in
unit: pytest -v -m"unit"
integration: pytest -v -m"integration"
pytest -v {posargs}

0 comments on commit e86580a

Please sign in to comment.