Skip to content

Commit

Permalink
validate property version only when a valid handle exists (CiscoUcs#106)
Browse files Browse the repository at this point in the history
Signed-off-by: Swapnil Wagh <waghswapnil@gmail.com>
  • Loading branch information
waghswapnil authored and vvb committed Feb 8, 2017
1 parent 4222f0c commit c26217c
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
6 changes: 5 additions & 1 deletion imcsdk/imcmo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand Down
17 changes: 17 additions & 0 deletions tests/common/test_imctoxml.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,20 @@ def test_001_mo_heirarchy_to_xml():
expected = b'<memoryUnitEnvStatsHist1 childAction="deleteNonPresent" dn="sys/chassis-1/blade-2/board/memarray-1/mem-9/dimm-env-stats/1" id="1" mostRecent="no" rn="1" suspect="no" temperature="28.000000" temperatureAvg="25.599997" temperatureMax="28.000000" temperatureMin="24.000000" thresholded="" timeCollected="2015-09-07T09:43:53.262"><memoryUnitEnvStatsHist2 childAction="deleteNonPresent" dn="sys/chassis-1/blade-2/board/memarray-1/mem-9/dimm-env-stats/1/1" id="1" mostRecent="no" rn="1" suspect="no" temperature="28.000000" temperatureAvg="25.599997" temperatureMax="28.000000" temperatureMin="24.000000" thresholded="" timeCollected="2015-09-07T09:43:53.262" /></memoryUnitEnvStatsHist1>'
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))
4 changes: 4 additions & 0 deletions tests/common/test_query_children.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit c26217c

Please sign in to comment.