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

Adhere to code style #3324

Merged
merged 4 commits into from
Mar 19, 2019
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
8 changes: 2 additions & 6 deletions btrfs/datadog_checks/btrfs/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
from .btrfs import BTRFS
from .__about__ import __version__
from .btrfs import BTRFS


__all__ = [
'__version__',
'BTRFS'
]
__all__ = ['__version__', 'BTRFS']
80 changes: 40 additions & 40 deletions btrfs/datadog_checks/btrfs/btrfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,18 @@
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
from six.moves import range

from datadog_checks.checks import AgentCheck


MIXED = "mixed"
DATA = "data"
METADATA = "metadata"
Expand All @@ -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
Expand All @@ -83,7 +85,6 @@ def sized_array(count):


class FileDescriptor(object):

def __init__(self, mountpoint):
self.fd = os.open(mountpoint, os.O_DIRECTORY)

Expand All @@ -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:
Expand Down Expand Up @@ -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)

Expand Down
12 changes: 3 additions & 9 deletions btrfs/setup.py
Original file line number Diff line number Diff line change
@@ -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

# Always prefer setuptools over distutils
from setuptools import setup

HERE = path.abspath(path.dirname(__file__))

# Get the long description from the README file
Expand All @@ -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',
Expand All @@ -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,
)
20 changes: 3 additions & 17 deletions btrfs/tests/test_btrfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,22 @@
# Licensed under Simplified BSD License (see LICENSE)

import collections

import mock
import pytest

# project
from datadog_checks.btrfs import BTRFS

btrfs_check = BTRFS('btrfs', {}, {})


@pytest.fixture
def aggregator():
from datadog_checks.stubs import aggregator
aggregator.reset()
return aggregator


def mock_get_usage():

return [
(1, 9672065024, 9093722112),
(34, 33554432, 16384),
(36, 805306368, 544276480),
(562949953421312, 184549376, 0)
(562949953421312, 184549376, 0),
]


Expand All @@ -35,14 +28,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())
Expand Down
1 change: 1 addition & 0 deletions btrfs/tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ envlist =

[testenv]
usedevelop = true
dd_check_style = true
platform = linux|darwin
deps =
-e../datadog_checks_base[deps]
Expand Down