summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIury Gregory Melo Ferreira <imelofer@redhat.com>2018-12-05 09:59:57 +0100
committerIury Gregory Melo Ferreira <imelofer@redhat.com>2018-12-07 15:12:17 +0100
commit22294abac6fdaa6e0c959cd2757497abae232cb7 (patch)
treeec568c4718b929e775915ba72387b9e06a8d3ee3
parentf7079e9acccfedc6b1bf5a1269869d39da80a700 (diff)
Accept None value for set-attribute
Allows the ``set-attribute`` introspection rule action to use ``None`` as a valid value. Co-Authored-By: Riccardo Pittau <elfosardo@gmail.com> Change-Id: I1aa11c8095c4557107223e352424e3b718e2ab35 Story: #2004546 Task: #28299
Notes
Notes (review): Code-Review+2: Mark Goddard <mark@stackhpc.com> Code-Review+2: Dmitry Tantsur <divius.inside@gmail.com> Workflow+1: Dmitry Tantsur <divius.inside@gmail.com> Verified+2: Zuul Submitted-by: Zuul Submitted-at: Sat, 08 Dec 2018 22:51:52 +0000 Reviewed-on: https://review.openstack.org/622898 Project: openstack/ironic-inspector Branch: refs/heads/master
-rw-r--r--ironic_inspector/plugins/rules.py12
-rw-r--r--ironic_inspector/test/unit/test_plugins_rules.py2
-rw-r--r--ironic_inspector/test/unit/test_rules.py12
-rw-r--r--releasenotes/notes/unset_property_instrospectionrules-78d64b8b7643e40d.yaml4
4 files changed, 29 insertions, 1 deletions
diff --git a/ironic_inspector/plugins/rules.py b/ironic_inspector/plugins/rules.py
index dd04a18..02a6b18 100644
--- a/ironic_inspector/plugins/rules.py
+++ b/ironic_inspector/plugins/rules.py
@@ -115,7 +115,10 @@ class FailAction(base.RuleActionPlugin):
115 115
116 116
117class SetAttributeAction(base.RuleActionPlugin): 117class SetAttributeAction(base.RuleActionPlugin):
118 REQUIRED_PARAMS = {'path', 'value'} 118 # NOTE(iurygregory): set as optional to accept None as value, check
119 # that the key 'value' is present, otherwise will raise ValueError.
120 OPTIONAL_PARAMS = {'value'}
121 REQUIRED_PARAMS = {'path'}
119 # TODO(dtantsur): proper validation of path 122 # TODO(dtantsur): proper validation of path
120 123
121 FORMATTED_PARAMS = ['value'] 124 FORMATTED_PARAMS = ['value']
@@ -124,6 +127,13 @@ class SetAttributeAction(base.RuleActionPlugin):
124 node_info.patch([{'op': 'add', 'path': params['path'], 127 node_info.patch([{'op': 'add', 'path': params['path'],
125 'value': params['value']}]) 128 'value': params['value']}])
126 129
130 def validate(self, params, **kwargs):
131 if 'value' in params:
132 super(base.RuleActionPlugin, self).validate(params, **kwargs)
133 else:
134 msg = _('missing required parameter(s): value')
135 raise ValueError(msg)
136
127 137
128class SetCapabilityAction(base.RuleActionPlugin): 138class SetCapabilityAction(base.RuleActionPlugin):
129 REQUIRED_PARAMS = {'name'} 139 REQUIRED_PARAMS = {'name'}
diff --git a/ironic_inspector/test/unit/test_plugins_rules.py b/ironic_inspector/test/unit/test_plugins_rules.py
index b3fd80a..c219116 100644
--- a/ironic_inspector/test/unit/test_plugins_rules.py
+++ b/ironic_inspector/test/unit/test_plugins_rules.py
@@ -158,6 +158,8 @@ class TestSetAttributeAction(test_base.NodeTest):
158 self.assertRaises(ValueError, self.act.validate, {'value': 42}) 158 self.assertRaises(ValueError, self.act.validate, {'value': 42})
159 self.assertRaises(ValueError, self.act.validate, 159 self.assertRaises(ValueError, self.act.validate,
160 {'path': '/extra/value'}) 160 {'path': '/extra/value'})
161 self.params['value'] = None
162 self.act.validate(self.params)
161 163
162 @mock.patch.object(node_cache.NodeInfo, 'patch') 164 @mock.patch.object(node_cache.NodeInfo, 'patch')
163 def test_apply(self, mock_patch): 165 def test_apply(self, mock_patch):
diff --git a/ironic_inspector/test/unit/test_rules.py b/ironic_inspector/test/unit/test_rules.py
index 8d53b0b..5ba8547 100644
--- a/ironic_inspector/test/unit/test_rules.py
+++ b/ironic_inspector/test/unit/test_rules.py
@@ -59,6 +59,18 @@ class TestCreateRule(BaseTest):
59 'actions': self.actions_json}, 59 'actions': self.actions_json},
60 rule_json) 60 rule_json)
61 61
62 def test_create_action_none_value(self):
63 self.actions_json = [{'action': 'set-attribute',
64 'path': '/properties/cpus', 'value': None}]
65 rule = rules.create([], self.actions_json)
66 rule_json = rule.as_dict()
67
68 self.assertTrue(rule_json.pop('uuid'))
69 self.assertEqual({'description': None,
70 'conditions': [],
71 'actions': self.actions_json},
72 rule_json)
73
62 def test_duplicate_uuid(self): 74 def test_duplicate_uuid(self):
63 rules.create([], self.actions_json, uuid=self.uuid) 75 rules.create([], self.actions_json, uuid=self.uuid)
64 self.assertRaisesRegex(utils.Error, 'already exists', 76 self.assertRaisesRegex(utils.Error, 'already exists',
diff --git a/releasenotes/notes/unset_property_instrospectionrules-78d64b8b7643e40d.yaml b/releasenotes/notes/unset_property_instrospectionrules-78d64b8b7643e40d.yaml
new file mode 100644
index 0000000..9340701
--- /dev/null
+++ b/releasenotes/notes/unset_property_instrospectionrules-78d64b8b7643e40d.yaml
@@ -0,0 +1,4 @@
1fixes:
2 - |
3 Allows the ``set-attribute`` introspection rule action to accept ``None``
4 as value for a property.