support py34

Change-Id: I1e44f68f259eecb7a12b11b366ac68e7f20cfc33
This commit is contained in:
Eyal 2016-04-19 13:09:31 +03:00
parent 05aa2e8617
commit e8a938b100
18 changed files with 77 additions and 40 deletions

View File

@ -1,6 +1,6 @@
[tox]
minversion = 1.6
envlist = py3,py27,pep8
envlist = py34,py27,pep8
skipsdist = True
[testenv]

View File

@ -109,7 +109,8 @@ class AlarmDriverBase(DriverBase):
self.cache[alarm_key] = alarm, now
# add alarms that were deleted
for cached_alarm, timestamp in self.cache.values():
values = list(self.cache.values())
for cached_alarm, timestamp in values:
if self._is_erroneous(cached_alarm) and timestamp is not now:
LOG.debug('deleting cached_alarm %s', cached_alarm)
cached_alarm[DSProps.EVENT_TYPE] = EventAction.DELETE_ENTITY

View File

@ -24,6 +24,22 @@ from vitrage.datasources.static_physical import STATIC_PHYSICAL_DATASOURCE
class StaticPhysicalDriver(DriverBase):
@staticmethod
def get_event_types(conf):
return []
@staticmethod
def enrich_event(event, event_type):
pass
@staticmethod
def get_topic(conf):
return None
@staticmethod
def get_skipped_event_types():
return []
ENTITIES_SECTION = 'entities'
def __init__(self, conf):

View File

@ -149,10 +149,10 @@ class ConsistencyEnforcer(object):
@staticmethod
def _filter_vertices_to_be_deleted(vertices):
return filter(
return list(filter(
lambda ver:
not (ver[VProps.CATEGORY] == EntityCategory.RESOURCE and
ver[VProps.TYPE] == OPENSTACK_CLUSTER), vertices)
ver[VProps.TYPE] == OPENSTACK_CLUSTER), vertices))
def _wait_for_action(self, function):
count_retries = 0

View File

@ -112,9 +112,9 @@ class ScenarioEvaluator(object):
@staticmethod
def _remove_overlap_scenarios(before, current):
intersection = filter(lambda x: x in before, current)
before = filter(lambda x: x not in intersection, before)
current = filter(lambda x: x not in intersection, current)
intersection = list(filter(lambda x: x in before, current))
before = list(filter(lambda x: x not in intersection, before))
current = list(filter(lambda x: x not in intersection, current))
return before, current
def _process_and_get_actions(self, element, triggered_scenarios, mode):

View File

@ -16,6 +16,6 @@
Graph abstraction
"""
from algo_driver import * # noqa
from driver import * # noqa
from utils import * # noqa
from vitrage.graph.algo_driver import * # noqa
from vitrage.graph.driver import * # noqa
from vitrage.graph.utils import * # noqa

View File

@ -12,8 +12,8 @@
# License for the specific language governing permissions and limitations
# under the License.
from algorithm import * # noqa
from networkx_algorithm import NXAlgorithm
from vitrage.graph.algo_driver.algorithm import * # noqa
from vitrage.graph.algo_driver.networkx_algorithm import NXAlgorithm
def create_algorithm(graph):

View File

@ -14,8 +14,8 @@
from oslo_log import log as logging
from algorithm import GraphAlgorithm
from sub_graph_matching import subgraph_matching
from vitrage.graph.algo_driver.algorithm import GraphAlgorithm
from vitrage.graph.algo_driver.sub_graph_matching import subgraph_matching
from vitrage.graph.driver import Direction
from vitrage.graph.driver import NXGraph
from vitrage.graph.query import create_predicate

View File

@ -77,25 +77,25 @@ def subgraph_matching(base_graph, subgraph, matches, validate=False):
curr_subgraph = queue.pop(0)
# STEP 1: STOPPING CONDITION
mapped_vertices = filter(
mapped_vertices = list(filter(
lambda v: v.get(MAPPED_V_ID),
curr_subgraph.get_vertices())
curr_subgraph.get_vertices()))
if len(mapped_vertices) == subgraph.num_vertices():
final_subgraphs.append(curr_subgraph)
continue
# STEP 2: CAN WE THROW THIS SUB-GRAPH?
vertices_with_unmapped_neighbors = filter(
vertices_with_unmapped_neighbors = list(filter(
lambda v: not v.get(NEIGHBORS_MAPPED),
mapped_vertices)
mapped_vertices))
if not vertices_with_unmapped_neighbors:
continue
# STEP 3: FIND A SUB-GRAPH VERTEX TO MAP
v_with_unmapped_neighbors = vertices_with_unmapped_neighbors.pop(0)
unmapped_neighbors = filter(
unmapped_neighbors = list(filter(
lambda v: not v.get(MAPPED_V_ID),
curr_subgraph.neighbors(v_with_unmapped_neighbors.vertex_id))
curr_subgraph.neighbors(v_with_unmapped_neighbors.vertex_id)))
if not unmapped_neighbors:
# Mark vertex as NEIGHBORS_MAPPED=True
v_with_unmapped_neighbors[NEIGHBORS_MAPPED] = True

View File

@ -12,9 +12,9 @@
# License for the specific language governing permissions and limitations
# under the License.
from elements import * # noqa
from graph import * # noqa
from networkx_graph import NXGraph
from vitrage.graph.driver.elements import * # noqa
from vitrage.graph.driver.graph import * # noqa
from vitrage.graph.driver.networkx_graph import NXGraph
def create_graph(name, root_id=None):

View File

@ -22,9 +22,9 @@ vitrage.graph.driver namespace.
import abc
import six
from elements import Edge
from elements import Vertex
from notifier import Notifier
from vitrage.graph.driver.elements import Edge
from vitrage.graph.driver.elements import Vertex
from vitrage.graph.driver.notifier import Notifier
class Direction(object):

View File

@ -20,12 +20,12 @@ from networkx.readwrite import json_graph
from oslo_log import log as logging
from elements import Edge
from elements import Vertex
from graph import Direction
from graph import Graph
from notifier import Notifier
from vitrage.common.constants import VertexProperties as VProps
from vitrage.graph.driver.elements import Edge
from vitrage.graph.driver.elements import Vertex
from vitrage.graph.driver.graph import Direction
from vitrage.graph.driver.graph import Graph
from vitrage.graph.driver.notifier import Notifier
from vitrage.graph.filter import check_filter
from vitrage.graph.query import create_predicate
@ -198,8 +198,8 @@ class NXGraph(Graph):
self._g.remove_edge(u=e.source_id, v=e.target_id, key=e.label)
def get_vertices(self, vertex_attr_filter=None, query_dict=None):
def check_vertex((v_id, vertex_data)):
return check_filter(vertex_data, vertex_attr_filter)
def check_vertex(vertex_data):
return check_filter(vertex_data[1], vertex_attr_filter)
if not query_dict:
items = filter(check_vertex, self._g.nodes_iter(data=True))

View File

@ -11,9 +11,10 @@
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import functools
from elements import Vertex
from vitrage.graph.driver.elements import Vertex
def _before_func(graph, item):

View File

@ -11,7 +11,9 @@
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from oslo_log import log as logging
import six
from vitrage.common.exception import VitrageError
@ -101,7 +103,7 @@ def _create_query_expression(query, parent_operator=None):
def _evaluatable_str(value):
"""wrap string/unicode with back tick"""
if isinstance(value, unicode) or isinstance(value, str):
if isinstance(value, six.string_types):
return '\'' + value + '\''
else:
return str(value)

View File

@ -12,10 +12,10 @@
# License for the specific language governing permissions and limitations
# under the License.
from driver.elements import Edge
from driver.elements import Vertex
from vitrage.common.constants import EdgeProperties as EConst
from vitrage.common.constants import VertexProperties as VConst
from vitrage.graph.driver.elements import Edge
from vitrage.graph.driver.elements import Vertex
def create_vertex(vitrage_id,

View File

@ -12,7 +12,7 @@
# License for the specific language governing permissions and limitations
# under the License.
import codecs
import json
from os.path import dirname
from os import walk
@ -44,8 +44,9 @@ def load_specs(target_filename, target_folder=None):
"""
target = _get_full_path(target_filename, target_folder)
reader = codecs.getreader("utf-8")
with open(target, "rb") as infile:
return json.load(infile)
return json.load(reader(infile))
def _get_full_path(target_filename, target_folder):

View File

@ -23,6 +23,22 @@ class MockNagiosDriver(NagiosDriver):
is asked to
"""
@staticmethod
def get_event_types(conf):
return []
@staticmethod
def enrich_event(event, event_type):
pass
@staticmethod
def get_topic(conf):
return None
@staticmethod
def get_skipped_event_types():
return []
def __init__(self, conf):
super(MockNagiosDriver, self).__init__(conf)
self.service_datas = None

View File

@ -53,7 +53,7 @@ class ScenarioRepositoryTest(base.BaseTest):
# Test assertions
self.assertIsNotNone(scenario_repository)
path, dirs, files = os.walk(self.conf.evaluator.templates_dir).next()
path, dirs, files = next(os.walk(self.conf.evaluator.templates_dir))
self.assertEqual(len(files), len(scenario_repository.templates))
def test_init_scenario_repository(self):