fix pylint in all files used by ./tools/run-pylint
'make pylint' was not checking tests and tools. This fixies a bunch of pylint/pep8 issues in that code. It also enables 'make pylint' to check them.
This commit is contained in:
commit
4e01d1f81e
2
Makefile
2
Makefile
@ -1,5 +1,5 @@
|
||||
CWD=$(shell pwd)
|
||||
PY_FILES=$(shell find cloudinit bin -name "*.py")
|
||||
PY_FILES=$(shell find cloudinit bin tests tools -name "*.py")
|
||||
PY_FILES+="bin/cloud-init"
|
||||
|
||||
all: test
|
||||
|
38
setup.py
38
setup.py
@ -23,12 +23,10 @@
|
||||
from glob import glob
|
||||
|
||||
import os
|
||||
import re
|
||||
|
||||
import setuptools
|
||||
from setuptools.command.install import install
|
||||
|
||||
from distutils.command.install_data import install_data
|
||||
from distutils.errors import DistutilsArgError
|
||||
|
||||
import subprocess
|
||||
@ -39,9 +37,9 @@ def is_f(p):
|
||||
|
||||
|
||||
INITSYS_FILES = {
|
||||
'sysvinit': filter((lambda x: is_f(x)), glob('sysvinit/*')),
|
||||
'systemd': filter((lambda x: is_f(x)), glob('systemd/*')),
|
||||
'upstart': filter((lambda x: is_f(x)), glob('upstart/*')),
|
||||
'sysvinit': [f for f in glob('sysvinit/*') if is_f(f)],
|
||||
'systemd': [f for f in glob('systemd/*') if is_f(f)],
|
||||
'upstart': [f for f in glob('upstart/*') if is_f(f)],
|
||||
}
|
||||
INITSYS_ROOTS = {
|
||||
'sysvinit': '/etc/rc.d/init.d',
|
||||
@ -70,17 +68,18 @@ def tiny_p(cmd, capture=True):
|
||||
def get_version():
|
||||
cmd = ['tools/read-version']
|
||||
(ver, _e) = tiny_p(cmd)
|
||||
return ver.strip()
|
||||
return str(ver).strip()
|
||||
|
||||
|
||||
def read_requires():
|
||||
cmd = ['tools/read-dependencies']
|
||||
(deps, _e) = tiny_p(cmd)
|
||||
return deps.splitlines()
|
||||
return str(deps).splitlines()
|
||||
|
||||
|
||||
# TODO: Is there a better way to do this??
|
||||
class InitsysInstallData(install):
|
||||
init_system = None
|
||||
user_options = install.user_options + [
|
||||
# This will magically show up in member variable 'init_sys'
|
||||
('init-system=', None,
|
||||
@ -96,13 +95,12 @@ class InitsysInstallData(install):
|
||||
def finalize_options(self):
|
||||
install.finalize_options(self)
|
||||
if self.init_system and self.init_system not in INITSYS_TYPES:
|
||||
raise DistutilsArgError(
|
||||
("You must specify one of (%s) when"
|
||||
" specifying a init system!") % (", ".join(INITSYS_TYPES))
|
||||
)
|
||||
raise DistutilsArgError(("You must specify one of (%s) when"
|
||||
" specifying a init system!") % (", ".join(INITSYS_TYPES)))
|
||||
elif self.init_system:
|
||||
self.distribution.data_files.append((INITSYS_ROOTS[self.init_system],
|
||||
INITSYS_FILES[self.init_system]))
|
||||
self.distribution.data_files.append(
|
||||
(INITSYS_ROOTS[self.init_system],
|
||||
INITSYS_FILES[self.init_system]))
|
||||
# Force that command to reinitalize (with new file list)
|
||||
self.distribution.reinitialize_command('install_data', True)
|
||||
|
||||
@ -123,11 +121,15 @@ setuptools.setup(name='cloud-init',
|
||||
('/etc/cloud/templates', glob('templates/*')),
|
||||
('/usr/share/cloud-init', []),
|
||||
('/usr/lib/cloud-init',
|
||||
['tools/uncloud-init', 'tools/write-ssh-key-fingerprints']),
|
||||
('/usr/share/doc/cloud-init', filter(is_f, glob('doc/*'))),
|
||||
('/usr/share/doc/cloud-init/examples', filter(is_f, glob('doc/examples/*'))),
|
||||
('/usr/share/doc/cloud-init/examples/seed', filter(is_f, glob('doc/examples/seed/*'))),
|
||||
],
|
||||
['tools/uncloud-init',
|
||||
'tools/write-ssh-key-fingerprints']),
|
||||
('/usr/share/doc/cloud-init',
|
||||
[f for f in glob('doc/*') if is_f(f)]),
|
||||
('/usr/share/doc/cloud-init/examples',
|
||||
[f for f in glob('doc/examples/*') if is_f(f)]),
|
||||
('/usr/share/doc/cloud-init/examples/seed',
|
||||
[f for f in glob('doc/examples/seed/*') if is_f(f)]),
|
||||
],
|
||||
install_requires=read_requires(),
|
||||
cmdclass = {
|
||||
# Use a subclass for install that handles
|
||||
|
@ -50,12 +50,14 @@ class TestWalkerHandleHandler(MockerTestCase):
|
||||
self.payload = "dummy payload"
|
||||
|
||||
# Mock the write_file function
|
||||
write_file_mock = self.mocker.replace(util.write_file, passthrough=False)
|
||||
write_file_mock = self.mocker.replace(util.write_file,
|
||||
passthrough=False)
|
||||
write_file_mock(expected_file_fullname, self.payload, 0600)
|
||||
|
||||
def test_no_errors(self):
|
||||
"""Payload gets written to file and added to C{pdata}."""
|
||||
import_mock = self.mocker.replace(importer.import_module, passthrough=False)
|
||||
import_mock = self.mocker.replace(importer.import_module,
|
||||
passthrough=False)
|
||||
import_mock(self.expected_module_name)
|
||||
self.mocker.result(self.module_fake)
|
||||
self.mocker.replay()
|
||||
@ -67,7 +69,8 @@ class TestWalkerHandleHandler(MockerTestCase):
|
||||
|
||||
def test_import_error(self):
|
||||
"""Module import errors are logged. No handler added to C{pdata}"""
|
||||
import_mock = self.mocker.replace(importer.import_module, passthrough=False)
|
||||
import_mock = self.mocker.replace(importer.import_module,
|
||||
passthrough=False)
|
||||
import_mock(self.expected_module_name)
|
||||
self.mocker.throw(ImportError())
|
||||
self.mocker.replay()
|
||||
@ -79,7 +82,8 @@ class TestWalkerHandleHandler(MockerTestCase):
|
||||
|
||||
def test_attribute_error(self):
|
||||
"""Attribute errors are logged. No handler added to C{pdata}"""
|
||||
import_mock = self.mocker.replace(importer.import_module, passthrough=False)
|
||||
import_mock = self.mocker.replace(importer.import_module,
|
||||
passthrough=False)
|
||||
import_mock(self.expected_module_name)
|
||||
self.mocker.result(self.module_fake)
|
||||
self.mocker.throw(AttributeError())
|
||||
@ -185,13 +189,15 @@ class TestCmdlineUrl(MockerTestCase):
|
||||
payload = "0"
|
||||
cmdline = "ro %s=%s bar=1" % (key, url)
|
||||
|
||||
mock_readurl = self.mocker.replace(url_helper.readurl, passthrough=False)
|
||||
mock_readurl = self.mocker.replace(url_helper.readurl,
|
||||
passthrough=False)
|
||||
mock_readurl(url)
|
||||
self.mocker.result(url_helper.UrlResponse(200, payload))
|
||||
self.mocker.replay()
|
||||
|
||||
self.assertEqual((key, url, None),
|
||||
util.get_cmdline_url(names=[key], starts="xxxxxx", cmdline=cmdline))
|
||||
util.get_cmdline_url(names=[key], starts="xxxxxx",
|
||||
cmdline=cmdline))
|
||||
|
||||
def test_valid_content(self):
|
||||
url = "http://example.com/foo"
|
||||
@ -199,7 +205,8 @@ class TestCmdlineUrl(MockerTestCase):
|
||||
payload = "xcloud-config\nmydata: foo\nbar: wark\n"
|
||||
cmdline = "ro %s=%s bar=1" % (key, url)
|
||||
|
||||
mock_readurl = self.mocker.replace(url_helper.readurl, passthrough=False)
|
||||
mock_readurl = self.mocker.replace(url_helper.readurl,
|
||||
passthrough=False)
|
||||
mock_readurl(url)
|
||||
self.mocker.result(url_helper.UrlResponse(200, payload))
|
||||
self.mocker.replay()
|
||||
|
@ -6,7 +6,6 @@ from mocker import MockerTestCase
|
||||
|
||||
from cloudinit import handlers
|
||||
from cloudinit import helpers
|
||||
from cloudinit import util
|
||||
|
||||
from cloudinit.handlers import upstart_job
|
||||
|
||||
|
@ -1,8 +1,6 @@
|
||||
import os
|
||||
from StringIO import StringIO
|
||||
from copy import copy
|
||||
|
||||
from cloudinit import util
|
||||
from cloudinit import url_helper
|
||||
from cloudinit.sources import DataSourceMAAS
|
||||
|
||||
|
@ -26,7 +26,8 @@ class TestNoConfig(MockerTestCase):
|
||||
self.mocker.replace(cc_ca_certs.update_ca_certs, passthrough=False)
|
||||
self.mocker.replay()
|
||||
|
||||
cc_ca_certs.handle(self.name, config, self.cloud_init, self.log, self.args)
|
||||
cc_ca_certs.handle(self.name, config, self.cloud_init, self.log,
|
||||
self.args)
|
||||
|
||||
|
||||
class TestConfig(MockerTestCase):
|
||||
@ -39,11 +40,12 @@ class TestConfig(MockerTestCase):
|
||||
self.args = []
|
||||
|
||||
# Mock out the functions that actually modify the system
|
||||
self.mock_add = self.mocker.replace(cc_ca_certs.add_ca_certs, passthrough=False)
|
||||
self.mock_add = self.mocker.replace(cc_ca_certs.add_ca_certs,
|
||||
passthrough=False)
|
||||
self.mock_update = self.mocker.replace(cc_ca_certs.update_ca_certs,
|
||||
passthrough=False)
|
||||
self.mock_remove = self.mocker.replace(cc_ca_certs.remove_default_ca_certs,
|
||||
passthrough=False)
|
||||
self.mock_remove = self.mocker.replace(
|
||||
cc_ca_certs.remove_default_ca_certs, passthrough=False)
|
||||
|
||||
# Order must be correct
|
||||
self.mocker.order()
|
||||
@ -183,8 +185,8 @@ class TestRemoveDefaultCaCerts(MockerTestCase):
|
||||
})
|
||||
|
||||
def test_commands(self):
|
||||
mock_delete_dir_contents = self.mocker.replace(util.delete_dir_contents,
|
||||
passthrough=False)
|
||||
mock_delete_dir_contents = self.mocker.replace(
|
||||
util.delete_dir_contents, passthrough=False)
|
||||
mock_write = self.mocker.replace(util.write_file, passthrough=False)
|
||||
mock_subp = self.mocker.replace(util.subp,
|
||||
passthrough=False)
|
||||
|
@ -4,18 +4,14 @@ import StringIO
|
||||
|
||||
import logging
|
||||
import os
|
||||
import shutil
|
||||
import tempfile
|
||||
|
||||
from email.mime.base import MIMEBase
|
||||
|
||||
from mocker import MockerTestCase
|
||||
|
||||
from cloudinit import helpers
|
||||
from cloudinit import log
|
||||
from cloudinit import sources
|
||||
from cloudinit import stages
|
||||
from cloudinit import util
|
||||
|
||||
INSTANCE_ID = "i-testing"
|
||||
|
||||
|
@ -14,7 +14,7 @@ class FakeSelinux(object):
|
||||
self.match_what = match_what
|
||||
self.restored = []
|
||||
|
||||
def matchpathcon(self, path, mode):
|
||||
def matchpathcon(self, path, mode): # pylint: disable=W0613
|
||||
if path == self.match_what:
|
||||
return
|
||||
else:
|
||||
@ -23,7 +23,7 @@ class FakeSelinux(object):
|
||||
def is_selinux_enabled(self):
|
||||
return True
|
||||
|
||||
def restorecon(self, path, recursive):
|
||||
def restorecon(self, path, recursive): # pylint: disable=W0613
|
||||
self.restored.append(path)
|
||||
|
||||
|
||||
|
@ -23,11 +23,8 @@ built on top of pep8.py
|
||||
|
||||
import inspect
|
||||
import logging
|
||||
import os
|
||||
import re
|
||||
import sys
|
||||
import tokenize
|
||||
import warnings
|
||||
|
||||
import pep8
|
||||
|
||||
@ -158,7 +155,7 @@ def add_cloud():
|
||||
if not inspect.isfunction(function):
|
||||
continue
|
||||
if name.startswith("cloud_"):
|
||||
exec("pep8.%s = %s" % (name, name))
|
||||
exec("pep8.%s = %s" % (name, name)) # pylint: disable=W0122
|
||||
|
||||
if __name__ == "__main__":
|
||||
# NOVA based 'hacking.py' error codes start with an N
|
||||
@ -167,7 +164,7 @@ if __name__ == "__main__":
|
||||
pep8.current_file = current_file
|
||||
pep8.readlines = readlines
|
||||
try:
|
||||
pep8._main()
|
||||
pep8._main() # pylint: disable=W0212
|
||||
finally:
|
||||
if len(_missingImport) > 0:
|
||||
print >> sys.stderr, ("%i imports missing in this test environment"
|
||||
|
@ -1,15 +1,15 @@
|
||||
#!/usr/bin/python
|
||||
|
||||
# Provides a somewhat random, somewhat compat, somewhat useful mock version of
|
||||
#
|
||||
# http://docs.amazonwebservices.com/AWSEC2/2007-08-29/DeveloperGuide/AESDG-chapter-instancedata.html
|
||||
# http://docs.amazonwebservices.com
|
||||
# /AWSEC2/2007-08-29/DeveloperGuide/AESDG-chapter-instancedata.htm
|
||||
|
||||
"""
|
||||
To use this to mimic the EC2 metadata service entirely, run it like:
|
||||
# Where 'eth0' is *some* interface.
|
||||
sudo ifconfig eth0:0 169.254.169.254 netmask 255.255.255.255
|
||||
|
||||
sudo ./mock-meta -a 169.254.169.254 -p 80
|
||||
sudo ./mock-meta.py -a 169.254.169.254 -p 80
|
||||
|
||||
Then:
|
||||
wget -q http://169.254.169.254/latest/meta-data/instance-id -O -; echo
|
||||
@ -23,7 +23,7 @@ import json
|
||||
import logging
|
||||
import os
|
||||
import random
|
||||
import string
|
||||
import string # pylint: disable=W0402
|
||||
import sys
|
||||
import yaml
|
||||
|
||||
@ -84,12 +84,12 @@ META_CAPABILITIES = [
|
||||
PUB_KEYS = {
|
||||
'brickies': [
|
||||
('ssh-rsa '
|
||||
'AAAAB3NzaC1yc2EAAAABIwAAAQEA3I7VUf2l5gSn5uavROsc5HRDpZdQueUq5ozemNSj8T'
|
||||
'7enqKHOEaFoU2VoPgGEWC9RyzSQVeyD6s7APMcE82EtmW4skVEgEGSbDc1pvxzxtchBj78'
|
||||
'hJP6Cf5TCMFSXw+Fz5rF1dR23QDbN1mkHs7adr8GW4kSWqU7Q7NDwfIrJJtO7Hi42GyXtv'
|
||||
'EONHbiRPOe8stqUly7MvUoN+5kfjBM8Qqpfl2+FNhTYWpMfYdPUnE7u536WqzFmsaqJctz'
|
||||
'3gBxH9Ex7dFtrxR4qiqEr9Qtlu3xGn7Bw07/+i1D+ey3ONkZLN+LQ714cgj8fRS4Hj29SC'
|
||||
'mXp5Kt5/82cD/VN3NtHw== brickies'),
|
||||
'AAAAB3NzaC1yc2EAAAABIwAAAQEA3I7VUf2l5gSn5uavROsc5HRDpZdQueUq5ozemN'
|
||||
'Sj8T7enqKHOEaFoU2VoPgGEWC9RyzSQVeyD6s7APMcE82EtmW4skVEgEGSbDc1pvxz'
|
||||
'xtchBj78hJP6Cf5TCMFSXw+Fz5rF1dR23QDbN1mkHs7adr8GW4kSWqU7Q7NDwfIrJJ'
|
||||
'tO7Hi42GyXtvEONHbiRPOe8stqUly7MvUoN+5kfjBM8Qqpfl2+FNhTYWpMfYdPUnE7'
|
||||
'u536WqzFmsaqJctz3gBxH9Ex7dFtrxR4qiqEr9Qtlu3xGn7Bw07/+i1D+ey3ONkZLN'
|
||||
'+LQ714cgj8fRS4Hj29SCmXp5Kt5/82cD/VN3NtHw== brickies'),
|
||||
'',
|
||||
],
|
||||
}
|
||||
@ -234,7 +234,7 @@ class MetaDataHandler(object):
|
||||
elif action == 'public-keys':
|
||||
nparams = params[1:]
|
||||
# This is a weird kludge, why amazon why!!!
|
||||
# public-keys is messed up, a list of /latest/meta-data/public-keys/
|
||||
# public-keys is messed up, list of /latest/meta-data/public-keys/
|
||||
# shows something like: '0=brickies'
|
||||
# but a GET to /latest/meta-data/public-keys/0=brickies will fail
|
||||
# you have to know to get '/latest/meta-data/public-keys/0', then
|
||||
@ -248,7 +248,8 @@ class MetaDataHandler(object):
|
||||
key_id = int(mybe_key)
|
||||
key_name = key_ids[key_id]
|
||||
except:
|
||||
raise WebException(httplib.BAD_REQUEST, "Unknown key id %r" % mybe_key)
|
||||
raise WebException(httplib.BAD_REQUEST,
|
||||
"Unknown key id %r" % mybe_key)
|
||||
# Extract the possible sub-params
|
||||
result = traverse(nparams[1:], {
|
||||
"openssh-key": "\n".join(avail_keys[key_name]),
|
||||
@ -303,7 +304,7 @@ class UserDataHandler(object):
|
||||
blob = "\n".join(lines)
|
||||
return blob.strip()
|
||||
|
||||
def get_data(self, params, who, **kwargs):
|
||||
def get_data(self, params, who, **kwargs): # pylint: disable=W0613
|
||||
if not params:
|
||||
return self._get_user_blob(who=who)
|
||||
return NOT_IMPL_RESPONSE
|
||||
@ -323,14 +324,12 @@ class Ec2Handler(BaseHTTPRequestHandler):
|
||||
versions = sorted(versions)
|
||||
return "\n".join(versions)
|
||||
|
||||
def log_message(self, format, *args):
|
||||
msg = "%s - %s" % (self.address_string(), format % (args))
|
||||
def log_message(self, fmt, *args):
|
||||
msg = "%s - %s" % (self.address_string(), fmt % (args))
|
||||
log.info(msg)
|
||||
|
||||
def _find_method(self, path):
|
||||
# Puke! (globals)
|
||||
global meta_fetcher
|
||||
global user_fetcher
|
||||
func_mapping = {
|
||||
'user-data': user_fetcher.get_data,
|
||||
'meta-data': meta_fetcher.get_data,
|
||||
@ -341,12 +340,14 @@ class Ec2Handler(BaseHTTPRequestHandler):
|
||||
return self._get_versions
|
||||
date = segments[0].strip().lower()
|
||||
if date not in self._get_versions():
|
||||
raise WebException(httplib.BAD_REQUEST, "Unknown version format %r" % date)
|
||||
raise WebException(httplib.BAD_REQUEST,
|
||||
"Unknown version format %r" % date)
|
||||
if len(segments) < 2:
|
||||
raise WebException(httplib.BAD_REQUEST, "No action provided")
|
||||
look_name = segments[1].lower()
|
||||
if look_name not in func_mapping:
|
||||
raise WebException(httplib.BAD_REQUEST, "Unknown requested data %r" % look_name)
|
||||
raise WebException(httplib.BAD_REQUEST,
|
||||
"Unknown requested data %r" % look_name)
|
||||
base_func = func_mapping[look_name]
|
||||
who = self.address_string()
|
||||
ip_from = self.client_address[0]
|
||||
@ -371,7 +372,8 @@ class Ec2Handler(BaseHTTPRequestHandler):
|
||||
self.send_response(httplib.OK)
|
||||
self.send_header("Content-Type", "binary/octet-stream")
|
||||
self.send_header("Content-Length", len(data))
|
||||
log.info("Sending data (len=%s):\n%s", len(data), format_text(data))
|
||||
log.info("Sending data (len=%s):\n%s", len(data),
|
||||
format_text(data))
|
||||
self.end_headers()
|
||||
self.wfile.write(data)
|
||||
except RuntimeError as e:
|
||||
@ -389,22 +391,25 @@ class Ec2Handler(BaseHTTPRequestHandler):
|
||||
self._do_response()
|
||||
|
||||
|
||||
def setup_logging(log_level, format='%(levelname)s: @%(name)s : %(message)s'):
|
||||
def setup_logging(log_level, fmt='%(levelname)s: @%(name)s : %(message)s'):
|
||||
root_logger = logging.getLogger()
|
||||
console_logger = logging.StreamHandler(sys.stdout)
|
||||
console_logger.setFormatter(logging.Formatter(format))
|
||||
console_logger.setFormatter(logging.Formatter(fmt))
|
||||
root_logger.addHandler(console_logger)
|
||||
root_logger.setLevel(log_level)
|
||||
|
||||
|
||||
def extract_opts():
|
||||
parser = OptionParser()
|
||||
parser.add_option("-p", "--port", dest="port", action="store", type=int, default=80,
|
||||
help="port from which to serve traffic (default: %default)", metavar="PORT")
|
||||
parser.add_option("-a", "--addr", dest="address", action="store", type=str, default='0.0.0.0',
|
||||
help="address from which to serve traffic (default: %default)", metavar="ADDRESS")
|
||||
parser.add_option("-f", '--user-data-file', dest='user_data_file', action='store',
|
||||
help="user data filename to serve back to incoming requests", metavar='FILE')
|
||||
parser.add_option("-p", "--port", dest="port", action="store", type=int,
|
||||
default=80, metavar="PORT",
|
||||
help="port from which to serve traffic (default: %default)")
|
||||
parser.add_option("-a", "--addr", dest="address", action="store", type=str,
|
||||
default='0.0.0.0', metavar="ADDRESS",
|
||||
help="address from which to serve traffic (default: %default)")
|
||||
parser.add_option("-f", '--user-data-file', dest='user_data_file',
|
||||
action='store', metavar='FILE',
|
||||
help="user data filename to serve back to incoming requests")
|
||||
(options, args) = parser.parse_args()
|
||||
out = dict()
|
||||
out['extra'] = args
|
||||
@ -420,8 +425,8 @@ def extract_opts():
|
||||
|
||||
|
||||
def setup_fetchers(opts):
|
||||
global meta_fetcher
|
||||
global user_fetcher
|
||||
global meta_fetcher # pylint: disable=W0603
|
||||
global user_fetcher # pylint: disable=W0603
|
||||
meta_fetcher = MetaDataHandler(opts)
|
||||
user_fetcher = UserDataHandler(opts)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user