summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorScott Moser <smoser@ubuntu.com>2013-03-07 14:54:25 -0500
committerScott Moser <smoser@ubuntu.com>2013-03-07 14:54:25 -0500
commitdca9b6c94e10f9f42ad0f129ae6fd38ebb44f4b5 (patch)
tree0b4ac8f1e658e07bda378c75b5fb33940a14265b
parent90ed3dee9672ba2756dd4a303f94e3de47e70404 (diff)
downloadvyos-cloud-init-dca9b6c94e10f9f42ad0f129ae6fd38ebb44f4b5.tar.gz
vyos-cloud-init-dca9b6c94e10f9f42ad0f129ae6fd38ebb44f4b5.zip
pep8 and pylint fixes
-rw-r--r--cloudinit/config/cc_power_state_change.py2
-rw-r--r--cloudinit/distros/__init__.py6
-rw-r--r--cloudinit/distros/debian.py5
-rw-r--r--cloudinit/distros/rhel.py5
-rw-r--r--cloudinit/ssh_util.py10
-rw-r--r--cloudinit/util.py2
-rw-r--r--doc/rtd/conf.py8
-rw-r--r--tests/unittests/helpers.py1
-rw-r--r--tests/unittests/test_datasource/test_nocloud.py2
-rw-r--r--tests/unittests/test_handler/test_handler_growpart.py22
-rw-r--r--tests/unittests/test_sshutil.py5
11 files changed, 37 insertions, 31 deletions
diff --git a/cloudinit/config/cc_power_state_change.py b/cloudinit/config/cc_power_state_change.py
index aefa3aff..de0c0bbd 100644
--- a/cloudinit/config/cc_power_state_change.py
+++ b/cloudinit/config/cc_power_state_change.py
@@ -75,7 +75,7 @@ def load_power_state(cfg):
','.join(opt_map.keys()))
delay = pstate.get("delay", "now")
- if delay != "now" and not re.match("\+[0-9]+", delay):
+ if delay != "now" and not re.match(r"\+[0-9]+", delay):
raise TypeError("power_state[delay] must be 'now' or '+m' (minutes).")
args = ["shutdown", opt_map[mode], delay]
diff --git a/cloudinit/distros/__init__.py b/cloudinit/distros/__init__.py
index 0db4aac7..2a2d8216 100644
--- a/cloudinit/distros/__init__.py
+++ b/cloudinit/distros/__init__.py
@@ -73,7 +73,7 @@ class Distro(object):
self._apply_hostname(hostname)
@abc.abstractmethod
- def package_command(self, cmd, args=None):
+ def package_command(self, cmd, args=None, pkgs=None):
raise NotImplementedError()
@abc.abstractmethod
@@ -370,7 +370,7 @@ class Distro(object):
# Import SSH keys
if 'ssh_authorized_keys' in kwargs:
keys = set(kwargs['ssh_authorized_keys']) or []
- ssh_util.setup_user_keys(keys, name, key_prefix=None)
+ ssh_util.setup_user_keys(keys, name, options=None)
return True
@@ -776,7 +776,7 @@ def normalize_users_groups(cfg, distro):
# Just add it on at the end...
base_users.append({'name': 'default'})
elif isinstance(base_users, (dict)):
- base_users['default'] = base_users.get('default', True)
+ base_users['default'] = dict(base_users).get('default', True)
elif isinstance(base_users, (str, basestring)):
# Just append it on to be re-parsed later
base_users += ",default"
diff --git a/cloudinit/distros/debian.py b/cloudinit/distros/debian.py
index 1a8e927b..1f2848d2 100644
--- a/cloudinit/distros/debian.py
+++ b/cloudinit/distros/debian.py
@@ -142,7 +142,10 @@ class Distro(distros.Distro):
# This ensures that the correct tz will be used for the system
util.copy(tz_file, self.tz_local_fn)
- def package_command(self, command, args=None, pkgs=[]):
+ def package_command(self, command, args=None, pkgs=None):
+ if pkgs is None:
+ pkgs = []
+
e = os.environ.copy()
# See: http://tiny.cc/kg91fw
# Or: http://tiny.cc/mh91fw
diff --git a/cloudinit/distros/rhel.py b/cloudinit/distros/rhel.py
index 2f91e386..9fee5fd1 100644
--- a/cloudinit/distros/rhel.py
+++ b/cloudinit/distros/rhel.py
@@ -208,7 +208,10 @@ class Distro(distros.Distro):
# This ensures that the correct tz will be used for the system
util.copy(tz_file, self.tz_local_fn)
- def package_command(self, command, args=None, pkgs=[]):
+ def package_command(self, command, args=None, pkgs=None):
+ if pkgs is None:
+ pkgs = []
+
cmd = ['yum']
# If enabled, then yum will be tolerant of errors on the command line
# with regard to packages.
diff --git a/cloudinit/ssh_util.py b/cloudinit/ssh_util.py
index 65fab117..95133236 100644
--- a/cloudinit/ssh_util.py
+++ b/cloudinit/ssh_util.py
@@ -19,9 +19,6 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
-from StringIO import StringIO
-
-import csv
import os
import pwd
@@ -42,6 +39,7 @@ VALID_KEY_TYPES = ("rsa", "dsa", "ssh-rsa", "ssh-dss", "ecdsa",
"ecdsa-sha2-nistp384-cert-v01@openssh.com",
"ecdsa-sha2-nistp521-cert-v01@openssh.com")
+
class AuthKeyLine(object):
def __init__(self, source, keytype=None, base64=None,
comment=None, options=None):
@@ -141,14 +139,14 @@ class AuthKeyLineParser(object):
ent = line.strip()
try:
(keytype, base64, comment) = parse_ssh_key(ent)
- except TypeError as e:
+ except TypeError:
(keyopts, remain) = self._extract_options(ent)
if options is None:
options = keyopts
-
+
try:
(keytype, base64, comment) = parse_ssh_key(remain)
- except TypeError as e:
+ except TypeError:
return AuthKeyLine(src_line)
return AuthKeyLine(src_line, keytype=keytype, base64=base64,
diff --git a/cloudinit/util.py b/cloudinit/util.py
index d0a6f81c..afde2066 100644
--- a/cloudinit/util.py
+++ b/cloudinit/util.py
@@ -1530,7 +1530,7 @@ def get_proc_env(pid):
fn = os.path.join("/proc/", str(pid), "environ")
try:
contents = load_file(fn)
- toks = contents.split("\0")
+ toks = contents.split("\x00")
for tok in toks:
if tok == "":
continue
diff --git a/doc/rtd/conf.py b/doc/rtd/conf.py
index 87fc40ab..c9ae79f4 100644
--- a/doc/rtd/conf.py
+++ b/doc/rtd/conf.py
@@ -17,13 +17,13 @@ from cloudinit import version
# General information about the project.
project = 'Cloud-Init'
-# -- General configuration -----------------------------------------------------
+# -- General configuration ----------------------------------------------------
# If your documentation needs a minimal Sphinx version, state it here.
#needs_sphinx = '1.0'
-# Add any Sphinx extension module names here, as strings. They can be extensions
-# coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
+# Add any Sphinx extension module names here, as strings. They can be
+# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
extensions = [
'sphinx.ext.intersphinx',
]
@@ -55,7 +55,7 @@ exclude_patterns = []
# output. They are ignored by default.
show_authors = False
-# -- Options for HTML output ---------------------------------------------------
+# -- Options for HTML output --------------------------------------------------
# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
diff --git a/tests/unittests/helpers.py b/tests/unittests/helpers.py
index 91a50e18..904677f1 100644
--- a/tests/unittests/helpers.py
+++ b/tests/unittests/helpers.py
@@ -183,6 +183,7 @@ class FilesystemMockingTestCase(ResourceUsingTestCase):
setattr(mod, f, trap_func)
self.patched_funcs.append((mod, f, func))
+
def populate_dir(path, files):
os.makedirs(path)
for (name, content) in files.iteritems():
diff --git a/tests/unittests/test_datasource/test_nocloud.py b/tests/unittests/test_datasource/test_nocloud.py
index 28e0a472..62fc5358 100644
--- a/tests/unittests/test_datasource/test_nocloud.py
+++ b/tests/unittests/test_datasource/test_nocloud.py
@@ -1,7 +1,7 @@
from cloudinit import helpers
-from tests.unittests.helpers import populate_dir
from cloudinit.sources import DataSourceNoCloud
from cloudinit import util
+from tests.unittests.helpers import populate_dir
from mocker import MockerTestCase
import os
diff --git a/tests/unittests/test_handler/test_handler_growpart.py b/tests/unittests/test_handler/test_handler_growpart.py
index 74c254e0..325244f2 100644
--- a/tests/unittests/test_handler/test_handler_growpart.py
+++ b/tests/unittests/test_handler/test_handler_growpart.py
@@ -1,7 +1,6 @@
from mocker import MockerTestCase
from cloudinit import cloud
-from cloudinit import helpers
from cloudinit import util
from cloudinit.config import cc_growpart
@@ -9,9 +8,7 @@ from cloudinit.config import cc_growpart
import errno
import logging
import os
-import mocker
import re
-import stat
# growpart:
# mode: auto # off, on, auto, 'growpart', 'parted'
@@ -85,6 +82,7 @@ growpart disk partition
Resize partition 1 on /dev/sda
"""
+
class TestDisabled(MockerTestCase):
def setUp(self):
super(TestDisabled, self).setUp()
@@ -106,6 +104,7 @@ class TestDisabled(MockerTestCase):
self.handle(self.name, config, self.cloud_init, self.log, self.args)
+
class TestConfig(MockerTestCase):
def setUp(self):
super(TestConfig, self).setUp()
@@ -125,9 +124,9 @@ class TestConfig(MockerTestCase):
def test_no_resizers_auto_is_fine(self):
subp = self.mocker.replace(util.subp, passthrough=False)
subp(['parted', '--help'], env={'LANG': 'C'})
- self.mocker.result((HELP_PARTED_NO_RESIZE,""))
+ self.mocker.result((HELP_PARTED_NO_RESIZE, ""))
subp(['growpart', '--help'], env={'LANG': 'C'})
- self.mocker.result((HELP_GROWPART_NO_RESIZE,""))
+ self.mocker.result((HELP_GROWPART_NO_RESIZE, ""))
self.mocker.replay()
config = {'growpart': {'mode': 'auto'}}
@@ -136,7 +135,7 @@ class TestConfig(MockerTestCase):
def test_no_resizers_mode_growpart_is_exception(self):
subp = self.mocker.replace(util.subp, passthrough=False)
subp(['growpart', '--help'], env={'LANG': 'C'})
- self.mocker.result((HELP_GROWPART_NO_RESIZE,""))
+ self.mocker.result((HELP_GROWPART_NO_RESIZE, ""))
self.mocker.replay()
config = {'growpart': {'mode': "growpart"}}
@@ -146,7 +145,7 @@ class TestConfig(MockerTestCase):
def test_mode_auto_prefers_parted(self):
subp = self.mocker.replace(util.subp, passthrough=False)
subp(['parted', '--help'], env={'LANG': 'C'})
- self.mocker.result((HELP_PARTED_RESIZE,""))
+ self.mocker.result((HELP_PARTED_RESIZE, ""))
self.mocker.replay()
ret = cc_growpart.resizer_factory(mode="auto")
@@ -173,7 +172,7 @@ class TestConfig(MockerTestCase):
self.handle(self.name, {}, self.cloud_init, self.log, self.args)
finally:
cc_growpart.RESIZERS = orig_resizers
-
+
class TestResize(MockerTestCase):
def setUp(self):
@@ -196,7 +195,7 @@ class TestResize(MockerTestCase):
real_stat = os.stat
resize_calls = []
- class myresizer():
+ class myresizer(object):
def resize(self, diskdev, partnum, partdev):
resize_calls.append((diskdev, partnum, partdev))
if partdev == "/dev/YYda2":
@@ -224,7 +223,7 @@ class TestResize(MockerTestCase):
if f[0] == name:
return f
return None
-
+
self.assertEqual(cc_growpart.RESIZE.NOCHANGE,
find("/dev/XXda1", resized)[1])
self.assertEqual(cc_growpart.RESIZE.CHANGED,
@@ -244,7 +243,8 @@ def simple_device_part_info(devpath):
ret = re.search("([^0-9]*)([0-9]*)$", devpath)
x = (ret.group(1), ret.group(2))
return x
-
+
+
class Bunch:
def __init__(self, **kwds):
self.__dict__.update(kwds)
diff --git a/tests/unittests/test_sshutil.py b/tests/unittests/test_sshutil.py
index 2415d06f..d8662cac 100644
--- a/tests/unittests/test_sshutil.py
+++ b/tests/unittests/test_sshutil.py
@@ -1,5 +1,5 @@
-from unittest import TestCase
from cloudinit import ssh_util
+from unittest import TestCase
VALID_CONTENT = {
@@ -34,6 +34,7 @@ TEST_OPTIONS = ("no-port-forwarding,no-agent-forwarding,no-X11-forwarding,"
'command="echo \'Please login as the user \"ubuntu\" rather than the'
'user \"root\".\';echo;sleep 10"')
+
class TestAuthKeyLineParser(TestCase):
def test_simple_parse(self):
# test key line with common 3 fields (keytype, base64, comment)
@@ -61,7 +62,7 @@ class TestAuthKeyLineParser(TestCase):
self.assertFalse(key.options)
self.assertFalse(key.comment)
self.assertEqual(key.keytype, ktype)
-
+
def test_parse_with_keyoptions(self):
# test key line with options in it
parser = ssh_util.AuthKeyLineParser()