pep8 and pylint fixes
This commit is contained in:
@@ -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]
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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():
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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")
|
||||
@@ -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":
|
||||
@@ -245,6 +244,7 @@ def simple_device_part_info(devpath):
|
||||
x = (ret.group(1), ret.group(2))
|
||||
return x
|
||||
|
||||
|
||||
class Bunch:
|
||||
def __init__(self, **kwds):
|
||||
self.__dict__.update(kwds)
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user