Enable several PEP8 checks

* E122 continuation line missing indentation or outdented
* E126 continuation line over-indented for hanging indent
* E127 continuation line over-indented for visual indent
* E128 continuation line under-indented for visual indent
* E131 continuation line unaligned for hanging indent
* E303 too many blank lines
* W601 .has_key() is deprecated, use 'in'
* H234 assertEquals is deprecated, use assertEqual
* H401 docstring should not start with a space
* H402 one line docstring needs punctuation.

Change-Id: I1c264dba19bfe7cb9173e8999429827bd026b930
This commit is contained in:
Christian Berendt 2015-01-21 17:21:34 +01:00
parent 62e5e8c703
commit c532db1461
19 changed files with 79 additions and 83 deletions

View File

@ -173,14 +173,14 @@ htmlhelp_basename = 'packstackdoc'
# -- Options for LaTeX output --------------------------------------------------
latex_elements = {
# The paper size ('letterpaper' or 'a4paper').
# 'papersize': 'letterpaper',
# The paper size ('letterpaper' or 'a4paper').
# 'papersize': 'letterpaper',
# The font size ('10pt', '11pt' or '12pt').
# 'pointsize': '10pt',
# The font size ('10pt', '11pt' or '12pt').
# 'pointsize': '10pt',
# Additional stuff for the LaTeX preamble.
# 'preamble': '',
# Additional stuff for the LaTeX preamble.
# 'preamble': '',
}
# Grouping the document tree into LaTeX files. List of tuples

View File

@ -52,8 +52,6 @@ DIR_PROJECT_DIR = os.environ.get('INSTALLER_PROJECT_DIR', os.path.join(os.getcwd
DIR_PLUGINS = os.path.join(DIR_PROJECT_DIR, "plugins")
DIR_MODULES = os.path.join(DIR_PROJECT_DIR, "modules")
EXEC_RPM = "rpm"
EXEC_SEMANAGE = "semanage"
EXEC_NSLOOKUP = "nslookup"

View File

@ -124,15 +124,15 @@ class Drone(object):
# remote host IP or hostname
self.node = node
# working directories on remote host
self.resource_dir = resource_dir or \
'/tmp/drone%s' % uuid.uuid4().hex[:8]
self.recipe_dir = recipe_dir or \
os.path.join(self.resource_dir, 'recipes')
self.resource_dir = (resource_dir or
'/tmp/drone%s' % uuid.uuid4().hex[:8])
self.recipe_dir = (recipe_dir or
os.path.join(self.resource_dir, 'recipes'))
# temporary directories
self.remote_tmpdir = remote_tmpdir or \
'/tmp/drone%s' % uuid.uuid4().hex[:8]
self.local_tmpdir = local_tmpdir or \
tempfile.mkdtemp(prefix='drone')
self.remote_tmpdir = (remote_tmpdir or
'/tmp/drone%s' % uuid.uuid4().hex[:8])
self.local_tmpdir = (local_tmpdir or
tempfile.mkdtemp(prefix='drone'))
def init_node(self):
"""

View File

@ -48,7 +48,6 @@ class Step(object):
sys.stdout.flush()
class Sequence(object):
"""
Wrapper for sequence of setup steps.

View File

@ -77,7 +77,7 @@ def _getInputFromUser(param):
else:
while loop:
# If the value was not supplied by the command line flags
if not commandLineValues.has_key(param.CONF_NAME):
if param.CONF_NAME not in commandLineValues:
message = StringIO()
message.write(param.PROMPT)
@ -121,11 +121,11 @@ def _getInputFromUser(param):
controller.CONF[param.CONF_NAME] = userInput
continue
else:
if commandLineValues.has_key(param.CONF_NAME):
if param.CONF_NAME in commandLineValues:
del commandLineValues[param.CONF_NAME]
else:
# Delete value from commandLineValues so that we will prompt the user for input
if commandLineValues.has_key(param.CONF_NAME):
if param.CONF_NAME in commandLineValues:
del commandLineValues[param.CONF_NAME]
loop = True
except KeyboardInterrupt:
@ -144,7 +144,7 @@ def input_param(param):
"""
# We need to check if a param needs confirmation, (i.e. ask user twice)
# Do not validate if it was given from the command line
if (param.NEED_CONFIRM and not commandLineValues.has_key(param.CONF_NAME)):
if param.NEED_CONFIRM and param.CONF_NAME not in commandLineValues:
# create a copy of the param so we can call it twice
confirmedParam = copy.deepcopy(param)
confirmedParamName = param.CONF_NAME + "_CONFIRMED"
@ -492,9 +492,9 @@ def _handleInteractiveParams():
# we clear the value of all params in the group
# in order to re-input them by the user
for param in group.parameters.itervalues():
if controller.CONF.has_key(param.CONF_NAME):
if param.CONF_NAME in controller.CONF:
del controller.CONF[param.CONF_NAME]
if commandLineValues.has_key(param.CONF_NAME):
if param.CONF_NAME in commandLineValues:
del commandLineValues[param.CONF_NAME]
else:
inputLoop = False
@ -529,7 +529,7 @@ def _getConditionValue(matchMember):
elif isinstance(matchMember, types.StringType):
# we assume that if we get a string as a member it is the name
# of a member of conf_params
if not controller.CONF.has_key(matchMember):
if matchMember not in controller.CONF:
param = controller.getParamByName(matchMember)
input_param(param)
returnValue = controller.CONF[matchMember]
@ -546,7 +546,7 @@ def _displaySummary():
logging.info("*** User input summary ***")
for group in controller.getAllGroups():
for param in group.parameters.itervalues():
if not param.USE_DEFAULT and controller.CONF.has_key(param.CONF_NAME):
if not param.USE_DEFAULT and param.CONF_NAME in controller.CONF:
cmdOption = param.CMD_OPTION
l = 30 - len(cmdOption)
maskParam = param.MASK_INPUT
@ -564,14 +564,14 @@ def _displaySummary():
logging.debug("user chose to re-enter the user parameters")
for group in controller.getAllGroups():
for param in group.parameters.itervalues():
if controller.CONF.has_key(param.CONF_NAME):
if param.CONF_NAME in controller.CONF:
if not param.MASK_INPUT:
param.DEFAULT_VALUE = controller.CONF[param.CONF_NAME]
# Remove the string from mask_value_set in order
# to remove values that might be over overwritten.
removeMaskString(controller.CONF[param.CONF_NAME])
del controller.CONF[param.CONF_NAME]
if commandLineValues.has_key(param.CONF_NAME):
if param.CONF_NAME in commandLineValues:
del commandLineValues[param.CONF_NAME]
print ""
logging.debug("calling handleParams in interactive mode")
@ -602,7 +602,7 @@ def _summaryParamsToLog():
logging.debug("*** The following params were used as user input:")
for group in controller.getAllGroups():
for param in group.parameters.itervalues():
if controller.CONF.has_key(param.CONF_NAME):
if param.CONF_NAME in controller.CONF:
maskedValue = mask(controller.CONF[param.CONF_NAME])
logging.debug("%s: %s" % (param.CMD_OPTION, maskedValue))
@ -725,7 +725,7 @@ def generateAnswerFile(outputFile, overrides={}):
def single_step_aio_install(options, logFile):
""" Installs an All in One host on this host"""
"""Installs an All in One host on this host."""
options.install_hosts = utils.get_localhost_ip()
@ -788,8 +788,8 @@ def initCmdLineParser():
usage = "usage: %prog [options] [--help]"
parser = OptionParser(usage=usage, version="%prog {0} {1}".format(version.release_string(), version.version_string()))
parser.add_option("--gen-answer-file", help="Generate a template of an answer file, using this option excludes all other options")
parser.add_option("--answer-file", help="Runs the configuration in non-interactive mode, extracting all information from the \
configuration file. using this option excludes all other options")
parser.add_option("--answer-file", help="Runs the configuration in non-interactive mode, extracting all information from the"
"configuration file. using this option excludes all other options")
parser.add_option("--install-hosts", help="Install on a set of hosts in a single step. The format should be a comma separated list "
"of hosts, the first is setup as a controller, and the others are setup as compute nodes."
"if only a single host is supplied then it is setup as an all in one installation. An answerfile "

View File

@ -90,8 +90,7 @@ class ScriptRunner(object):
environ = os.environ
environ['LANG'] = 'en_US.UTF8'
obj = subprocess.Popen(cmd, stdin=_PIPE, stdout=_PIPE, stderr=_PIPE,
close_fds=True, shell=False,
env=environ)
close_fds=True, shell=False, env=environ)
script = "function t(){ exit $? ; } \n trap t ERR \n" + script
out, err = obj.communicate(script)

View File

@ -24,15 +24,15 @@ from ..test_base import PackstackTestCaseMixin
class ProcessorsTestCase(PackstackTestCaseMixin, TestCase):
def test_process_host(self):
"""Test packstack.installer.processors.process_host"""
"""Test packstack.installer.processors.process_host."""
proc_local = process_host('localhost', 'HOSTNAME')
self.assertIn(proc_local, ['127.0.0.1', '::1'])
def test_process_ssh_key(self):
"""Test packstack.installer.processors.process_ssh_key"""
"""Test packstack.installer.processors.process_ssh_key."""
path = process_ssh_key(os.path.join(self.tempdir, 'id_rsa'), 'SSH_KEY')
# test if key was created
self.assertEquals(True, bool(path))
self.assertEqual(True, bool(path))
# test if key exists
# XXX: process_ssh_key does not create ssh key during test run
# ... not sure why, nevertheless it works in normal run

View File

@ -44,7 +44,7 @@ class ParameterTestCase(PackstackTestCaseMixin, TestCase):
shutil.rmtree(self.tempdir)
def test_sorteddict(self):
"""Test packstack.installer.utils.datastructures.SortedDict"""
"""Test packstack.installer.utils.datastructures.SortedDict."""
sdict = SortedDict()
sdict['1'] = 1
sdict['2'] = 2
@ -53,7 +53,7 @@ class ParameterTestCase(PackstackTestCaseMixin, TestCase):
self.assertListEqual(sdict.values(), [1, 2, 3, 4, 5])
def test_retry(self):
"""Test packstack.installer.utils.decorators.retry"""
"""Test packstack.installer.utils.decorators.retry."""
@retry(count=3, delay=0, retry_on=ValueError)
def test_sum():
@ -72,12 +72,12 @@ class ParameterTestCase(PackstackTestCaseMixin, TestCase):
self.assertRaises(ValueError, test_sum)
def test_network(self):
"""Test packstack.installer.utils.network functions"""
"""Test packstack.installer.utils.network functions."""
self.assertIn(host2ip('localhost', allow_localhost=True),
['127.0.0.1', '::1'])
def test_shell(self):
"""Test packstack.installer.utils.shell functions"""
"""Test packstack.installer.utils.shell functions."""
rc, out = execute(['echo', 'this is test'])
self.assertEqual(out.strip(), 'this is test')
rc, out = execute('echo "this is test"', use_shell=True)
@ -97,7 +97,7 @@ class ParameterTestCase(PackstackTestCaseMixin, TestCase):
self.assertEqual(out.strip(), 'this is test')
def test_strings(self):
"""Test packstack.installer.utils.strings functions"""
"""Test packstack.installer.utils.strings functions."""
self.assertEqual(color_text('test text', 'red'),
'\033[0;31mtest text\033[0m')
self.assertEqual(mask_string('test text', mask_list=['text']),
@ -108,9 +108,9 @@ class ParameterTestCase(PackstackTestCaseMixin, TestCase):
self.assertEqual(masked, 'test %s' % STR_MASK)
def test_shortcuts(self):
"""Test packstack.installer.utils.shortcuts functions"""
"""Test packstack.installer.utils.shortcuts functions."""
conf = {"A_HOST": "1.1.1.1", "B_HOSTS": "2.2.2.2,1.1.1.1",
"C_HOSTS": "3.3.3.3/vdc"}
hostlist = list(hosts(conf))
hostlist.sort()
self.assertEquals(['1.1.1.1', '2.2.2.2', '3.3.3.3'], hostlist)
self.assertEqual(['1.1.1.1', '2.2.2.2', '3.3.3.3'], hostlist)

View File

@ -34,24 +34,24 @@ class ValidatorsTestCase(PackstackTestCaseMixin, TestCase):
shutil.rmtree(self.tempdir)
def test_validate_integer(self):
"""Test packstack.installer.validators.validate_integer"""
"""Test packstack.installer.validators.validate_integer."""
validate_integer('1')
self.assertRaises(ParamValidationError, validate_integer, 'test')
def test_validate_regexp(self):
"""Test packstack.installer.validators.validate_regexp"""
"""Test packstack.installer.validators.validate_regexp."""
validate_regexp('Test_123', options=['\w'])
self.assertRaises(ParamValidationError, validate_regexp,
'!#$%', options=['\w'])
def test_validate_port(self):
"""Test packstack.installer.validators.validate_port"""
"""Test packstack.installer.validators.validate_port."""
validate_port('666')
self.assertRaises(ParamValidationError, validate_port, 'test')
self.assertRaises(ParamValidationError, validate_port, '-3')
def test_validate_not_empty(self):
"""Test packstack.installer.validators.validate_not_empty"""
"""Test packstack.installer.validators.validate_not_empty."""
validate_not_empty('test')
validate_not_empty(False)
self.assertRaises(ParamValidationError, validate_not_empty, '')
@ -59,20 +59,20 @@ class ValidatorsTestCase(PackstackTestCaseMixin, TestCase):
self.assertRaises(ParamValidationError, validate_not_empty, {})
def test_validate_options(self):
"""Test packstack.installer.validators.validate_options"""
"""Test packstack.installer.validators.validate_options."""
validate_options('a', options=['a', 'b'])
validate_options('b', options=['a', 'b'])
self.assertRaises(ParamValidationError, validate_options,
'c', options=['a', 'b'])
def test_validate_ip(self):
"""Test packstack.installer.validators.validate_ip"""
"""Test packstack.installer.validators.validate_ip."""
validate_ip('127.0.0.1')
validate_ip('::1')
self.assertRaises(ParamValidationError, validate_ip, 'test')
def test_validate_file(self):
"""Test packstack.installer.validators.validate_file"""
"""Test packstack.installer.validators.validate_file."""
fname = os.path.join(self.tempdir, '.test_validate_file')
bad_name = os.path.join(self.tempdir, '.me_no_exists')
with open(fname, 'w') as f:
@ -81,18 +81,18 @@ class ValidatorsTestCase(PackstackTestCaseMixin, TestCase):
self.assertRaises(ParamValidationError, validate_file, bad_name)
def test_validate_ping(self):
"""Test packstack.installer.validators.validate_ping"""
"""Test packstack.installer.validators.validate_ping."""
# ping to broadcast fails
self.assertRaises(ParamValidationError, validate_ping,
'255.255.255.255')
def test_validate_ssh(self):
"""Test packstack.installer.validators.validate_ssh"""
"""Test packstack.installer.validators.validate_ssh."""
# ssh to broadcast fails
self.assertRaises(ParamValidationError, validate_ssh,
'255.255.255.255')
def test_validate_float(self):
"""Test packstack.installer.validators.validate_float"""
"""Test packstack.installer.validators.validate_float."""
validate_float('5.3')
self.assertRaises(ParamValidationError, validate_float, 'test')

View File

@ -27,4 +27,4 @@ class OSPluginUtilsTestCase(PackstackTestCaseMixin, TestCase):
"C_HOSTS": "3.3.3.3/vdc"}
hosts = gethostlist(conf)
hosts.sort()
self.assertEquals(['1.1.1.1', '2.2.2.2', '3.3.3.3'], hosts)
self.assertEqual(['1.1.1.1', '2.2.2.2', '3.3.3.3'], hosts)

View File

@ -27,7 +27,7 @@ from packstack.modules.puppet import validate_logfile
class PuppetTestCase(PackstackTestCaseMixin, TestCase):
def test_validate_logfile(self):
"""Test packstack.modules.validate_logfile"""
"""Test packstack.modules.validate_logfile."""
filename = os.path.join(self.tempdir, "puppet.log")
# test valid run
with open(filename, "w") as fp:

View File

@ -22,7 +22,7 @@ from packstack.plugins import serverprep_001
class OSPluginUtilsTestCase(PackstackTestCaseMixin, TestCase):
def test_rhn_creds_quoted(self):
"""Make sure RHN password is quoted"""
"""Make sure RHN password is quoted."""
# On non-RHEL, the CONFIG_{RH,SATELLITE} options are never set,
# i.e. this test would always fail. Therefore, only run it on RHEL.

View File

@ -33,6 +33,6 @@ commands = python setup.py build_sphinx
# E123, E125 skipped as they are invalid PEP-8.
#
# All other checks should be enabled in the future.
ignore = E123,E125,H803,E128,F403,F821,E127,F811,F841,E501,W601,E131,E126,E303,E122,H402,H302,H303,H304,H301,H306,H234,H405,H404,H904,H201,H305,H307,H501,H102,H233,H101,H233,H401,H232
ignore = E123,E125,H803,F403,F821,F811,F841,E501,H302,H303,H304,H301,H306,H405,H404,H904,H201,H305,H307,H501,H102,H233,H101,H233,H232
show-source = True
exclude=.venv,.git,.tox