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

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.
"""
# pylint: disable-msg=C0103
# C0103: Invalid name ganeti-confd
import os
import sys
import logging
import time
try:
# pylint: disable-msg=E0611
from pyinotify import pyinotify
except ImportError:
import pyinotify
......@@ -102,6 +106,8 @@ class ConfdInotifyEventHandler(pyinotify.ProcessEvent):
# no need to call the parent's constructor
self.watch_manager = watch_manager
self.callback = callback
# pylint: disable-msg=E1103
# pylint for some reason doesn't see the below constants
self.mask = pyinotify.EventsCodes.IN_IGNORED | \
pyinotify.EventsCodes.IN_MODIFY
self.file = filename
......
......@@ -26,6 +26,8 @@ inheritance from parent classes requires it.
"""
# pylint: disable-msg=C0103
# C0103: Invalid name ganeti-masterd
import os
import sys
......@@ -61,6 +63,7 @@ EXIT_NODESETUP_ERROR = constants.EXIT_NODESETUP_ERROR
class ClientRequestWorker(workerpool.BaseWorker):
# pylint: disable-msg=W0221
def RunTask(self, server, request, client_address):
"""Process the request.
......@@ -70,7 +73,7 @@ class ClientRequestWorker(workerpool.BaseWorker):
try:
server.finish_request(request, client_address)
server.close_request(request)
except:
except: # pylint: disable-msg=W0702
server.handle_error(request, client_address)
server.close_request(request)
......@@ -108,7 +111,7 @@ class IOServer(SocketServer.UnixStreamServer):
self.request_workers.AddTask(self, request, client_address)
@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."""
assert isinstance(signal_handlers, dict) and \
len(signal_handlers) > 0, \
......@@ -141,6 +144,8 @@ class ClientRqHandler(SocketServer.BaseRequestHandler):
READ_SIZE = 4096
def setup(self):
# pylint: disable-msg=W0201
# setup() is the api for initialising for this class
self._buffer = ""
self._msgs = collections.deque()
self._ops = ClientOps(self.server)
......@@ -204,11 +209,13 @@ class ClientOps:
def __init__(self, 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
# TODO: Parameter validation
# TODO: Rewrite to not exit in each 'if/elif' branch
if method == luxi.REQ_SUBMIT_JOB:
logging.info("Received new job")
ops = [opcodes.OpCode.LoadOpCode(state) for state in args]
......@@ -333,6 +340,8 @@ class GanetiContext(object):
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
def __init__(self):
......@@ -498,12 +507,12 @@ def _RunInSeparateProcess(fn):
# Call function
result = int(bool(fn()))
assert result in (0, 1)
except:
except: # pylint: disable-msg=W0702
logging.exception("Error while calling function in separate process")
# 0 and 1 are reserved for the return value
result = 33
os._exit(result)
os._exit(result) # pylint: disable-msg=W0212
# Parent process
......@@ -544,7 +553,7 @@ def CheckMasterd(options, args):
confirmation = sys.stdin.readline().strip()
if confirmation != "YES":
print >>sys.stderr, "Aborting."
print >> sys.stderr, "Aborting."
sys.exit(constants.EXIT_FAILURE)
return
......
......@@ -21,8 +21,13 @@
"""Ganeti node daemon"""
# functions in this module need to have a given name structure, so:
# pylint: disable-msg=C0103
# pylint: disable-msg=C0103,W0142
# 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 sys
......@@ -66,7 +71,7 @@ def _RequireJobQueueLock(fn):
return wrapper
class NodeHttpServer(http.server.HttpServer):
class NodeHttpServer(http.server.HttpServer): # pylint: disable-msg=R0904
"""The server implementation.
This class holds all methods exposed over the RPC interface.
......@@ -786,7 +791,7 @@ def ExecNoded(options, args):
"""Main node daemon function, executed with the PID file held.
"""
global queue_lock
global queue_lock # pylint: disable-msg=W0603
# Read SSL certificate
if options.ssl:
......
......@@ -18,9 +18,14 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
# 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 logging
import optparse
......
......@@ -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 sys
import time
......@@ -115,7 +119,7 @@ class WatcherState(object):
self._data = {}
else:
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
self._data = {}
logging.warning(("Invalid state file. Using defaults."
......@@ -369,7 +373,7 @@ class Watcher(object):
try:
logging.info("Activating disks for instance %s", instance.name)
instance.ActivateDisks()
except Exception:
except Exception: # pylint: disable-msg=W0703
logging.exception("Error while activating disks for instance %s",
instance.name)
......@@ -400,7 +404,7 @@ class Watcher(object):
instance.name, last)
instance.Restart()
self.started_instances.add(instance.name)
except Exception:
except Exception: # pylint: disable-msg=W0703
logging.exception("Error while restarting instance %s",
instance.name)
......@@ -464,7 +468,7 @@ def main():
"""Main function.
"""
global client
global client # pylint: disable-msg=W0603
options, args = ParseOptions()
......
......@@ -25,6 +25,7 @@
import asyncore
try:
# pylint: disable-msg=E0611
from pyinotify import pyinotify
except ImportError:
import pyinotify
......@@ -34,7 +35,7 @@ class AsyncNotifier(asyncore.file_dispatcher):
"""An asyncore dispatcher for inotify events.
"""
# pylint: disable-msg=W0622,W0212
def __init__(self, watch_manager, default_proc_fun=None, map=None):
"""Initializes this class.
......
......@@ -392,7 +392,7 @@ def LeaveCluster(modify_ssh_setup):
utils.RemoveFile(constants.HMAC_CLUSTER_KEY)
utils.RemoveFile(constants.RAPI_CERT_FILE)
utils.RemoveFile(constants.SSL_CERT_FILE)
except:
except: # pylint: disable-msg=W0702
logging.exception("Error while removing cluster secrets")
result = utils.RunCmd([constants.DAEMON_UTIL, "stop", constants.CONFD])
......@@ -1195,6 +1195,8 @@ def BlockdevCreate(disk, size, owner, on_primary, info):
it's not required to return anything.
"""
# TODO: remove the obsolete 'size' argument
# pylint: disable-msg=W0613
clist = []
if disk.children:
for child in disk.children:
......
......@@ -18,6 +18,7 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
# 02110-1301, USA.
"""Module used during the Ganeti build process"""
import imp
import os
......
......@@ -170,7 +170,7 @@ UN_PREFIX = "-"
class _Argument:
def __init__(self, min=0, max=None):
def __init__(self, min=0, max=None): # pylint: disable-msg=W0622
self.min = min
self.max = max
......@@ -185,6 +185,7 @@ class ArgSuggest(_Argument):
Value can be any of the ones passed to the constructor.
"""
# pylint: disable-msg=W0622
def __init__(self, min=0, max=None, choices=None):
_Argument.__init__(self, min=min, max=max)
self.choices = choices
......
......@@ -261,6 +261,8 @@ class LogicalUnit(object):
"""
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):
"""Notify the LU about the results of its hooks.
......@@ -699,7 +701,7 @@ def _BuildInstanceHookEnvByObject(lu, instance, override=None):
}
if override:
args.update(override)
return _BuildInstanceHookEnv(**args)
return _BuildInstanceHookEnv(**args) # pylint: disable-msg=W0142
def _AdjustCandidatePool(lu, exceptions):
......@@ -909,6 +911,7 @@ class LUDestroyCluster(LogicalUnit):
try:
hm.RunPhase(constants.HOOKS_PHASE_POST, [master])
except:
# pylint: disable-msg=W0702
self.LogWarning("Errors occurred running hooks on %s" % master)
result = self.rpc.call_node_stop_master(master, False)
......@@ -1029,7 +1032,7 @@ class LUVerifyCluster(LogicalUnit):
"""
node = nodeinfo.name
_ErrorIf = self._ErrorIf
_ErrorIf = self._ErrorIf # pylint: disable-msg=C0103
# main result, node_result should be a non-empty dict
test = not node_result or not isinstance(node_result, dict)
......@@ -1176,7 +1179,7 @@ class LUVerifyCluster(LogicalUnit):
available on the instance's node.
"""
_ErrorIf = self._ErrorIf
_ErrorIf = self._ErrorIf # pylint: disable-msg=C0103
node_current = instanceconfig.primary_node
node_vol_should = {}
......@@ -1291,7 +1294,7 @@ class LUVerifyCluster(LogicalUnit):
"""
self.bad = False
_ErrorIf = self._ErrorIf
_ErrorIf = self._ErrorIf # pylint: disable-msg=C0103
verbose = self.op.verbose
self._feedback_fn = feedback_fn
feedback_fn("* Verifying global settings")
......@@ -2476,6 +2479,7 @@ class LURemoveNode(LogicalUnit):
try:
hm.RunPhase(constants.HOOKS_PHASE_POST, [node.name])
except:
# pylint: disable-msg=W0702
self.LogWarning("Errors occurred running hooks on %s" % node.name)
result = self.rpc.call_node_leave_cluster(node.name, modify_ssh_setup)
......@@ -2489,6 +2493,7 @@ class LUQueryNodes(NoHooksLU):
"""Logical unit for querying nodes.
"""
# pylint: disable-msg=W0142
_OP_REQP = ["output_fields", "names", "use_locking"]
REQ_BGL = False
......@@ -3019,7 +3024,7 @@ class LUAddNode(LogicalUnit):
# later in the procedure; this also means that if the re-add
# fails, we are left with a non-offlined, broken node
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")
# if we demote the node, we do cleanup later in the procedure
new_node.master_candidate = self.master_candidate
......@@ -4261,6 +4266,7 @@ class LUQueryInstances(NoHooksLU):
"""Logical unit for querying instances.
"""
# pylint: disable-msg=W0142
_OP_REQP = ["output_fields", "names", "use_locking"]
REQ_BGL = False
_SIMPLE_FIELDS = ["name", "os", "network_port", "hypervisor",
......@@ -4322,6 +4328,8 @@ class LUQueryInstances(NoHooksLU):
"""Computes the list of nodes and their attributes.
"""
# pylint: disable-msg=R0912
# way too many branches here
all_info = self.cfg.GetAllInstancesInfo()
if self.wanted == locking.ALL_SET:
# caller didn't specify instance names, so ordering is not important
......@@ -8454,6 +8462,8 @@ class IAllocator(object):
easy usage
"""
# pylint: disable-msg=R0902
# lots of instance attributes
_ALLO_KEYS = [
"mem_size", "disks", "disk_template",
"os", "tags", "nics", "vcpus", "hypervisor",
......
......@@ -50,7 +50,7 @@ class ConfdQuery(object):
"""
self.reader = reader
def Exec(self, query):
def Exec(self, query): # pylint: disable-msg=R0201
"""Process a single UDP request from a client.
Different queries should override this function, which by defaults returns
......
......@@ -105,7 +105,7 @@ class AsyncUDPSocket(asyncore.dispatcher):
raise
ip, port = address
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
# if we failed handling a single request, we still want to continue.
logging.error("Unexpected exception", exc_info=True)
......@@ -139,7 +139,7 @@ class AsyncUDPSocket(asyncore.dispatcher):
else:
raise
self._out_queue.pop(0)
except:
except: # pylint: disable-msg=W0702
# 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.
logging.error("Unexpected exception", exc_info=True)
......
......@@ -299,7 +299,7 @@ class HttpVersionNotSupported(HttpException):
code = 505
class HttpJsonConverter:
class HttpJsonConverter: # pylint: disable-msg=W0232
CONTENT_TYPE = "application/json"
def Encode(self, data):
......
......@@ -333,7 +333,7 @@ class HttpClientWorker(workerpool.BaseWorker):
"""HTTP client worker class.
"""
def RunTask(self, pend_req):
def RunTask(self, pend_req): # pylint: disable-msg=W0221
try:
HttpClientRequestExecutor(pend_req.request)
finally:
......
......@@ -514,6 +514,7 @@ class HttpServer(http.HttpBase, asyncore.dispatcher):
"""Called for each incoming connection
"""
# pylint: disable-msg=W0212
(connection, client_addr) = self.socket.accept()
self._CollectChildren(False)
......@@ -533,7 +534,7 @@ class HttpServer(http.HttpBase, asyncore.dispatcher):
self.socket = None
self.request_executor(self, connection, client_addr)
except Exception:
except Exception: # pylint: disable-msg=W0703
logging.exception("Error while handling request from %s:%s",
client_addr[0], client_addr[1])
os._exit(1)
......
......@@ -190,7 +190,7 @@ class BaseHypervisor(object):
"""
raise NotImplementedError
def MigrationInfo(self, instance):
def MigrationInfo(self, instance): # pylint: disable-msg=R0201,W0613
"""Get instance information to perform a migration.
By default assume no information is needed.
......
......@@ -154,6 +154,7 @@ class _QueuedJob(object):
@ivar change: a Condition variable we use for waiting for job changes
"""
# pylint: disable-msg=W0212
__slots__ = ["queue", "id", "ops", "log_serial",
"received_timestamp", "start_timestamp", "end_timestamp",
"lock_status", "change",
......@@ -419,7 +420,7 @@ class _JobQueueWorker(workerpool.BaseWorker):
"""The actual job workers.
"""
def RunTask(self, job):
def RunTask(self, job): # pylint: disable-msg=W0221
"""Job executor.
This functions processes a job. It is closely tied to the _QueuedJob and
......@@ -559,6 +560,7 @@ def _RequireOpenQueue(fn):
"""
def wrapper(self, *args, **kwargs):
# pylint: disable-msg=W0212
assert self._queue_lock is not None, "Queue should be open"
return fn(self, *args, **kwargs)
return wrapper
......@@ -963,7 +965,7 @@ class JobQueue(object):
try:
job = _QueuedJob.Restore(self, data)
except Exception, err:
except Exception, err: # pylint: disable-msg=W0703
new_path = self._GetArchivedJobPath(job_id)
if filepath == new_path:
# job already archived (future case)
......
......@@ -287,7 +287,7 @@ class SingleNotifyPipeCondition(_BaseCondition):
if self._nwaiters == 0:
self._Cleanup()
def notifyAll(self):
def notifyAll(self): # pylint: disable-msg=C0103
"""Close the writing side of the pipe to notify all waiters.
"""
......@@ -345,7 +345,7 @@ class PipeCondition(_BaseCondition):
assert self._nwaiters > 0
self._nwaiters -= 1
def notifyAll(self):
def notifyAll(self): # pylint: disable-msg=C0103
"""Notify all currently waiting threads.
"""
......@@ -382,7 +382,7 @@ class _CountingCondition(object):
self._cond = threading.Condition(lock=lock)
self._nwaiters = 0
def notifyAll(self):
def notifyAll(self): # pylint: disable-msg=C0103
"""Notifies the condition.
"""
......
......@@ -286,7 +286,7 @@ class Client(object):
old_transp = self.transport
self.transport = None
old_transp.Close()
except Exception:
except Exception: # pylint: disable-msg=W0703
pass
def CallMethod(self, method, args):
......
......@@ -136,7 +136,7 @@ class _LockAttemptTimeoutStrategy(object):
return timeout
class OpExecCbBase:
class OpExecCbBase: # pylint: disable-msg=W0232
"""Base class for OpCode execution callbacks.
"""
......
......@@ -26,11 +26,12 @@ pass to and from external parties.
"""
# pylint: disable-msg=E0203
# pylint: disable-msg=E0203,W0201
# E0203: Access to member %r before its definition, since we use
# objects.py which doesn't explicitely initialise its members
# W0201: Attribute '%s' defined outside __init__
import ConfigParser
import re
......@@ -153,7 +154,7 @@ class ConfigObject(object):
raise errors.ConfigurationError("Invalid object passed to FromDict:"
" expected dict, got %s" % type(val))
val_str = dict([(str(k), v) for k, v in val.iteritems()])
obj = cls(**val_str)
obj = cls(**val_str) # pylint: disable-msg=W0142
return obj
@staticmethod
......
......@@ -18,5 +18,6 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
# 02110-1301, USA.
"""Ganeti RAPI module"""
RAPI_ACCESS_WRITE = "write"
......@@ -672,6 +672,7 @@ class _R_Tags(baserlib.R_Generic):
Example: ["tag1", "tag2", "tag3"]
"""
# pylint: disable-msg=W0212
return baserlib._Tags_GET(self.TAG_LEVEL, name=self.name)
def PUT(self):
......@@ -681,6 +682,7 @@ class _R_Tags(baserlib.R_Generic):
you'll have back a job id.
"""
# pylint: disable-msg=W0212
if 'tag' not in self.queryargs:
raise http.HttpBadRequest("Please specify tag(s) to add using the"
" the 'tag' parameter")
......@@ -696,6 +698,7 @@ class _R_Tags(baserlib.R_Generic):
/tags?tag=[tag]&tag=[tag]
"""
# pylint: disable-msg=W0212
if 'tag' not in self.queryargs:
# no we not gonna delete all tags
raise http.HttpBadRequest("Cannot delete all tags - please specify"
......
......@@ -163,7 +163,7 @@ class RpcResult(object):
args = (msg, prereq)
else:
args = (msg, )
raise ec(*args)
raise ec(*args) # pylint: disable-msg=W0142
class Client:
......
......@@ -23,6 +23,14 @@
"""
# pylint: disable-msg=W0232,R0201
# W0232, since we use these as singletons rather than object holding
# data
# R0201, for the same reason
# TODO: FileStorage initialised with paths whereas the others not
import logging
......@@ -50,7 +58,7 @@ class _Base:
"""
raise NotImplementedError()
def Modify(self, name, changes):
def Modify(self, name, changes): # pylint: disable-msg=W0613
"""Modifies an entity within the storage unit.
@type name: string
......@@ -76,7 +84,7 @@ class _Base:
raise NotImplementedError()
class FileStorage(_Base):
class FileStorage(_Base): # pylint: disable-msg=W0223
"""File storage unit.
"""
......@@ -153,7 +161,7 @@ class FileStorage(_Base):
return values
class _LvmBase(_Base):
class _LvmBase(_Base): # pylint: disable-msg=W0223
"""Base class for LVM storage containers.
@cvar LIST_FIELDS: list of tuples consisting of three elements: SF_*
......@@ -248,7 +256,7 @@ class _LvmBase(_Base):
if callable(mapper):