Merge "Check whether action value is string before calling format()"

This commit is contained in:
Jenkins 2016-08-03 13:31:21 +00:00 committed by Gerrit Code Review
commit 571df6eb16
3 changed files with 21 additions and 1 deletions

View File

@ -19,6 +19,7 @@ import jsonschema
from oslo_db import exception as db_exc
from oslo_utils import timeutils
from oslo_utils import uuidutils
import six
from sqlalchemy import orm
from ironic_inspector.common.i18n import _, _LE, _LI
@ -202,7 +203,7 @@ class IntrospectionRule(object):
ext = ext_mgr[act.action].obj
for formatted_param in ext.FORMATTED_PARAMS:
value = act.params.get(formatted_param)
if not value:
if not value or not isinstance(value, six.string_types):
continue
# NOTE(aarefiev): verify provided value with introspection

View File

@ -419,6 +419,20 @@ class TestApplyActions(BaseTest):
self.assertRaises(utils.Error, self.rule.apply_actions,
self.node_info, data=self.data)
def test_apply_data_non_format_value(self, mock_ext_mgr):
self.rule = rules.create(actions_json=[
{'action': 'set-attribute',
'path': '/driver_info/ipmi_address',
'value': 1}],
conditions_json=self.conditions_json
)
mock_ext_mgr.return_value.__getitem__.return_value = self.ext_mock
self.rule.apply_actions(self.node_info, data=self.data)
self.assertEqual(1, self.act_mock.apply.call_count)
self.assertFalse(self.act_mock.rollback.called)
def test_rollback(self, mock_ext_mgr):
mock_ext_mgr.return_value.__getitem__.return_value = self.ext_mock

View File

@ -0,0 +1,5 @@
---
fixes:
This fixes setting non string 'value' field for rule's
actions. As non string value is obviously not a formatted
value, this adds a check to avoid AttributeError exception.