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(): ...@@ -173,7 +173,7 @@ def GetMasterInfo():
master_ip = cfg.GetMasterIP() master_ip = cfg.GetMasterIP()
master_node = cfg.GetMasterNode() master_node = cfg.GetMasterNode()
except errors.ConfigurationError, err: 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 return master_netdev, master_ip, master_node
...@@ -680,7 +680,7 @@ def GetAllInstancesInfo(hypervisor_list): ...@@ -680,7 +680,7 @@ def GetAllInstancesInfo(hypervisor_list):
for hname in hypervisor_list: for hname in hypervisor_list:
iinfo = hypervisor.GetHypervisor(hname).GetAllInstancesInfo() iinfo = hypervisor.GetHypervisor(hname).GetAllInstancesInfo()
if iinfo: if iinfo:
for name, inst_id, memory, vcpus, state, times in iinfo: for name, _, memory, vcpus, state, times in iinfo:
value = { value = {
'memory': memory, 'memory': memory,
'vcpus': vcpus, 'vcpus': vcpus,
...@@ -796,7 +796,7 @@ def _GetVGInfo(vg_name): ...@@ -796,7 +796,7 @@ def _GetVGInfo(vg_name):
"pv_count": int(valarr[2]), "pv_count": int(valarr[2]),
} }
except ValueError, err: except ValueError, err:
logging.exception("Fail to parse vgs output") logging.exception("Fail to parse vgs output: %s", err)
else: else:
logging.error("vgs output has the wrong number of fields (expected" logging.error("vgs output has the wrong number of fields (expected"
" three): %s", str(valarr)) " three): %s", str(valarr))
...@@ -840,7 +840,7 @@ def _RemoveBlockDevLinks(instance_name, disks): ...@@ -840,7 +840,7 @@ def _RemoveBlockDevLinks(instance_name, disks):
"""Remove the block device symlinks belonging to the given instance. """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) link_name = _GetBlockDevSymlinkPath(instance_name, idx)
if os.path.islink(link_name): if os.path.islink(link_name):
try: try:
...@@ -1534,7 +1534,7 @@ def DiagnoseOS(top_dirs=None): ...@@ -1534,7 +1534,7 @@ def DiagnoseOS(top_dirs=None):
try: try:
f_names = utils.ListVisibleFiles(dir_name) f_names = utils.ListVisibleFiles(dir_name)
except EnvironmentError, err: 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 break
for name in f_names: for name in f_names:
os_path = os.path.sep.join([dir_name, name]) os_path = os.path.sep.join([dir_name, name])
...@@ -2360,7 +2360,6 @@ def DrbdWaitSync(nodes_ip, disks): ...@@ -2360,7 +2360,6 @@ def DrbdWaitSync(nodes_ip, disks):
min_resync = 100 min_resync = 100
alldone = True alldone = True
failure = False
for rd in bdevs: for rd in bdevs:
stats = rd.GetProcStatus() stats = rd.GetProcStatus()
if not (stats.is_connected or stats.is_in_resync): if not (stats.is_connected or stats.is_in_resync):
...@@ -2382,7 +2381,7 @@ def PowercycleNode(hypervisor_type): ...@@ -2382,7 +2381,7 @@ def PowercycleNode(hypervisor_type):
hyper = hypervisor.GetHypervisor(hypervisor_type) hyper = hypervisor.GetHypervisor(hypervisor_type)
try: try:
pid = os.fork() pid = os.fork()
except OSError, err: except OSError:
# if we can't fork, we'll pretend that we're in the child process # if we can't fork, we'll pretend that we're in the child process
pid = 0 pid = 0
if pid > 0: if pid > 0:
...@@ -2497,7 +2496,7 @@ class HooksRunner(object): ...@@ -2497,7 +2496,7 @@ class HooksRunner(object):
dir_name = "%s/%s" % (self._BASE_DIR, subdir) dir_name = "%s/%s" % (self._BASE_DIR, subdir)
try: try:
dir_contents = utils.ListVisibleFiles(dir_name) dir_contents = utils.ListVisibleFiles(dir_name)
except OSError, err: except OSError:
# FIXME: must log output in case of failures # FIXME: must log output in case of failures
return rr return rr
...@@ -2619,7 +2618,7 @@ class DevCacheManager(object): ...@@ -2619,7 +2618,7 @@ class DevCacheManager(object):
try: try:
utils.WriteFile(fpath, data=fdata) utils.WriteFile(fpath, data=fdata)
except EnvironmentError, err: 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 @classmethod
def RemoveCache(cls, dev_path): def RemoveCache(cls, dev_path):
...@@ -2641,4 +2640,4 @@ class DevCacheManager(object): ...@@ -2641,4 +2640,4 @@ class DevCacheManager(object):
try: try:
utils.RemoveFile(fpath) utils.RemoveFile(fpath)
except EnvironmentError, err: 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 @@ ...@@ -26,12 +26,10 @@
import os import os
import os.path import os.path
import time import time
import tempfile
import re import re
import platform import platform
import logging import logging
import copy import copy
import random
from ganeti import ssh from ganeti import ssh
from ganeti import utils from ganeti import utils
...@@ -40,7 +38,6 @@ from ganeti import hypervisor ...@@ -40,7 +38,6 @@ from ganeti import hypervisor
from ganeti import locking from ganeti import locking
from ganeti import constants from ganeti import constants
from ganeti import objects from ganeti import objects
from ganeti import opcodes
from ganeti import serializer from ganeti import serializer
from ganeti import ssconf from ganeti import ssconf
...@@ -637,7 +634,7 @@ def _CheckInstanceBridgesExist(lu, instance, node=None): ...@@ -637,7 +634,7 @@ def _CheckInstanceBridgesExist(lu, instance, node=None):
""" """
if node is None: if node is None:
node=instance.primary_node node = instance.primary_node
_CheckNicsBridgesExist(lu, instance.nics, node) _CheckNicsBridgesExist(lu, instance.nics, node)
...@@ -2582,8 +2579,8 @@ class LUQueryClusterInfo(NoHooksLU): ...@@ -2582,8 +2579,8 @@ class LUQueryClusterInfo(NoHooksLU):
"master": cluster.master_node, "master": cluster.master_node,
"default_hypervisor": cluster.default_hypervisor, "default_hypervisor": cluster.default_hypervisor,
"enabled_hypervisors": cluster.enabled_hypervisors, "enabled_hypervisors": cluster.enabled_hypervisors,
"hvparams": dict([(hypervisor, cluster.hvparams[hypervisor]) "hvparams": dict([(hvname, cluster.hvparams[hvname])
for hypervisor in cluster.enabled_hypervisors]), for hvname in cluster.enabled_hypervisors]),
"beparams": cluster.beparams, "beparams": cluster.beparams,
"nicparams": cluster.nicparams, "nicparams": cluster.nicparams,
"candidate_pool_size": cluster.candidate_pool_size, "candidate_pool_size": cluster.candidate_pool_size,
...@@ -4536,7 +4533,8 @@ class LUCreateInstance(LogicalUnit): ...@@ -4536,7 +4533,8 @@ class LUCreateInstance(LogicalUnit):
bridge = nic.get("bridge", None) bridge = nic.get("bridge", None)
link = nic.get("link", None) link = nic.get("link", None)
if bridge and link: 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: elif bridge and nic_mode == constants.NIC_MODE_ROUTED:
raise errors.OpPrereqError("Cannot pass 'bridge' on a routed nic") raise errors.OpPrereqError("Cannot pass 'bridge' on a routed nic")
elif bridge: elif bridge:
...@@ -5927,7 +5925,8 @@ class LUSetInstanceParams(LogicalUnit): ...@@ -5927,7 +5925,8 @@ class LUSetInstanceParams(LogicalUnit):
nic_bridge = nic_dict.get('bridge', None) nic_bridge = nic_dict.get('bridge', None)
nic_link = nic_dict.get('link', None) nic_link = nic_dict.get('link', None)
if nic_bridge and nic_link: 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: elif nic_bridge and nic_bridge.lower() == constants.VALUE_NONE:
nic_dict['bridge'] = None nic_dict['bridge'] = None
elif nic_link and nic_link.lower() == constants.VALUE_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}. ...@@ -39,6 +39,7 @@ dict is the same, see the docstring for L{BaseHypervisor.PARAMETERS}.
import os import os
import re import re
import logging
from ganeti import errors from ganeti import errors
......
...@@ -56,7 +56,7 @@ class KVMHypervisor(hv_base.BaseHypervisor): ...@@ -56,7 +56,7 @@ class KVMHypervisor(hv_base.BaseHypervisor):
constants.HV_ACPI: hv_base.NO_CHECK, constants.HV_ACPI: hv_base.NO_CHECK,
constants.HV_SERIAL_CONSOLE: hv_base.NO_CHECK, constants.HV_SERIAL_CONSOLE: hv_base.NO_CHECK,
constants.HV_VNC_BIND_ADDRESS: \ 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" "the VNC bind address must be either a valid IP address or an absolute"
" pathname", None, None), " pathname", None, None),
constants.HV_VNC_TLS: hv_base.NO_CHECK, constants.HV_VNC_TLS: hv_base.NO_CHECK,
...@@ -86,7 +86,7 @@ class KVMHypervisor(hv_base.BaseHypervisor): ...@@ -86,7 +86,7 @@ class KVMHypervisor(hv_base.BaseHypervisor):
hv_base.BaseHypervisor.__init__(self) hv_base.BaseHypervisor.__init__(self)
# Let's make sure the directories we need exist, even if the RUN_DIR lives # 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. # 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) utils.EnsureDirs(dirs)
def _InstancePidAlive(self, instance_name): def _InstancePidAlive(self, instance_name):
......
...@@ -364,4 +364,4 @@ class HooksMaster(object): ...@@ -364,4 +364,4 @@ class HooksMaster(object):
phase = constants.HOOKS_PHASE_POST phase = constants.HOOKS_PHASE_POST
hpath = constants.HOOKS_NAME_CFGUPDATE hpath = constants.HOOKS_NAME_CFGUPDATE
nodes = [self.lu.cfg.GetMasterNode()] nodes = [self.lu.cfg.GetMasterNode()]
results = self._RunWrapper(nodes, hpath, phase) self._RunWrapper(nodes, hpath, phase)
...@@ -578,10 +578,10 @@ class Disk(ConfigObject): ...@@ -578,10 +578,10 @@ class Disk(ConfigObject):
"""Checks that this disk is correctly configured. """Checks that this disk is correctly configured.
""" """
errors = [] errs = []
if self.mode not in constants.DISK_ACCESS_SET: if self.mode not in constants.DISK_ACCESS_SET:
errors.append("Disk access mode '%s' is invalid" % (self.mode, )) errs.append("Disk access mode '%s' is invalid" % (self.mode, ))
return errors return errs
class Instance(TaggableObject): class Instance(TaggableObject):
......
...@@ -396,19 +396,19 @@ def ForceDictType(target, key_types, allowed_values=None): ...@@ -396,19 +396,19 @@ def ForceDictType(target, key_types, allowed_values=None):
if target[key] in allowed_values: if target[key] in allowed_values:
continue continue
type = key_types[key] ktype = key_types[key]
if type not in constants.ENFORCEABLE_TYPES: if ktype not in constants.ENFORCEABLE_TYPES:
msg = "'%s' has non-enforceable type %s" % (key, type) msg = "'%s' has non-enforceable type %s" % (key, ktype)
raise errors.ProgrammerError(msg) raise errors.ProgrammerError(msg)
if type == constants.VTYPE_STRING: if ktype == constants.VTYPE_STRING:
if not isinstance(target[key], basestring): if not isinstance(target[key], basestring):
if isinstance(target[key], bool) and not target[key]: if isinstance(target[key], bool) and not target[key]:
target[key] = '' target[key] = ''
else: else:
msg = "'%s' (value %s) is not a valid string" % (key, target[key]) msg = "'%s' (value %s) is not a valid string" % (key, target[key])
raise errors.TypeEnforcementError(msg) raise errors.TypeEnforcementError(msg)
elif type == constants.VTYPE_BOOL: elif ktype == constants.VTYPE_BOOL:
if isinstance(target[key], basestring) and target[key]: if isinstance(target[key], basestring) and target[key]:
if target[key].lower() == constants.VALUE_FALSE: if target[key].lower() == constants.VALUE_FALSE:
target[key] = False target[key] = False
...@@ -421,14 +421,14 @@ def ForceDictType(target, key_types, allowed_values=None): ...@@ -421,14 +421,14 @@ def ForceDictType(target, key_types, allowed_values=None):
target[key] = True target[key] = True
else: else:
target[key] = False target[key] = False
elif type == constants.VTYPE_SIZE: elif ktype == constants.VTYPE_SIZE:
try: try:
target[key] = ParseUnit(target[key]) target[key] = ParseUnit(target[key])
except errors.UnitParseError, err: except errors.UnitParseError, err:
msg = "'%s' (value %s) is not a valid size. error: %s" % \ msg = "'%s' (value %s) is not a valid size. error: %s" % \
(key, target[key], err) (key, target[key], err)
raise errors.TypeEnforcementError(msg) raise errors.TypeEnforcementError(msg)
elif type == constants.VTYPE_INT: elif ktype == constants.VTYPE_INT:
try: try:
target[key] = int(target[key]) target[key] = int(target[key])
except (ValueError, TypeError): except (ValueError, TypeError):
...@@ -1526,7 +1526,6 @@ def RemovePidFile(name): ...@@ -1526,7 +1526,6 @@ def RemovePidFile(name):
@param name: the daemon name used to derive the pidfile name @param name: the daemon name used to derive the pidfile name
""" """
pid = os.getpid()
pidfilename = DaemonPidFileName(name) pidfilename = DaemonPidFileName(name)
# TODO: we could check here that the file contains our pid # TODO: we could check here that the file contains our pid
try: 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