Add task command
This patch adds the task command which allows to perform the following operations on tasks in Fuel: - List tasks task list - Show details about a task task show Blueprint: re-thinking-fuel-client Change-Id: I3994ddc52f7454114b81ba9aa1ee22e6225fe477
This commit is contained in:
@@ -50,6 +50,7 @@ def get_client(resource, version='v1'):
|
||||
'v1': {
|
||||
'environment': v1.environment,
|
||||
'node': v1.node,
|
||||
'task': v1.task
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
41
fuelclient/commands/task.py
Normal file
41
fuelclient/commands/task.py
Normal file
@@ -0,0 +1,41 @@
|
||||
# Copyright 2015 Mirantis, Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from fuelclient.commands import base
|
||||
|
||||
|
||||
class TaskMixIn(object):
|
||||
entity_name = 'task'
|
||||
|
||||
|
||||
class TaskList(TaskMixIn, base.BaseListCommand):
|
||||
"""Show list of all avaliable nodes."""
|
||||
columns = ('id',
|
||||
'status',
|
||||
'name',
|
||||
'cluster',
|
||||
'result',
|
||||
'progress')
|
||||
|
||||
|
||||
class TaskShow(TaskMixIn, base.BaseShowCommand):
|
||||
"""Show info about node with given id."""
|
||||
columns = ('id',
|
||||
'uuid',
|
||||
'status',
|
||||
'name',
|
||||
'cluster',
|
||||
'result',
|
||||
'progress',
|
||||
'message')
|
||||
38
fuelclient/tests/cli/test_task.py
Normal file
38
fuelclient/tests/cli/test_task.py
Normal file
@@ -0,0 +1,38 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# Copyright 2015 Mirantis, Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import mock
|
||||
|
||||
from fuelclient.tests.cli import test_v2_engine
|
||||
|
||||
|
||||
class TestTaskCommand(test_v2_engine.BaseCLITest):
|
||||
|
||||
def test_task_list(self):
|
||||
args = 'task list'
|
||||
self.exec_v2_command(args)
|
||||
|
||||
self.m_get_client.assert_called_once_with('task', mock.ANY)
|
||||
self.m_client.get_all.assert_called_once_with()
|
||||
|
||||
def test_task_show(self):
|
||||
task_id = 42
|
||||
args = 'task show {task_id}'.format(task_id=task_id)
|
||||
|
||||
self.exec_v2_command(args)
|
||||
|
||||
self.m_get_client.assert_called_once_with('task', mock.ANY)
|
||||
self.m_client.get_by_id.assert_called_once_with(task_id)
|
||||
46
fuelclient/tests/lib/test_task.py
Normal file
46
fuelclient/tests/lib/test_task.py
Normal file
@@ -0,0 +1,46 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# Copyright 2015 Mirantis, Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import requests_mock as rm
|
||||
|
||||
import fuelclient
|
||||
from fuelclient.tests.lib import test_api
|
||||
|
||||
|
||||
class TestTaskFacade(test_api.BaseLibTest):
|
||||
|
||||
def setUp(self):
|
||||
super(TestTaskFacade, self).setUp()
|
||||
|
||||
self.version = 'v1'
|
||||
self.res_uri = '/api/{version}/tasks/'.format(version=self.version)
|
||||
|
||||
self.client = fuelclient.get_client('task', self.version)
|
||||
|
||||
def test_node_list(self):
|
||||
self.client.get_all()
|
||||
|
||||
self.assertEqual(rm.GET, self.session_adapter.last_request.method)
|
||||
self.assertEqual(self.res_uri, self.session_adapter.last_request.path)
|
||||
|
||||
def test_node_show(self):
|
||||
task_id = 42
|
||||
expected_uri = self.get_object_uri(self.res_uri, task_id)
|
||||
|
||||
self.client.get_by_id(task_id)
|
||||
|
||||
self.assertEqual(rm.GET, self.session_adapter.last_request.method)
|
||||
self.assertEqual(expected_uri, self.session_adapter.last_request.path)
|
||||
@@ -14,9 +14,11 @@
|
||||
|
||||
from fuelclient. v1 import environment
|
||||
from fuelclient. v1 import node
|
||||
from fuelclient. v1 import task
|
||||
|
||||
|
||||
__all__ = (
|
||||
'environment',
|
||||
'node',
|
||||
'task'
|
||||
)
|
||||
|
||||
25
fuelclient/v1/task.py
Normal file
25
fuelclient/v1/task.py
Normal file
@@ -0,0 +1,25 @@
|
||||
# Copyright 2015 Mirantis, Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from fuelclient import objects
|
||||
from fuelclient.v1 import base_v1
|
||||
|
||||
|
||||
class TaskClient(base_v1.BaseV1Client):
|
||||
|
||||
_entity_wrapper = objects.Task
|
||||
|
||||
|
||||
def get_client():
|
||||
return TaskClient()
|
||||
@@ -38,6 +38,8 @@ fuelclient =
|
||||
env_add_nodes=fuelclient.commands.environment:EnvAddNodes
|
||||
node_list=fuelclient.commands.node:NodeList
|
||||
node_show=fuelclient.commands.node:NodeShow
|
||||
task_list=fuelclient.commands.task:TaskList
|
||||
task_show=fuelclient.commands.task:TaskShow
|
||||
|
||||
[global]
|
||||
setup-hooks =
|
||||
|
||||
Reference in New Issue
Block a user