From 386a159dabbd70e0b06499eea8cdd24efef78193 Mon Sep 17 00:00:00 2001 From: Swapnil Wagh Date: Wed, 1 Feb 2017 12:04:13 +0530 Subject: [PATCH] add comments and an extra testcase Signed-off-by: Swapnil Wagh --- imcsdk/imccoreutils.py | 2 +- imcsdk/imchandle.py | 5 +++++ tests/common/test_query_children.py | 5 +++++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/imcsdk/imccoreutils.py b/imcsdk/imccoreutils.py index e0c6bea6..6ef00faf 100644 --- a/imcsdk/imccoreutils.py +++ b/imcsdk/imccoreutils.py @@ -327,7 +327,7 @@ def extract_molist_from_method_response(method_response, def filter_molist_on_class_id(mo_list, class_id=None): - if class_id is None: + if not class_id: return mo_list out_list = [mo for mo in mo_list if mo._class_id.lower() == class_id.lower()] diff --git a/imcsdk/imchandle.py b/imcsdk/imchandle.py index 3d981f04..627719d5 100644 --- a/imcsdk/imchandle.py +++ b/imcsdk/imchandle.py @@ -323,6 +323,11 @@ def query_children(self, in_mo=None, in_dn=None, class_id=None, parent_dn = in_dn meta_class_id = None + # Setting the default class-id to None + # When hierarchy and class-id are passed together to Cisco IMC, + # an empty response is received. + # Hence, passing the class-id only when hierarchy is not set + # When both hierarchy and class-id are set, do local filtering for class-id if class_id and not hierarchy: meta_class_id = imccoreutils.find_class_id_in_mo_meta_ignore_case( class_id) diff --git a/tests/common/test_query_children.py b/tests/common/test_query_children.py index 5a7b0769..36d862a6 100644 --- a/tests/common/test_query_children.py +++ b/tests/common/test_query_children.py @@ -38,6 +38,11 @@ def test_hierarchy(): assert_equal(len(mos) > 30, True) +def test_hierarchy_with_empty_class_id(): + mos = handle.query_children(in_dn="sys/svc-ext", hierarchy=True, class_id="") + assert_equal(len(mos) > 30, True) + + def test_hierarchy_with_class_id(): mos = handle.query_children(in_dn="sys/svc-ext", class_id="commSnmpUser", hierarchy=True)