add flake8 as pep8 codestyle check.

Enable test for pep8 and use flake8 as check tool.

Story: 2003310
Task: 24446

Change-Id: Idf5cbde46dc1a2a579587438b83f2dcb7b9352bb
Signed-off-by: chenyan <yan.chen@intel.com>
This commit is contained in:
chenyan 2018-08-09 09:42:44 +08:00
parent 5994fbdb68
commit 7bdf6fd47c
8 changed files with 144 additions and 130 deletions

View File

@ -2,5 +2,9 @@
- project:
check:
jobs:
- openstack-tox-pep8
- openstack-tox-linters:
voting: false
gate:
jobs:
- openstack-tox-pep8

View File

@ -19,6 +19,7 @@ import six
class ClientException(Exception):
pass
# Fields explanation:
#
# alarm_id: a text string of the alarm identifier
@ -148,31 +149,32 @@ class FaultAPIs(object):
sep = constants.FM_CLIENT_STR_SEP
return (sep + self._check_val(data.uuid) + sep + data.alarm_id + sep +
data.alarm_state + sep + data.entity_type_id + sep +
data.entity_instance_id + sep + self._check_val(data.timestamp)
+ sep + data.severity + sep + self._check_val(data.reason_text)
+ sep + data.alarm_type + sep + data.probable_cause + sep +
data.entity_instance_id + sep +
self._check_val(data.timestamp) +
sep + data.severity + sep + self._check_val(data.reason_text) +
sep + data.alarm_type + sep + data.probable_cause + sep +
self._check_val(data.proposed_repair_action) + sep +
str(data.service_affecting) + sep + str(data.suppression) + sep)
@staticmethod
def _str_to_alarm(alarm_str):
l = alarm_str.split(constants.FM_CLIENT_STR_SEP)
if len(l) < constants.MAX_ALARM_ATTRIBUTES:
line = alarm_str.split(constants.FM_CLIENT_STR_SEP)
if len(line) < constants.MAX_ALARM_ATTRIBUTES:
return None
else:
data = Fault(l[constants.FM_ALARM_ID_INDEX],
l[constants.FM_ALARM_STATE_INDEX],
l[constants.FM_ENT_TYPE_ID_INDEX],
l[constants.FM_ENT_INST_ID_INDEX],
l[constants.FM_SEVERITY_INDEX],
l[constants.FM_REASON_TEXT_INDEX],
l[constants.FM_ALARM_TYPE_INDEX],
l[constants.FM_CAUSE_INDEX],
l[constants.FM_REPAIR_ACTION_INDEX],
l[constants.FM_SERVICE_AFFECTING_INDEX],
l[constants.FM_SUPPRESSION_INDEX],
l[constants.FM_UUID_INDEX],
l[constants.FM_TIMESTAMP_INDEX])
data = Fault(line[constants.FM_ALARM_ID_INDEX],
line[constants.FM_ALARM_STATE_INDEX],
line[constants.FM_ENT_TYPE_ID_INDEX],
line[constants.FM_ENT_INST_ID_INDEX],
line[constants.FM_SEVERITY_INDEX],
line[constants.FM_REASON_TEXT_INDEX],
line[constants.FM_ALARM_TYPE_INDEX],
line[constants.FM_CAUSE_INDEX],
line[constants.FM_REPAIR_ACTION_INDEX],
line[constants.FM_SERVICE_AFFECTING_INDEX],
line[constants.FM_SUPPRESSION_INDEX],
line[constants.FM_UUID_INDEX],
line[constants.FM_TIMESTAMP_INDEX])
return data
@staticmethod
@ -243,5 +245,3 @@ class FaultAPIs(object):
if given < threshold:
return True
return False

View File

@ -17,15 +17,18 @@
# under the License.
import sys
from fm_api import *
from fm_api import Fault, FaultAPIs
from fm_api import constants
def print_alarm(alarm):
alarm_str = "alarm_id: " + alarm.alarm_id + ", " + "uuid: " + alarm.uuid + ", "
alarm_str = "alarm_id: " + alarm.alarm_id + ", "
alarm_str += "uuid: " + alarm.uuid + ", "
alarm_str += "alarm_type: " + alarm.alarm_type + "\n"
alarm_str += "state: " + alarm.alarm_state + ", ""severity: " + alarm.severity + ", " \
+ "entity_type_id: " + alarm.entity_type_id + ", timestamp: "+ alarm.timestamp + "\n"
alarm_str += "state: " + alarm.alarm_state + ", "
alarm_str += "severity: " + alarm.severity + ", "
alarm_str += "entity_type_id: " + alarm.entity_type_id + ", "
alarm_str += "timestamp: " + alarm.timestamp + "\n"
alarm_str += "entity_instance_id: " + alarm.entity_instance_id + ", "
alarm_str += "probable cause:" + alarm.probable_cause + "\n"
print(alarm_str)
@ -73,7 +76,8 @@ def get_all(instance_id):
ser = FaultAPIs()
ll = ser.get_faults(instance_id)
if ll is not None:
print("Total alarm returned: %d\n" % len(ll))
print("Total alarm returned: %d\n"
% len(ll))
for i in ll:
print_alarm(i)
else:
@ -84,12 +88,14 @@ def get_list(alarm_id):
ser = FaultAPIs()
ll = ser.get_faults_by_id(alarm_id)
if ll is not None:
print("Total alarm returned: %d\n" % len(ll))
print("Total alarm returned: %d\n"
% len(ll))
for i in ll:
print_alarm(i)
else:
print("No alarm returned")
if __name__ == "__main__":
if sys.argv[1] == "create":
sys.exit(create())

View File

@ -77,6 +77,7 @@ def get_events_yaml_filename():
return events_yaml_name
return "/etc/fm/events.yaml"
#
# Main
#
@ -132,7 +133,7 @@ for event_type in event_types:
yaml_event_list.append(string_event_type)
if str(event_type) not in uneditable_descriptions:
event_description = (event_types.get(event_type) \
event_description = (event_types.get(event_type)
.get('Description'))
else:
event_description = event_types.get(event_type).get('Description')
@ -195,7 +196,3 @@ for event_type in event_supp:
session.commit()
session.close()

View File

@ -14,6 +14,7 @@ import constants as fm_constants
FM_ALARM_H = "fmAlarm.h"
def get_events_alarm_list(events):
for alarm_id in events:
if isinstance(alarm_id, float):
@ -30,6 +31,7 @@ def get_events_alarm_list(events):
return events_alarm_list
def get_constants_alarms():
fm_constants_raw_dict = fm_constants.__dict__
@ -64,7 +66,7 @@ def get_fm_alarms():
fm_alarm_lines = [k for k in fm_alarms_file if 'FM_ALARM_ID' in k]
for line in fm_alarm_lines:
alarm_name = line.split()[1]
# alarm_name = line.split()[1]
group_name = line.split()[2]
group_name = group_name[1:]
alarm_right_digits_value = line.split()[3]
@ -75,6 +77,7 @@ def get_fm_alarms():
return fm_alarms
#
# Main
#
@ -110,4 +113,3 @@ for alarm_id in fm_alarms:
exitValue = 1
exit(exitValue)

View File

@ -4,15 +4,15 @@
# SPDX-License-Identifier: Apache-2.0
#
# Python3 compatibility
from __future__ import print_function
import sys
import os
import yaml
import constants
# Python3 compatibility
from __future__ import print_function
# Record Format (for full description see events.yaml)
#
# 100.001:
@ -98,8 +98,6 @@ serviceAffecting_FieldName : serviceAffecting_FieldValues
}
def checkField(fieldKey, fieldValues, key, event):
if fieldKey not in event:
print("\n ERROR: %s missing \'%s\' field." % (key, fieldKey))
@ -120,19 +118,19 @@ def checkField( fieldKey, fieldValues, key, event ):
if not fieldValues:
return True
for listvalue in event[fieldKey]:
if not listvalue in fieldValues:
if listvalue not in fieldValues:
print("\n ERROR: \'%s\' is not a valid \'%s\' field value." % (listvalue, fieldKey))
print(" Valid values are:", fieldValues)
return False
if type(event[fieldKey]) is dict:
for dictKey, dictValue in event[fieldKey].items():
if not dictKey in severity_FieldValues:
if dictKey not in severity_FieldValues:
print("\n ERROR: \'%s\' is not a valid \'%s\' index value." % (dictKey, fieldKey))
print(" Valid index values are:", severity_FieldValues)
return False
if fieldValues:
if not dictValue in fieldValues:
if dictValue not in fieldValues:
print("\n ERROR: \'%s\' is not a valid \'%s\' field value." % (dictValue, fieldKey))
print(" Valid values are:", fieldValues)
return False
@ -149,7 +147,6 @@ def checkTypeField( key, event ):
return False
def checkFields(key, event):
isOk = True
if not checkTypeField(key, event):
@ -200,4 +197,3 @@ with open(sys.argv[1], 'r') as stream:
print(exc)
exit(exitValue)

View File

@ -1,3 +1,4 @@
bashate >= 0.2
PyYAML >= 3.1.0
yamllint >= 0.5.2
flake8 >= 2.5.4 # MIT

20
tox.ini
View File

@ -1,5 +1,5 @@
[tox]
envlist = linters
envlist = linters,pep8
minversion = 2.3
skipsdist = True
@ -28,13 +28,21 @@ commands =
-o -type f -name '*.yaml' \
-print0 | xargs -0 yamllint"
####
# Add flake8 as pep8 codestyle check.
[testenv:pep8]
usedevelop = False
skip_install = True
deps =
pep8
description =
Run style checks.
commands =
pep8
flake8
[flake8]
# E123, E125 skipped as they are invalid PEP-8.
# E501 skipped because some of the code files include templates
# that end up quite wide
show-source = True
ignore = E123,E125,E501,H405
exclude = .venv,.git,.tox,dist,doc,*lib/python*,*egg,build,release-tag-*
[testenv:venv]
commands = {posargs}