Merge "Enable more inclusive cluster filtering when listing events"
This commit is contained in:
commit
acbf5e8a5a
|
@ -2330,10 +2330,18 @@ class EngineService(service.Service):
|
|||
filters['otype'] = req.otype
|
||||
if req.obj_attr_is_set('action'):
|
||||
filters['action'] = req.action
|
||||
if req.obj_attr_is_set('cluster_id'):
|
||||
filters['cluster_id'] = req.cluster_id
|
||||
if req.obj_attr_is_set('level'):
|
||||
filters['level'] = req.level
|
||||
if req.obj_attr_is_set('cluster_id'):
|
||||
cluster_ids = []
|
||||
for cid in req.cluster_id:
|
||||
try:
|
||||
cluster = co.Cluster.find(ctx, cid)
|
||||
cluster_ids.append(cluster.id)
|
||||
except exception.ResourceNotFound:
|
||||
return []
|
||||
if len(cluster_ids) > 0:
|
||||
filters['cluster_id'] = cluster_ids
|
||||
if filters:
|
||||
query['filters'] = filters
|
||||
|
||||
|
|
|
@ -17,6 +17,7 @@ from oslo_messaging.rpc import dispatcher as rpc
|
|||
from senlin.common import consts
|
||||
from senlin.common import exception as exc
|
||||
from senlin.engine import service
|
||||
from senlin.objects import cluster as co
|
||||
from senlin.objects import event as eo
|
||||
from senlin.objects.requests import events as oreo
|
||||
from senlin.tests.unit.common import base
|
||||
|
@ -73,6 +74,52 @@ class EventTest(base.SenlinTestCase):
|
|||
marker=marker_uuid,
|
||||
project_safe=True)
|
||||
|
||||
@mock.patch.object(co.Cluster, 'find')
|
||||
@mock.patch.object(eo.Event, 'get_all')
|
||||
def test_event_list_with_cluster_id(self, mock_load, mock_find):
|
||||
obj_1 = mock.Mock()
|
||||
obj_1.as_dict.return_value = {'level': consts.EVENT_LEVELS['DEBUG']}
|
||||
obj_2 = mock.Mock()
|
||||
obj_2.as_dict.return_value = {'level': consts.EVENT_LEVELS['INFO']}
|
||||
mock_load.return_value = [obj_1, obj_2]
|
||||
fake_clusters = [mock.Mock(id='FAKE1'), mock.Mock(id='FAKE2')]
|
||||
mock_find.side_effect = fake_clusters
|
||||
|
||||
req = oreo.EventListRequest(cluster_id=['CLUSTERA', 'CLUSTER2'],
|
||||
project_safe=True)
|
||||
|
||||
result = self.eng.event_list(self.ctx, req.obj_to_primitive())
|
||||
|
||||
expected = [{'level': 'DEBUG'}, {'level': 'INFO'}]
|
||||
self.assertEqual(expected, result)
|
||||
|
||||
filters = {'cluster_id': ['FAKE1', 'FAKE2']}
|
||||
mock_load.assert_called_once_with(self.ctx, filters=filters,
|
||||
project_safe=True)
|
||||
mock_find.assert_has_calls([
|
||||
mock.call(self.ctx, 'CLUSTERA'),
|
||||
mock.call(self.ctx, 'CLUSTER2')
|
||||
])
|
||||
|
||||
@mock.patch.object(co.Cluster, 'find')
|
||||
@mock.patch.object(eo.Event, 'get_all')
|
||||
def test_event_list_with_cluster_not_found(self, mock_load, mock_find):
|
||||
mock_find.side_effect = [
|
||||
mock.Mock(id='FAKE1'),
|
||||
exc.ResourceNotFound(type='cluster', id='CLUSTER2'),
|
||||
]
|
||||
req = oreo.EventListRequest(cluster_id=['CLUSTERA', 'CLUSTER2'],
|
||||
project_safe=True)
|
||||
|
||||
result = self.eng.event_list(self.ctx, req.obj_to_primitive())
|
||||
|
||||
self.assertEqual([], result)
|
||||
self.assertEqual(0, mock_load.call_count)
|
||||
mock_find.assert_has_calls([
|
||||
mock.call(self.ctx, 'CLUSTERA'),
|
||||
mock.call(self.ctx, 'CLUSTER2')
|
||||
])
|
||||
|
||||
def test_event_list_with_bad_params(self):
|
||||
req = oreo.EventListRequest(project_safe=False)
|
||||
ex = self.assertRaises(rpc.ExpectedException,
|
||||
|
|
Loading…
Reference in New Issue