diff --git a/mistralclient/api/base.py b/mistralclient/api/base.py index 231a9676..8db4162c 100644 --- a/mistralclient/api/base.py +++ b/mistralclient/api/base.py @@ -13,7 +13,6 @@ # limitations under the License. import json - import logging LOG = logging.getLogger(__name__) @@ -139,9 +138,10 @@ class ResourceManager(object): def get_json(response): - """This method provided backward compatibility with old versions - of requests library. + """Gets JSON representation of response. + This method provided backward compatibility with old versions + of requests library. """ json_field_or_function = getattr(response, 'json', None) diff --git a/mistralclient/api/v1/client.py b/mistralclient/api/v1/client.py index a5e2d0c2..81aafc0c 100644 --- a/mistralclient/api/v1/client.py +++ b/mistralclient/api/v1/client.py @@ -15,10 +15,10 @@ import six from mistralclient.api import httpclient -from mistralclient.api.v1 import workbooks from mistralclient.api.v1 import executions -from mistralclient.api.v1 import tasks from mistralclient.api.v1 import listeners +from mistralclient.api.v1 import tasks +from mistralclient.api.v1 import workbooks class Client(object): @@ -31,11 +31,11 @@ class Client(object): raise RuntimeError('Mistral url should be string') if auth_url: - (mistral_url, auth_token, project_id, user_id) = \ + (mistral_url, auth_token, project_id, user_id) = ( self.authenticate(mistral_url, username, api_key, project_name, auth_url, project_id, endpoint_type, service_type, auth_token, - user_id) + user_id)) if not mistral_url: mistral_url = "http://localhost:8989/v1" diff --git a/mistralclient/api/v1/listeners.py b/mistralclient/api/v1/listeners.py index 51a1c634..4ce6b85e 100644 --- a/mistralclient/api/v1/listeners.py +++ b/mistralclient/api/v1/listeners.py @@ -38,7 +38,7 @@ class ListenerManager(base.ResourceManager): def update(self, workbook_name, id, webhook=None, description=None, events=None): - # TODO: need to describe what events is + # TODO(everyone): need to describe what events is self._ensure_not_empty(workbook_name=workbook_name, id=id) data = { diff --git a/mistralclient/api/v1/tasks.py b/mistralclient/api/v1/tasks.py index a39259f3..690b1d65 100644 --- a/mistralclient/api/v1/tasks.py +++ b/mistralclient/api/v1/tasks.py @@ -31,8 +31,8 @@ class TaskManager(base.ResourceManager): if execution_id: if workbook_name: - uri = '/workbooks/%s/executions/%s/tasks/%s' % \ - (workbook_name, execution_id, id) + uri = ('/workbooks/%s/executions/%s/tasks/%s' % + (workbook_name, execution_id, id)) else: uri = '/executions/%s/tasks/%s' % (execution_id, id) else: @@ -43,8 +43,8 @@ class TaskManager(base.ResourceManager): def list(self, workbook_name, execution_id): if execution_id: if workbook_name: - uri = '/workbooks/%s/executions/%s/tasks' % \ - (workbook_name, execution_id) + uri = ('/workbooks/%s/executions/%s/tasks' % + (workbook_name, execution_id)) else: uri = '/executions/%s/tasks' % execution_id else: @@ -57,8 +57,8 @@ class TaskManager(base.ResourceManager): if execution_id: if workbook_name: - uri = '/workbooks/%s/executions/%s/tasks/%s' % \ - (workbook_name, execution_id, id) + uri = ('/workbooks/%s/executions/%s/tasks/%s' % + (workbook_name, execution_id, id)) else: uri = '/executions/%s/tasks/%s' % (execution_id, id) else: diff --git a/mistralclient/api/v2/actions.py b/mistralclient/api/v2/actions.py index 4beea116..7b4e8202 100644 --- a/mistralclient/api/v2/actions.py +++ b/mistralclient/api/v2/actions.py @@ -13,6 +13,7 @@ # limitations under the License. import json + from mistralclient.api import base diff --git a/mistralclient/api/v2/client.py b/mistralclient/api/v2/client.py index 9fcb8b78..64d98b5d 100644 --- a/mistralclient/api/v2/client.py +++ b/mistralclient/api/v2/client.py @@ -17,9 +17,9 @@ import six from mistralclient.api import httpclient from mistralclient.api.v2 import actions from mistralclient.api.v2 import cron_triggers -from mistralclient.api.v2 import workbooks from mistralclient.api.v2 import executions from mistralclient.api.v2 import tasks +from mistralclient.api.v2 import workbooks from mistralclient.api.v2 import workflows @@ -33,11 +33,11 @@ class Client(object): raise RuntimeError('Mistral url should be string') if auth_url: - (mistral_url, auth_token, project_id, user_id) = \ + (mistral_url, auth_token, project_id, user_id) = ( self.authenticate(mistral_url, username, api_key, project_name, auth_url, project_id, endpoint_type, service_type, auth_token, - user_id) + user_id)) if not mistral_url: mistral_url = "http://localhost:8989/v2" diff --git a/mistralclient/api/v2/cron_triggers.py b/mistralclient/api/v2/cron_triggers.py index 8c63f501..f8e594ea 100644 --- a/mistralclient/api/v2/cron_triggers.py +++ b/mistralclient/api/v2/cron_triggers.py @@ -13,6 +13,7 @@ # limitations under the License. import json + from mistralclient.api import base diff --git a/mistralclient/api/v2/executions.py b/mistralclient/api/v2/executions.py index b1bb1c71..a546d76a 100644 --- a/mistralclient/api/v2/executions.py +++ b/mistralclient/api/v2/executions.py @@ -13,6 +13,7 @@ # limitations under the License. import json + import six from mistralclient.api import base diff --git a/mistralclient/commands/v1/executions.py b/mistralclient/commands/v1/executions.py index f9dbf420..6448a7bc 100644 --- a/mistralclient/commands/v1/executions.py +++ b/mistralclient/commands/v1/executions.py @@ -17,11 +17,11 @@ import json import logging -from cliff.command import Command as BaseCommand -from cliff.lister import Lister as ListCommand -from cliff.show import ShowOne as ShowCommand +from cliff import command +from cliff import lister +from cliff import show -from mistralclient.api.v1.executions import ExecutionManager +from mistralclient.api.v1 import executions as e LOG = logging.getLogger(__name__) @@ -47,7 +47,7 @@ def format(execution=None): return (columns, data) -class List(ListCommand): +class List(lister.Lister): "List all executions" def get_parser(self, prog_name): @@ -60,7 +60,7 @@ class List(ListCommand): def take_action(self, parsed_args): data = [format(execution)[1] for execution - in ExecutionManager(self.app.client) + in e.ExecutionManager(self.app.client) .list(parsed_args.workbook)] if data: @@ -69,7 +69,7 @@ class List(ListCommand): return format() -class Get(ShowCommand): +class Get(show.ShowOne): "Show specific execution" def get_parser(self, prog_name): @@ -84,13 +84,14 @@ class Get(ShowCommand): return parser def take_action(self, parsed_args): - execution = ExecutionManager(self.app.client)\ - .get(parsed_args.workbook, parsed_args.id) + execution = e.ExecutionManager(self.app.client).get( + parsed_args.workbook, + parsed_args.id) return format(execution) -class Create(ShowCommand): +class Create(show.ShowOne): "Create new execution" def get_parser(self, prog_name): @@ -113,15 +114,15 @@ class Create(ShowCommand): except: ctx = open(parsed_args.context).read() - execution = ExecutionManager(self.app.client)\ - .create(parsed_args.workbook, - parsed_args.task, - ctx) + execution = e.ExecutionManager(self.app.client).create( + parsed_args.workbook, + parsed_args.task, + ctx) return format(execution) -class Delete(BaseCommand): +class Delete(command.Command): "Delete execution" def get_parser(self, prog_name): @@ -136,11 +137,11 @@ class Delete(BaseCommand): return parser def take_action(self, parsed_args): - ExecutionManager(self.app.client)\ - .delete(parsed_args.workbook, parsed_args.id) + e.ExecutionManager(self.app.client).delete( + parsed_args.workbook, parsed_args.id) -class Update(ShowCommand): +class Update(show.ShowOne): "Update execution" def get_parser(self, prog_name): @@ -159,9 +160,9 @@ class Update(ShowCommand): return parser def take_action(self, parsed_args): - execution = ExecutionManager(self.app.client)\ - .update(parsed_args.workbook, - parsed_args.id, - parsed_args.state) + execution = e.ExecutionManager(self.app.client).update( + parsed_args.workbook, + parsed_args.id, + parsed_args.state) return format(execution) diff --git a/mistralclient/commands/v1/tasks.py b/mistralclient/commands/v1/tasks.py index 1dd77a83..7e12bb57 100644 --- a/mistralclient/commands/v1/tasks.py +++ b/mistralclient/commands/v1/tasks.py @@ -16,10 +16,10 @@ import logging -from cliff.lister import Lister as ListCommand -from cliff.show import ShowOne as ShowCommand +from cliff import lister +from cliff import show -from mistralclient.api.v1.tasks import TaskManager +from mistralclient.api.v1 import tasks as t LOG = logging.getLogger(__name__) @@ -51,7 +51,7 @@ def format(task=None): return (columns, data) -class List(ListCommand): +class List(lister.Lister): "List all tasks" def get_parser(self, prog_name): @@ -67,7 +67,7 @@ class List(ListCommand): def take_action(self, parsed_args): data = [format(task)[1] for task - in TaskManager(self.app.client) + in t.TaskManager(self.app.client) .list(parsed_args.workbook, parsed_args.execution)] @@ -77,7 +77,7 @@ class List(ListCommand): return format() -class Get(ShowCommand): +class Get(show.ShowOne): "Show specific task" def get_parser(self, prog_name): @@ -94,15 +94,15 @@ class Get(ShowCommand): return parser def take_action(self, parsed_args): - execution = TaskManager(self.app.client)\ - .get(parsed_args.workbook, - parsed_args.execution, - parsed_args.id) + execution = t.TaskManager(self.app.client).get( + parsed_args.workbook, + parsed_args.execution, + parsed_args.id) return format(execution) -class Update(ShowCommand): +class Update(show.ShowOne): "Update task" def get_parser(self, prog_name): @@ -124,9 +124,10 @@ class Update(ShowCommand): return parser def take_action(self, parsed_args): - execution = TaskManager(self.app.client).update(parsed_args.workbook, - parsed_args.execution, - parsed_args.id, - parsed_args.state) + execution = t.TaskManager(self.app.client).update( + parsed_args.workbook, + parsed_args.execution, + parsed_args.id, + parsed_args.state) return format(execution) diff --git a/mistralclient/commands/v1/workbooks.py b/mistralclient/commands/v1/workbooks.py index 5e9fd08a..28dea716 100644 --- a/mistralclient/commands/v1/workbooks.py +++ b/mistralclient/commands/v1/workbooks.py @@ -17,11 +17,11 @@ import argparse import logging -from cliff.command import Command as BaseCommand -from cliff.lister import Lister as ListCommand -from cliff.show import ShowOne as ShowCommand +from cliff import command +from cliff import lister +from cliff import show -from mistralclient.api.v1.workbooks import WorkbookManager +from mistralclient.api.v1 import workbooks as w LOG = logging.getLogger(__name__) @@ -45,12 +45,12 @@ def format(workbook=None): return (columns, data) -class List(ListCommand): +class List(lister.Lister): "List all workbooks" def take_action(self, parsed_args): data = [format(workbook)[1] for workbook - in WorkbookManager(self.app.client).list()] + in w.WorkbookManager(self.app.client).list()] if data: return (format()[0], data) @@ -58,7 +58,7 @@ class List(ListCommand): return format() -class Get(ShowCommand): +class Get(show.ShowOne): "Show specific workbook" def get_parser(self, prog_name): @@ -69,12 +69,12 @@ class Get(ShowCommand): return parser def take_action(self, parsed_args): - workbook = WorkbookManager(self.app.client).get(parsed_args.name) + workbook = w.WorkbookManager(self.app.client).get(parsed_args.name) return format(workbook) -class Create(ShowCommand): +class Create(show.ShowOne): "Create new workbook" def get_parser(self, prog_name): @@ -100,20 +100,20 @@ class Create(ShowCommand): return parser def take_action(self, parsed_args): - workbook = WorkbookManager(self.app.client)\ - .create(parsed_args.name, - parsed_args.description, - str(parsed_args.tags).split(',')) + workbook = w.WorkbookManager(self.app.client).create( + parsed_args.name, + parsed_args.description, + str(parsed_args.tags).split(',')) if parsed_args.definition: - WorkbookManager(self.app.client)\ - .upload_definition(parsed_args.name, - parsed_args.definition.read()) + w.WorkbookManager(self.app.client).upload_definition( + parsed_args.name, + parsed_args.definition.read()) return format(workbook) -class Delete(BaseCommand): +class Delete(command.Command): "Delete workbook" def get_parser(self, prog_name): @@ -125,10 +125,10 @@ class Delete(BaseCommand): return parser def take_action(self, parsed_args): - WorkbookManager(self.app.client).delete(parsed_args.name) + w.WorkbookManager(self.app.client).delete(parsed_args.name) -class Update(ShowCommand): +class Update(show.ShowOne): "Update workbook" def get_parser(self, prog_name): @@ -148,15 +148,15 @@ class Update(ShowCommand): return parser def take_action(self, parsed_args): - workbook = WorkbookManager(self.app.client)\ - .update(parsed_args.name, - parsed_args.description, - parsed_args.tags) + workbook = w.WorkbookManager(self.app.client).update( + parsed_args.name, + parsed_args.description, + parsed_args.tags) return format(workbook) -class UploadDefinition(BaseCommand): +class UploadDefinition(command.Command): "Upload workbook definition" def get_parser(self, prog_name): @@ -172,12 +172,12 @@ class UploadDefinition(BaseCommand): return parser def take_action(self, parsed_args): - WorkbookManager(self.app.client)\ - .upload_definition(parsed_args.name, - parsed_args.path.read()) + w.WorkbookManager(self.app.client).upload_definition( + parsed_args.name, + parsed_args.path.read()) -class GetDefinition(BaseCommand): +class GetDefinition(command.Command): "Show workbook definition" def get_parser(self, prog_name): @@ -189,7 +189,7 @@ class GetDefinition(BaseCommand): return parser def take_action(self, parsed_args): - definition = WorkbookManager(self.app.client)\ - .get_definition(parsed_args.name) + definition = w.WorkbookManager( + self.app.client).get_definition(parsed_args.name) self.app.stdout.write(definition) diff --git a/mistralclient/commands/v2/actions.py b/mistralclient/commands/v2/actions.py index 44d62b9c..01ea0af2 100644 --- a/mistralclient/commands/v2/actions.py +++ b/mistralclient/commands/v2/actions.py @@ -115,8 +115,8 @@ class Create(base.MistralLister): return format def _get_resources(self, parsed_args): - return actions.ActionManager(self.app.client)\ - .create(parsed_args.definition.read()) + return actions.ActionManager(self.app.client).create( + parsed_args.definition.read()) class Delete(command.Command): @@ -151,8 +151,8 @@ class Update(base.MistralLister): return format def _get_resources(self, parsed_args): - return actions.ActionManager(self.app.client).\ - update(parsed_args.definition.read()) + return actions.ActionManager(self.app.client).update( + parsed_args.definition.read()) class GetDefinition(command.Command): @@ -166,7 +166,7 @@ class GetDefinition(command.Command): return parser def take_action(self, parsed_args): - definition = actions.ActionManager(self.app.client)\ - .get(parsed_args.name).definition + definition = actions.ActionManager(self.app.client).get( + parsed_args.name).definition self.app.stdout.write(definition or "\n") diff --git a/mistralclient/commands/v2/base.py b/mistralclient/commands/v2/base.py index d38cde8d..9f605d75 100644 --- a/mistralclient/commands/v2/base.py +++ b/mistralclient/commands/v2/base.py @@ -15,9 +15,9 @@ # import abc -import six from cliff import lister +import six @six.add_metaclass(abc.ABCMeta) diff --git a/mistralclient/commands/v2/cron_triggers.py b/mistralclient/commands/v2/cron_triggers.py index 85fa2553..917814f3 100644 --- a/mistralclient/commands/v2/cron_triggers.py +++ b/mistralclient/commands/v2/cron_triggers.py @@ -35,23 +35,24 @@ def format(trigger=None, lister=False): 'Name', 'Pattern', 'Workflow', - # TODO (rakhmerov): Uncomment when passwords are handled properly. - # 'Workflow input', + # TODO(rakhmerov): Uncomment when passwords are handled properly. + # TODO(rakhmerov): Add 'Workflow input' column. 'Next execution time', 'Created at', 'Updated at' ) if trigger: - # wf_input = trigger.workflow_input if not lister \ - # else base.cut(trigger.workflow_input) + # TODO(rakhmerov): Add following here: + # TODO(rakhmerov): wf_input = trigger.workflow_input if not lister + # TODO(rakhmerov:): else base.cut(trigger.workflow_input) data = ( trigger.name, trigger.pattern, trigger.workflow_name, - # TODO (rakhmerov): Uncomment when passwords are handled properly. - # wf_input, + # TODO(rakhmerov): Uncomment when passwords are handled properly. + # TODo(rakhmerov): Add 'wf_input' here. trigger.next_execution_time, trigger.created_at, ) diff --git a/mistralclient/commands/v2/executions.py b/mistralclient/commands/v2/executions.py index 22b8f3d4..11431c58 100644 --- a/mistralclient/commands/v2/executions.py +++ b/mistralclient/commands/v2/executions.py @@ -71,8 +71,8 @@ class Get(show.ShowOne): return parser def take_action(self, parsed_args): - execution = executions.ExecutionManager(self.app.client)\ - .get(parsed_args.id) + execution = executions.ExecutionManager(self.app.client).get( + parsed_args.id) return format(execution) @@ -117,10 +117,10 @@ class Create(show.ShowOne): else: params = {} - execution = executions.ExecutionManager(self.app.client)\ - .create(parsed_args.workflow_name, - wf_input, - **params) + execution = executions.ExecutionManager(self.app.client).create( + parsed_args.workflow_name, + wf_input, + **params) return format(execution) @@ -158,9 +158,9 @@ class Update(show.ShowOne): return parser def take_action(self, parsed_args): - execution = executions.ExecutionManager(self.app.client)\ - .update(parsed_args.id, - parsed_args.state) + execution = executions.ExecutionManager(self.app.client).update( + parsed_args.id, + parsed_args.state) return format(execution) @@ -176,8 +176,8 @@ class GetInput(command.Command): return parser def take_action(self, parsed_args): - ex_input = executions.ExecutionManager(self.app.client)\ - .get(parsed_args.id).input + ex_input = executions.ExecutionManager(self.app.client).get( + parsed_args.id).input try: ex_input = json.loads(ex_input) @@ -199,8 +199,8 @@ class GetOutput(command.Command): return parser def take_action(self, parsed_args): - output = executions.ExecutionManager(self.app.client)\ - .get(parsed_args.id).output + output = executions.ExecutionManager(self.app.client).get( + parsed_args.id).output try: output = json.loads(output) diff --git a/mistralclient/commands/v2/tasks.py b/mistralclient/commands/v2/tasks.py index 3ca0be46..29b755bf 100644 --- a/mistralclient/commands/v2/tasks.py +++ b/mistralclient/commands/v2/tasks.py @@ -71,8 +71,8 @@ class Get(show.ShowOne): return parser def take_action(self, parsed_args): - execution = tasks.TaskManager(self.app.client)\ - .get(parsed_args.id) + execution = tasks.TaskManager(self.app.client).get( + parsed_args.id) return format(execution) @@ -113,8 +113,8 @@ class GetOutput(command.Command): return parser def take_action(self, parsed_args): - output = tasks.TaskManager(self.app.client)\ - .get(parsed_args.id).output + output = tasks.TaskManager(self.app.client).get( + parsed_args.id).output try: output = json.loads(output) @@ -137,8 +137,8 @@ class GetResult(command.Command): return parser def take_action(self, parsed_args): - result = tasks.TaskManager(self.app.client)\ - .get(parsed_args.id).result + result = tasks.TaskManager(self.app.client).get( + parsed_args.id).result try: result = json.loads(result) @@ -162,8 +162,8 @@ class GetInput(command.Command): return parser def take_action(self, parsed_args): - result = tasks.TaskManager(self.app.client)\ - .get(parsed_args.id).input + result = tasks.TaskManager(self.app.client).get( + parsed_args.id).input try: result = json.loads(result) diff --git a/mistralclient/commands/v2/workbooks.py b/mistralclient/commands/v2/workbooks.py index 8e102b5c..5fce58e2 100644 --- a/mistralclient/commands/v2/workbooks.py +++ b/mistralclient/commands/v2/workbooks.py @@ -97,8 +97,8 @@ class Create(show.ShowOne): return parser def take_action(self, parsed_args): - workbook = workbooks.WorkbookManager(self.app.client)\ - .create(parsed_args.definition.read()) + workbook = workbooks.WorkbookManager(self.app.client).create( + parsed_args.definition.read()) return format(workbook) @@ -132,8 +132,8 @@ class Update(show.ShowOne): return parser def take_action(self, parsed_args): - workbook = workbooks.WorkbookManager(self.app.client)\ - .update(parsed_args.definition.read()) + workbook = workbooks.WorkbookManager(self.app.client).update( + parsed_args.definition.read()) return format(workbook) @@ -149,7 +149,7 @@ class GetDefinition(command.Command): return parser def take_action(self, parsed_args): - definition = workbooks.WorkbookManager(self.app.client)\ - .get(parsed_args.name).definition + definition = workbooks.WorkbookManager(self.app.client).get( + parsed_args.name).definition self.app.stdout.write(definition or "\n") diff --git a/mistralclient/commands/v2/workflows.py b/mistralclient/commands/v2/workflows.py index 4044ca27..2c2ea3fe 100644 --- a/mistralclient/commands/v2/workflows.py +++ b/mistralclient/commands/v2/workflows.py @@ -108,8 +108,8 @@ class Create(base.MistralLister): "definition file.") def _get_resources(self, parsed_args): - return workflows.WorkflowManager(self.app.client).\ - create(parsed_args.definition.read()) + return workflows.WorkflowManager(self.app.client).create( + parsed_args.definition.read()) class Delete(command.Command): @@ -160,7 +160,7 @@ class GetDefinition(command.Command): return parser def take_action(self, parsed_args): - definition = workflows.WorkflowManager(self.app.client)\ - .get(parsed_args.name).definition + definition = workflows.WorkflowManager(self.app.client).get( + parsed_args.name).definition self.app.stdout.write(definition or "\n") diff --git a/mistralclient/shell.py b/mistralclient/shell.py index 0533a1f9..2d574afb 100644 --- a/mistralclient/shell.py +++ b/mistralclient/shell.py @@ -21,23 +21,21 @@ Command-line interface to the Mistral APIs import logging import sys -from mistralclient.openstack.common.cliutils import env - from mistralclient.api import client - -import mistralclient.commands.v1.workbooks import mistralclient.commands.v1.executions import mistralclient.commands.v1.tasks +import mistralclient.commands.v1.workbooks import mistralclient.commands.v2.actions import mistralclient.commands.v2.cron_triggers import mistralclient.commands.v2.executions import mistralclient.commands.v2.tasks import mistralclient.commands.v2.workbooks import mistralclient.commands.v2.workflows +from mistralclient.openstack.common import cliutils as c from cliff import app -from cliff import help from cliff import commandmanager +from cliff import help import argparse @@ -126,49 +124,50 @@ class MistralShell(app.App): '--os-mistral-url', action='store', dest='mistral_url', - default=env('OS_MISTRAL_URL', default='http://localhost:8989/v2'), + default=c.env('OS_MISTRAL_URL', + default='http://localhost:8989/v2'), help='Mistral API host (Env: OS_MISTRAL_URL)' ) parser.add_argument( '--os-username', action='store', dest='username', - default=env('OS_USERNAME', default='admin'), + default=c.env('OS_USERNAME', default='admin'), help='Authentication username (Env: OS_USERNAME)' ) parser.add_argument( '--os-password', action='store', dest='password', - default=env('OS_PASSWORD', default='openstack'), + default=c.env('OS_PASSWORD', default='openstack'), help='Authentication password (Env: OS_PASSWORD)' ) parser.add_argument( '--os-tenant-id', action='store', dest='tenant_id', - default=env('OS_TENANT_ID'), + default=c.env('OS_TENANT_ID'), help='Authentication tenant identifier (Env: OS_TENANT_ID)' ) parser.add_argument( '--os-tenant-name', action='store', dest='tenant_name', - default=env('OS_TENANT_NAME', 'Default'), + default=c.env('OS_TENANT_NAME', 'Default'), help='Authentication tenant name (Env: OS_TENANT_NAME)' ) parser.add_argument( '--os-auth-token', action='store', dest='token', - default=env('OS_AUTH_TOKEN'), + default=c.env('OS_AUTH_TOKEN'), help='Authentication token (Env: OS_AUTH_TOKEN)' ) parser.add_argument( '--os-auth-url', action='store', dest='auth_url', - default=env('OS_AUTH_URL'), + default=c.env('OS_AUTH_URL'), help='Authentication URL (Env: OS_AUTH_URL)' ) return parser diff --git a/mistralclient/tests/functional/cli/base.py b/mistralclient/tests/functional/cli/base.py index 3b3749ed..45d7528f 100644 --- a/mistralclient/tests/functional/cli/base.py +++ b/mistralclient/tests/functional/cli/base.py @@ -14,10 +14,9 @@ import os -from tempest_lib.cli import base - from tempest import config from tempest import test +from tempest_lib.cli import base CONF = config.CONF diff --git a/mistralclient/tests/functional/client/v1/base.py b/mistralclient/tests/functional/client/v1/base.py index 01747d30..ebf2db1a 100644 --- a/mistralclient/tests/functional/client/v1/base.py +++ b/mistralclient/tests/functional/client/v1/base.py @@ -1,8 +1,22 @@ +# Copyright (c) 2014 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 os -import testtools from tempest import clients from tempest.common import rest_client +import testtools from mistralclient.api import base from mistralclient.api.v1 import client as mclient @@ -71,8 +85,8 @@ class MistralBase(testtools.TestCase): def assert_item_in_list(self, items, **props): def _matches(item, **props): for prop_name, prop_val in props.iteritems(): - v = item[prop_name] if isinstance(item, dict) \ - else getattr(item, prop_name) + v = item[prop_name] if isinstance(item, dict) else getattr( + item, prop_name) if v != prop_val: return False diff --git a/mistralclient/tests/functional/client/v1/tests.py b/mistralclient/tests/functional/client/v1/tests.py index 882d3dba..958907c1 100644 --- a/mistralclient/tests/functional/client/v1/tests.py +++ b/mistralclient/tests/functional/client/v1/tests.py @@ -1,3 +1,17 @@ +# Copyright (c) 2014 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 base import MistralBase @@ -35,8 +49,8 @@ class Workbooks(MistralURLDefine): def test_upload_get_definition(self): self.mistral_client.workbooks.upload_definition("wb", self.definition) - received_definition = \ - self.mistral_client.workbooks.get_definition("wb") + received_definition = (self.mistral_client. + workbooks.get_definition("wb")) self.assertEqual(self.definition, received_definition) diff --git a/mistralclient/tests/unit/base.py b/mistralclient/tests/unit/base.py index 742f13a8..0ac01ff1 100644 --- a/mistralclient/tests/unit/base.py +++ b/mistralclient/tests/unit/base.py @@ -12,10 +12,11 @@ # See the License for the specific language governing permissions and # limitations under the License. -import unittest2 -import mock import json +import mock +import unittest2 + class FakeResponse(object): """Fake response for testing Mistral Client.""" @@ -35,8 +36,8 @@ class BaseClientTest(unittest2.TestCase): if isinstance(content, dict): content = json.dumps(content) - self._client.http_client.get = \ - mock.MagicMock(return_value=FakeResponse(status_code, content)) + self._client.http_client.get = mock.MagicMock( + return_value=FakeResponse(status_code, content)) return self._client.http_client.get @@ -44,8 +45,8 @@ class BaseClientTest(unittest2.TestCase): if isinstance(content, dict): content = json.dumps(content) - self._client.http_client.post = \ - mock.MagicMock(return_value=FakeResponse(status_code, content)) + self._client.http_client.post = mock.MagicMock( + return_value=FakeResponse(status_code, content)) return self._client.http_client.post @@ -53,14 +54,14 @@ class BaseClientTest(unittest2.TestCase): if isinstance(content, dict): content = json.dumps(content) - self._client.http_client.put = \ - mock.MagicMock(return_value=FakeResponse(status_code, content)) + self._client.http_client.put = mock.MagicMock( + return_value=FakeResponse(status_code, content)) return self._client.http_client.put def mock_http_delete(self, status_code=204): - self._client.http_client.delete = \ - mock.MagicMock(return_value=FakeResponse(status_code)) + self._client.http_client.delete = mock.MagicMock( + return_value=FakeResponse(status_code)) return self._client.http_client.delete diff --git a/mistralclient/tests/unit/v1/test_cli_executions.py b/mistralclient/tests/unit/v1/test_cli_executions.py index d8a0ff1e..4db7d31a 100644 --- a/mistralclient/tests/unit/v1/test_cli_executions.py +++ b/mistralclient/tests/unit/v1/test_cli_executions.py @@ -14,15 +14,14 @@ # under the License. # +import mock import pkg_resources as pkg -import mock - -from mistralclient.tests.unit import base +from mistralclient.api.v1 import executions as e from mistralclient.commands.v1 import executions -from mistralclient.api.v1.executions import Execution +from mistralclient.tests.unit import base -EXECUTION = Execution(mock, { +EXECUTION = e.Execution(mock, { 'id': '123', 'workbook_name': 'some', 'task': 'else', diff --git a/mistralclient/tests/unit/v1/test_cli_tasks.py b/mistralclient/tests/unit/v1/test_cli_tasks.py index ab92ae8e..e29cb168 100644 --- a/mistralclient/tests/unit/v1/test_cli_tasks.py +++ b/mistralclient/tests/unit/v1/test_cli_tasks.py @@ -16,12 +16,11 @@ import mock +from mistralclient.api.v1 import tasks as t +from mistralclient.commands.v1 import tasks from mistralclient.tests.unit import base -from mistralclient.commands.v1 import tasks -from mistralclient.api.v1.tasks import Task - -TASK = Task(mock, { +TASK = t.Task(mock, { 'id': '123', 'workbook_name': 'some', 'execution_id': 'thing', diff --git a/mistralclient/tests/unit/v1/test_cli_workbooks.py b/mistralclient/tests/unit/v1/test_cli_workbooks.py index e130d62a..64d7b3f4 100644 --- a/mistralclient/tests/unit/v1/test_cli_workbooks.py +++ b/mistralclient/tests/unit/v1/test_cli_workbooks.py @@ -16,12 +16,11 @@ import mock +from mistralclient.api.v1 import workbooks as w +from mistralclient.commands.v1 import workbooks from mistralclient.tests.unit import base -from mistralclient.commands.v1 import workbooks -from mistralclient.api.v1.workbooks import Workbook - -WORKBOOK = Workbook(mock, { +WORKBOOK = w.Workbook(mock, { 'name': 'a', 'description': 'some', 'tags': ['a', 'b'] diff --git a/mistralclient/tests/unit/v1/test_executions.py b/mistralclient/tests/unit/v1/test_executions.py index 68dafcd5..ab96ca28 100644 --- a/mistralclient/tests/unit/v1/test_executions.py +++ b/mistralclient/tests/unit/v1/test_executions.py @@ -12,13 +12,14 @@ # See the License for the specific language governing permissions and # limitations under the License. -import unittest2 import json -from mistralclient.tests.unit.v1 import base -from mistralclient.api.v1.executions import Execution +import unittest2 -# TODO: Later we need additional tests verifying all the errors etc. +from mistralclient.api.v1 import executions as e +from mistralclient.tests.unit.v1 import base + +# TODO(everyone): Later we need additional tests verifying all the errors etc. EXECS = [ { @@ -55,7 +56,7 @@ class TestExecutions(base.BaseClientV1Test): EXECS[0]['context']) self.assertIsNotNone(ex) - self.assertDictEqual(Execution(self.executions, EXECS[0]).__dict__, + self.assertDictEqual(e.Execution(self.executions, EXECS[0]).__dict__, ex.__dict__) arg_body = mock.call_args[0][1] @@ -105,7 +106,7 @@ class TestExecutions(base.BaseClientV1Test): EXECS[0]['state']) self.assertIsNotNone(ex) - self.assertEqual(Execution(self.executions, EXECS[0]).__dict__, + self.assertEqual(e.Execution(self.executions, EXECS[0]).__dict__, ex.__dict__) mock.assert_called_once_with( URL_TEMPLATE_ID % (EXECS[0]['workbook_name'], EXECS[0]['id']), @@ -119,7 +120,7 @@ class TestExecutions(base.BaseClientV1Test): self.assertEqual(1, len(executions)) ex = executions[0] - self.assertEqual(Execution(self.executions, EXECS[0]).__dict__, + self.assertEqual(e.Execution(self.executions, EXECS[0]).__dict__, ex.__dict__) mock.assert_called_once_with(URL_TEMPLATE % EXECS[0]['workbook_name']) @@ -128,7 +129,7 @@ class TestExecutions(base.BaseClientV1Test): ex = self.executions.get(EXECS[0]['workbook_name'], EXECS[0]['id']) - self.assertEqual(Execution(self.executions, EXECS[0]).__dict__, + self.assertEqual(e.Execution(self.executions, EXECS[0]).__dict__, ex.__dict__) mock.assert_called_once_with( URL_TEMPLATE_ID % (EXECS[0]['workbook_name'], EXECS[0]['id'])) diff --git a/mistralclient/tests/unit/v1/test_listeners.py b/mistralclient/tests/unit/v1/test_listeners.py index d740fe41..ef54e727 100644 --- a/mistralclient/tests/unit/v1/test_listeners.py +++ b/mistralclient/tests/unit/v1/test_listeners.py @@ -14,10 +14,10 @@ import json +from mistralclient.api.v1 import listeners as l from mistralclient.tests.unit.v1 import base -from mistralclient.api.v1.listeners import Listener -# TODO: later we need additional tests verifying all the errors etc. +# TODO(everyone): later we need additional tests verifying all the errors etc. LISTENERS = [ { @@ -47,7 +47,7 @@ class TestListeners(base.BaseClientV1Test): LISTENERS[0]['description']) self.assertIsNotNone(lsnr) - self.assertEqual(Listener(self.listeners, LISTENERS[0]).__dict__, + self.assertEqual(l.Listener(self.listeners, LISTENERS[0]).__dict__, lsnr.__dict__) mock.assert_called_once_with( URL_TEMPLATE % (LISTENERS[0]['workbook_name']), @@ -69,7 +69,7 @@ class TestListeners(base.BaseClientV1Test): LISTENERS[0]['description']) self.assertIsNotNone(lsnr) - self.assertEqual(Listener(self.listeners, LISTENERS[0]).__dict__, + self.assertEqual(l.Listener(self.listeners, LISTENERS[0]).__dict__, lsnr.__dict__) mock.assert_called_once_with( URL_TEMPLATE_ID % (LISTENERS[0]['workbook_name'], @@ -84,7 +84,7 @@ class TestListeners(base.BaseClientV1Test): self.assertEqual(1, len(listeners)) lsnr = listeners[0] - self.assertEqual(Listener(self.listeners, LISTENERS[0]).__dict__, + self.assertEqual(l.Listener(self.listeners, LISTENERS[0]).__dict__, lsnr.__dict__) mock.assert_called_once_with( URL_TEMPLATE % (LISTENERS[0]['workbook_name'])) @@ -95,7 +95,7 @@ class TestListeners(base.BaseClientV1Test): lsnr = self.listeners.get(LISTENERS[0]['workbook_name'], LISTENERS[0]['id']) - self.assertEqual(Listener(self.listeners, LISTENERS[0]).__dict__, + self.assertEqual(l.Listener(self.listeners, LISTENERS[0]).__dict__, lsnr.__dict__) mock.assert_called_once_with( URL_TEMPLATE_ID % (LISTENERS[0]['workbook_name'], diff --git a/mistralclient/tests/unit/v1/test_tasks.py b/mistralclient/tests/unit/v1/test_tasks.py index b728a17b..e784f1c6 100644 --- a/mistralclient/tests/unit/v1/test_tasks.py +++ b/mistralclient/tests/unit/v1/test_tasks.py @@ -14,10 +14,10 @@ import json +from mistralclient.api.v1 import tasks as t from mistralclient.tests.unit.v1 import base -from mistralclient.api.v1.tasks import Task -# TODO: later we need additional tests verifying all the errors etc. +# TODO(everyone): later we need additional tests verifying all the errors etc. TASKS = [ { @@ -49,7 +49,7 @@ class TestTasks(base.BaseClientV1Test): TASKS[0]['state']) self.assertIsNotNone(task) - self.assertEqual(Task(self.tasks, TASKS[0]).__dict__, task.__dict__) + self.assertEqual(t.Task(self.tasks, TASKS[0]).__dict__, task.__dict__) mock.assert_called_once_with( URL_TEMPLATE_ID % (TASKS[0]['workbook_name'], TASKS[0]['execution_id'], @@ -65,7 +65,7 @@ class TestTasks(base.BaseClientV1Test): self.assertEqual(1, len(tasks)) task = tasks[0] - self.assertEqual(Task(self.tasks, TASKS[0]).__dict__, task.__dict__) + self.assertEqual(t.Task(self.tasks, TASKS[0]).__dict__, task.__dict__) mock.assert_called_once_with( URL_TEMPLATE % (TASKS[0]['workbook_name'], TASKS[0]['execution_id'])) @@ -77,7 +77,7 @@ class TestTasks(base.BaseClientV1Test): TASKS[0]['execution_id'], TASKS[0]['id']) - self.assertEqual(Task(self.tasks, TASKS[0]).__dict__, task.__dict__) + self.assertEqual(t.Task(self.tasks, TASKS[0]).__dict__, task.__dict__) mock.assert_called_once_with( URL_TEMPLATE_ID % (TASKS[0]['workbook_name'], TASKS[0]['execution_id'], diff --git a/mistralclient/tests/unit/v1/test_workbooks.py b/mistralclient/tests/unit/v1/test_workbooks.py index c96243af..85c12fbf 100644 --- a/mistralclient/tests/unit/v1/test_workbooks.py +++ b/mistralclient/tests/unit/v1/test_workbooks.py @@ -14,10 +14,10 @@ import json +from mistralclient.api.v1 import workbooks as w from mistralclient.tests.unit.v1 import base -from mistralclient.api.v1.workbooks import Workbook -# TODO: later we need additional tests verifying all the errors etc. +# TODO(everyone): later we need additional tests verifying all the errors etc. WORKBOOKS = [ { @@ -66,7 +66,7 @@ class TestWorkbooks(base.BaseClientV1Test): WORKBOOKS[0]['tags']) self.assertIsNotNone(wb) - self.assertEqual(Workbook(self.workbooks, WORKBOOKS[0]).__dict__, + self.assertEqual(w.Workbook(self.workbooks, WORKBOOKS[0]).__dict__, wb.__dict__) mock.assert_called_once_with(URL_TEMPLATE, json.dumps(WORKBOOKS[0])) @@ -78,7 +78,7 @@ class TestWorkbooks(base.BaseClientV1Test): WORKBOOKS[0]['tags']) self.assertIsNotNone(wb) - self.assertEqual(Workbook(self.workbooks, WORKBOOKS[0]).__dict__, + self.assertEqual(w.Workbook(self.workbooks, WORKBOOKS[0]).__dict__, wb.__dict__) mock.assert_called_once_with( URL_TEMPLATE_NAME % WORKBOOKS[0]['name'], @@ -92,7 +92,7 @@ class TestWorkbooks(base.BaseClientV1Test): self.assertEqual(1, len(workbooks)) wb = workbooks[0] - self.assertEqual(Workbook(self.workbooks, WORKBOOKS[0]).__dict__, + self.assertEqual(w.Workbook(self.workbooks, WORKBOOKS[0]).__dict__, wb.__dict__) mock.assert_called_once_with(URL_TEMPLATE) @@ -102,7 +102,7 @@ class TestWorkbooks(base.BaseClientV1Test): wb = self.workbooks.get(WORKBOOKS[0]['name']) self.assertIsNotNone(wb) - self.assertEqual(Workbook(self.workbooks, WORKBOOKS[0]).__dict__, + self.assertEqual(w.Workbook(self.workbooks, WORKBOOKS[0]).__dict__, wb.__dict__) mock.assert_called_once_with(URL_TEMPLATE_NAME % WORKBOOKS[0]['name']) diff --git a/mistralclient/tests/unit/v2/test_cli_actions.py b/mistralclient/tests/unit/v2/test_cli_actions.py index 64d7cd92..dfae6dff 100644 --- a/mistralclient/tests/unit/v2/test_cli_actions.py +++ b/mistralclient/tests/unit/v2/test_cli_actions.py @@ -16,10 +16,9 @@ import mock -from mistralclient.tests.unit import base - -from mistralclient.commands.v2 import actions as action_cmd from mistralclient.api.v2 import actions +from mistralclient.commands.v2 import actions as action_cmd +from mistralclient.tests.unit import base ACTION_DICT = { diff --git a/mistralclient/tests/unit/v2/test_cli_cron_triggers.py b/mistralclient/tests/unit/v2/test_cli_cron_triggers.py index b1a86bad..5ab036e4 100644 --- a/mistralclient/tests/unit/v2/test_cli_cron_triggers.py +++ b/mistralclient/tests/unit/v2/test_cli_cron_triggers.py @@ -16,10 +16,9 @@ import mock -from mistralclient.tests.unit import base - -from mistralclient.commands.v2 import cron_triggers as cron_triggers_cmd from mistralclient.api.v2 import cron_triggers +from mistralclient.commands.v2 import cron_triggers as cron_triggers_cmd +from mistralclient.tests.unit import base TRIGGER_DICT = { diff --git a/mistralclient/tests/unit/v2/test_cli_executions.py b/mistralclient/tests/unit/v2/test_cli_executions.py index 5ae6e1ac..c3f4580c 100644 --- a/mistralclient/tests/unit/v2/test_cli_executions.py +++ b/mistralclient/tests/unit/v2/test_cli_executions.py @@ -14,13 +14,12 @@ # under the License. # +import mock import pkg_resources as pkg -import mock - -from mistralclient.tests.unit import base -from mistralclient.commands.v2 import executions as execution_cmd from mistralclient.api.v2 import executions +from mistralclient.commands.v2 import executions as execution_cmd +from mistralclient.tests.unit import base EXECUTION = executions.Execution(mock, { 'id': '123', diff --git a/mistralclient/tests/unit/v2/test_cli_tasks.py b/mistralclient/tests/unit/v2/test_cli_tasks.py index 141e7a09..5020ef6e 100644 --- a/mistralclient/tests/unit/v2/test_cli_tasks.py +++ b/mistralclient/tests/unit/v2/test_cli_tasks.py @@ -15,12 +15,12 @@ # import json + import mock -from mistralclient.tests.unit import base - -from mistralclient.commands.v2 import tasks as task_cmd from mistralclient.api.v2 import tasks +from mistralclient.commands.v2 import tasks as task_cmd +from mistralclient.tests.unit import base TASK_DICT = { 'id': '123', diff --git a/mistralclient/tests/unit/v2/test_cli_workbooks.py b/mistralclient/tests/unit/v2/test_cli_workbooks.py index 27289774..46d28fdc 100644 --- a/mistralclient/tests/unit/v2/test_cli_workbooks.py +++ b/mistralclient/tests/unit/v2/test_cli_workbooks.py @@ -16,10 +16,9 @@ import mock -from mistralclient.tests.unit import base - -from mistralclient.commands.v2 import workbooks as workbook_cmd from mistralclient.api.v2 import workbooks +from mistralclient.commands.v2 import workbooks as workbook_cmd +from mistralclient.tests.unit import base WORKBOOK_DICT = { diff --git a/mistralclient/tests/unit/v2/test_cli_workflows.py b/mistralclient/tests/unit/v2/test_cli_workflows.py index c931242c..ed141228 100644 --- a/mistralclient/tests/unit/v2/test_cli_workflows.py +++ b/mistralclient/tests/unit/v2/test_cli_workflows.py @@ -16,10 +16,9 @@ import mock -from mistralclient.tests.unit import base - -from mistralclient.commands.v2 import workflows as workflow_cmd from mistralclient.api.v2 import workflows +from mistralclient.commands.v2 import workflows as workflow_cmd +from mistralclient.tests.unit import base WORKFLOW_DICT = { diff --git a/mistralclient/tests/unit/v2/test_executions.py b/mistralclient/tests/unit/v2/test_executions.py index cac41684..3910624e 100644 --- a/mistralclient/tests/unit/v2/test_executions.py +++ b/mistralclient/tests/unit/v2/test_executions.py @@ -12,13 +12,14 @@ # See the License for the specific language governing permissions and # limitations under the License. -import unittest2 import json -from mistralclient.tests.unit.v2 import base -from mistralclient.api.v2 import executions +import unittest2 -# TODO: Later we need additional tests verifying all the errors etc. +from mistralclient.api.v2 import executions +from mistralclient.tests.unit.v2 import base + +# TODO(everyone): Later we need additional tests verifying all the errors etc. EXEC = { 'id': "123", diff --git a/mistralclient/tests/unit/v2/test_tasks.py b/mistralclient/tests/unit/v2/test_tasks.py index 9c714900..cfa61082 100644 --- a/mistralclient/tests/unit/v2/test_tasks.py +++ b/mistralclient/tests/unit/v2/test_tasks.py @@ -14,10 +14,10 @@ import json -from mistralclient.tests.unit.v2 import base from mistralclient.api.v2 import tasks +from mistralclient.tests.unit.v2 import base -# TODO: later we need additional tests verifying all the errors etc. +# TODO(everyone): later we need additional tests verifying all the errors etc. TASK = { 'id': "1", diff --git a/mistralclient/tests/unit/v2/test_workbooks.py b/mistralclient/tests/unit/v2/test_workbooks.py index 3646e953..86f49d85 100644 --- a/mistralclient/tests/unit/v2/test_workbooks.py +++ b/mistralclient/tests/unit/v2/test_workbooks.py @@ -14,10 +14,10 @@ import json -from mistralclient.tests.unit.v2 import base from mistralclient.api.v2 import workbooks +from mistralclient.tests.unit.v2 import base -# TODO: later we need additional tests verifying all the errors etc. +# TODO(everyone): later we need additional tests verifying all the errors etc. WB_DEF = """ diff --git a/tox.ini b/tox.ini index cadd09b9..452f9902 100644 --- a/tox.ini +++ b/tox.ini @@ -38,7 +38,8 @@ setenv = VIRTUAL_ENV={envdir} commands = bash tools/lintstack.sh [flake8] +#H201 no 'except:' at least use 'except Exception:' show-source = true -ignore = H803,H305,H405,H904,H101,H102,H201,H302,H306,H307 +ignore = H201 builtins = _ exclude=.venv,.git,.tox,dist,doc,*openstack/common*,*lib/python*,*egg,tools