Fixing tasks operations in mistralclient
* Deleted PUT/update operation from lib and CLI * Recovered filtering tasks by workflow execution: mistral task-list [workflow-execution-id] Partially implements blueprint mistral-refactor-task-output Change-Id: I0bf975f874865bbd178120cb3f1062812f3351ac
This commit is contained in:
@@ -22,15 +22,6 @@ class Task(base.Resource):
|
|||||||
class TaskManager(base.ResourceManager):
|
class TaskManager(base.ResourceManager):
|
||||||
resource_class = Task
|
resource_class = Task
|
||||||
|
|
||||||
def update(self, id, state):
|
|
||||||
self._ensure_not_empty(id=id, state=state)
|
|
||||||
|
|
||||||
data = {
|
|
||||||
'state': state
|
|
||||||
}
|
|
||||||
|
|
||||||
return self._update('/tasks/%s' % id, data)
|
|
||||||
|
|
||||||
def list(self, workflow_execution_id=None):
|
def list(self, workflow_execution_id=None):
|
||||||
url = '/tasks'
|
url = '/tasks'
|
||||||
|
|
||||||
|
@@ -52,11 +52,22 @@ def format(task=None):
|
|||||||
class List(base.MistralLister):
|
class List(base.MistralLister):
|
||||||
"""List all tasks."""
|
"""List all tasks."""
|
||||||
|
|
||||||
|
def get_parser(self, prog_name):
|
||||||
|
parser = super(List, self).get_parser(prog_name)
|
||||||
|
|
||||||
|
parser.add_argument(
|
||||||
|
'workflow_execution',
|
||||||
|
nargs='?',
|
||||||
|
help='Workflow execution ID associated with list of Tasks.')
|
||||||
|
return parser
|
||||||
|
|
||||||
def _get_format_function(self):
|
def _get_format_function(self):
|
||||||
return format
|
return format
|
||||||
|
|
||||||
def _get_resources(self, parsed_args):
|
def _get_resources(self, parsed_args):
|
||||||
return tasks.TaskManager(self.app.client).list()
|
return tasks.TaskManager(self.app.client).list(
|
||||||
|
parsed_args.workflow_execution
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class Get(show.ShowOne):
|
class Get(show.ShowOne):
|
||||||
@@ -77,30 +88,6 @@ class Get(show.ShowOne):
|
|||||||
return format(execution)
|
return format(execution)
|
||||||
|
|
||||||
|
|
||||||
class Update(show.ShowOne):
|
|
||||||
"""Update task."""
|
|
||||||
|
|
||||||
def get_parser(self, prog_name):
|
|
||||||
parser = super(Update, self).get_parser(prog_name)
|
|
||||||
|
|
||||||
parser.add_argument(
|
|
||||||
'id',
|
|
||||||
help='Task identifier')
|
|
||||||
parser.add_argument(
|
|
||||||
'state',
|
|
||||||
choices=['IDLE', 'RUNNING', 'SUCCESS', 'ERROR'],
|
|
||||||
help='Task state')
|
|
||||||
|
|
||||||
return parser
|
|
||||||
|
|
||||||
def take_action(self, parsed_args):
|
|
||||||
execution = tasks.TaskManager(self.app.client).update(
|
|
||||||
parsed_args.id,
|
|
||||||
parsed_args.state)
|
|
||||||
|
|
||||||
return format(execution)
|
|
||||||
|
|
||||||
|
|
||||||
class GetResult(command.Command):
|
class GetResult(command.Command):
|
||||||
"""Show task output data."""
|
"""Show task output data."""
|
||||||
|
|
||||||
|
@@ -285,7 +285,6 @@ class MistralShell(app.App):
|
|||||||
'task-get': mistralclient.commands.v2.tasks.Get,
|
'task-get': mistralclient.commands.v2.tasks.Get,
|
||||||
'task-get-input': mistralclient.commands.v2.tasks.GetInput,
|
'task-get-input': mistralclient.commands.v2.tasks.GetInput,
|
||||||
'task-get-result': mistralclient.commands.v2.tasks.GetResult,
|
'task-get-result': mistralclient.commands.v2.tasks.GetResult,
|
||||||
'task-update': mistralclient.commands.v2.tasks.Update,
|
|
||||||
'action-list': mistralclient.commands.v2.actions.List,
|
'action-list': mistralclient.commands.v2.actions.List,
|
||||||
'action-get': mistralclient.commands.v2.actions.Get,
|
'action-get': mistralclient.commands.v2.actions.Get,
|
||||||
'action-create': mistralclient.commands.v2.actions.Create,
|
'action-create': mistralclient.commands.v2.actions.Create,
|
||||||
|
@@ -44,16 +44,6 @@ TASK_WITH_INPUT = tasks.Task(mock, TASK_WITH_INPUT_DICT)
|
|||||||
|
|
||||||
|
|
||||||
class TestCLITasksV2(base.BaseCommandTest):
|
class TestCLITasksV2(base.BaseCommandTest):
|
||||||
@mock.patch('mistralclient.api.v2.tasks.TaskManager.update')
|
|
||||||
def test_update(self, mock):
|
|
||||||
mock.return_value = TASK
|
|
||||||
|
|
||||||
result = self.call(task_cmd.Update,
|
|
||||||
app_args=['id', 'ERROR'])
|
|
||||||
|
|
||||||
self.assertEqual(('123', 'some', 'thing', '321', 'RUNNING'),
|
|
||||||
result[1])
|
|
||||||
|
|
||||||
@mock.patch('mistralclient.api.v2.tasks.TaskManager.list')
|
@mock.patch('mistralclient.api.v2.tasks.TaskManager.list')
|
||||||
def test_list(self, mock):
|
def test_list(self, mock):
|
||||||
mock.return_value = (TASK,)
|
mock.return_value = (TASK,)
|
||||||
@@ -63,6 +53,15 @@ class TestCLITasksV2(base.BaseCommandTest):
|
|||||||
self.assertEqual([('123', 'some', 'thing', '321', 'RUNNING')],
|
self.assertEqual([('123', 'some', 'thing', '321', 'RUNNING')],
|
||||||
result[1])
|
result[1])
|
||||||
|
|
||||||
|
@mock.patch('mistralclient.api.v2.tasks.TaskManager.list')
|
||||||
|
def test_list_with_workflow_execution(self, mock):
|
||||||
|
mock.return_value = (TASK,)
|
||||||
|
|
||||||
|
result = self.call(task_cmd.List, app_args=['workflow_execution'])
|
||||||
|
|
||||||
|
self.assertEqual([('123', 'some', 'thing', '321', 'RUNNING')],
|
||||||
|
result[1])
|
||||||
|
|
||||||
@mock.patch('mistralclient.api.v2.tasks.TaskManager.get')
|
@mock.patch('mistralclient.api.v2.tasks.TaskManager.get')
|
||||||
def test_get(self, mock):
|
def test_get(self, mock):
|
||||||
mock.return_value = TASK
|
mock.return_value = TASK
|
||||||
|
@@ -12,8 +12,6 @@
|
|||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
import json
|
|
||||||
|
|
||||||
from mistralclient.api.v2 import tasks
|
from mistralclient.api.v2 import tasks
|
||||||
from mistralclient.tests.unit.v2 import base
|
from mistralclient.tests.unit.v2 import base
|
||||||
|
|
||||||
@@ -25,7 +23,8 @@ TASK = {
|
|||||||
'name': 'my_task',
|
'name': 'my_task',
|
||||||
'workflow_name': 'my_wf',
|
'workflow_name': 'my_wf',
|
||||||
'state': 'RUNNING',
|
'state': 'RUNNING',
|
||||||
'tags': ['deployment', 'demo']
|
'tags': ['deployment', 'demo'],
|
||||||
|
'result': {'some': 'result'}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -34,20 +33,6 @@ URL_TEMPLATE_ID = '/tasks/%s'
|
|||||||
|
|
||||||
|
|
||||||
class TestTasksV2(base.BaseClientV2Test):
|
class TestTasksV2(base.BaseClientV2Test):
|
||||||
def test_update(self):
|
|
||||||
mock = self.mock_http_put(content=TASK)
|
|
||||||
body = {
|
|
||||||
'state': TASK['state']
|
|
||||||
}
|
|
||||||
|
|
||||||
task = self.tasks.update(TASK['id'],
|
|
||||||
TASK['state'])
|
|
||||||
|
|
||||||
self.assertIsNotNone(task)
|
|
||||||
self.assertEqual(tasks.Task(self.tasks, TASK).__dict__, task.__dict__)
|
|
||||||
mock.assert_called_once_with(
|
|
||||||
URL_TEMPLATE_ID % TASK['id'], json.dumps(body))
|
|
||||||
|
|
||||||
def test_list(self):
|
def test_list(self):
|
||||||
mock = self.mock_http_get(content={'tasks': [TASK]})
|
mock = self.mock_http_get(content={'tasks': [TASK]})
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user