From 7c4d6c7b8488c263e768c26be110ee45071e6c96 Mon Sep 17 00:00:00 2001 From: Michael Hanselmann Date: Fri, 3 Jul 2009 22:42:23 +0200 Subject: [PATCH] Fix pylint warnings Signed-off-by: Michael Hanselmann Reviewed-by: Iustin Pop --- lib/backend.py | 18 +++++++++--------- lib/cmdlib.py | 24 +++++++++--------------- lib/config.py | 4 ++-- lib/http/__init__.py | 3 --- lib/http/auth.py | 2 -- lib/http/client.py | 10 ---------- lib/http/server.py | 5 +---- lib/hypervisor/hv_fake.py | 1 - lib/hypervisor/hv_xen.py | 2 +- lib/jstore.py | 2 -- lib/luxi.py | 2 +- lib/mcpu.py | 2 +- lib/objects.py | 6 +++--- lib/rapi/baserlib.py | 4 +--- lib/rpc.py | 1 - lib/utils.py | 11 ++++------- 16 files changed, 32 insertions(+), 65 deletions(-) diff --git a/lib/backend.py b/lib/backend.py index 3f965a6..27d634e 100644 --- a/lib/backend.py +++ b/lib/backend.py @@ -141,7 +141,7 @@ def GetMasterInfo(): master_netdev = cfg.GetMasterNetdev() master_ip = cfg.GetMasterIP() master_node = cfg.GetMasterNode() - except errors.ConfigurationError, err: + except errors.ConfigurationError: logging.exception("Cluster configuration incomplete") return (None, None, None) return (master_netdev, master_ip, master_node) @@ -573,7 +573,7 @@ def GetInstanceList(hypervisor_list): try: names = hypervisor.GetHypervisor(hname).ListInstances() results.extend(names) - except errors.HypervisorError, err: + except errors.HypervisorError: logging.exception("Error enumerating instances for hypevisor %s", hname) raise @@ -918,7 +918,7 @@ def InstanceShutdown(instance): # test every 10secs for 2min time.sleep(1) - for dummy in range(11): + for _ in range(11): if instance.name not in GetInstanceList([hv_name]): break time.sleep(10) @@ -2024,7 +2024,7 @@ def BlockdevRename(devlist): # but we don't have the owner here - maybe parse from existing # cache? for now, we only lose lvm data when we rename, which # is less critical than DRBD or MD - except errors.BlockDeviceError, err: + except errors.BlockDeviceError: logging.exception("Can't rename device '%s' to '%s'", dev, unique_id) result = False return result @@ -2109,7 +2109,7 @@ def RemoveFileStorageDir(file_storage_dir): # deletes dir only if empty, otherwise we want to return False try: os.rmdir(file_storage_dir) - except OSError, err: + except OSError: logging.exception("Cannot remove file storage directory '%s'", file_storage_dir) result = False, @@ -2138,7 +2138,7 @@ def RenameFileStorageDir(old_file_storage_dir, new_file_storage_dir): if os.path.isdir(old_file_storage_dir): try: os.rename(old_file_storage_dir, new_file_storage_dir) - except OSError, err: + except OSError: logging.exception("Cannot rename '%s' to '%s'", old_file_storage_dir, new_file_storage_dir) result = False, @@ -2544,7 +2544,7 @@ class HooksRunner(object): dir_name = "%s/%s" % (self._BASE_DIR, subdir) try: dir_contents = utils.ListVisibleFiles(dir_name) - except OSError, err: + except OSError: # FIXME: must log output in case of failures return rr @@ -2667,7 +2667,7 @@ class DevCacheManager(object): fdata = "%s %s %s\n" % (str(owner), state, iv_name) try: utils.WriteFile(fpath, data=fdata) - except EnvironmentError, err: + except EnvironmentError: logging.exception("Can't update bdev cache for %s", dev_path) @classmethod @@ -2689,5 +2689,5 @@ class DevCacheManager(object): fpath = cls._ConvertPath(dev_path) try: utils.RemoveFile(fpath) - except EnvironmentError, err: + except EnvironmentError: logging.exception("Can't update bdev cache for %s", dev_path) diff --git a/lib/cmdlib.py b/lib/cmdlib.py index 0809489..7885ef1 100644 --- a/lib/cmdlib.py +++ b/lib/cmdlib.py @@ -26,12 +26,10 @@ import os import os.path import time -import tempfile import re import platform import logging import copy -import random from ganeti import ssh from ganeti import utils @@ -40,7 +38,6 @@ from ganeti import hypervisor from ganeti import locking from ganeti import constants from ganeti import objects -from ganeti import opcodes from ganeti import serializer from ganeti import ssconf @@ -454,7 +451,7 @@ def _CheckNodeNotDrained(lu, node): def _BuildInstanceHookEnv(name, primary_node, secondary_nodes, os_type, status, memory, vcpus, nics, disk_template, disks, - bep, hvp, hypervisor): + bep, hvp, hypervisor_name): """Builds instance related env variables for hooks This builds the hook environment from individual variables. @@ -484,8 +481,8 @@ def _BuildInstanceHookEnv(name, primary_node, secondary_nodes, os_type, status, @param bep: the backend parameters for the instance @type hvp: dict @param hvp: the hypervisor parameters for the instance - @type hypervisor: string - @param hypervisor: the hypervisor for the instance + @type hypervisor_name: string + @param hypervisor_name: the hypervisor for the instance @rtype: dict @return: the hook environment for this instance @@ -504,7 +501,7 @@ def _BuildInstanceHookEnv(name, primary_node, secondary_nodes, os_type, status, "INSTANCE_MEMORY": memory, "INSTANCE_VCPUS": vcpus, "INSTANCE_DISK_TEMPLATE": disk_template, - "INSTANCE_HYPERVISOR": hypervisor, + "INSTANCE_HYPERVISOR": hypervisor_name, } if nics: @@ -1293,7 +1290,6 @@ class LUVerifyDisks(NoHooksLU): node_lvs = self.rpc.call_volume_list(nodes, vg_name) - to_act = set() for node in nodes: # node_volume lvs = node_lvs[node] @@ -2513,8 +2509,8 @@ class LUQueryClusterInfo(NoHooksLU): "master": cluster.master_node, "default_hypervisor": cluster.default_hypervisor, "enabled_hypervisors": cluster.enabled_hypervisors, - "hvparams": dict([(hypervisor, cluster.hvparams[hypervisor]) - for hypervisor in cluster.enabled_hypervisors]), + "hvparams": dict([(hypervisor_name, cluster.hvparams[hypervisor]) + for hypervisor_name in cluster.enabled_hypervisors]), "beparams": cluster.beparams, "candidate_pool_size": cluster.candidate_pool_size, "default_bridge": cluster.default_bridge, @@ -2677,7 +2673,7 @@ def _StartInstanceDisks(lu, instance, force): """Start the disks of an instance. """ - disks_ok, dummy = _AssembleInstanceDisks(lu, instance, + disks_ok, _ = _AssembleInstanceDisks(lu, instance, ignore_secondaries=force) if not disks_ok: _ShutdownInstanceDisks(lu, instance) @@ -3675,7 +3671,7 @@ class LUFailoverInstance(LogicalUnit): logging.info("Starting instance %s on node %s", instance.name, target_node) - disks_ok, dummy = _AssembleInstanceDisks(self, instance, + disks_ok, _ = _AssembleInstanceDisks(self, instance, ignore_secondaries=True) if not disks_ok: _ShutdownInstanceDisks(self, instance) @@ -5431,7 +5427,6 @@ class LUReplaceDisks(LogicalUnit): logging.debug("Allocated minors %s" % (minors,)) self.proc.LogStep(4, steps_total, "changing drbd configuration") for idx, (dev, new_minor) in enumerate(zip(instance.disks, minors)): - size = dev.size info("activating a new drbd on %s for disk/%d" % (new_node, idx)) # create new devices on new_node; note that we create two IDs: # one without port, so the drbd will be activated without @@ -5966,7 +5961,7 @@ class LUSetInstanceParams(LogicalUnit): This only checks the instance list against the existing names. """ - force = self.force = self.op.force + self.force = self.op.force # checking the new params on the primary/secondary nodes @@ -6942,7 +6937,6 @@ class IAllocator(object): """ if call_fn is None: call_fn = self.lu.rpc.call_iallocator_runner - data = self.in_text result = call_fn(self.lu.cfg.GetMasterNode(), name, self.in_text) result.Raise() diff --git a/lib/config.py b/lib/config.py index ceea4e7..679edb3 100644 --- a/lib/config.py +++ b/lib/config.py @@ -474,8 +474,8 @@ class ConfigWriter: def _AppendUsedPorts(instance_name, disk, used): duplicates = [] if disk.dev_type == constants.LD_DRBD8 and len(disk.logical_id) >= 5: - nodeA, nodeB, dummy, minorA, minorB = disk.logical_id[:5] - for node, port in ((nodeA, minorA), (nodeB, minorB)): + node_a, node_b, _, minor_a, minor_b = disk.logical_id[:5] + for node, port in ((node_a, minor_a), (node_b, minor_b)): assert node in used, ("Node '%s' of instance '%s' not found" " in node list" % (node, instance_name)) if port in used[node]: diff --git a/lib/http/__init__.py b/lib/http/__init__.py index b7455dc..c98fa58 100644 --- a/lib/http/__init__.py +++ b/lib/http/__init__.py @@ -367,15 +367,12 @@ def SocketOperation(sock, op, arg1, timeout): # TODO: event_poll/event_check/override if op in (SOCKOP_SEND, SOCKOP_HANDSHAKE): event_poll = select.POLLOUT - event_check = select.POLLOUT elif op == SOCKOP_RECV: event_poll = select.POLLIN - event_check = select.POLLIN | select.POLLPRI elif op == SOCKOP_SHUTDOWN: event_poll = None - event_check = None # The timeout is only used when OpenSSL requests polling for a condition. # It is not advisable to have no timeout for shutdown. diff --git a/lib/http/auth.py b/lib/http/auth.py index ff880ac..670b897 100644 --- a/lib/http/auth.py +++ b/lib/http/auth.py @@ -23,12 +23,10 @@ """ import logging -import time import re import base64 import binascii -from ganeti import constants from ganeti import utils from ganeti import http diff --git a/lib/http/client.py b/lib/http/client.py index 776fade..717581f 100644 --- a/lib/http/client.py +++ b/lib/http/client.py @@ -22,23 +22,13 @@ """ -import BaseHTTPServer -import cgi -import logging -import OpenSSL import os import select import socket -import sys -import time -import signal import errno import threading -from ganeti import constants -from ganeti import serializer from ganeti import workerpool -from ganeti import utils from ganeti import http diff --git a/lib/http/server.py b/lib/http/server.py index 95a3756..0afdcd0 100644 --- a/lib/http/server.py +++ b/lib/http/server.py @@ -31,9 +31,6 @@ import socket import time import signal -from ganeti import constants -from ganeti import serializer -from ganeti import utils from ganeti import http @@ -498,7 +495,7 @@ class HttpServer(http.HttpBase): # As soon as too many children run, we'll not respond to new # requests. The real solution would be to add a timeout for children # and killing them after some time. - pid, status = os.waitpid(0, 0) + pid, _ = os.waitpid(0, 0) except os.error: pid = None if pid and pid in self._children: diff --git a/lib/hypervisor/hv_fake.py b/lib/hypervisor/hv_fake.py index ccac842..73ed60e 100644 --- a/lib/hypervisor/hv_fake.py +++ b/lib/hypervisor/hv_fake.py @@ -25,7 +25,6 @@ import os import os.path -import re from ganeti import utils from ganeti import constants diff --git a/lib/hypervisor/hv_xen.py b/lib/hypervisor/hv_xen.py index 4579f4db..76a8df1 100644 --- a/lib/hypervisor/hv_xen.py +++ b/lib/hypervisor/hv_xen.py @@ -89,7 +89,7 @@ class XenHypervisor(hv_base.BaseHypervisor): @return: list of (name, id, memory, vcpus, state, time spent) """ - for dummy in range(5): + for _ in range(5): result = utils.RunCmd(["xm", "list"]) if not result.failed: break diff --git a/lib/jstore.py b/lib/jstore.py index 4d9189e..5c59968 100644 --- a/lib/jstore.py +++ b/lib/jstore.py @@ -22,9 +22,7 @@ """Module implementing the job queue handling.""" import os -import logging import errno -import re from ganeti import constants from ganeti import errors diff --git a/lib/luxi.py b/lib/luxi.py index ff947ea..8c2720c 100644 --- a/lib/luxi.py +++ b/lib/luxi.py @@ -284,7 +284,7 @@ class Client(object): old_transp = self.transport self.transport = None old_transp.Close() - except Exception, err: + except Exception: pass def CallMethod(self, method, args): diff --git a/lib/mcpu.py b/lib/mcpu.py index a6014a1..67c5e95 100644 --- a/lib/mcpu.py +++ b/lib/mcpu.py @@ -361,4 +361,4 @@ class HooksMaster(object): phase = constants.HOOKS_PHASE_POST hpath = constants.HOOKS_NAME_CFGUPDATE nodes = [self.lu.cfg.GetMasterNode()] - results = self._RunWrapper(nodes, hpath, phase) + self._RunWrapper(nodes, hpath, phase) diff --git a/lib/objects.py b/lib/objects.py index 8106287..5c2ff3d 100644 --- a/lib/objects.py +++ b/lib/objects.py @@ -504,10 +504,10 @@ class Disk(ConfigObject): """Checks that this disk is correctly configured. """ - errors = [] + all_errors = [] if self.mode not in constants.DISK_ACCESS_SET: - errors.append("Disk access mode '%s' is invalid" % (self.mode, )) - return errors + all_errors.append("Disk access mode '%s' is invalid" % (self.mode, )) + return all_errors class Instance(TaggableObject): diff --git a/lib/rapi/baserlib.py b/lib/rapi/baserlib.py index 2bca63b..270d61a 100644 --- a/lib/rapi/baserlib.py +++ b/lib/rapi/baserlib.py @@ -25,8 +25,6 @@ import logging -import ganeti.cli - from ganeti import luxi from ganeti import rapi from ganeti import http @@ -247,7 +245,7 @@ class R_Generic(object): val = 0 try: val = int(val) - except (ValueError, TypeError), err: + except (ValueError, TypeError): raise http.HttpBadRequest("Invalid value for the" " '%s' parameter" % (name,)) return val diff --git a/lib/rpc.py b/lib/rpc.py index fc99fc2..958ae8b 100644 --- a/lib/rpc.py +++ b/lib/rpc.py @@ -31,7 +31,6 @@ # R0904: Too many public methods import os -import socket import logging import zlib import base64 diff --git a/lib/utils.py b/lib/utils.py index 3d33694..df2d180 100644 --- a/lib/utils.py +++ b/lib/utils.py @@ -27,7 +27,6 @@ the command line scripts. """ -import sys import os import time import subprocess @@ -59,7 +58,6 @@ from ganeti import constants _locksheld = [] _re_shell_unquoted = re.compile('^[-.,=:/_+@A-Za-z0-9]+$') -debug = False debug_locks = False #: when set to True, L{RunCmd} is disabled @@ -687,7 +685,7 @@ def TryConvert(fn, val): """ try: nv = fn(val) - except (ValueError, TypeError), err: + except (ValueError, TypeError): nv = val return nv @@ -1097,7 +1095,7 @@ def TcpPing(target, port, timeout=10, live_port_needed=False, source=None): if source is not None: try: sock.bind((source, 0)) - except socket.error, (errcode, errstring): + except socket.error, (errcode, _): if errcode == errno.EADDRNOTAVAIL: success = False @@ -1360,14 +1358,14 @@ def FirstFree(seq, base=0): def all(seq, pred=bool): "Returns True if pred(x) is True for every element in the iterable" - for elem in itertools.ifilterfalse(pred, seq): + for _ in itertools.ifilterfalse(pred, seq): return False return True def any(seq, pred=bool): "Returns True if pred(x) is True for at least one element in the iterable" - for elem in itertools.ifilter(pred, seq): + for _ in itertools.ifilter(pred, seq): return True return False @@ -1552,7 +1550,6 @@ def RemovePidFile(name): @param name: the daemon name used to derive the pidfile name """ - pid = os.getpid() pidfilename = DaemonPidFileName(name) # TODO: we could check here that the file contains our pid try: -- 1.7.10.4