Commit 38206f3c authored by Iustin Pop's avatar Iustin Pop
Browse files

Fix pylint-detected issues

This is mostly:
  - whitespace fix (space at EOL in some files, not all, broken
    indentation, etc)
  - variable names overriding others (one is a real bug in there)
  - too-long-lines
  - cleanup of most unused imports (not all)

Reviewed-by: ultrotter
parent 3b9e6a30
......@@ -1348,7 +1348,8 @@ def FinalizeExport(instance, snap_disks):
config.set(constants.INISECT_INS, 'nic%d_mac' %
nic_count, '%s' % nic.mac)
config.set(constants.INISECT_INS, 'nic%d_ip' % nic_count, '%s' % nic.ip)
config.set(constants.INISECT_INS, 'nic%d_bridge' % nic_count, '%s' % nic.bridge)
config.set(constants.INISECT_INS, 'nic%d_bridge' % nic_count,
'%s' % nic.bridge)
# TODO: redundant: on load can read nics until it doesn't exist
config.set(constants.INISECT_INS, 'nic_count' , '%d' % nic_count)
......
......@@ -32,13 +32,12 @@ from cStringIO import StringIO
from ganeti import utils
from ganeti import logger
from ganeti import errors
from ganeti import mcpu
from ganeti import constants
from ganeti import opcodes
from ganeti import luxi
from optparse import (OptionParser, make_option, TitledHelpFormatter,
Option, OptionValueError, SUPPRESS_HELP)
Option, OptionValueError)
__all__ = ["DEBUG_OPT", "NOHDR_OPT", "SEP_OPT", "GenericMain",
"SubmitOpCode", "GetClient",
......
......@@ -38,11 +38,9 @@ from ganeti import utils
from ganeti import errors
from ganeti import hypervisor
from ganeti import locking
from ganeti import config
from ganeti import constants
from ganeti import objects
from ganeti import opcodes
from ganeti import ssconf
from ganeti import serializer
......@@ -870,7 +868,8 @@ class LUVerifyCluster(LogicalUnit):
lu_result: previous Exec result
"""
# We only really run POST phase hooks, and are only interested in their results
# We only really run POST phase hooks, and are only interested in
# their results
if phase == constants.HOOKS_PHASE_POST:
# Used to change hooks' output to proper indentation
indent_re = re.compile('^', re.M)
......@@ -4395,8 +4394,8 @@ class LUExportInstance(LogicalUnit):
if self.op.shutdown:
# shutdown the instance, but not the disks
if not rpc.call_instance_shutdown(src_node, instance):
raise errors.OpExecError("Could not shutdown instance %s on node %s" %
(instance.name, src_node))
raise errors.OpExecError("Could not shutdown instance %s on node %s" %
(instance.name, src_node))
vgname = self.cfg.GetVGName()
......@@ -4929,9 +4928,8 @@ class IAllocator(object):
if rcode == constants.IARUN_NOTFOUND:
raise errors.OpExecError("Can't find allocator '%s'" % name)
elif rcode == constants.IARUN_FAILURE:
raise errors.OpExecError("Instance allocator call failed: %s,"
" output: %s" %
(fail, stdout+stderr))
raise errors.OpExecError("Instance allocator call failed: %s,"
" output: %s" % (fail, stdout+stderr))
self.out_text = stdout
if validate:
self._ValidateResult()
......
......@@ -34,7 +34,6 @@ much memory.
import os
import tempfile
import random
import re
from ganeti import errors
from ganeti import locking
......
......@@ -25,7 +25,6 @@ import OpenSSL
import time
import logging
from ganeti import errors
from ganeti import logger
from ganeti import serializer
......
......@@ -197,11 +197,11 @@ class _JobQueueWorker(workerpool.BaseWorker):
op.result = None
queue.UpdateJobUnlocked(job)
input = op.input
input_opcode = op.input
finally:
queue.release()
result = proc.ExecOpCode(input, op.Log)
result = proc.ExecOpCode(input_opcode, op.Log)
queue.acquire()
try:
......
......@@ -30,9 +30,6 @@ Ganeti code. It offers some utility functions for easy logging.
import sys
import logging
import os, os.path
from ganeti import constants
def SetupLogging(logfile, debug=False, stderr_logging=False, program=""):
......
......@@ -31,11 +31,9 @@ The module is also be used by the master daemon.
import socket
import collections
import simplejson
import time
import errno
from ganeti import opcodes
from ganeti import serializer
from ganeti import constants
......
......@@ -34,7 +34,6 @@ from ganeti import constants
from ganeti import errors
from ganeti import rpc
from ganeti import cmdlib
from ganeti import config
from ganeti import ssconf
from ganeti import logger
from ganeti import locking
......
......@@ -23,17 +23,14 @@
"""
import re
import ganeti.cli
import ganeti.errors
import ganeti.opcodes
from ganeti import constants
from ganeti import utils
from ganeti.rapi import baserlib
from ganeti.rapi import httperror
from ganeti.rapi import baserlib
from ganeti.rapi import httperror
I_FIELDS = ["name", "os", "pnode", "snodes",
......@@ -42,7 +39,7 @@ I_FIELDS = ["name", "os", "pnode", "snodes",
"sda_size", "sdb_size", "vcpus",
"oper_state", "status", "tags"]
N_FIELDS = ["name","dtotal", "dfree",
N_FIELDS = ["name", "dtotal", "dfree",
"mtotal", "mnode", "mfree",
"pinst_cnt", "sinst_cnt", "tags"]
......@@ -114,10 +111,10 @@ class R_nodes(baserlib.R_Generic):
"""
DOC_URI = "/nodes"
def GET(self):
"""Returns a list of all nodes.
Returns:
A dictionary with 'name' and 'uri' keys for each of them.
......@@ -131,7 +128,7 @@ class R_nodes(baserlib.R_Generic):
"uri": "\/instances\/node2.example.com"
}]
If the optional 'bulk' argument is provided and set to 'true'
If the optional 'bulk' argument is provided and set to 'true'
value (i.e '?bulk=1'), the output contains detailed
information about nodes as a list.
......@@ -153,7 +150,7 @@ class R_nodes(baserlib.R_Generic):
"""
op = ganeti.opcodes.OpQueryNodes(output_fields=["name"], names=[])
nodeslist = baserlib.ExtractField(ganeti.cli.SubmitOpCode(op), 0)
if 'bulk' in self.queryargs:
op = ganeti.opcodes.OpQueryNodes(output_fields=N_FIELDS,
names=nodeslist)
......@@ -170,7 +167,7 @@ class R_nodes_name(baserlib.R_Generic):
DOC_URI = "/nodes/[node_name]"
def GET(self):
"""Send information about a node.
"""Send information about a node.
"""
node_name = self.items[0]
......@@ -207,7 +204,7 @@ class R_instances(baserlib.R_Generic):
def GET(self):
"""Returns a list of all available instances.
Returns:
A dictionary with 'name' and 'uri' keys for each of them.
......@@ -221,7 +218,7 @@ class R_instances(baserlib.R_Generic):
"uri": "\/instances\/mail.example.com"
}]
If the optional 'bulk' argument is provided and set to 'true'
If the optional 'bulk' argument is provided and set to 'true'
value (i.e '?bulk=1'), the output contains detailed
information about instances as a list.
......@@ -250,7 +247,7 @@ class R_instances(baserlib.R_Generic):
"""
op = ganeti.opcodes.OpQueryInstances(output_fields=["name"], names=[])
instanceslist = baserlib.ExtractField(ganeti.cli.SubmitOpCode(op), 0)
if 'bulk' in self.queryargs:
op = ganeti.opcodes.OpQueryInstances(output_fields=I_FIELDS,
names=instanceslist)
......
......@@ -23,14 +23,11 @@
"""
import re
import ganeti.opcodes
from ganeti import constants
from ganeti import luxi
from ganeti.rapi import baserlib
from ganeti.rapi import baserlib
from ganeti.rapi.rlib1 import I_FIELDS, N_FIELDS
......@@ -46,7 +43,7 @@ class R_2_jobs(baserlib.R_Generic):
Returns:
A dictionary with jobs id and uri.
"""
fields = ["id"]
# Convert the list of lists to the list of ids
......@@ -63,21 +60,21 @@ class R_2_jobs_id(baserlib.R_Generic):
def GET(self):
"""Returns a job status.
Returns:
Returns:
A dictionary with job parameters.
The result includes:
id - job ID as a number
status - current job status as a string
ops - involved OpCodes as a list of dictionaries for each opcodes in
ops - involved OpCodes as a list of dictionaries for each opcodes in
the job
opstatus - OpCodes status as a list
opresult - OpCodes results as a list of lists
"""
fields = ["id", "ops", "status", "opstatus", "opresult"]
job_id = self.items[0]
result = luxi.Client().QueryJobs([job_id,], fields)[0]
result = luxi.Client().QueryJobs([job_id, ], fields)[0]
return baserlib.MapFields(fields, result)
......@@ -86,10 +83,10 @@ class R_2_nodes(baserlib.R_Generic):
"""
DOC_URI = "/2/nodes"
def GET(self):
"""Returns a list of all nodes.
Returns:
A dictionary with 'name' and 'uri' keys for each of them.
......@@ -103,7 +100,7 @@ class R_2_nodes(baserlib.R_Generic):
"uri": "\/instances\/node2.example.com"
}]
If the optional 'bulk' argument is provided and set to 'true'
If the optional 'bulk' argument is provided and set to 'true'
value (i.e '?bulk=1'), the output contains detailed
information about nodes as a list.
......@@ -125,11 +122,12 @@ class R_2_nodes(baserlib.R_Generic):
"""
op = ganeti.opcodes.OpQueryNodes(output_fields=["name"], names=[])
nodeslist = baserlib.ExtractField(ganeti.cli.SubmitOpCode(op), 0)
if 'bulk' in self.queryargs:
op = ganeti.opcodes.OpQueryNodes(output_fields=N_FIELDS,
names=nodeslist)
result = ganeti.cli.SubmitOpCode(op)
return baserlib.MapBulkFields(result, N_FIELDS)
return baserlib.BuildUriList(nodeslist, "/nodes/%s", uri_fields=("id", "uri"))
return baserlib.BuildUriList(nodeslist, "/nodes/%s",
uri_fields=("id", "uri"))
......@@ -33,8 +33,6 @@ import simplejson
from ganeti import logger
from ganeti import utils
from ganeti import errors
from ganeti import constants
from ganeti import objects
from ganeti import ssconf
......
......@@ -74,13 +74,13 @@ class RunResult(object):
"failed", "fail_reason", "cmd"]
def __init__(self, exit_code, signal, stdout, stderr, cmd):
def __init__(self, exit_code, signal_, stdout, stderr, cmd):
self.cmd = cmd
self.exit_code = exit_code
self.signal = signal
self.signal = signal_
self.stdout = stdout
self.stderr = stderr
self.failed = (signal is not None or exit_code != 0)
self.failed = (signal_ is not None or exit_code != 0)
if self.signal is not None:
self.fail_reason = "terminated by signal %s" % self.signal
......@@ -168,12 +168,12 @@ def RunCmd(cmd):
status = child.wait()
if status >= 0:
exitcode = status
signal = None
signal_ = None
else:
exitcode = None
signal = -status
signal_ = -status
return RunResult(exitcode, signal, out, err, strcmd)
return RunResult(exitcode, signal_, out, err, strcmd)
def RemoveFile(filename):
......@@ -1092,13 +1092,13 @@ def RemovePidFile(name):
pass
def KillProcess(pid, signal=signal.SIGTERM, timeout=30):
def KillProcess(pid, signal_=signal.SIGTERM, timeout=30):
"""Kill a process given by its pid.
@type pid: int
@param pid: The PID to terminate.
@type signal: int
@param signal: The signal to send, by default SIGTERM
@type signal_: int
@param signal_: The signal to send, by default SIGTERM
@type timeout: int
@param timeout: The timeout after which, if the process is still alive,
a SIGKILL will be sent. If not positive, no such checking
......@@ -1111,7 +1111,7 @@ def KillProcess(pid, signal=signal.SIGTERM, timeout=30):
if not IsProcessAlive(pid):
return
os.kill(pid, signal)
os.kill(pid, signal_)
if timeout <= 0:
return
end = time.time() + timeout
......
......@@ -27,9 +27,6 @@ import collections
import logging
import threading
from ganeti import errors
from ganeti import utils
class BaseWorker(threading.Thread, object):
"""Base worker class for worker pools.
......
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