From 0f3532d75e7203534b7a8740cdce83bfcf1e582d Mon Sep 17 00:00:00 2001 From: Christine Date: Mon, 18 Mar 2019 14:56:52 -0400 Subject: [PATCH 1/4] Format style for btrfs --- btrfs/datadog_checks/btrfs/__init__.py | 8 +-- btrfs/datadog_checks/btrfs/btrfs.py | 80 +++++++++++++------------- btrfs/setup.py | 10 +--- btrfs/tests/test_btrfs.py | 13 ++--- btrfs/tox.ini | 1 + 5 files changed, 49 insertions(+), 63 deletions(-) diff --git a/btrfs/datadog_checks/btrfs/__init__.py b/btrfs/datadog_checks/btrfs/__init__.py index f890a4dc955f0..380d1e5940c52 100644 --- a/btrfs/datadog_checks/btrfs/__init__.py +++ b/btrfs/datadog_checks/btrfs/__init__.py @@ -1,8 +1,4 @@ -from .btrfs import BTRFS from .__about__ import __version__ +from .btrfs import BTRFS - -__all__ = [ - '__version__', - 'BTRFS' -] +__all__ = ['__version__', 'BTRFS'] diff --git a/btrfs/datadog_checks/btrfs/btrfs.py b/btrfs/datadog_checks/btrfs/btrfs.py index 98c25c7adbd18..b6270d06842a9 100644 --- a/btrfs/datadog_checks/btrfs/btrfs.py +++ b/btrfs/datadog_checks/btrfs/btrfs.py @@ -4,11 +4,11 @@ from __future__ import division import array -from collections import defaultdict import fcntl import itertools import os import struct +from collections import defaultdict import psutil from six import iteritems @@ -16,7 +16,6 @@ from datadog_checks.checks import AgentCheck - MIXED = "mixed" DATA = "data" METADATA = "metadata" @@ -33,41 +32,44 @@ # https://github.com/torvalds/linux/blob/98820a7e244b17b8a4d9e9d1ff9d3b4e5bfca58b/include/uapi/linux/btrfs_tree.h#L829-L840 # https://github.com/torvalds/linux/blob/98820a7e244b17b8a4d9e9d1ff9d3b4e5bfca58b/include/uapi/linux/btrfs_tree.h#L879 -FLAGS_MAPPER = defaultdict(lambda: (SINGLE, UNKNOWN), { - 1: (SINGLE, DATA), - 2: (SINGLE, SYSTEM), - 4: (SINGLE, METADATA), - 5: (SINGLE, MIXED), - 9: (RAID0, DATA), - 10: (RAID0, SYSTEM), - 12: (RAID0, METADATA), - 13: (RAID0, MIXED), - 17: (RAID1, DATA), - 18: (RAID1, SYSTEM), - 20: (RAID1, METADATA), - 21: (RAID1, MIXED), - 33: (DUP, DATA), - 34: (DUP, SYSTEM), - 36: (DUP, METADATA), - 37: (DUP, MIXED), - 65: (RAID10, DATA), - 66: (RAID10, SYSTEM), - 68: (RAID10, METADATA), - 69: (RAID10, MIXED), - 129: (RAID5, DATA), - 130: (RAID5, SYSTEM), - 132: (RAID5, METADATA), - 133: (RAID5, MIXED), - 257: (RAID6, DATA), - 258: (RAID6, SYSTEM), - 260: (RAID6, METADATA), - 261: (RAID6, MIXED), - 562949953421312: (SINGLE, GLB_RSV) -}) - -BTRFS_IOC_SPACE_INFO = 0xc0109414 -BTRFS_IOC_DEV_INFO = 0xd000941e -BTRFS_IOC_FS_INFO = 0x8400941f +FLAGS_MAPPER = defaultdict( + lambda: (SINGLE, UNKNOWN), + { + 1: (SINGLE, DATA), + 2: (SINGLE, SYSTEM), + 4: (SINGLE, METADATA), + 5: (SINGLE, MIXED), + 9: (RAID0, DATA), + 10: (RAID0, SYSTEM), + 12: (RAID0, METADATA), + 13: (RAID0, MIXED), + 17: (RAID1, DATA), + 18: (RAID1, SYSTEM), + 20: (RAID1, METADATA), + 21: (RAID1, MIXED), + 33: (DUP, DATA), + 34: (DUP, SYSTEM), + 36: (DUP, METADATA), + 37: (DUP, MIXED), + 65: (RAID10, DATA), + 66: (RAID10, SYSTEM), + 68: (RAID10, METADATA), + 69: (RAID10, MIXED), + 129: (RAID5, DATA), + 130: (RAID5, SYSTEM), + 132: (RAID5, METADATA), + 133: (RAID5, MIXED), + 257: (RAID6, DATA), + 258: (RAID6, SYSTEM), + 260: (RAID6, METADATA), + 261: (RAID6, MIXED), + 562949953421312: (SINGLE, GLB_RSV), + }, +) + +BTRFS_IOC_SPACE_INFO = 0xC0109414 +BTRFS_IOC_DEV_INFO = 0xD000941E +BTRFS_IOC_FS_INFO = 0x8400941F TWO_LONGS_STRUCT = struct.Struct("=2Q") # 2 Longs THREE_LONGS_STRUCT = struct.Struct("=3Q") # 3 Longs @@ -83,7 +85,6 @@ def sized_array(count): class FileDescriptor(object): - def __init__(self, mountpoint): self.fd = os.open(mountpoint, os.O_DIRECTORY) @@ -101,7 +102,6 @@ def open(self, dir): class BTRFS(AgentCheck): - def __init__(self, name, init_config, agentConfig, instances=None): AgentCheck.__init__(self, name, init_config, agentConfig, instances=instances) if instances is not None and len(instances) > 1: @@ -183,7 +183,7 @@ def check(self, instance): tags = [ 'usage_type:{}'.format(usage_type), 'replication_type:{}'.format(replication_type), - "device:{}".format(device) + "device:{}".format(device), ] tags.extend(custom_tags) diff --git a/btrfs/setup.py b/btrfs/setup.py index 506ca06ecee5c..af8a74d59443d 100644 --- a/btrfs/setup.py +++ b/btrfs/setup.py @@ -1,9 +1,10 @@ # Always prefer setuptools over distutils -from setuptools import setup # To use a consistent encoding from codecs import open from os import path +from setuptools import setup + HERE = path.abspath(path.dirname(__file__)) # Get the long description from the README file @@ -30,17 +31,13 @@ def get_requirements(fpath): long_description=long_description, long_description_content_type='text/markdown', keywords='datadog agent btrfs check', - # The project's main homepage. url='https://github.com/DataDog/integrations-core', - # Author details author='Datadog', author_email='packages@datadoghq.com', - # License license='BSD', - # See https://pypi.python.org/pypi?%3Aaction=list_classifiers classifiers=[ 'Development Status :: 5 - Production/Stable', @@ -51,13 +48,10 @@ def get_requirements(fpath): 'Programming Language :: Python :: 2', 'Programming Language :: Python :: 2.7', ], - # The package we're going to ship packages=['datadog_checks.btrfs'], - # Run-time dependencies install_requires=[CHECKS_BASE_REQ], - # Extra files to ship with the wheel package include_package_data=True, ) diff --git a/btrfs/tests/test_btrfs.py b/btrfs/tests/test_btrfs.py index c02219111ac8b..ecd19caa1467a 100644 --- a/btrfs/tests/test_btrfs.py +++ b/btrfs/tests/test_btrfs.py @@ -3,6 +3,7 @@ # Licensed under Simplified BSD License (see LICENSE) import collections + import mock import pytest @@ -15,6 +16,7 @@ @pytest.fixture def aggregator(): from datadog_checks.stubs import aggregator + aggregator.reset() return aggregator @@ -25,7 +27,7 @@ def mock_get_usage(): (1, 9672065024, 9093722112), (34, 33554432, 16384), (36, 805306368, 544276480), - (562949953421312, 184549376, 0) + (562949953421312, 184549376, 0), ] @@ -35,14 +37,7 @@ def get_mock_devices(): device_tuple = collections.namedtuple('device_tuple', 'device mountpoint fstype opts') - return [ - device_tuple( - device='/dev/disk1', - mountpoint='/', - fstype='btrfs', - opts='local,multilabel' - ) - ] + return [device_tuple(device='/dev/disk1', mountpoint='/', fstype='btrfs', opts='local,multilabel')] @mock.patch('datadog_checks.btrfs.btrfs.psutil.disk_partitions', return_value=get_mock_devices()) diff --git a/btrfs/tox.ini b/btrfs/tox.ini index 97524e31188f8..be3190c392e35 100644 --- a/btrfs/tox.ini +++ b/btrfs/tox.ini @@ -7,6 +7,7 @@ envlist = [testenv] usedevelop = true +dd_check_style = true platform = linux|darwin deps = -e../datadog_checks_base[deps] From 2464dfd7525d6542d12165fe031383cc0fd846a7 Mon Sep 17 00:00:00 2001 From: Ofek Lev Date: Mon, 18 Mar 2019 22:12:36 -0400 Subject: [PATCH 2/4] fix --- btrfs/setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/btrfs/setup.py b/btrfs/setup.py index af8a74d59443d..5125be6130ba5 100644 --- a/btrfs/setup.py +++ b/btrfs/setup.py @@ -1,8 +1,8 @@ -# Always prefer setuptools over distutils # To use a consistent encoding from codecs import open from os import path +# Always prefer setuptools over distutils from setuptools import setup HERE = path.abspath(path.dirname(__file__)) From b8d7b0565524e13f68e9d63eefb7902ce439c71e Mon Sep 17 00:00:00 2001 From: Ofek Lev Date: Mon, 18 Mar 2019 22:13:15 -0400 Subject: [PATCH 3/4] remove --- btrfs/tests/test_btrfs.py | 8 -------- 1 file changed, 8 deletions(-) diff --git a/btrfs/tests/test_btrfs.py b/btrfs/tests/test_btrfs.py index ecd19caa1467a..3bb9b7dae38fc 100644 --- a/btrfs/tests/test_btrfs.py +++ b/btrfs/tests/test_btrfs.py @@ -13,14 +13,6 @@ btrfs_check = BTRFS('btrfs', {}, {}) -@pytest.fixture -def aggregator(): - from datadog_checks.stubs import aggregator - - aggregator.reset() - return aggregator - - def mock_get_usage(): return [ From 1ebb555a3f978432cacc931a7dfa649d19a6089c Mon Sep 17 00:00:00 2001 From: Ofek Lev Date: Mon, 18 Mar 2019 22:18:41 -0400 Subject: [PATCH 4/4] fix --- btrfs/tests/test_btrfs.py | 1 - 1 file changed, 1 deletion(-) diff --git a/btrfs/tests/test_btrfs.py b/btrfs/tests/test_btrfs.py index 3bb9b7dae38fc..065294d58eb2c 100644 --- a/btrfs/tests/test_btrfs.py +++ b/btrfs/tests/test_btrfs.py @@ -5,7 +5,6 @@ import collections import mock -import pytest # project from datadog_checks.btrfs import BTRFS