From c4f606ba1dcc1b8be55d9ebe88a201090f8cafa9 Mon Sep 17 00:00:00 2001 From: GowthamShanmugam Date: Wed, 17 Apr 2019 19:16:02 +0530 Subject: [PATCH] Fix pep8 bugzilla: 1602858 tendrl-bug-id: #1080 Signed-off-by: GowthamShanmugam --- .../flows/unmanage_cluster/__init__.py | 8 +++---- tendrl/commons/message.py | 24 +++++++++---------- .../tests/manager/test_manager_init.py | 2 +- .../tests/objects/test_objects_init.py | 2 +- .../tests/utils/test_ansible_module_runner.py | 8 +++---- tendrl/commons/utils/log_utils.py | 8 +++---- tox.ini | 2 +- 7 files changed, 27 insertions(+), 27 deletions(-) diff --git a/tendrl/commons/flows/unmanage_cluster/__init__.py b/tendrl/commons/flows/unmanage_cluster/__init__.py index aab2d60c..633e388a 100644 --- a/tendrl/commons/flows/unmanage_cluster/__init__.py +++ b/tendrl/commons/flows/unmanage_cluster/__init__.py @@ -17,10 +17,10 @@ def run(self): ).load() if _cluster.is_managed == "no": if _cluster.current_job['job_name'] == self.__class__.__name__ \ - and _cluster.current_job['status'] == 'finished': - raise FlowExecutionFailedError( - "Cluster is already in un-managed state" - ) + and _cluster.current_job['status'] == 'finished': + raise FlowExecutionFailedError( + "Cluster is already in un-managed state" + ) if _cluster.current_job['status'] == 'in_progress' and \ ( 'job_id' in _cluster.locked_by and diff --git a/tendrl/commons/message.py b/tendrl/commons/message.py index 5f5fd776..f1cce417 100644 --- a/tendrl/commons/message.py +++ b/tendrl/commons/message.py @@ -3,7 +3,11 @@ from inspect import getframeinfo from inspect import stack import json +from ruamel import yaml import sys +from tendrl.commons.utils.time_utils import now # flake8:noqa +import traceback + is_collectd_imported = False if '/usr/lib64/collectd' in sys.path: is_collectd_imported = True @@ -16,11 +20,6 @@ # An appropriate solution needs to be carved out -from tendrl.commons.utils.time_utils import now # flake8:noqa - -import traceback -from ruamel import yaml - class Message(object): """At the time of message object intialization @@ -96,13 +95,13 @@ def validate(self): # Check payload type is dict if type(self.payload) != dict: return False - + # Check mandatory fields if (self.priority not in priorities or self.node_id is None or "message" not in self.payload): return False - + if self.job_id is not None: if self.flow_id is None: return False @@ -119,7 +118,7 @@ def __init__(self, priority, publisher, payload): # skip last function call # This will give traceback upto before try function call formatted_stack = traceback.extract_stack()[:-2] - _, _ , exc_traceback = sys.exc_info() + _, _, exc_traceback = sys.exc_info() # This will give traceback inside try block recent_call = traceback.extract_tb(exc_traceback) caller = getframeinfo(stack()[1][0]) @@ -149,13 +148,14 @@ def format_exception(self, formatted_stack): tb = [] for item in formatted_stack: file, line, function, statement = item - tb.append({"file" : file, - "line" : line, - "function" : function, - "statement" : statement + tb.append({"file": file, + "line": line, + "function": function, + "statement": statement }) return tb + # To serialize when json contains old message object def serialize_message(obj): if isinstance(obj, Message): diff --git a/tendrl/commons/tests/manager/test_manager_init.py b/tendrl/commons/tests/manager/test_manager_init.py index 06e8b44a..08ea67a9 100644 --- a/tendrl/commons/tests/manager/test_manager_init.py +++ b/tendrl/commons/tests/manager/test_manager_init.py @@ -18,7 +18,7 @@ def job_consume(): return "Thread Consuming Job" monkeypatch.setattr(jobs, 'JobConsumerThread', job_consume) manager = Manager("test") - assert manager._sds_sync_thread is "test" + assert manager._sds_sync_thread == "test" assert manager._message_handler_thread is None assert manager._job_consumer_thread == "Thread Consuming Job" diff --git a/tendrl/commons/tests/objects/test_objects_init.py b/tendrl/commons/tests/objects/test_objects_init.py index 2b2d4246..5a0922bd 100644 --- a/tendrl/commons/tests/objects/test_objects_init.py +++ b/tendrl/commons/tests/objects/test_objects_init.py @@ -188,7 +188,7 @@ def test_save(): with patch.object(Client, "write", return_value=True): with patch.object(Client, "read", return_value=maps.NamedDict(value="")): - obj.save(True) + obj.save(True) with patch.object(Client, "write", return_value=True): with patch.object(objects.BaseObject, "_hash", return_value=None): diff --git a/tendrl/commons/tests/utils/test_ansible_module_runner.py b/tendrl/commons/tests/utils/test_ansible_module_runner.py index e86bb478..fe67fbb2 100644 --- a/tendrl/commons/tests/utils/test_ansible_module_runner.py +++ b/tendrl/commons/tests/utils/test_ansible_module_runner.py @@ -24,18 +24,18 @@ def test_AnsibleExecutableGenerationFailed_constructor(): ansible_obj = AnsibleExecutableGenerationFailed() assert ansible_obj.message == "Executabe could not be generated for " \ "module None . Error: None" - ansible_obj = AnsibleExecutableGenerationFailed(module_path="Test\path", + ansible_obj = AnsibleExecutableGenerationFailed(module_path="Test\\path", arguments="temp_args", err="No Error") assert ansible_obj.message == "Executabe could not be generated for " \ - "module Test\path . Error: No Error" + "module Test\\path . Error: No Error" def test_AnsibleModuleNotFound_constructor(): ansible_obj = AnsibleModuleNotFound() assert ansible_obj.message == "Ansible module None not found" - ansible_obj = AnsibleModuleNotFound(module_path="Test\path") - assert ansible_obj.message == "Ansible module Test\path not found" + ansible_obj = AnsibleModuleNotFound(module_path="Test\\path") + assert ansible_obj.message == "Ansible module Test\\path not found" @mock.patch('tendrl.commons.event.Event.__init__', diff --git a/tendrl/commons/utils/log_utils.py b/tendrl/commons/utils/log_utils.py index 1211366c..61593eab 100644 --- a/tendrl/commons/utils/log_utils.py +++ b/tendrl/commons/utils/log_utils.py @@ -32,7 +32,7 @@ def log(log_priority, publisher_id, log_payload, job_id=None, ) ) except Exception: - if log_priority.lower() == "error": - sys.stderr.write(log_payload.get("message", "") + "\n") - else: - sys.stdout.write(log_payload.get("message", "") + "\n") + if log_priority.lower() == "error": + sys.stderr.write(log_payload.get("message", "") + "\n") + else: + sys.stdout.write(log_payload.get("message", "") + "\n") diff --git a/tox.ini b/tox.ini index 7940ad15..f0a2eb01 100644 --- a/tox.ini +++ b/tox.ini @@ -53,7 +53,7 @@ commands = python check_commit_msg.py # E123, E125 skipped as they are invalid PEP-8. # see: http://flake8.readthedocs.io/en/latest/config.html#settings show-source = True -ignore = E123,E125,W504 +ignore = E123,E125,W504,E402 builtins = _, NS exclude=.venv,.git,.tox,dist,doc,*lib/python*,*egg,build