Merge "Fixing tasks operations in mistralclient"

This commit is contained in:
Jenkins 2015-03-23 12:38:38 +00:00 committed by Gerrit Code Review
commit ef011f0bea
5 changed files with 23 additions and 62 deletions

View File

@ -22,15 +22,6 @@ class Task(base.Resource):
class TaskManager(base.ResourceManager):
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):
url = '/tasks'

View File

@ -52,11 +52,22 @@ def format(task=None):
class List(base.MistralLister):
"""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):
return format
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):
@ -77,30 +88,6 @@ class Get(show.ShowOne):
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):
"""Show task output data."""

View File

@ -285,7 +285,6 @@ class MistralShell(app.App):
'task-get': mistralclient.commands.v2.tasks.Get,
'task-get-input': mistralclient.commands.v2.tasks.GetInput,
'task-get-result': mistralclient.commands.v2.tasks.GetResult,
'task-update': mistralclient.commands.v2.tasks.Update,
'action-list': mistralclient.commands.v2.actions.List,
'action-get': mistralclient.commands.v2.actions.Get,
'action-create': mistralclient.commands.v2.actions.Create,

View File

@ -44,16 +44,6 @@ TASK_WITH_INPUT = tasks.Task(mock, TASK_WITH_INPUT_DICT)
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')
def test_list(self, mock):
mock.return_value = (TASK,)
@ -63,6 +53,15 @@ class TestCLITasksV2(base.BaseCommandTest):
self.assertEqual([('123', 'some', 'thing', '321', 'RUNNING')],
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')
def test_get(self, mock):
mock.return_value = TASK

View File

@ -12,8 +12,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import json
from mistralclient.api.v2 import tasks
from mistralclient.tests.unit.v2 import base
@ -25,7 +23,8 @@ TASK = {
'name': 'my_task',
'workflow_name': 'my_wf',
'state': 'RUNNING',
'tags': ['deployment', 'demo']
'tags': ['deployment', 'demo'],
'result': {'some': 'result'}
}
@ -34,20 +33,6 @@ URL_TEMPLATE_ID = '/tasks/%s'
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):
mock = self.mock_http_get(content={'tasks': [TASK]})