Commit 29921401 authored by Iustin Pop's avatar Iustin Pop
Browse files

Fix various pylint warnings



There were multiple issues:
  - copy-paste resulted in wrong indentation
  - wrong function name
  - missing spaces around assignment
  - overriding built-in names (type, dir) or already defines ones
    (errors, hypervisor)
Signed-off-by: default avatarIustin Pop <iustin@google.com>
Reviewed-by: default avatarGuido Trotter <ultrotter@google.com>
parent 3bd3d643
......@@ -173,7 +173,7 @@ def GetMasterInfo():
master_ip = cfg.GetMasterIP()
master_node = cfg.GetMasterNode()
except errors.ConfigurationError, err:
_Fail("Cluster configuration incomplete", exc=True)
_Fail("Cluster configuration incomplete: %s", err, exc=True)
return master_netdev, master_ip, master_node
......@@ -680,7 +680,7 @@ def GetAllInstancesInfo(hypervisor_list):
for hname in hypervisor_list:
iinfo = hypervisor.GetHypervisor(hname).GetAllInstancesInfo()
if iinfo:
for name, inst_id, memory, vcpus, state, times in iinfo:
for name, _, memory, vcpus, state, times in iinfo:
value = {
'memory': memory,
'vcpus': vcpus,
......@@ -796,7 +796,7 @@ def _GetVGInfo(vg_name):
"pv_count": int(valarr[2]),
}
except ValueError, err:
logging.exception("Fail to parse vgs output")
logging.exception("Fail to parse vgs output: %s", err)
else:
logging.error("vgs output has the wrong number of fields (expected"
" three): %s", str(valarr))
......@@ -840,7 +840,7 @@ def _RemoveBlockDevLinks(instance_name, disks):
"""Remove the block device symlinks belonging to the given instance.
"""
for idx, disk in enumerate(disks):
for idx, _ in enumerate(disks):
link_name = _GetBlockDevSymlinkPath(instance_name, idx)
if os.path.islink(link_name):
try:
......@@ -1534,7 +1534,7 @@ def DiagnoseOS(top_dirs=None):
try:
f_names = utils.ListVisibleFiles(dir_name)
except EnvironmentError, err:
logging.exception("Can't list the OS directory %s", dir_name)
logging.exception("Can't list the OS directory %s: %s", dir_name, err)
break
for name in f_names:
os_path = os.path.sep.join([dir_name, name])
......@@ -2360,7 +2360,6 @@ def DrbdWaitSync(nodes_ip, disks):
min_resync = 100
alldone = True
failure = False
for rd in bdevs:
stats = rd.GetProcStatus()
if not (stats.is_connected or stats.is_in_resync):
......@@ -2382,7 +2381,7 @@ def PowercycleNode(hypervisor_type):
hyper = hypervisor.GetHypervisor(hypervisor_type)
try:
pid = os.fork()
except OSError, err:
except OSError:
# if we can't fork, we'll pretend that we're in the child process
pid = 0
if pid > 0:
......@@ -2497,7 +2496,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
......@@ -2619,7 +2618,7 @@ class DevCacheManager(object):
try:
utils.WriteFile(fpath, data=fdata)
except EnvironmentError, err:
logging.exception("Can't update bdev cache for %s", dev_path)
logging.exception("Can't update bdev cache for %s: %s", dev_path, err)
@classmethod
def RemoveCache(cls, dev_path):
......@@ -2641,4 +2640,4 @@ class DevCacheManager(object):
try:
utils.RemoveFile(fpath)
except EnvironmentError, err:
logging.exception("Can't update bdev cache for %s", dev_path)
logging.exception("Can't update bdev cache for %s: %s", dev_path, err)
......@@ -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
......@@ -637,7 +634,7 @@ def _CheckInstanceBridgesExist(lu, instance, node=None):
"""
if node is None:
node=instance.primary_node
node = instance.primary_node
_CheckNicsBridgesExist(lu, instance.nics, node)
......@@ -2582,8 +2579,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([(hvname, cluster.hvparams[hvname])
for hvname in cluster.enabled_hypervisors]),
"beparams": cluster.beparams,
"nicparams": cluster.nicparams,
"candidate_pool_size": cluster.candidate_pool_size,
......@@ -4536,7 +4533,8 @@ class LUCreateInstance(LogicalUnit):
bridge = nic.get("bridge", None)
link = nic.get("link", None)
if bridge and link:
raise errors.OpPrereqError("Cannot pass 'bridge' and 'link' at the same time")
raise errors.OpPrereqError("Cannot pass 'bridge' and 'link'"
" at the same time")
elif bridge and nic_mode == constants.NIC_MODE_ROUTED:
raise errors.OpPrereqError("Cannot pass 'bridge' on a routed nic")
elif bridge:
......@@ -5927,7 +5925,8 @@ class LUSetInstanceParams(LogicalUnit):
nic_bridge = nic_dict.get('bridge', None)
nic_link = nic_dict.get('link', None)
if nic_bridge and nic_link:
raise errors.OpPrereqError("Cannot pass 'bridge' and 'link' at the same time")
raise errors.OpPrereqError("Cannot pass 'bridge' and 'link'"
" at the same time")
elif nic_bridge and nic_bridge.lower() == constants.VALUE_NONE:
nic_dict['bridge'] = None
elif nic_link and nic_link.lower() == constants.VALUE_NONE:
......
......@@ -39,6 +39,7 @@ dict is the same, see the docstring for L{BaseHypervisor.PARAMETERS}.
import os
import re
import logging
from ganeti import errors
......
......@@ -56,7 +56,7 @@ class KVMHypervisor(hv_base.BaseHypervisor):
constants.HV_ACPI: hv_base.NO_CHECK,
constants.HV_SERIAL_CONSOLE: hv_base.NO_CHECK,
constants.HV_VNC_BIND_ADDRESS: \
(False, lambda x: (utils.IsValidIP(x) or utils.IsAbsNormPath(x)),
(False, lambda x: (utils.IsValidIP(x) or utils.IsNormAbsPath(x)),
"the VNC bind address must be either a valid IP address or an absolute"
" pathname", None, None),
constants.HV_VNC_TLS: hv_base.NO_CHECK,
......@@ -86,7 +86,7 @@ class KVMHypervisor(hv_base.BaseHypervisor):
hv_base.BaseHypervisor.__init__(self)
# Let's make sure the directories we need exist, even if the RUN_DIR lives
# in a tmpfs filesystem or has been otherwise wiped out.
dirs = [(dir, constants.RUN_DIRS_MODE) for dir in self._DIRS]
dirs = [(dname, constants.RUN_DIRS_MODE) for dname in self._DIRS]
utils.EnsureDirs(dirs)
def _InstancePidAlive(self, instance_name):
......
......@@ -364,4 +364,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)
......@@ -40,19 +40,19 @@ __all__ = ["ConfigObject", "ConfigData", "NIC", "Disk", "Instance",
"OS", "Node", "Cluster", "FillDict"]
def FillDict(defaults_dict, custom_dict):
"""Basic function to apply settings on top a default dict.
"""Basic function to apply settings on top a default dict.
@type defaults_dict: dict
@param defaults_dict: dictionary holding the default values
@type custom_dict: dict
@param custom_dict: dictionary holding customized value
@rtype: dict
@return: dict with the 'full' values
@type defaults_dict: dict
@param defaults_dict: dictionary holding the default values
@type custom_dict: dict
@param custom_dict: dictionary holding customized value
@rtype: dict
@return: dict with the 'full' values
"""
ret_dict = copy.deepcopy(defaults_dict)
ret_dict.update(custom_dict)
return ret_dict
"""
ret_dict = copy.deepcopy(defaults_dict)
ret_dict.update(custom_dict)
return ret_dict
def UpgradeGroupedParams(target, defaults):
......@@ -578,10 +578,10 @@ class Disk(ConfigObject):
"""Checks that this disk is correctly configured.
"""
errors = []
errs = []
if self.mode not in constants.DISK_ACCESS_SET:
errors.append("Disk access mode '%s' is invalid" % (self.mode, ))
return errors
errs.append("Disk access mode '%s' is invalid" % (self.mode, ))
return errs
class Instance(TaggableObject):
......
......@@ -396,19 +396,19 @@ def ForceDictType(target, key_types, allowed_values=None):
if target[key] in allowed_values:
continue
type = key_types[key]
if type not in constants.ENFORCEABLE_TYPES:
msg = "'%s' has non-enforceable type %s" % (key, type)
ktype = key_types[key]
if ktype not in constants.ENFORCEABLE_TYPES:
msg = "'%s' has non-enforceable type %s" % (key, ktype)
raise errors.ProgrammerError(msg)
if type == constants.VTYPE_STRING:
if ktype == constants.VTYPE_STRING:
if not isinstance(target[key], basestring):
if isinstance(target[key], bool) and not target[key]:
target[key] = ''
else:
msg = "'%s' (value %s) is not a valid string" % (key, target[key])
raise errors.TypeEnforcementError(msg)
elif type == constants.VTYPE_BOOL:
elif ktype == constants.VTYPE_BOOL:
if isinstance(target[key], basestring) and target[key]:
if target[key].lower() == constants.VALUE_FALSE:
target[key] = False
......@@ -421,14 +421,14 @@ def ForceDictType(target, key_types, allowed_values=None):
target[key] = True
else:
target[key] = False
elif type == constants.VTYPE_SIZE:
elif ktype == constants.VTYPE_SIZE:
try:
target[key] = ParseUnit(target[key])
except errors.UnitParseError, err:
msg = "'%s' (value %s) is not a valid size. error: %s" % \
(key, target[key], err)
raise errors.TypeEnforcementError(msg)
elif type == constants.VTYPE_INT:
elif ktype == constants.VTYPE_INT:
try:
target[key] = int(target[key])
except (ValueError, TypeError):
......@@ -1526,7 +1526,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