summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--tests/unittests/test__init__.py21
-rw-r--r--tests/unittests/test_builtin_handlers.py1
-rw-r--r--tests/unittests/test_datasource/test_maas.py2
-rw-r--r--tests/unittests/test_handler/test_handler_ca_certs.py14
-rw-r--r--tests/unittests/test_userdata.py4
-rwxr-xr-xtools/hacking.py7
-rwxr-xr-xtools/mock-meta.py65
7 files changed, 59 insertions, 55 deletions
diff --git a/tests/unittests/test__init__.py b/tests/unittests/test__init__.py
index af18955d..464c8c2f 100644
--- a/tests/unittests/test__init__.py
+++ b/tests/unittests/test__init__.py
@@ -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()
diff --git a/tests/unittests/test_builtin_handlers.py b/tests/unittests/test_builtin_handlers.py
index 84d85d4d..5bba8bc9 100644
--- a/tests/unittests/test_builtin_handlers.py
+++ b/tests/unittests/test_builtin_handlers.py
@@ -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
diff --git a/tests/unittests/test_datasource/test_maas.py b/tests/unittests/test_datasource/test_maas.py
index 261c410a..8a155f39 100644
--- a/tests/unittests/test_datasource/test_maas.py
+++ b/tests/unittests/test_datasource/test_maas.py
@@ -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
diff --git a/tests/unittests/test_handler/test_handler_ca_certs.py b/tests/unittests/test_handler/test_handler_ca_certs.py
index 1f96e992..948de4c4 100644
--- a/tests/unittests/test_handler/test_handler_ca_certs.py
+++ b/tests/unittests/test_handler/test_handler_ca_certs.py
@@ -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)
diff --git a/tests/unittests/test_userdata.py b/tests/unittests/test_userdata.py
index 861642b6..fbbf07f2 100644
--- a/tests/unittests/test_userdata.py
+++ b/tests/unittests/test_userdata.py
@@ -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"
diff --git a/tools/hacking.py b/tools/hacking.py
index d0c27d25..a2e6e829 100755
--- a/tools/hacking.py
+++ b/tools/hacking.py
@@ -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"
diff --git a/tools/mock-meta.py b/tools/mock-meta.py
index 4548e4ae..78838f64 100755
--- a/tools/mock-meta.py
+++ b/tools/mock-meta.py
@@ -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)