Inspector rules API does not return all attributes

When using the Inspector rules API to query existing introspection
rules, inspector does not return 'invert' or 'multiple' attributes of
conditions associated with the rules.

Change-Id: I08606cea676ecf57bbb3b73077c4832240fbe0d2
Closes-Bug: #1670372
This commit is contained in:
Annie Lezil 2017-03-08 00:28:56 +00:00 committed by dparalen
parent 3f2ba0c3df
commit 33a28f34f8
6 changed files with 40 additions and 7 deletions

View File

@ -397,3 +397,4 @@ Version History
are requested, API gets HTTP 400 response. are requested, API gets HTTP 400 response.
* **1.10** adds node state to the GET /v1/introspection/<Node ID> and * **1.10** adds node state to the GET /v1/introspection/<Node ID> and
GET /v1/introspection API response data. GET /v1/introspection API response data.
* **1.11** adds invert&multiple fields into rules response data

View File

@ -112,6 +112,8 @@ class RuleCondition(Base):
res = self.params.copy() res = self.params.copy()
res['op'] = self.op res['op'] = self.op
res['field'] = self.field res['field'] = self.field
res['multiple'] = self.multiple
res['invert'] = self.invert
return res return res

View File

@ -51,7 +51,7 @@ MINIMUM_API_VERSION = (1, 0)
# TODO(dtantsur): set to the current version as soon we move setting IPMI # TODO(dtantsur): set to the current version as soon we move setting IPMI
# credentials support completely. # credentials support completely.
DEFAULT_API_VERSION = (1, 8) DEFAULT_API_VERSION = (1, 8)
CURRENT_API_VERSION = (1, 10) CURRENT_API_VERSION = (1, 11)
_LOGGING_EXCLUDED_KEYS = ('logs',) _LOGGING_EXCLUDED_KEYS = ('logs',)

View File

@ -43,6 +43,7 @@ from ironic_inspector import main
from ironic_inspector import node_cache from ironic_inspector import node_cache
from ironic_inspector import rules from ironic_inspector import rules
from ironic_inspector.test import base from ironic_inspector.test import base
from ironic_inspector.test.unit import test_rules
CONF = """ CONF = """
@ -393,9 +394,16 @@ class Test(Base):
res = self.call_list_rules() res = self.call_list_rules()
self.assertEqual([], res) self.assertEqual([], res)
rule = {'conditions': [], rule = {
'actions': [{'action': 'fail', 'message': 'boom'}], 'conditions': [
'description': 'Cool actions'} 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) res = self.call_add_rule(rule)
self.assertTrue(res['uuid']) self.assertTrue(res['uuid'])
rule['uuid'] = res['uuid'] rule['uuid'] = res['uuid']

View File

@ -13,7 +13,6 @@
# under the License. # under the License.
"""Tests for introspection rules.""" """Tests for introspection rules."""
import mock import mock
from oslo_utils import uuidutils from oslo_utils import uuidutils
@ -41,6 +40,13 @@ class BaseTest(test_base.NodeTest):
'local_gb': 42, 'local_gb': 42,
} }
@staticmethod
def condition_defaults(condition):
condition = condition.copy()
condition.setdefault('multiple', 'any')
condition.setdefault('invert', False)
return condition
class TestCreateRule(BaseTest): class TestCreateRule(BaseTest):
def test_only_actions(self): def test_only_actions(self):
@ -60,12 +66,22 @@ class TestCreateRule(BaseTest):
uuid=self.uuid) uuid=self.uuid)
def test_with_conditions(self): 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 = rules.create(self.conditions_json, self.actions_json)
rule_json = rule.as_dict() rule_json = rule.as_dict()
self.assertTrue(rule_json.pop('uuid')) self.assertTrue(rule_json.pop('uuid'))
self.assertEqual({'description': None, self.assertEqual({'description': None,
'conditions': self.conditions_json, 'conditions': [BaseTest.condition_defaults(cond)
for cond in self.conditions_json],
'actions': self.actions_json}, 'actions': self.actions_json},
rule_json) rule_json)
@ -140,7 +156,8 @@ class TestGetRule(BaseTest):
self.assertTrue(rule_json.pop('uuid')) self.assertTrue(rule_json.pop('uuid'))
self.assertEqual({'description': None, self.assertEqual({'description': None,
'conditions': self.conditions_json, 'conditions': [BaseTest.condition_defaults(cond)
for cond in self.conditions_json],
'actions': self.actions_json}, 'actions': self.actions_json},
rule_json) rule_json)

View File

@ -0,0 +1,5 @@
---
features:
- |
Querying **inspector** rules API now also returns the ``invert`` and
``multiple`` attributes of the associated conditions.