Skip to content

Commit

Permalink
check for property access value of READ_WRITE on any platform (CiscoU…
Browse files Browse the repository at this point in the history
…cs#99)

* check for property access value of READ_WRITE on any platform

Signed-off-by: Swapnil Wagh <waghswapnil@gmail.com>

* function name change and refactoring

Signed-off-by: Swapnil Wagh <waghswapnil@gmail.com>

* testcase for the change

Signed-off-by: Swapnil Wagh <waghswapnil@gmail.com>
  • Loading branch information
waghswapnil authored and vvb committed Jan 24, 2017
1 parent c5594e4 commit a869e26
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 1 deletion.
14 changes: 14 additions & 0 deletions imcsdk/imccoreutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
from . imcmeta import MO_CLASS_ID, METHOD_CLASS_ID, OTHER_TYPE_CLASS_ID, \
MO_CLASS_META
from .imcexception import ImcOperationError, ImcValidationException
from imccoremeta import MoPropertyMeta

log = logging.getLogger('imc')

Expand Down Expand Up @@ -751,6 +752,19 @@ def validate_property_value(mo, prop, value):
return False


def is_writable_prop(mo, prop, platform=None):

for platform in IMC_PLATFORM_LIST:
prop_ = _get_property_from_prop_meta_for_platform(
mo,
prop,
platform)
if prop_ and prop_.access == MoPropertyMeta.READ_WRITE:
return True

return False


def property_exists_in_prop_map(mo, prop_name):

for platform in IMC_PLATFORM_LIST:
Expand Down
2 changes: 1 addition & 1 deletion imcsdk/imcmo.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ def __set_prop(self, name, value, mark_dirty=True, forced=False):
return
if not forced:
prop = imccoreutils.get_prop_meta(self, name)
if prop.access != imccoremeta.MoPropertyMeta.READ_WRITE:
if not imccoreutils.is_writable_prop(self, name):
if getattr(self, name) is not None or \
prop.access != \
imccoremeta.MoPropertyMeta.CREATE_ONLY:
Expand Down
9 changes: 9 additions & 0 deletions tests/common/test_imcpropval.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

from nose.tools import *
from imcsdk.mometa.compute.ComputeRackUnit import ComputeRackUnit
from imcsdk.mometa.power.PowerBudget import PowerBudget

obj = None

Expand Down Expand Up @@ -46,3 +47,11 @@ def test_003_set_naming_property():
# This is a naming property. so, it is create only
# Should fail with an exception
obj.server_id = "15"


def test_004_set_rw_ro_property():
obj = PowerBudget(parent_mo_or_dn='sys/rack-unit-1')
obj.status = 'modified'

obj = PowerBudget(parent_mo_or_dn='sys/chassis-1/server-1')
obj.status = 'modified'
2 changes: 2 additions & 0 deletions tests/unit_tests/test_ipmi.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ def test_invalid_enable_ipmi(login_mock, set_mo_mock):
username='admin',
password='right')

test_cimc._set_platform(platform=IMC_PLATFORM.TYPE_CLASSIC)

# Scenario: Invalid priv value
assert_raises(ValueError, ipmi_enable, test_cimc, priv="Wrong")

Expand Down

0 comments on commit a869e26

Please sign in to comment.