diff --git a/doc/source/http-api.rst b/doc/source/http-api.rst index 82d38a429..df882c103 100644 --- a/doc/source/http-api.rst +++ b/doc/source/http-api.rst @@ -397,3 +397,4 @@ Version History are requested, API gets HTTP 400 response. * **1.10** adds node state to the GET /v1/introspection/ and GET /v1/introspection API response data. +* **1.11** adds invert&multiple fields into rules response data diff --git a/ironic_inspector/db.py b/ironic_inspector/db.py index 9208369c3..042ff06e1 100644 --- a/ironic_inspector/db.py +++ b/ironic_inspector/db.py @@ -112,6 +112,8 @@ class RuleCondition(Base): res = self.params.copy() res['op'] = self.op res['field'] = self.field + res['multiple'] = self.multiple + res['invert'] = self.invert return res diff --git a/ironic_inspector/main.py b/ironic_inspector/main.py index cb84e1401..fa30f0eae 100644 --- a/ironic_inspector/main.py +++ b/ironic_inspector/main.py @@ -51,7 +51,7 @@ MINIMUM_API_VERSION = (1, 0) # TODO(dtantsur): set to the current version as soon we move setting IPMI # credentials support completely. DEFAULT_API_VERSION = (1, 8) -CURRENT_API_VERSION = (1, 10) +CURRENT_API_VERSION = (1, 11) _LOGGING_EXCLUDED_KEYS = ('logs',) diff --git a/ironic_inspector/test/functional.py b/ironic_inspector/test/functional.py index fd8a6c528..ccea85155 100644 --- a/ironic_inspector/test/functional.py +++ b/ironic_inspector/test/functional.py @@ -43,6 +43,7 @@ from ironic_inspector import main from ironic_inspector import node_cache from ironic_inspector import rules from ironic_inspector.test import base +from ironic_inspector.test.unit import test_rules CONF = """ @@ -393,9 +394,16 @@ class Test(Base): res = self.call_list_rules() self.assertEqual([], res) - rule = {'conditions': [], - 'actions': [{'action': 'fail', 'message': 'boom'}], - 'description': 'Cool actions'} + rule = { + 'conditions': [ + test_rules.BaseTest.condition_defaults( + {'op': 'eq', 'field': 'memory_mb', 'value': 1024} + ) + ], + 'actions': [{'action': 'fail', 'message': 'boom'}], + 'description': 'Cool actions' + } + res = self.call_add_rule(rule) self.assertTrue(res['uuid']) rule['uuid'] = res['uuid'] diff --git a/ironic_inspector/test/unit/test_rules.py b/ironic_inspector/test/unit/test_rules.py index 4164a6c6d..a82fe7a08 100644 --- a/ironic_inspector/test/unit/test_rules.py +++ b/ironic_inspector/test/unit/test_rules.py @@ -13,7 +13,6 @@ # under the License. """Tests for introspection rules.""" - import mock from oslo_utils import uuidutils @@ -41,6 +40,13 @@ class BaseTest(test_base.NodeTest): 'local_gb': 42, } + @staticmethod + def condition_defaults(condition): + condition = condition.copy() + condition.setdefault('multiple', 'any') + condition.setdefault('invert', False) + return condition + class TestCreateRule(BaseTest): def test_only_actions(self): @@ -60,12 +66,22 @@ class TestCreateRule(BaseTest): uuid=self.uuid) def test_with_conditions(self): + self.conditions_json.extend([ + # multiple present&default, invert absent + {'op': 'eq', 'field': 'local_gb', 'value': 60, 'multiple': 'any'}, + # multiple absent, invert present&default + {'op': 'eq', 'field': 'local_gb', 'value': 60, 'invert': False}, + # multiple&invert present&non-default + {'op': 'eq', 'field': 'memory_mb', 'value': 1024, + 'multiple': 'all', 'invert': True}, + ]) rule = rules.create(self.conditions_json, self.actions_json) rule_json = rule.as_dict() self.assertTrue(rule_json.pop('uuid')) self.assertEqual({'description': None, - 'conditions': self.conditions_json, + 'conditions': [BaseTest.condition_defaults(cond) + for cond in self.conditions_json], 'actions': self.actions_json}, rule_json) @@ -140,7 +156,8 @@ class TestGetRule(BaseTest): self.assertTrue(rule_json.pop('uuid')) self.assertEqual({'description': None, - 'conditions': self.conditions_json, + 'conditions': [BaseTest.condition_defaults(cond) + for cond in self.conditions_json], 'actions': self.actions_json}, rule_json) diff --git a/releasenotes/notes/Inspector_rules_API_does_not_return_all_attributes-98a9765726c405d5.yaml b/releasenotes/notes/Inspector_rules_API_does_not_return_all_attributes-98a9765726c405d5.yaml new file mode 100644 index 000000000..1b5a743f5 --- /dev/null +++ b/releasenotes/notes/Inspector_rules_API_does_not_return_all_attributes-98a9765726c405d5.yaml @@ -0,0 +1,5 @@ +--- +features: + - | + Querying **inspector** rules API now also returns the ``invert`` and + ``multiple`` attributes of the associated conditions.