Commit 7260cfbe authored by Iustin Pop's avatar Iustin Pop
Browse files

Add targeted pylint disables



This patch should have only:

- pylint disables
- docstring changes
- whitespace changes
Signed-off-by: default avatarIustin Pop <iustin@google.com>
Reviewed-by: default avatarOlivier Tharan <olive@google.com>
parent e7beaa02
...@@ -26,12 +26,16 @@ It uses UDP+HMAC for authentication with a global cluster key. ...@@ -26,12 +26,16 @@ It uses UDP+HMAC for authentication with a global cluster key.
""" """
# pylint: disable-msg=C0103
# C0103: Invalid name ganeti-confd
import os import os
import sys import sys
import logging import logging
import time import time
try: try:
# pylint: disable-msg=E0611
from pyinotify import pyinotify from pyinotify import pyinotify
except ImportError: except ImportError:
import pyinotify import pyinotify
...@@ -102,6 +106,8 @@ class ConfdInotifyEventHandler(pyinotify.ProcessEvent): ...@@ -102,6 +106,8 @@ class ConfdInotifyEventHandler(pyinotify.ProcessEvent):
# no need to call the parent's constructor # no need to call the parent's constructor
self.watch_manager = watch_manager self.watch_manager = watch_manager
self.callback = callback self.callback = callback
# pylint: disable-msg=E1103
# pylint for some reason doesn't see the below constants
self.mask = pyinotify.EventsCodes.IN_IGNORED | \ self.mask = pyinotify.EventsCodes.IN_IGNORED | \
pyinotify.EventsCodes.IN_MODIFY pyinotify.EventsCodes.IN_MODIFY
self.file = filename self.file = filename
......
...@@ -26,6 +26,8 @@ inheritance from parent classes requires it. ...@@ -26,6 +26,8 @@ inheritance from parent classes requires it.
""" """
# pylint: disable-msg=C0103
# C0103: Invalid name ganeti-masterd
import os import os
import sys import sys
...@@ -61,6 +63,7 @@ EXIT_NODESETUP_ERROR = constants.EXIT_NODESETUP_ERROR ...@@ -61,6 +63,7 @@ EXIT_NODESETUP_ERROR = constants.EXIT_NODESETUP_ERROR
class ClientRequestWorker(workerpool.BaseWorker): class ClientRequestWorker(workerpool.BaseWorker):
# pylint: disable-msg=W0221
def RunTask(self, server, request, client_address): def RunTask(self, server, request, client_address):
"""Process the request. """Process the request.
...@@ -70,7 +73,7 @@ class ClientRequestWorker(workerpool.BaseWorker): ...@@ -70,7 +73,7 @@ class ClientRequestWorker(workerpool.BaseWorker):
try: try:
server.finish_request(request, client_address) server.finish_request(request, client_address)
server.close_request(request) server.close_request(request)
except: except: # pylint: disable-msg=W0702
server.handle_error(request, client_address) server.handle_error(request, client_address)
server.close_request(request) server.close_request(request)
...@@ -108,7 +111,7 @@ class IOServer(SocketServer.UnixStreamServer): ...@@ -108,7 +111,7 @@ class IOServer(SocketServer.UnixStreamServer):
self.request_workers.AddTask(self, request, client_address) self.request_workers.AddTask(self, request, client_address)
@utils.SignalHandled([signal.SIGINT, signal.SIGTERM]) @utils.SignalHandled([signal.SIGINT, signal.SIGTERM])
def serve_forever(self, signal_handlers=None): def serve_forever(self, signal_handlers=None): # pylint: disable-msg=W0221
"""Handle one request at a time until told to quit.""" """Handle one request at a time until told to quit."""
assert isinstance(signal_handlers, dict) and \ assert isinstance(signal_handlers, dict) and \
len(signal_handlers) > 0, \ len(signal_handlers) > 0, \
...@@ -141,6 +144,8 @@ class ClientRqHandler(SocketServer.BaseRequestHandler): ...@@ -141,6 +144,8 @@ class ClientRqHandler(SocketServer.BaseRequestHandler):
READ_SIZE = 4096 READ_SIZE = 4096
def setup(self): def setup(self):
# pylint: disable-msg=W0201
# setup() is the api for initialising for this class
self._buffer = "" self._buffer = ""
self._msgs = collections.deque() self._msgs = collections.deque()
self._ops = ClientOps(self.server) self._ops = ClientOps(self.server)
...@@ -204,11 +209,13 @@ class ClientOps: ...@@ -204,11 +209,13 @@ class ClientOps:
def __init__(self, server): def __init__(self, server):
self.server = server self.server = server
def handle_request(self, method, args): def handle_request(self, method, args): # pylint: disable-msg=R0911
queue = self.server.context.jobqueue queue = self.server.context.jobqueue
# TODO: Parameter validation # TODO: Parameter validation
# TODO: Rewrite to not exit in each 'if/elif' branch
if method == luxi.REQ_SUBMIT_JOB: if method == luxi.REQ_SUBMIT_JOB:
logging.info("Received new job") logging.info("Received new job")
ops = [opcodes.OpCode.LoadOpCode(state) for state in args] ops = [opcodes.OpCode.LoadOpCode(state) for state in args]
...@@ -333,6 +340,8 @@ class GanetiContext(object): ...@@ -333,6 +340,8 @@ class GanetiContext(object):
This class creates and holds common objects shared by all threads. This class creates and holds common objects shared by all threads.
""" """
# pylint: disable-msg=W0212
# we do want to ensure a singleton here
_instance = None _instance = None
def __init__(self): def __init__(self):
...@@ -498,12 +507,12 @@ def _RunInSeparateProcess(fn): ...@@ -498,12 +507,12 @@ def _RunInSeparateProcess(fn):
# Call function # Call function
result = int(bool(fn())) result = int(bool(fn()))
assert result in (0, 1) assert result in (0, 1)
except: except: # pylint: disable-msg=W0702
logging.exception("Error while calling function in separate process") logging.exception("Error while calling function in separate process")
# 0 and 1 are reserved for the return value # 0 and 1 are reserved for the return value
result = 33 result = 33
os._exit(result) os._exit(result) # pylint: disable-msg=W0212
# Parent process # Parent process
...@@ -544,7 +553,7 @@ def CheckMasterd(options, args): ...@@ -544,7 +553,7 @@ def CheckMasterd(options, args):
confirmation = sys.stdin.readline().strip() confirmation = sys.stdin.readline().strip()
if confirmation != "YES": if confirmation != "YES":
print >>sys.stderr, "Aborting." print >> sys.stderr, "Aborting."
sys.exit(constants.EXIT_FAILURE) sys.exit(constants.EXIT_FAILURE)
return return
......
...@@ -21,8 +21,13 @@ ...@@ -21,8 +21,13 @@
"""Ganeti node daemon""" """Ganeti node daemon"""
# functions in this module need to have a given name structure, so: # pylint: disable-msg=C0103,W0142
# pylint: disable-msg=C0103
# C0103: Functions in this module need to have a given name structure,
# and the name of the daemon doesn't match
# W0142: Used * or ** magic, since we do use it extensively in this
# module
import os import os
import sys import sys
...@@ -66,7 +71,7 @@ def _RequireJobQueueLock(fn): ...@@ -66,7 +71,7 @@ def _RequireJobQueueLock(fn):
return wrapper return wrapper
class NodeHttpServer(http.server.HttpServer): class NodeHttpServer(http.server.HttpServer): # pylint: disable-msg=R0904
"""The server implementation. """The server implementation.
This class holds all methods exposed over the RPC interface. This class holds all methods exposed over the RPC interface.
...@@ -786,7 +791,7 @@ def ExecNoded(options, args): ...@@ -786,7 +791,7 @@ def ExecNoded(options, args):
"""Main node daemon function, executed with the PID file held. """Main node daemon function, executed with the PID file held.
""" """
global queue_lock global queue_lock # pylint: disable-msg=W0603
# Read SSL certificate # Read SSL certificate
if options.ssl: if options.ssl:
......
...@@ -18,9 +18,14 @@ ...@@ -18,9 +18,14 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
# 02110-1301, USA. # 02110-1301, USA.
""" Ganeti Remote API master script. """Ganeti Remote API master script.
""" """
# pylint: disable-msg=C0103,W0142
# C0103: Invalid name ganeti-watcher
import glob import glob
import logging import logging
import optparse import optparse
......
...@@ -27,6 +27,10 @@ by a node reboot. Run from cron or similar. ...@@ -27,6 +27,10 @@ by a node reboot. Run from cron or similar.
""" """
# pylint: disable-msg=C0103,W0142
# C0103: Invalid name ganeti-watcher
import os import os
import sys import sys
import time import time
...@@ -115,7 +119,7 @@ class WatcherState(object): ...@@ -115,7 +119,7 @@ class WatcherState(object):
self._data = {} self._data = {}
else: else:
self._data = serializer.Load(state_data) self._data = serializer.Load(state_data)
except Exception, msg: except Exception, msg: # pylint: disable-msg=W0703
# Ignore errors while loading the file and treat it as empty # Ignore errors while loading the file and treat it as empty
self._data = {} self._data = {}
logging.warning(("Invalid state file. Using defaults." logging.warning(("Invalid state file. Using defaults."
...@@ -369,7 +373,7 @@ class Watcher(object): ...@@ -369,7 +373,7 @@ class Watcher(object):
try: try:
logging.info("Activating disks for instance %s", instance.name) logging.info("Activating disks for instance %s", instance.name)
instance.ActivateDisks() instance.ActivateDisks()
except Exception: except Exception: # pylint: disable-msg=W0703
logging.exception("Error while activating disks for instance %s", logging.exception("Error while activating disks for instance %s",
instance.name) instance.name)
...@@ -400,7 +404,7 @@ class Watcher(object): ...@@ -400,7 +404,7 @@ class Watcher(object):
instance.name, last) instance.name, last)
instance.Restart() instance.Restart()
self.started_instances.add(instance.name) self.started_instances.add(instance.name)
except Exception: except Exception: # pylint: disable-msg=W0703
logging.exception("Error while restarting instance %s", logging.exception("Error while restarting instance %s",
instance.name) instance.name)
...@@ -464,7 +468,7 @@ def main(): ...@@ -464,7 +468,7 @@ def main():
"""Main function. """Main function.
""" """
global client global client # pylint: disable-msg=W0603
options, args = ParseOptions() options, args = ParseOptions()
......
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
import asyncore import asyncore
try: try:
# pylint: disable-msg=E0611
from pyinotify import pyinotify from pyinotify import pyinotify
except ImportError: except ImportError:
import pyinotify import pyinotify
...@@ -34,7 +35,7 @@ class AsyncNotifier(asyncore.file_dispatcher): ...@@ -34,7 +35,7 @@ class AsyncNotifier(asyncore.file_dispatcher):
"""An asyncore dispatcher for inotify events. """An asyncore dispatcher for inotify events.
""" """
# pylint: disable-msg=W0622,W0212
def __init__(self, watch_manager, default_proc_fun=None, map=None): def __init__(self, watch_manager, default_proc_fun=None, map=None):
"""Initializes this class. """Initializes this class.
......
...@@ -392,7 +392,7 @@ def LeaveCluster(modify_ssh_setup): ...@@ -392,7 +392,7 @@ def LeaveCluster(modify_ssh_setup):
utils.RemoveFile(constants.HMAC_CLUSTER_KEY) utils.RemoveFile(constants.HMAC_CLUSTER_KEY)
utils.RemoveFile(constants.RAPI_CERT_FILE) utils.RemoveFile(constants.RAPI_CERT_FILE)
utils.RemoveFile(constants.SSL_CERT_FILE) utils.RemoveFile(constants.SSL_CERT_FILE)
except: except: # pylint: disable-msg=W0702
logging.exception("Error while removing cluster secrets") logging.exception("Error while removing cluster secrets")
result = utils.RunCmd([constants.DAEMON_UTIL, "stop", constants.CONFD]) result = utils.RunCmd([constants.DAEMON_UTIL, "stop", constants.CONFD])
...@@ -1195,6 +1195,8 @@ def BlockdevCreate(disk, size, owner, on_primary, info): ...@@ -1195,6 +1195,8 @@ def BlockdevCreate(disk, size, owner, on_primary, info):
it's not required to return anything. it's not required to return anything.
""" """
# TODO: remove the obsolete 'size' argument
# pylint: disable-msg=W0613
clist = [] clist = []
if disk.children: if disk.children:
for child in disk.children: for child in disk.children:
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
# 02110-1301, USA. # 02110-1301, USA.
"""Module used during the Ganeti build process"""
import imp import imp
import os import os
......
...@@ -170,7 +170,7 @@ UN_PREFIX = "-" ...@@ -170,7 +170,7 @@ UN_PREFIX = "-"
class _Argument: class _Argument:
def __init__(self, min=0, max=None): def __init__(self, min=0, max=None): # pylint: disable-msg=W0622
self.min = min self.min = min
self.max = max self.max = max
...@@ -185,6 +185,7 @@ class ArgSuggest(_Argument): ...@@ -185,6 +185,7 @@ class ArgSuggest(_Argument):
Value can be any of the ones passed to the constructor. Value can be any of the ones passed to the constructor.
""" """
# pylint: disable-msg=W0622
def __init__(self, min=0, max=None, choices=None): def __init__(self, min=0, max=None, choices=None):
_Argument.__init__(self, min=min, max=max) _Argument.__init__(self, min=min, max=max)
self.choices = choices self.choices = choices
......
...@@ -261,6 +261,8 @@ class LogicalUnit(object): ...@@ -261,6 +261,8 @@ class LogicalUnit(object):
""" """
raise NotImplementedError raise NotImplementedError
# this is valid in this entire class even if added here
# pylint: disable-msg=R0201
def HooksCallBack(self, phase, hook_results, feedback_fn, lu_result): def HooksCallBack(self, phase, hook_results, feedback_fn, lu_result):
"""Notify the LU about the results of its hooks. """Notify the LU about the results of its hooks.
...@@ -699,7 +701,7 @@ def _BuildInstanceHookEnvByObject(lu, instance, override=None): ...@@ -699,7 +701,7 @@ def _BuildInstanceHookEnvByObject(lu, instance, override=None):
} }
if override: if override:
args.update(override) args.update(override)
return _BuildInstanceHookEnv(**args) return _BuildInstanceHookEnv(**args) # pylint: disable-msg=W0142
def _AdjustCandidatePool(lu, exceptions): def _AdjustCandidatePool(lu, exceptions):
...@@ -909,6 +911,7 @@ class LUDestroyCluster(LogicalUnit): ...@@ -909,6 +911,7 @@ class LUDestroyCluster(LogicalUnit):
try: try:
hm.RunPhase(constants.HOOKS_PHASE_POST, [master]) hm.RunPhase(constants.HOOKS_PHASE_POST, [master])
except: except:
# pylint: disable-msg=W0702
self.LogWarning("Errors occurred running hooks on %s" % master) self.LogWarning("Errors occurred running hooks on %s" % master)
result = self.rpc.call_node_stop_master(master, False) result = self.rpc.call_node_stop_master(master, False)
...@@ -1029,7 +1032,7 @@ class LUVerifyCluster(LogicalUnit): ...@@ -1029,7 +1032,7 @@ class LUVerifyCluster(LogicalUnit):
""" """
node = nodeinfo.name node = nodeinfo.name
_ErrorIf = self._ErrorIf _ErrorIf = self._ErrorIf # pylint: disable-msg=C0103
# main result, node_result should be a non-empty dict # main result, node_result should be a non-empty dict
test = not node_result or not isinstance(node_result, dict) test = not node_result or not isinstance(node_result, dict)
...@@ -1176,7 +1179,7 @@ class LUVerifyCluster(LogicalUnit): ...@@ -1176,7 +1179,7 @@ class LUVerifyCluster(LogicalUnit):
available on the instance's node. available on the instance's node.
""" """
_ErrorIf = self._ErrorIf _ErrorIf = self._ErrorIf # pylint: disable-msg=C0103
node_current = instanceconfig.primary_node node_current = instanceconfig.primary_node
node_vol_should = {} node_vol_should = {}
...@@ -1291,7 +1294,7 @@ class LUVerifyCluster(LogicalUnit): ...@@ -1291,7 +1294,7 @@ class LUVerifyCluster(LogicalUnit):
""" """
self.bad = False self.bad = False
_ErrorIf = self._ErrorIf _ErrorIf = self._ErrorIf # pylint: disable-msg=C0103
verbose = self.op.verbose verbose = self.op.verbose
self._feedback_fn = feedback_fn self._feedback_fn = feedback_fn
feedback_fn("* Verifying global settings") feedback_fn("* Verifying global settings")
...@@ -2476,6 +2479,7 @@ class LURemoveNode(LogicalUnit): ...@@ -2476,6 +2479,7 @@ class LURemoveNode(LogicalUnit):
try: try:
hm.RunPhase(constants.HOOKS_PHASE_POST, [node.name]) hm.RunPhase(constants.HOOKS_PHASE_POST, [node.name])
except: except:
# pylint: disable-msg=W0702
self.LogWarning("Errors occurred running hooks on %s" % node.name) self.LogWarning("Errors occurred running hooks on %s" % node.name)
result = self.rpc.call_node_leave_cluster(node.name, modify_ssh_setup) result = self.rpc.call_node_leave_cluster(node.name, modify_ssh_setup)
...@@ -2489,6 +2493,7 @@ class LUQueryNodes(NoHooksLU): ...@@ -2489,6 +2493,7 @@ class LUQueryNodes(NoHooksLU):
"""Logical unit for querying nodes. """Logical unit for querying nodes.
""" """
# pylint: disable-msg=W0142
_OP_REQP = ["output_fields", "names", "use_locking"] _OP_REQP = ["output_fields", "names", "use_locking"]
REQ_BGL = False REQ_BGL = False
...@@ -3019,7 +3024,7 @@ class LUAddNode(LogicalUnit): ...@@ -3019,7 +3024,7 @@ class LUAddNode(LogicalUnit):
# later in the procedure; this also means that if the re-add # later in the procedure; this also means that if the re-add
# fails, we are left with a non-offlined, broken node # fails, we are left with a non-offlined, broken node
if self.op.readd: if self.op.readd:
new_node.drained = new_node.offline = False new_node.drained = new_node.offline = False # pylint: disable-msg=W0201
self.LogInfo("Readding a node, the offline/drained flags were reset") self.LogInfo("Readding a node, the offline/drained flags were reset")
# if we demote the node, we do cleanup later in the procedure # if we demote the node, we do cleanup later in the procedure
new_node.master_candidate = self.master_candidate new_node.master_candidate = self.master_candidate
...@@ -4261,6 +4266,7 @@ class LUQueryInstances(NoHooksLU): ...@@ -4261,6 +4266,7 @@ class LUQueryInstances(NoHooksLU):
"""Logical unit for querying instances. """Logical unit for querying instances.
""" """
# pylint: disable-msg=W0142
_OP_REQP = ["output_fields", "names", "use_locking"] _OP_REQP = ["output_fields", "names", "use_locking"]
REQ_BGL = False REQ_BGL = False
_SIMPLE_FIELDS = ["name", "os", "network_port", "hypervisor", _SIMPLE_FIELDS = ["name", "os", "network_port", "hypervisor",
...@@ -4322,6 +4328,8 @@ class LUQueryInstances(NoHooksLU): ...@@ -4322,6 +4328,8 @@ class LUQueryInstances(NoHooksLU):
"""Computes the list of nodes and their attributes. """Computes the list of nodes and their attributes.
""" """
# pylint: disable-msg=R0912
# way too many branches here
all_info = self.cfg.GetAllInstancesInfo() all_info = self.cfg.GetAllInstancesInfo()
if self.wanted == locking.ALL_SET: if self.wanted == locking.ALL_SET:
# caller didn't specify instance names, so ordering is not important # caller didn't specify instance names, so ordering is not important
...@@ -8454,6 +8462,8 @@ class IAllocator(object): ...@@ -8454,6 +8462,8 @@ class IAllocator(object):
easy usage easy usage
""" """
# pylint: disable-msg=R0902
# lots of instance attributes
_ALLO_KEYS = [ _ALLO_KEYS = [
"mem_size", "disks", "disk_template", "mem_size", "disks", "disk_template",
"os", "tags", "nics", "vcpus", "hypervisor", "os", "tags", "nics", "vcpus", "hypervisor",
......
...@@ -50,7 +50,7 @@ class ConfdQuery(object): ...@@ -50,7 +50,7 @@ class ConfdQuery(object):
""" """
self.reader = reader self.reader = reader
def Exec(self, query): def Exec(self, query): # pylint: disable-msg=R0201
"""Process a single UDP request from a client. """Process a single UDP request from a client.
Different queries should override this function, which by defaults returns Different queries should override this function, which by defaults returns
......
...@@ -105,7 +105,7 @@ class AsyncUDPSocket(asyncore.dispatcher): ...@@ -105,7 +105,7 @@ class AsyncUDPSocket(asyncore.dispatcher):
raise raise
ip, port = address ip, port = address
self.handle_datagram(payload, ip, port) self.handle_datagram(payload, ip, port)
except: except: # pylint: disable-msg=W0702
# we need to catch any exception here, log it, but proceed, because even # we need to catch any exception here, log it, but proceed, because even
# if we failed handling a single request, we still want to continue. # if we failed handling a single request, we still want to continue.
logging.error("Unexpected exception", exc_info=True) logging.error("Unexpected exception", exc_info=True)
...@@ -139,7 +139,7 @@ class AsyncUDPSocket(asyncore.dispatcher): ...@@ -139,7 +139,7 @@ class AsyncUDPSocket(asyncore.dispatcher):
else: else:
raise raise
self._out_queue.pop(0) self._out_queue.pop(0)
except: except: # pylint: disable-msg=W0702
# we need to catch any exception here, log it, but proceed, because even # we need to catch any exception here, log it, but proceed, because even
# if we failed sending a single datagram we still want to continue. # if we failed sending a single datagram we still want to continue.
logging.error("Unexpected exception", exc_info=True) logging.error("Unexpected exception", exc_info=True)
......
...@@ -299,7 +299,7 @@ class HttpVersionNotSupported(HttpException): ...@@ -299,7 +299,7 @@ class HttpVersionNotSupported(HttpException):
code = 505 code = 505
class HttpJsonConverter: class HttpJsonConverter: # pylint: disable-msg=W0232
CONTENT_TYPE = "application/json" CONTENT_TYPE = "application/json"
def Encode(self, data): def Encode(self, data):
......
...@@ -333,7 +333,7 @@ class HttpClientWorker(workerpool.BaseWorker): ...@@ -333,7 +333,7 @@ class HttpClientWorker(workerpool.BaseWorker):
"""HTTP client worker class. """HTTP client worker class.
"""