Commit 7c4d6c7b authored by Michael Hanselmann's avatar Michael Hanselmann
Browse files

Fix pylint warnings


Signed-off-by: default avatarMichael Hanselmann <hansmi@google.com>
Reviewed-by: default avatarIustin Pop <iustin@google.com>
parent 70c771f6
......@@ -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)
......@@ -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()
......
......@@ -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]:
......
......@@ -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.
......
......@@ -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
......
......@@ -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
......
......@@ -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:
......
......@@ -25,7 +25,6 @@
import os
import os.path
import re
from ganeti import utils
from ganeti import constants
......
......@@ -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
......
......@@ -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
......
......@@ -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):
......
......@@ -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)
......@@ -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):
......
......@@ -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
......
......@@ -31,7 +31,6 @@
# R0904: Too many public methods
import os
import socket
import logging
import zlib
import base64
......
......@@ -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:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment