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

View File

@ -15,14 +15,15 @@ import argparse
import configparser
import logging
import os
import sys
import statsd
import sys
import afsmon
logger = logging.getLogger("afsmon.main")
class AFSMonCmd:
class AFSMonCmd(object):
def cmd_show(self):
for fs in self.fileservers:
@ -58,7 +59,7 @@ class AFSMonCmd:
hn = f.hostname.replace('.', '_')
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:
self.statsd.gauge(
'afs.%s.part.%s.used' % (hn, p.partition), p.used)
@ -75,7 +76,6 @@ class AFSMonCmd:
self.statsd.gauge(
'afs.%s.vol.%s.quota' % (hn, vn), v.quota)
def main(self, args=None):
if args is None:
args = sys.argv[1:]
@ -107,7 +107,8 @@ class AFSMonCmd:
logger.debug("Debugging enabled")
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.read(self.args.config)

View File

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

View File

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