diff --git a/ironic_inspector/rules.py b/ironic_inspector/rules.py index 23d60330c..60b752a16 100644 --- a/ironic_inspector/rules.py +++ b/ironic_inspector/rules.py @@ -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 diff --git a/ironic_inspector/test/unit/test_rules.py b/ironic_inspector/test/unit/test_rules.py index 8524d971c..b90fae738 100644 --- a/ironic_inspector/test/unit/test_rules.py +++ b/ironic_inspector/test/unit/test_rules.py @@ -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 diff --git a/releasenotes/notes/check-formatted-value-from-nonstring-3d851cb42ce3a0ac.yaml b/releasenotes/notes/check-formatted-value-from-nonstring-3d851cb42ce3a0ac.yaml new file mode 100644 index 000000000..90d9069d7 --- /dev/null +++ b/releasenotes/notes/check-formatted-value-from-nonstring-3d851cb42ce3a0ac.yaml @@ -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.