diff --git a/imcsdk/imcmo.py b/imcsdk/imcmo.py index a1afac74..62f53b4f 100644 --- a/imcsdk/imcmo.py +++ b/imcsdk/imcmo.py @@ -295,6 +295,7 @@ def to_xml(self, xml_doc=None, option=None, elem_name=None, cookie=None): return platform = None + handle = None if cookie: handle = imccoreutils.get_handle_from_cookie(cookie) if handle: @@ -320,7 +321,10 @@ def to_xml(self, xml_doc=None, option=None, elem_name=None, cookie=None): self._dirty_mask & prop.mask != 0)): value = getattr(self, key) if value is not None: - if prop.version <= handle.version: + if handle: + if prop.version <= handle.version: + xml_obj.set(prop.xml_attribute, value) + else: xml_obj.set(prop.xml_attribute, value) else: if key not in self.__xtra_props: diff --git a/tests/common/test_imctoxml.py b/tests/common/test_imctoxml.py index 5b403eb3..01d13ed2 100644 --- a/tests/common/test_imctoxml.py +++ b/tests/common/test_imctoxml.py @@ -54,3 +54,20 @@ def test_001_mo_heirarchy_to_xml(): expected = b'' obj = response.out_configs.child[0].child[0].child[0] assert_equal(xc.to_xml_str(obj.to_xml()), expected) + + +def test_mo_to_xml(): + from imcsdk.mometa.aaa.AaaUser import AaaUser + + mo = AaaUser(parent_mo_or_dn='sys/user-ext', id='11') + mo.name = 'abcd' + mo.priv = 'admin' + mo.pwd = 'abcd' + xml = mo.to_xml() + xml_str = xc.to_xml_str(xml) + new_mo = xc.from_xml_str(xml_str) + assert_equal(len(mo.__dict__), len(new_mo.__dict__)) + for prop in mo.__dict__: + if prop == '_dirty_mask': + continue + assert_equal(getattr(mo, prop), getattr(new_mo, prop)) diff --git a/tests/common/test_query_children.py b/tests/common/test_query_children.py index 36d862a6..07049fca 100644 --- a/tests/common/test_query_children.py +++ b/tests/common/test_query_children.py @@ -48,3 +48,7 @@ def test_hierarchy_with_class_id(): hierarchy=True) for mo in mos: assert_equal(mo._class_id, "CommSnmpUser") + + +def test_full_hierarchy(): + mos = handle.query_children(in_dn='sys', hierarchy=True)