Skip to content

Commit

Permalink
Fixed issue CiscoDevNet#876
Browse files Browse the repository at this point in the history
  • Loading branch information
Yan Gorelik committed Feb 11, 2019
1 parent 1c85459 commit 2e59ab7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
11 changes: 8 additions & 3 deletions sdk/python/core/ydk/entity_utils/entity_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,10 +248,15 @@ def _get_child_entity_from_top(top_entity, filter_entity):
if filter_entity is None:
return top_entity

if isinstance(top_entity, list) and isinstance(filter_entity, list) and len(top_entity) == len(filter_entity):
if isinstance(top_entity, list) and isinstance(filter_entity, list):
entities = []
for i in range(len(top_entity)):
entity = _get_child_entity_from_top(top_entity[i], filter_entity[i])
for filter in filter_entity:
filter_abs_path = filter.get_absolute_path()
entity = None
for ent in top_entity:
if ent.get_segment_path() in filter_abs_path:
entity = _get_child_entity_from_top(top_entity[i], filter_entity[i])
break;
entities.append(entity)
return entities
elif isinstance(top_entity, Entity) and isinstance(filter_entity, Entity):
Expand Down
9 changes: 5 additions & 4 deletions sdk/python/core/ydk/types/py_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def __init__(self):
self._is_frozen = False
self.parent = None
self.ylist_key = None
self.logger = logging.getLogger("ydk.types.EntityCollection")
self.logger = logging.getLogger("ydk.types.Entity")
self._local_refs = {}
self._children_name_map = OrderedDict()
self._children_yang_names = set()
Expand All @@ -108,7 +108,6 @@ def __init__(self):
self._segment_path = lambda : ''
self._absolute_path = lambda : ''
self._python_type_validation_enabled = True
self.logger = logging.getLogger("ydk.types.Entity")

def __eq__(self, other):
if not isinstance(other, Entity):
Expand Down Expand Up @@ -406,10 +405,10 @@ class EntityCollection(object):
Each Entity instance has unique segment path value, which is used as a key in the dictionary.
"""
def __init__(self, *entities):
self.logger = logging.getLogger("ydk.types.EntityCollection")
self._entity_map = OrderedDict()
for entity in entities:
self.append(entity)
self.logger = logging.getLogger("ydk.types.EntityCollection")

def __eq__(self, other):
if not isinstance(other, EntityCollection):
Expand All @@ -432,7 +431,7 @@ def append(self, entities):
- list of Entity class instances
"""
if entities is None:
self._log_error_and_raise_exception("Cannot add None object to the EntityCollection", YInvalidArgumentError)
self.logger.debug("Cannot add None object to the EntityCollection")
elif isinstance(entities, Entity):
key = self._key(entities)
self._entity_map[key] = entities
Expand All @@ -441,6 +440,8 @@ def append(self, entities):
if isinstance(entity, Entity):
key = self._key(entity)
self._entity_map[key] = entity
elif entity is None:
self.logger.debug("Cannot add None object to the EntityCollection")
else:
msg = "Argument %s is not supported by EntityCollection class; data ignored"%type(entity)
self._log_error_and_raise_exception(msg, YInvalidArgumentError)
Expand Down

0 comments on commit 2e59ab7

Please sign in to comment.