fix misc intellij inspection warnings

docstring, pep8
also disable some intellij warnings

Change-Id: I11fc0e681cd6e3afb89cd034ed9236f0aeb37cdb
This commit is contained in:
Eyal 2016-03-22 16:46:37 +02:00
parent 43e37bdd79
commit 0e3de32fd5
39 changed files with 72 additions and 60 deletions

View File

@ -22,7 +22,7 @@ sys.path.insert(0, os.path.abspath('../..'))
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
extensions = [
'sphinx.ext.autodoc',
#'sphinx.ext.intersphinx',
# 'sphinx.ext.intersphinx',
'oslosphinx'
]
@ -72,4 +72,4 @@ latex_documents = [
]
# Example configuration for intersphinx: refer to the Python standard library.
#intersphinx_mapping = {'http://docs.python.org/': None}
# intersphinx_mapping = {'http://docs.python.org/': None}

View File

@ -14,14 +14,14 @@ The template is written in YAML language, with the following structure.
metadata: ...
definitions:
entities:
- entity: ...
- entity: ...
relationships:
- relationship: ...
- relationship: ...
entities:
- entity: ...
- entity: ...
relationships:
- relationship: ...
- relationship: ...
scenarios:
scenario:
scenario:
condition: <if statement true do the action>
actions:
- action: ...

View File

@ -29,6 +29,7 @@ LOG = log.getLogger(__name__)
class Processor(processor.ProcessorBase):
def __init__(self, conf, initialization_status, e_graph=None):
super(Processor, self).__init__()
self.conf = conf
self.transformer_manager = TransformerManager(self.conf)
self.state_manager = StateManager(self.conf)

View File

@ -22,7 +22,7 @@ from vitrage.entity_graph.states.normalized_alarm_severity \
class AlarmNormalizator(NormalizatorBase):
def __init__(self):
pass
super(AlarmNormalizator, self).__init__()
def important_states(self):
return ImportantStates(NormalizedAlarmSeverity.UNKNOWN,

View File

@ -22,7 +22,7 @@ from vitrage.entity_graph.states.normalized_resource_state \
class ResourceNormalizator(NormalizatorBase):
def __init__(self):
pass
super(ResourceNormalizator, self).__init__()
def important_states(self):
return ImportantStates(NormalizedResourceState.UNRECOGNIZED,

View File

@ -204,8 +204,8 @@ class StateManager(object):
@staticmethod
def _get_all_local_variables_of_class(class_instance):
return [attr for attr in dir(class_instance) if not callable(attr)
and not attr.startswith("__")]
return [attr for attr in dir(class_instance) if not callable(attr) and
not attr.startswith("__")]
def _is_all_plugins_states_exists(self, states_plugins, error_plugins):
plugins = self.conf.synchronizer_plugins.plugin_type

View File

@ -123,6 +123,7 @@ class ActionExecutor(object):
@staticmethod
def _register_action_recipes():
# noinspection PyDictCreation
recipes = {}
recipes[ActionType.SET_STATE] = importutils.import_object(

View File

@ -53,6 +53,7 @@ class ScenarioEvaluator(object):
def process_event(self, before, current, is_vertex):
"""Notification of a change in the entity graph.
:param is_vertex:
:param before: The graph element (vertex or edge) prior to the
change that happened. None if the element was just created.
:param current: The graph element (vertex or edge) after the

View File

@ -22,7 +22,7 @@ def syntax_validate(template_conf):
pass
def validate_scenario_condition(condition_str):
def validate_scenario_condition(condition):
"""Validate the condition content.
Check:

View File

@ -134,7 +134,7 @@ def _get_edges_to_mapped_vertices(graph, vertex_id):
"""Get all edges (to/from) vertex where neighbor has a MAPPED_V_ID
:type graph: driver.Graph
:type vertex: driver.Vertex
:type vertex_id: driver.Vertex
:rtype: set of driver.Edge
"""
subgraph_edges_to_mapped_vertices = []

View File

@ -22,6 +22,7 @@ def create_graph(name, root_id=None):
For now only return NXGraph
:param root_id:
:type name: str
:rtype: Graph
"""

View File

@ -149,13 +149,13 @@ class Graph(object):
Fetch an edge from the graph, according to its two vertices and label
:param source_id: vertex id of the source vertex
:type source_id: str
:type source_id: str or None
:param target_id: vertex id of the target vertex
:type target_id: str
:param label: the label property of the edge
:type label: str
:type label: str or None
:return: The edge between the two vertices or None
:rtype: Edge
@ -310,6 +310,7 @@ class Graph(object):
vertex_attr_filter={'prop_key':['YES', 'CAT']},
edge_attr_filter={'LABEL':['ON', 'WITH']})
:param direction:
:param v_id: vertex id
:type v_id: str
:param vertex_attr_filter: expected keys and values

View File

@ -147,6 +147,7 @@ class NXGraph(Graph):
def update_vertex(self, v, hard_update=False):
"""Update the vertex properties
:param hard_update:
:type v: Vertex
"""
orig_prop = self._g.node.get(v.vertex_id, None)
@ -160,6 +161,7 @@ class NXGraph(Graph):
def update_edge(self, e, hard_update=False):
"""Update the edge properties
:param hard_update:
:type e: Edge
"""
orig_prop = self._g.edge.get(

View File

@ -20,7 +20,7 @@ def check_filter(data, attr_filter, *args):
:param attr_filter: a dictionary of either
field_name : value (mandatory)
field_name : list of values - data[field_name] must match ANY of the values
:param ignore_keys: list of filter keys to ignore (if exist)
:param args: list of filter keys to ignore (if exist)
:rtype: bool
"""
if not attr_filter:

View File

@ -81,6 +81,7 @@ def create_edge(source_id,
metadata=None):
"""A builder to create an edge
:param update_timestamp:
:param source_id:
:type source_id: str
:param target_id:

View File

@ -45,6 +45,7 @@ class AodhNotifier(NotifierBase):
elif event_type == NotifierEventTypes.ACTIVATE_DEDUCED_ALARM_EVENT:
self._activate_aodh_alarm(data)
# noinspection PyMethodMayBeStatic
def _activate_aodh_alarm(self, data):
LOG.info('### Activate aodh alarm')
# alarm_name = aodh_alarm_name_generator(
@ -84,6 +85,7 @@ class AodhNotifier(NotifierBase):
# user_id
# time_constraints
# noinspection PyMethodMayBeStatic
def _deactivate_aodh_alarm(self, data):
LOG.info('### Deactivate aodh alarm')
# try:

View File

@ -69,6 +69,7 @@ class AodhTransformer(BaseAlarmTransformer):
update_timestamp=update_timestamp,
metadata=metadata)
# noinspection PyMethodMayBeStatic
def _create_neighbors(self, entity_event):
# TODO(iafek): get neighbour resource by its id
return []

View File

@ -64,6 +64,7 @@ class TestConsistencyFunctional(TestEntityGraphFunctionalBase):
),
]
# noinspection PyAttributeOutsideInit
def setUp(self):
super(TestConsistencyFunctional, self).setUp()
self.initialization_status = InitializationStatus()

View File

@ -28,6 +28,7 @@ class TestProcessorFunctional(TestEntityGraphFunctionalBase):
NUM_VERTICES_AFTER_DELETION = 1
NUM_EDGES_AFTER_DELETION = 0
# noinspection PyAttributeOutsideInit
def setUp(self):
super(TestProcessorFunctional, self).setUp()
self.conf = cfg.ConfigOpts()

View File

@ -29,6 +29,7 @@ from vitrage.tests.functional.entity_graph.base import \
class TestStateManagerFunctional(TestEntityGraphFunctionalBase):
# noinspection PyAttributeOutsideInit
def setUp(self):
super(TestStateManagerFunctional, self).setUp()
self.conf = cfg.ConfigOpts()

View File

@ -12,7 +12,6 @@
# License for the specific language governing permissions and limitations
# under the License.
__author__ = 'erosensw'
from vitrage.tests.mocks.utils import generate_vals
from vitrage.tests.mocks.utils import merge_vals

View File

@ -47,9 +47,6 @@ def generate_random_events_list(generator_spec_list):
:param generator_spec_list: list of generators
:type generator_spec_list: list
:param default_num: default number of events to generate
:type default_num: list
:return list of synchronizer events
:rtype list
@ -72,9 +69,6 @@ def generate_sequential_events_list(generator_spec_list):
:param generator_spec_list: list of generators
:type generator_spec_list: list
:param default_num: default number of events to generate
:type default_num: list
:return list of synchronizer events
:rtype list
@ -239,7 +233,7 @@ def simple_nagios_alarm_generators(host_num,
Returns generators for a given number of Nagios alarms.
:param host_num: number of hosts
:param snapshot_events: number of snapshot alarms per hosts
:param events_num: number of snapshot alarms per hosts
:param snap_vals: preset vals for ALL snapshot events
:return: generators for zone_num zones as specified
"""

View File

@ -29,9 +29,6 @@ def generate_random_events_list(generator_spec_list):
:param generator_spec_list: list of generators
:type generator_spec_list: list
:param default_num: default number of events to generate
:type default_num: list
:return list of synchronizer events
:rtype list
@ -55,7 +52,7 @@ def simple_instance_generators(host_num, vm_num, snapshot_events=0,
:param host_num: number of hosts
:param vm_num: number of vms
:param snapshot_events: number of snapshot events per instance
:param update_events: number of update events per instance
:param snap_vals: number of update events per instance
:return: generators for vm_num vms as specified
"""
@ -86,7 +83,7 @@ def simple_host_generators(zone_num, host_num, snapshot_events=0,
:param zone_num: number of hosts
:param host_num: number of vms
:param snapshot_events: number of snapshot events per instance
:param update_events: number of update events per instance
:param snap_vals: number of update events per instance
:return: generators for vm_num vms as specified
"""
@ -114,9 +111,8 @@ def simple_zone_generators(zone_num, snapshot_events=0, snap_vals=None):
instances. Instances will be distributed across hosts in round-robin style.
:param zone_num: number of hosts
:param host_num: number of vms
:param snapshot_events: number of snapshot events per instance
:param update_events: number of update events per instance
:param snap_vals: number of update events per instance
:return: generators for vm_num vms as specified
"""

View File

@ -125,6 +125,7 @@ class EventTraceGenerator(object):
def generate_data_stream(models, event_num=100):
"""Generates a list of events.
:param models:
:param event_num: number of events to generate
:type event_num: int
:return: list of generated events
@ -142,6 +143,7 @@ def generate_data_stream(models, event_num=100):
def generate_round_robin_data_stream(models, event_num=100):
"""Generates a list of events.
:param models:
:param event_num: number of events to generate
:type event_num: int
:return: list of generated events
@ -417,6 +419,7 @@ def combine_data(static_info_re, mapping_info, external_info):
def get_trace_generators(entity_spec_list, default_events=100):
"""Returns a collection of event generators.
:param default_events:
:param entity_spec_list: list of generator specs.
:type entity_spec_list: list
:return: list of generators

View File

@ -12,7 +12,6 @@
# License for the specific language governing permissions and limitations
# under the License.
__author__ = 'erosensw'
import json
from os.path import dirname

View File

@ -22,6 +22,7 @@ from vitrage.tests.unit.entity_graph.base import TestEntityGraphUnitBase
class TestBaseProcessor(TestEntityGraphUnitBase):
# noinspection PyAttributeOutsideInit
def setUp(self):
super(TestBaseProcessor, self).setUp()
self.conf = cfg.ConfigOpts()

View File

@ -40,6 +40,7 @@ class TestProcessor(TestEntityGraphUnitBase):
NUM_VERTICES_AFTER_DELETION = 1
NUM_EDGES_AFTER_DELETION = 0
# noinspection PyAttributeOutsideInit
def setUp(self):
super(TestProcessor, self).setUp()
self.conf = cfg.ConfigOpts()

View File

@ -51,6 +51,7 @@ class TestStateManager(base.BaseTest):
for plugin_name in conf.synchronizer_plugins.plugin_type:
load_plugin(conf, plugin_name)
# noinspection PyAttributeOutsideInit
def setUp(self):
super(TestStateManager, self).setUp()
self.conf = cfg.ConfigOpts()

View File

@ -109,7 +109,7 @@ class BasicTemplateTest(base.BaseTest):
1. condition consists from one variable (type EdgeDescription)
2. Actions - set state action
:param scenarios: parsed scenarios
:param scenarios_definition:
:param entities
"""
self.assertIsNotNone(scenarios)
self.assertEqual(len(scenarios), 1)

View File

@ -403,6 +403,7 @@ class GraphTest(GraphTestBase):
else:
self.assertIsNone(act, msg)
# noinspection PyAttributeOutsideInit
def test_graph_callbacks(self):
g = create_graph('test_graph_callbacks')

View File

@ -291,8 +291,8 @@ class GraphAlgorithmTest(GraphTestBase):
mappings = ga.sub_graph_matching(t, [
Mapping(t_v_host, host_vertex, is_vertex=True)])
self.assertEqual(
ENTITY_GRAPH_VMS_PER_HOST * ENTITY_GRAPH_ALARMS_PER_VM
* ENTITY_GRAPH_ALARMS_PER_HOST,
ENTITY_GRAPH_VMS_PER_HOST * ENTITY_GRAPH_ALARMS_PER_VM *
ENTITY_GRAPH_ALARMS_PER_HOST,
len(mappings),
'Template - Four connected vertices'
'(host alarm -ON-> host -CONTAINS-> instance <-ON- instance alarm)'
@ -316,19 +316,19 @@ class GraphAlgorithmTest(GraphTestBase):
len(mappings),
'Template - Five connected vertices'
'(host alarm -ON-> host -CONTAINS-> instance <-ON- instance alarm'
',host -USES-> switch) template_root is a specific instance alarm '
+ str(mappings))
',host -USES-> switch) template_root '
'is a specific instance alarm ' + str(mappings))
mappings = ga.sub_graph_matching(t, [
Mapping(t_v_host, host_vertex, is_vertex=True)])
self.assertEqual(
ENTITY_GRAPH_VMS_PER_HOST * ENTITY_GRAPH_ALARMS_PER_VM
* ENTITY_GRAPH_ALARMS_PER_HOST,
ENTITY_GRAPH_VMS_PER_HOST * ENTITY_GRAPH_ALARMS_PER_VM *
ENTITY_GRAPH_ALARMS_PER_HOST,
len(mappings),
'Template - Five connected vertices'
'(host alarm -ON-> host -CONTAINS-> instance <-ON- instance alarm'
',host -USES-> switch) template_root is a specific host '
+ str(mappings))
',host -USES-> switch) template_root is a specific host ' +
str(mappings))
mappings = ga.sub_graph_matching(t, [
Mapping(t_v_switch, v_switch, is_vertex=True),
@ -338,8 +338,8 @@ class GraphAlgorithmTest(GraphTestBase):
len(mappings),
'Template - Five connected vertices, two mappings given'
'(host alarm -ON-> host -CONTAINS-> instance <-ON- instance alarm'
',host -USES-> switch) template_root is a specific host '
+ str(mappings))
',host -USES-> switch) template_root is a specific host ' +
str(mappings))
t.add_vertex(t_v_node_not_in_graph)
t.add_edge(e_host_to_node_not_in_graph)
@ -350,8 +350,8 @@ class GraphAlgorithmTest(GraphTestBase):
len(mappings),
'Template - Five connected vertices and a invalid edge'
'(host alarm -ON-> host -CONTAINS-> instance <-ON- instance alarm'
',host -USES-> switch) template_root is a instance alarm '
+ str(mappings))
',host -USES-> switch) template_root is a instance alarm ' +
str(mappings))
t.remove_vertex(t_v_node_not_in_graph)
t.remove_vertex(t_v_host_alarm)

View File

@ -35,6 +35,7 @@ NOVA_HOST = 'nova.host'
class NagiosTransformerTest(base.BaseTest):
# noinspection PyAttributeOutsideInit
def setUp(self):
super(NagiosTransformerTest, self).setUp()

View File

@ -35,6 +35,7 @@ NOVA_ZONE = 'nova.zone'
class NovaHostTransformerTest(base.BaseTest):
# noinspection PyAttributeOutsideInit
def setUp(self):
super(NovaHostTransformerTest, self).setUp()

View File

@ -36,6 +36,7 @@ NOVA_HOST = 'nova.host'
class NovaInstanceTransformerTest(base.BaseTest):
# noinspection PyAttributeOutsideInit
def setUp(self):
super(NovaInstanceTransformerTest, self).setUp()

View File

@ -34,6 +34,7 @@ NOVA_HOST = 'nova.host'
class NovaZoneTransformerTest(base.BaseTest):
# noinspection PyAttributeOutsideInit
def setUp(self):
super(NovaZoneTransformerTest, self).setUp()

View File

@ -69,6 +69,7 @@ class TestStaticPhysicalSynchronizer(base.BaseTest):
'/static_plugins/changes_plugins'),
]
# noinspection PyAttributeOutsideInit
def setUp(self):
super(TestStaticPhysicalSynchronizer, self).setUp()
self.conf = cfg.ConfigOpts()
@ -102,10 +103,9 @@ class TestStaticPhysicalSynchronizer(base.BaseTest):
entities = self.static_physical_synchronizer.get_all(SyncMode.UPDATE)
self.assertEqual(5, len(entities))
self.conf = cfg.ConfigOpts()
self.conf.register_opts(self.CHANGES_OPTS,
group=STATIC_PHYSICAL)
self.static_physical_synchronizer.cfg = self.conf
conf = cfg.ConfigOpts()
conf.register_opts(self.CHANGES_OPTS, group=STATIC_PHYSICAL)
self.static_physical_synchronizer.cfg = conf
# Action
changes = self.static_physical_synchronizer.get_changes(

View File

@ -34,6 +34,7 @@ STATIC_PHYSICAL = 'static_physical'
class TestStaticPhysicalTransformer(base.BaseTest):
# noinspection PyAttributeOutsideInit
def setUp(self):
super(TestStaticPhysicalTransformer, self).setUp()

View File

@ -40,23 +40,21 @@ class BaseTopologyTest(BaseVitrageTest):
def test_get_tree(self):
"""Wrapper that returns a test tree."""
self.graph_type = 'tree'
self.graph = self._get_topology()
self._get_topology('tree')
def test_get_graph(self):
"""Wrapper that returns a test graph."""
self.graph_type = 'graph'
self.graph = self._get_topology()
self._get_topology('graph')
if self._validate_graph_correctness() is False:
LOG.error('The graph ' + self.name + ' is not correct')
else:
LOG.info('The graph ' + self.name + ' is correct')
def _get_topology(self):
def _get_topology(self, graph_type):
"""Get Graph objects returned by the v1 client """
try:
g = TopologyController().get_graph(graph_type=self.graph_type,
g = TopologyController().get_graph(graph_type=graph_type,
depth=self.depth,
query=self.query,
root=self.root)

View File

@ -31,10 +31,10 @@ class BaseMock(testtools.TestCase):
]
def create_processor_with_graph(self):
self.conf = cfg.ConfigOpts()
self.conf.register_opts(self.PROCESSOR_OPTS, group='entity_graph')
conf = cfg.ConfigOpts()
conf.register_opts(self.PROCESSOR_OPTS, group='entity_graph')
events = self._create_mock_events()
processor = proc.Processor(self.conf, InitializationStatus())
processor = proc.Processor(conf, InitializationStatus())
for event in events:
processor.process_event(event)