full pep8 compliance (part1)

first stage of moving to full pep8 compliance

Change-Id: I4626a0949da5b9c49776d1e16cb9ebb49b4e6723
This commit is contained in:
Gordon Chung 2013-11-19 12:27:34 -05:00
parent 6de3134f29
commit 6f77240c02
8 changed files with 21 additions and 26 deletions

View File

@ -18,7 +18,6 @@
from ceilometer.alarm import evaluator
from ceilometer.alarm.evaluator import OK, ALARM, UNKNOWN
from ceilometer.openstack.common.gettextutils import _
from ceilometer.openstack.common import log
@ -43,12 +42,12 @@ class CombinationEvaluator(evaluator.Evaluator):
"""
missing_states = len(alarm.rule['alarm_ids']) - len(states)
sufficient = missing_states == 0
if not sufficient and alarm.state != UNKNOWN:
if not sufficient and alarm.state != evaluator.UNKNOWN:
reason = _('%(missing_states)d alarms in %(alarm_ids)s'
' are in unknown state') % \
{'missing_states': missing_states,
'alarm_ids': ",".join(alarm.rule['alarm_ids'])}
self._refresh(alarm, UNKNOWN, reason)
self._refresh(alarm, evaluator.UNKNOWN, reason)
return sufficient
@staticmethod
@ -80,10 +79,10 @@ class CombinationEvaluator(evaluator.Evaluator):
"""Transition alarm state if necessary.
"""
op = alarm.rule['operator']
if COMPARATORS[op](s == ALARM for s in underlying_states):
state = ALARM
if COMPARATORS[op](s == evaluator.ALARM for s in underlying_states):
state = evaluator.ALARM
else:
state = OK
state = evaluator.OK
continuous = alarm.repeat_actions
reason = self._reason(alarm, state)
@ -96,7 +95,7 @@ class CombinationEvaluator(evaluator.Evaluator):
state = self._get_alarm_state(_id)
#note(sileht): alarm can be evaluated only with
#stable state of other alarm
if state and state != UNKNOWN:
if state and state != evaluator.UNKNOWN:
states.append(state)
if self._sufficient_states(alarm, states):

View File

@ -21,7 +21,6 @@ import datetime
import operator
from ceilometer.alarm import evaluator
from ceilometer.alarm.evaluator import OK, ALARM, UNKNOWN
from ceilometer.openstack.common.gettextutils import _
from ceilometer.openstack.common import log
from ceilometer.openstack.common import timeutils
@ -91,17 +90,17 @@ class ThresholdEvaluator(evaluator.Evaluator):
transitioning to unknown otherwise.
"""
sufficient = len(statistics) >= self.quorum
if not sufficient and alarm.state != UNKNOWN:
if not sufficient and alarm.state != evaluator.UNKNOWN:
reason = _('%d datapoints are unknown') % alarm.rule[
'evaluation_periods']
self._refresh(alarm, UNKNOWN, reason)
self._refresh(alarm, evaluator.UNKNOWN, reason)
return sufficient
@staticmethod
def _reason(alarm, statistics, distilled, state):
"""Fabricate reason string."""
count = len(statistics)
disposition = 'inside' if state == OK else 'outside'
disposition = 'inside' if state == evaluator.OK else 'outside'
last = getattr(statistics[-1], alarm.rule['statistic'])
transition = alarm.state != state
if transition:
@ -129,16 +128,16 @@ class ThresholdEvaluator(evaluator.Evaluator):
"""
distilled = all(compared)
unequivocal = distilled or not any(compared)
unknown = alarm.state == UNKNOWN
unknown = alarm.state == evaluator.UNKNOWN
continuous = alarm.repeat_actions
if unequivocal:
state = ALARM if distilled else OK
state = evaluator.ALARM if distilled else evaluator.OK
reason = self._reason(alarm, statistics, distilled, state)
if alarm.state != state or continuous:
self._refresh(alarm, state, reason)
elif unknown or continuous:
trending_state = ALARM if compared[-1] else OK
trending_state = evaluator.ALARM if compared[-1] else evaluator.OK
state = trending_state if unknown else alarm.state
reason = self._reason(alarm, statistics, distilled, state)
self._refresh(alarm, state, reason)

View File

@ -37,7 +37,7 @@ metadata_headers = X-TEST
from __future__ import absolute_import
from swift.common.utils import split_path, get_logger
from swift.common import utils
import webob
REQUEST = webob
@ -68,7 +68,7 @@ class CeilometerMiddleware(object):
def __init__(self, app, conf):
self.app = app
self.logger = get_logger(conf, log_route='ceilometer')
self.logger = utils.get_logger(conf, log_route='ceilometer')
self.metadata_headers = [h.strip().replace('-', '_').lower()
for h in conf.get(
@ -119,7 +119,8 @@ class CeilometerMiddleware(object):
def publish_sample(self, env, bytes_received, bytes_sent):
req = REQUEST.Request(env)
try:
version, account, container, obj = split_path(req.path, 2, 4, True)
version, account, container, obj = utils.split_path(req.path, 2,
4, True)
except ValueError:
return
now = timeutils.utcnow().isoformat()

View File

@ -26,8 +26,7 @@ import six
from ceilometer.compute import manager
from ceilometer.compute.pollsters import cpu
from ceilometer.compute.virt import inspector as virt_inspector
from . import base
from ceilometer.tests.compute.pollsters import base
class TestCPUPollster(base.TestPollsterBase):

View File

@ -23,8 +23,7 @@ import mock
from ceilometer.compute import manager
from ceilometer.compute.pollsters import disk
from ceilometer.compute.virt import inspector as virt_inspector
from . import base
from ceilometer.tests.compute.pollsters import base
class TestDiskPollsters(base.TestPollsterBase):

View File

@ -22,8 +22,7 @@ import mock
from ceilometer.compute import manager
from ceilometer.compute.pollsters import instance as pollsters_instance
from . import base
from ceilometer.tests.compute.pollsters import base
class TestInstancePollster(base.TestPollsterBase):

View File

@ -23,8 +23,7 @@ import mock
from ceilometer.compute import manager
from ceilometer.compute.pollsters import net
from ceilometer.compute.virt import inspector as virt_inspector
from . import base
from ceilometer.tests.compute.pollsters import base
class TestNetPollster(base.TestPollsterBase):

View File

@ -45,7 +45,7 @@ deps = -r{toxinidir}/requirements.txt
commands = {posargs}
[flake8]
ignore = H301
ignore = H302
builtins = _
exclude=.venv,.git,.tox,dist,doc,./ceilometer/openstack/common,*lib/python*,*egg,tools,nova_tests,build
show-source = True