Merge "Inspector rules API does not return all attributes"

This commit is contained in:
Jenkins 2017-05-17 15:35:40 +00:00 committed by Gerrit Code Review
commit 65945d1086
6 changed files with 40 additions and 7 deletions

View File

@ -397,3 +397,4 @@ Version History
are requested, API gets HTTP 400 response.
* **1.10** adds node state to the GET /v1/introspection/<Node ID> and
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['op'] = self.op
res['field'] = self.field
res['multiple'] = self.multiple
res['invert'] = self.invert
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
# credentials support completely.
DEFAULT_API_VERSION = (1, 8)
CURRENT_API_VERSION = (1, 10)
CURRENT_API_VERSION = (1, 11)
_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 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']

View File

@ -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)

View File

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