Wrong result is returned when call events getting API
For current implementation, events getting API only support 'eq' query operation when query field is the one of 'event_type', 'message_id', 'start_timestamp' and 'end_timestamp'. But there is a problem, if the query operation wasn't specified as 'eq'(e.g. 'ne'), the returned result is still the same as the query operation was specified as 'eq'. This patch add a check for this situation: if the query field is the one of 'event_type', 'message_id', 'start_timestamp', 'end_timestamp', and the query operation user specified is not 'eq', then a client side error will be thrown. Also, corresponding unit test case is added. Change-Id: I4e4b127045de6e933281d9289271af891c3c80fe Closes-Bug: #1511592
This commit is contained in:
parent
d26ebcc74b
commit
ac3ff88c03
@ -192,6 +192,12 @@ def _event_query_to_event_filter(q):
|
||||
{'operator': i.op, 'supported': base.operation_kind})
|
||||
raise base.ClientSideError(error)
|
||||
if i.field in evt_model_filter:
|
||||
if i.op != 'eq':
|
||||
error = (_('operator %(operator)s is not supported. Only'
|
||||
' equality operator is available for field'
|
||||
' %(field)s') %
|
||||
{'operator': i.op, 'field': i.field})
|
||||
raise base.ClientSideError(error)
|
||||
evt_model_filter[i.field] = i.value
|
||||
else:
|
||||
trait_type = i.type or 'string'
|
||||
|
@ -25,6 +25,7 @@ import wsme
|
||||
|
||||
from ceilometer.alarm.storage import base as alarm_storage_base
|
||||
from ceilometer.api.controllers.v2 import base as v2_base
|
||||
from ceilometer.api.controllers.v2 import events
|
||||
from ceilometer.api.controllers.v2 import meters
|
||||
from ceilometer.api.controllers.v2 import utils
|
||||
from ceilometer import storage
|
||||
@ -37,6 +38,10 @@ class TestQuery(base.BaseTestCase):
|
||||
super(TestQuery, self).setUp()
|
||||
self.useFixture(fixtures.MonkeyPatch(
|
||||
'pecan.response', mock.MagicMock()))
|
||||
self.useFixture(mockpatch.Patch('ceilometer.api.controllers.v2.events'
|
||||
'._build_rbac_query_filters',
|
||||
return_value={'t_filter': [],
|
||||
'admin_proj': None}))
|
||||
|
||||
def test_get_value_as_type_with_integer(self):
|
||||
query = v2_base.Query(field='metadata.size',
|
||||
@ -154,6 +159,15 @@ class TestQuery(base.BaseTestCase):
|
||||
expected = value
|
||||
self.assertEqual(expected, query._get_value_as_type())
|
||||
|
||||
def test_event_query_to_event_filter_with_bad_op(self):
|
||||
# bug 1511592
|
||||
query = v2_base.Query(field='event_type',
|
||||
op='ne',
|
||||
value='compute.instance.create.end',
|
||||
type='string')
|
||||
self.assertRaises(v2_base.ClientSideError,
|
||||
events._event_query_to_event_filter, [query])
|
||||
|
||||
|
||||
class TestValidateGroupByFields(base.BaseTestCase):
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user