Merge "Validate project_safe when listing actions"
This commit is contained in:
commit
b54ebaa737
@ -1765,7 +1765,13 @@ class EngineService(service.Service):
|
|||||||
return {'action': action.id}
|
return {'action': action.id}
|
||||||
|
|
||||||
def action_find(self, context, identity):
|
def action_find(self, context, identity):
|
||||||
'''Find an action with the given identity (could be name or ID).'''
|
"""Find an action with the given identity.
|
||||||
|
|
||||||
|
:param context: An instance of the request context.
|
||||||
|
:param identity: The UUID, name or short-id of an action.
|
||||||
|
:return: A DB object of action or an exception `ActionNotFound` if no
|
||||||
|
matching action is found.
|
||||||
|
"""
|
||||||
if uuidutils.is_uuid_like(identity):
|
if uuidutils.is_uuid_like(identity):
|
||||||
action = db_api.action_get(context, identity)
|
action = db_api.action_get(context, identity)
|
||||||
if not action:
|
if not action:
|
||||||
@ -1783,14 +1789,29 @@ class EngineService(service.Service):
|
|||||||
@request_context
|
@request_context
|
||||||
def action_list(self, context, filters=None, limit=None, marker=None,
|
def action_list(self, context, filters=None, limit=None, marker=None,
|
||||||
sort=None, project_safe=True):
|
sort=None, project_safe=True):
|
||||||
|
"""List action records matching the specified criteria.
|
||||||
|
|
||||||
|
:param context: An instance of the request context.
|
||||||
|
:param filters: A dictionary of key-value pairs for filtering out the
|
||||||
|
result list.
|
||||||
|
:param limit: An integer specifying the maximum number of objects to
|
||||||
|
return in a response.
|
||||||
|
:param marker: An UUID specifying the action after which the result
|
||||||
|
list starts.
|
||||||
|
:param sort: A list of sorting keys (each optionally attached with a
|
||||||
|
sorting direction) separated by commas.
|
||||||
|
:param project_safe: A boolean indicating whether actions from all
|
||||||
|
projects will be returned.
|
||||||
|
:return: A list of `Action` object representations.
|
||||||
|
"""
|
||||||
limit = utils.parse_int_param('limit', limit)
|
limit = utils.parse_int_param('limit', limit)
|
||||||
all_actions = action_mod.Action.load_all(context, filters=filters,
|
project_safe = utils.parse_bool_param('project_safe', project_safe)
|
||||||
limit=limit, marker=marker,
|
results = action_mod.Action.load_all(context, filters=filters,
|
||||||
sort=sort,
|
limit=limit, marker=marker,
|
||||||
project_safe=project_safe)
|
sort=sort,
|
||||||
|
project_safe=project_safe)
|
||||||
|
|
||||||
return [a.to_dict() for a in all_actions]
|
return [a.to_dict() for a in results]
|
||||||
|
|
||||||
@request_context
|
@request_context
|
||||||
def action_create(self, context, name, cluster, action, inputs=None):
|
def action_create(self, context, name, cluster, action, inputs=None):
|
||||||
@ -1828,12 +1849,26 @@ class EngineService(service.Service):
|
|||||||
|
|
||||||
@request_context
|
@request_context
|
||||||
def action_get(self, context, identity):
|
def action_get(self, context, identity):
|
||||||
|
"""Get the details about specified action.
|
||||||
|
|
||||||
|
:param context: An instance of the request context.
|
||||||
|
:param identity: The UUID, name or short-id of an action.
|
||||||
|
:return: A dictionary containing the details about an action, or an
|
||||||
|
exception `ActionNotFound` if no matching action is found.
|
||||||
|
"""
|
||||||
db_action = self.action_find(context, identity)
|
db_action = self.action_find(context, identity)
|
||||||
action = action_mod.Action.load(context, db_action=db_action)
|
action = action_mod.Action.load(context, db_action=db_action)
|
||||||
return action.to_dict()
|
return action.to_dict()
|
||||||
|
|
||||||
@request_context
|
@request_context
|
||||||
def action_delete(self, context, identity):
|
def action_delete(self, context, identity):
|
||||||
|
"""Delete the specified action object.
|
||||||
|
|
||||||
|
:param context: An instance of the request context.
|
||||||
|
:param identity: The UUID, name or short-id of an action object.
|
||||||
|
:return: None if deletion was successful, or an exception of type
|
||||||
|
`ResourceInUse`.
|
||||||
|
"""
|
||||||
db_action = self.action_find(context, identity)
|
db_action = self.action_find(context, identity)
|
||||||
LOG.info(_LI("Deleting action '%s'."), identity)
|
LOG.info(_LI("Deleting action '%s'."), identity)
|
||||||
try:
|
try:
|
||||||
|
@ -123,13 +123,19 @@ class ActionTest(base.SenlinTestCase):
|
|||||||
marker='M', sort='S',
|
marker='M', sort='S',
|
||||||
project_safe=False)
|
project_safe=False)
|
||||||
|
|
||||||
def test_action_list_with_bad_limit(self):
|
def test_action_list_with_bad_params(self):
|
||||||
ex = self.assertRaises(rpc.ExpectedException,
|
ex = self.assertRaises(rpc.ExpectedException,
|
||||||
self.eng.action_list,
|
self.eng.action_list,
|
||||||
self.ctx, limit='large')
|
self.ctx, limit='large')
|
||||||
|
|
||||||
self.assertEqual(exc.InvalidParameter, ex.exc_info[0])
|
self.assertEqual(exc.InvalidParameter, ex.exc_info[0])
|
||||||
|
|
||||||
|
ex = self.assertRaises(rpc.ExpectedException,
|
||||||
|
self.eng.action_list,
|
||||||
|
self.ctx, project_safe='yes')
|
||||||
|
|
||||||
|
self.assertEqual(exc.InvalidParameter, ex.exc_info[0])
|
||||||
|
|
||||||
@mock.patch.object(service.EngineService, 'cluster_find')
|
@mock.patch.object(service.EngineService, 'cluster_find')
|
||||||
def test_action_create(self, mock_find):
|
def test_action_create(self, mock_find):
|
||||||
x_cluster = mock.Mock()
|
x_cluster = mock.Mock()
|
||||||
|
Loading…
Reference in New Issue
Block a user