pep8 fixes

This commit is contained in:
Ian Wienand 2018-06-01 14:36:23 +10:00
parent 719425d9f2
commit a7122e2a2d
4 changed files with 21 additions and 22 deletions

View File

@ -12,21 +12,19 @@
# under the License. # under the License.
import collections import collections
import logging
import io import io
import sys import logging
import subprocess
import re import re
import subprocess
from datetime import datetime from datetime import datetime
from enum import Enum from enum import Enum
from prettytable import PrettyTable from prettytable import PrettyTable
logger = logging.getLogger("afsmon") logger = logging.getLogger("afsmon")
#
# Fileserver
#
class FileServerStatus(Enum): class FileServerStatus(Enum):
NORMAL = 0 NORMAL = 0
@ -41,7 +39,8 @@ Partition = collections.namedtuple(
Volume = collections.namedtuple( Volume = collections.namedtuple(
'Voume', 'volume, id, perms, used, quota, percent_used') 'Voume', 'volume, id, perms, used, quota, percent_used')
class FileServerStats:
class FileServerStats(object):
'''AFS fileserver status '''AFS fileserver status
Call ``get_stats()`` to populate the statistics for the server. Call ``get_stats()`` to populate the statistics for the server.
@ -75,19 +74,18 @@ class FileServerStats:
# Matching: # Matching:
# mirror.yum-puppetlabs.readonly 536871036 RO 63026403 K On-line # mirror.yum-puppetlabs.readonly 536871036 RO 63026403 K On-line
vol_regex = re.compile( vol_regex = re.compile(
'^(?P<vol>[^\s]+)\s+(?P<id>\d+)\s(?P<perms>R[OW])\s+(?P<used>\d+) K' '^(?P<vol>[^\s]+)\s+(?P<id>\d+)\s(?P<perms>R[OW])\s+(?P<used>\d+) K'
) )
# Read the output into chunks where each chunk is the info for # Read the output into chunks where each chunk is the info for
# one volume. # one volume.
chunks = []
lines = io.StringIO(output) lines = io.StringIO(output)
while True: while True:
line = lines.readline() line = lines.readline()
if not line: if not line:
break break
chunk = '' chunk = ''
if "On-line" in line: # chunks start with this if "On-line" in line: # chunks start with this
chunk += line chunk += line
# read in the next 9 lines of status # read in the next 9 lines of status
for i in range(8): for i in range(8):
@ -103,7 +101,6 @@ class FileServerStats:
Volume(m['vol'], m['id'], m['perms'], Volume(m['vol'], m['id'], m['perms'],
used, quota, percent_used)) used, quota, percent_used))
def _get_calls_waiting(self): def _get_calls_waiting(self):
cmd = ["rxdebug", self.hostname, "7000", "-rxstats", "-noconns"] cmd = ["rxdebug", self.hostname, "7000", "-rxstats", "-noconns"]
logger.debug("Running: %s" % cmd) logger.debug("Running: %s" % cmd)
@ -191,7 +188,7 @@ class FileServerStats:
self.table.add_row(["%s free" % n, p.free]) self.table.add_row(["%s free" % n, p.free])
self.table.add_row(["%s total" % n, p.total]) self.table.add_row(["%s total" % n, p.total])
self.table.add_row(["%s %%used" % n, self.table.add_row(["%s %%used" % n,
"%s%%" % p.percent_used]) "%s%%" % p.percent_used])
for v in self.volumes: for v in self.volumes:
# Only add the RW volumes to the table as for now we're # Only add the RW volumes to the table as for now we're
# mostly just worried about viewing the quota. # mostly just worried about viewing the quota.

View File

@ -15,14 +15,15 @@ import argparse
import configparser import configparser
import logging import logging
import os import os
import sys
import statsd import statsd
import sys
import afsmon import afsmon
logger = logging.getLogger("afsmon.main") logger = logging.getLogger("afsmon.main")
class AFSMonCmd:
class AFSMonCmd(object):
def cmd_show(self): def cmd_show(self):
for fs in self.fileservers: for fs in self.fileservers:
@ -58,7 +59,7 @@ class AFSMonCmd:
hn = f.hostname.replace('.', '_') hn = f.hostname.replace('.', '_')
self.statsd.gauge('afs.%s.idle_threads' % hn, f.idle_threads) self.statsd.gauge('afs.%s.idle_threads' % hn, f.idle_threads)
self.statsd.gauge('afs.%s.calls_waiting'% hn, f.calls_waiting) self.statsd.gauge('afs.%s.calls_waiting' % hn, f.calls_waiting)
for p in f.partitions: for p in f.partitions:
self.statsd.gauge( self.statsd.gauge(
'afs.%s.part.%s.used' % (hn, p.partition), p.used) 'afs.%s.part.%s.used' % (hn, p.partition), p.used)
@ -75,7 +76,6 @@ class AFSMonCmd:
self.statsd.gauge( self.statsd.gauge(
'afs.%s.vol.%s.quota' % (hn, vn), v.quota) 'afs.%s.vol.%s.quota' % (hn, vn), v.quota)
def main(self, args=None): def main(self, args=None):
if args is None: if args is None:
args = sys.argv[1:] args = sys.argv[1:]
@ -107,7 +107,8 @@ class AFSMonCmd:
logger.debug("Debugging enabled") logger.debug("Debugging enabled")
if not os.path.exists(self.args.config): if not os.path.exists(self.args.config):
raise ValueError("Config file %s does not exist" % self.args.config) raise ValueError("Config file %s does not exist" %
self.args.config)
self.config = configparser.RawConfigParser() self.config = configparser.RawConfigParser()
self.config.read(self.args.config) self.config.read(self.args.config)

View File

@ -13,20 +13,21 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
import os
import logging
import fixtures import fixtures
import logging
import os
import select import select
import socket import socket
import testtools import testtools
import threading import threading
import time import time
_TRUE_VALUES = ('True', 'true', '1', 'yes') _TRUE_VALUES = ('True', 'true', '1', 'yes')
logger = logging.getLogger("afsmon.tests.base") logger = logging.getLogger("afsmon.tests.base")
class FakeStatsd(threading.Thread): class FakeStatsd(threading.Thread):
def __init__(self): def __init__(self):
threading.Thread.__init__(self) threading.Thread.__init__(self)

View File

@ -12,8 +12,8 @@
import afsmon import afsmon
import configparser import configparser
from afsmon.tests import base
from afsmon.cmd.main import AFSMonCmd from afsmon.cmd.main import AFSMonCmd
from afsmon.tests import base
""" """
test_afsmon test_afsmon
@ -22,6 +22,7 @@ test_afsmon
Tests for `afsmon` module. Tests for `afsmon` module.
""" """
class TestPyAFSMon(base.TestCase): class TestPyAFSMon(base.TestCase):
def setUp(self): def setUp(self):
@ -68,4 +69,3 @@ class TestPyAFSMon(base.TestCase):
self.assertReportedStat( self.assertReportedStat(
'afs.afs01_dfw_openstack_org.vol.mirror_moo.quota', 'afs.afs01_dfw_openstack_org.vol.mirror_moo.quota',
value='2048', kind='g') value='2048', kind='g')