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

Make the error message more clear in case a path is not accessible #2369

Merged
merged 3 commits into from
Oct 11, 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
19 changes: 9 additions & 10 deletions directory/datadog_checks/directory/directory.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

from datadog_checks.checks import AgentCheck
from datadog_checks.config import is_affirmative
from datadog_checks.errors import ConfigurationError
Copy link
Member

Choose a reason for hiding this comment

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

this exception only exists since #2367, shouldn't this be reflected on the version constraint of this integration on the datadog-checks-base wheel? (just asking, not sure what the policy is)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We're still transitioning and very few of the checks pin the base check version, directory is one of those not pinning. At this moment there's not a real policy, we help users who need to update to manually setup the right set of packages in the agent on a case by case policy. This will change as soon as we outline the Agent CLI requirements for the single check update.

from .traverse import walk


Expand Down Expand Up @@ -37,7 +38,7 @@ def check(self, instance):
try:
directory = instance['directory']
except KeyError:
raise Exception('DirectoryCheck: missing `directory` in config')
raise ConfigurationError('DirectoryCheck: missing `directory` in config')

abs_directory = abspath(directory)
name = instance.get('name', directory)
Expand All @@ -54,15 +55,13 @@ def check(self, instance):
custom_tags = instance.get('tags', [])

if not exists(abs_directory):
if ignore_missing:
self.log.info(
'DirectoryCheck: the directory `{}` does not exist. Skipping.'.format(abs_directory)
)
return

raise Exception(
'DirectoryCheck: the directory `{}` does not exist. Skipping.'.format(abs_directory)
)
msg = "Either directory '{}' doesn't exist or the Agent doesn't "\
"have permissions to access it, skipping.".format(abs_directory)

if not ignore_missing:
raise ConfigurationError(msg)

self.log.warning(msg)

self._get_stats(
abs_directory,
Expand Down
9 changes: 6 additions & 3 deletions directory/tests/test_directory.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@
import tempfile

import pytest
import mock

from datadog_checks.dev.utils import create_file, temp_dir as temp_directory
from datadog_checks.directory import DirectoryCheck
from datadog_checks.errors import ConfigurationError

CHECK_NAME = 'directory'

Expand Down Expand Up @@ -227,12 +229,13 @@ def test_non_existent_directory():
"""
Missing or inaccessible directory coverage.
"""
config = {'instances': [{'directory': '/non-existent/directory'}]}
with pytest.raises(Exception):
dir_check.check(config)
with pytest.raises(ConfigurationError):
dir_check.check({'directory': '/non-existent/directory'})


def test_non_existent_directory_ignore_missing():
config = {'directory': '/non-existent/directory',
'ignore_missing': True}
dir_check._get_stats = mock.MagicMock()
dir_check.check(config)
dir_check._get_stats.assert_called_once()