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:
parent
5994fbdb68
commit
7bdf6fd47c
@ -2,5 +2,9 @@
|
|||||||
- project:
|
- project:
|
||||||
check:
|
check:
|
||||||
jobs:
|
jobs:
|
||||||
|
- openstack-tox-pep8
|
||||||
- openstack-tox-linters:
|
- openstack-tox-linters:
|
||||||
voting: false
|
voting: false
|
||||||
|
gate:
|
||||||
|
jobs:
|
||||||
|
- openstack-tox-pep8
|
||||||
|
@ -19,6 +19,7 @@ import six
|
|||||||
class ClientException(Exception):
|
class ClientException(Exception):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
# Fields explanation:
|
# Fields explanation:
|
||||||
#
|
#
|
||||||
# alarm_id: a text string of the alarm identifier
|
# alarm_id: a text string of the alarm identifier
|
||||||
@ -148,31 +149,32 @@ class FaultAPIs(object):
|
|||||||
sep = constants.FM_CLIENT_STR_SEP
|
sep = constants.FM_CLIENT_STR_SEP
|
||||||
return (sep + self._check_val(data.uuid) + sep + data.alarm_id + sep +
|
return (sep + self._check_val(data.uuid) + sep + data.alarm_id + sep +
|
||||||
data.alarm_state + sep + data.entity_type_id + sep +
|
data.alarm_state + sep + data.entity_type_id + sep +
|
||||||
data.entity_instance_id + sep + self._check_val(data.timestamp)
|
data.entity_instance_id + sep +
|
||||||
+ sep + data.severity + sep + self._check_val(data.reason_text)
|
self._check_val(data.timestamp) +
|
||||||
+ sep + data.alarm_type + sep + data.probable_cause + sep +
|
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 +
|
self._check_val(data.proposed_repair_action) + sep +
|
||||||
str(data.service_affecting) + sep + str(data.suppression) + sep)
|
str(data.service_affecting) + sep + str(data.suppression) + sep)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _str_to_alarm(alarm_str):
|
def _str_to_alarm(alarm_str):
|
||||||
l = alarm_str.split(constants.FM_CLIENT_STR_SEP)
|
line = alarm_str.split(constants.FM_CLIENT_STR_SEP)
|
||||||
if len(l) < constants.MAX_ALARM_ATTRIBUTES:
|
if len(line) < constants.MAX_ALARM_ATTRIBUTES:
|
||||||
return None
|
return None
|
||||||
else:
|
else:
|
||||||
data = Fault(l[constants.FM_ALARM_ID_INDEX],
|
data = Fault(line[constants.FM_ALARM_ID_INDEX],
|
||||||
l[constants.FM_ALARM_STATE_INDEX],
|
line[constants.FM_ALARM_STATE_INDEX],
|
||||||
l[constants.FM_ENT_TYPE_ID_INDEX],
|
line[constants.FM_ENT_TYPE_ID_INDEX],
|
||||||
l[constants.FM_ENT_INST_ID_INDEX],
|
line[constants.FM_ENT_INST_ID_INDEX],
|
||||||
l[constants.FM_SEVERITY_INDEX],
|
line[constants.FM_SEVERITY_INDEX],
|
||||||
l[constants.FM_REASON_TEXT_INDEX],
|
line[constants.FM_REASON_TEXT_INDEX],
|
||||||
l[constants.FM_ALARM_TYPE_INDEX],
|
line[constants.FM_ALARM_TYPE_INDEX],
|
||||||
l[constants.FM_CAUSE_INDEX],
|
line[constants.FM_CAUSE_INDEX],
|
||||||
l[constants.FM_REPAIR_ACTION_INDEX],
|
line[constants.FM_REPAIR_ACTION_INDEX],
|
||||||
l[constants.FM_SERVICE_AFFECTING_INDEX],
|
line[constants.FM_SERVICE_AFFECTING_INDEX],
|
||||||
l[constants.FM_SUPPRESSION_INDEX],
|
line[constants.FM_SUPPRESSION_INDEX],
|
||||||
l[constants.FM_UUID_INDEX],
|
line[constants.FM_UUID_INDEX],
|
||||||
l[constants.FM_TIMESTAMP_INDEX])
|
line[constants.FM_TIMESTAMP_INDEX])
|
||||||
return data
|
return data
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@ -243,5 +245,3 @@ class FaultAPIs(object):
|
|||||||
if given < threshold:
|
if given < threshold:
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
@ -17,15 +17,18 @@
|
|||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
from fm_api import *
|
from fm_api import Fault, FaultAPIs
|
||||||
from fm_api import constants
|
from fm_api import constants
|
||||||
|
|
||||||
|
|
||||||
def print_alarm(alarm):
|
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 += "alarm_type: " + alarm.alarm_type + "\n"
|
||||||
alarm_str += "state: " + alarm.alarm_state + ", ""severity: " + alarm.severity + ", " \
|
alarm_str += "state: " + alarm.alarm_state + ", "
|
||||||
+ "entity_type_id: " + alarm.entity_type_id + ", timestamp: "+ alarm.timestamp + "\n"
|
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 += "entity_instance_id: " + alarm.entity_instance_id + ", "
|
||||||
alarm_str += "probable cause:" + alarm.probable_cause + "\n"
|
alarm_str += "probable cause:" + alarm.probable_cause + "\n"
|
||||||
print(alarm_str)
|
print(alarm_str)
|
||||||
@ -73,7 +76,8 @@ def get_all(instance_id):
|
|||||||
ser = FaultAPIs()
|
ser = FaultAPIs()
|
||||||
ll = ser.get_faults(instance_id)
|
ll = ser.get_faults(instance_id)
|
||||||
if ll is not None:
|
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:
|
for i in ll:
|
||||||
print_alarm(i)
|
print_alarm(i)
|
||||||
else:
|
else:
|
||||||
@ -84,12 +88,14 @@ def get_list(alarm_id):
|
|||||||
ser = FaultAPIs()
|
ser = FaultAPIs()
|
||||||
ll = ser.get_faults_by_id(alarm_id)
|
ll = ser.get_faults_by_id(alarm_id)
|
||||||
if ll is not None:
|
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:
|
for i in ll:
|
||||||
print_alarm(i)
|
print_alarm(i)
|
||||||
else:
|
else:
|
||||||
print("No alarm returned")
|
print("No alarm returned")
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
if sys.argv[1] == "create":
|
if sys.argv[1] == "create":
|
||||||
sys.exit(create())
|
sys.exit(create())
|
||||||
|
@ -77,6 +77,7 @@ def get_events_yaml_filename():
|
|||||||
return events_yaml_name
|
return events_yaml_name
|
||||||
return "/etc/fm/events.yaml"
|
return "/etc/fm/events.yaml"
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# Main
|
# Main
|
||||||
#
|
#
|
||||||
@ -132,7 +133,7 @@ for event_type in event_types:
|
|||||||
yaml_event_list.append(string_event_type)
|
yaml_event_list.append(string_event_type)
|
||||||
|
|
||||||
if str(event_type) not in uneditable_descriptions:
|
if str(event_type) not in uneditable_descriptions:
|
||||||
event_description = (event_types.get(event_type) \
|
event_description = (event_types.get(event_type)
|
||||||
.get('Description'))
|
.get('Description'))
|
||||||
else:
|
else:
|
||||||
event_description = event_types.get(event_type).get('Description')
|
event_description = event_types.get(event_type).get('Description')
|
||||||
@ -195,7 +196,3 @@ for event_type in event_supp:
|
|||||||
session.commit()
|
session.commit()
|
||||||
|
|
||||||
session.close()
|
session.close()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -14,6 +14,7 @@ import constants as fm_constants
|
|||||||
|
|
||||||
FM_ALARM_H = "fmAlarm.h"
|
FM_ALARM_H = "fmAlarm.h"
|
||||||
|
|
||||||
|
|
||||||
def get_events_alarm_list(events):
|
def get_events_alarm_list(events):
|
||||||
for alarm_id in events:
|
for alarm_id in events:
|
||||||
if isinstance(alarm_id, float):
|
if isinstance(alarm_id, float):
|
||||||
@ -30,6 +31,7 @@ def get_events_alarm_list(events):
|
|||||||
|
|
||||||
return events_alarm_list
|
return events_alarm_list
|
||||||
|
|
||||||
|
|
||||||
def get_constants_alarms():
|
def get_constants_alarms():
|
||||||
fm_constants_raw_dict = fm_constants.__dict__
|
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]
|
fm_alarm_lines = [k for k in fm_alarms_file if 'FM_ALARM_ID' in k]
|
||||||
|
|
||||||
for line in fm_alarm_lines:
|
for line in fm_alarm_lines:
|
||||||
alarm_name = line.split()[1]
|
# alarm_name = line.split()[1]
|
||||||
group_name = line.split()[2]
|
group_name = line.split()[2]
|
||||||
group_name = group_name[1:]
|
group_name = group_name[1:]
|
||||||
alarm_right_digits_value = line.split()[3]
|
alarm_right_digits_value = line.split()[3]
|
||||||
@ -75,6 +77,7 @@ def get_fm_alarms():
|
|||||||
|
|
||||||
return fm_alarms
|
return fm_alarms
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# Main
|
# Main
|
||||||
#
|
#
|
||||||
@ -110,4 +113,3 @@ for alarm_id in fm_alarms:
|
|||||||
exitValue = 1
|
exitValue = 1
|
||||||
|
|
||||||
exit(exitValue)
|
exit(exitValue)
|
||||||
|
|
||||||
|
@ -4,15 +4,15 @@
|
|||||||
# SPDX-License-Identifier: Apache-2.0
|
# SPDX-License-Identifier: Apache-2.0
|
||||||
#
|
#
|
||||||
|
|
||||||
|
# Python3 compatibility
|
||||||
|
from __future__ import print_function
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
|
|
||||||
import yaml
|
import yaml
|
||||||
import constants
|
import constants
|
||||||
|
|
||||||
# Python3 compatibility
|
|
||||||
from __future__ import print_function
|
|
||||||
|
|
||||||
# Record Format (for full description see events.yaml)
|
# Record Format (for full description see events.yaml)
|
||||||
#
|
#
|
||||||
# 100.001:
|
# 100.001:
|
||||||
@ -98,8 +98,6 @@ serviceAffecting_FieldName : serviceAffecting_FieldValues
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def checkField(fieldKey, fieldValues, key, event):
|
def checkField(fieldKey, fieldValues, key, event):
|
||||||
if fieldKey not in event:
|
if fieldKey not in event:
|
||||||
print("\n ERROR: %s missing \'%s\' field." % (key, fieldKey))
|
print("\n ERROR: %s missing \'%s\' field." % (key, fieldKey))
|
||||||
@ -120,19 +118,19 @@ def checkField( fieldKey, fieldValues, key, event ):
|
|||||||
if not fieldValues:
|
if not fieldValues:
|
||||||
return True
|
return True
|
||||||
for listvalue in event[fieldKey]:
|
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("\n ERROR: \'%s\' is not a valid \'%s\' field value." % (listvalue, fieldKey))
|
||||||
print(" Valid values are:", fieldValues)
|
print(" Valid values are:", fieldValues)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
if type(event[fieldKey]) is dict:
|
if type(event[fieldKey]) is dict:
|
||||||
for dictKey, dictValue in event[fieldKey].items():
|
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("\n ERROR: \'%s\' is not a valid \'%s\' index value." % (dictKey, fieldKey))
|
||||||
print(" Valid index values are:", severity_FieldValues)
|
print(" Valid index values are:", severity_FieldValues)
|
||||||
return False
|
return False
|
||||||
if fieldValues:
|
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("\n ERROR: \'%s\' is not a valid \'%s\' field value." % (dictValue, fieldKey))
|
||||||
print(" Valid values are:", fieldValues)
|
print(" Valid values are:", fieldValues)
|
||||||
return False
|
return False
|
||||||
@ -149,7 +147,6 @@ def checkTypeField( key, event ):
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def checkFields(key, event):
|
def checkFields(key, event):
|
||||||
isOk = True
|
isOk = True
|
||||||
if not checkTypeField(key, event):
|
if not checkTypeField(key, event):
|
||||||
@ -200,4 +197,3 @@ with open(sys.argv[1], 'r') as stream:
|
|||||||
print(exc)
|
print(exc)
|
||||||
|
|
||||||
exit(exitValue)
|
exit(exitValue)
|
||||||
|
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
bashate >= 0.2
|
bashate >= 0.2
|
||||||
PyYAML >= 3.1.0
|
PyYAML >= 3.1.0
|
||||||
yamllint >= 0.5.2
|
yamllint >= 0.5.2
|
||||||
|
flake8 >= 2.5.4 # MIT
|
||||||
|
20
tox.ini
20
tox.ini
@ -1,5 +1,5 @@
|
|||||||
[tox]
|
[tox]
|
||||||
envlist = linters
|
envlist = linters,pep8
|
||||||
minversion = 2.3
|
minversion = 2.3
|
||||||
skipsdist = True
|
skipsdist = True
|
||||||
|
|
||||||
@ -28,13 +28,21 @@ commands =
|
|||||||
-o -type f -name '*.yaml' \
|
-o -type f -name '*.yaml' \
|
||||||
-print0 | xargs -0 yamllint"
|
-print0 | xargs -0 yamllint"
|
||||||
|
|
||||||
|
####
|
||||||
|
# Add flake8 as pep8 codestyle check.
|
||||||
[testenv:pep8]
|
[testenv:pep8]
|
||||||
usedevelop = False
|
description =
|
||||||
skip_install = True
|
Run style checks.
|
||||||
deps =
|
|
||||||
pep8
|
|
||||||
commands =
|
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]
|
[testenv:venv]
|
||||||
commands = {posargs}
|
commands = {posargs}
|
||||||
|
Loading…
Reference in New Issue
Block a user