pep8 and pylint fixes
This commit is contained in:
@@ -75,7 +75,7 @@ def load_power_state(cfg):
|
|||||||
','.join(opt_map.keys()))
|
','.join(opt_map.keys()))
|
||||||
|
|
||||||
delay = pstate.get("delay", "now")
|
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).")
|
raise TypeError("power_state[delay] must be 'now' or '+m' (minutes).")
|
||||||
|
|
||||||
args = ["shutdown", opt_map[mode], delay]
|
args = ["shutdown", opt_map[mode], delay]
|
||||||
|
|||||||
@@ -73,7 +73,7 @@ class Distro(object):
|
|||||||
self._apply_hostname(hostname)
|
self._apply_hostname(hostname)
|
||||||
|
|
||||||
@abc.abstractmethod
|
@abc.abstractmethod
|
||||||
def package_command(self, cmd, args=None):
|
def package_command(self, cmd, args=None, pkgs=None):
|
||||||
raise NotImplementedError()
|
raise NotImplementedError()
|
||||||
|
|
||||||
@abc.abstractmethod
|
@abc.abstractmethod
|
||||||
@@ -370,7 +370,7 @@ class Distro(object):
|
|||||||
# Import SSH keys
|
# Import SSH keys
|
||||||
if 'ssh_authorized_keys' in kwargs:
|
if 'ssh_authorized_keys' in kwargs:
|
||||||
keys = set(kwargs['ssh_authorized_keys']) or []
|
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
|
return True
|
||||||
|
|
||||||
@@ -776,7 +776,7 @@ def normalize_users_groups(cfg, distro):
|
|||||||
# Just add it on at the end...
|
# Just add it on at the end...
|
||||||
base_users.append({'name': 'default'})
|
base_users.append({'name': 'default'})
|
||||||
elif isinstance(base_users, (dict)):
|
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)):
|
elif isinstance(base_users, (str, basestring)):
|
||||||
# Just append it on to be re-parsed later
|
# Just append it on to be re-parsed later
|
||||||
base_users += ",default"
|
base_users += ",default"
|
||||||
|
|||||||
@@ -142,7 +142,10 @@ class Distro(distros.Distro):
|
|||||||
# This ensures that the correct tz will be used for the system
|
# This ensures that the correct tz will be used for the system
|
||||||
util.copy(tz_file, self.tz_local_fn)
|
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()
|
e = os.environ.copy()
|
||||||
# See: http://tiny.cc/kg91fw
|
# See: http://tiny.cc/kg91fw
|
||||||
# Or: http://tiny.cc/mh91fw
|
# 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
|
# This ensures that the correct tz will be used for the system
|
||||||
util.copy(tz_file, self.tz_local_fn)
|
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']
|
cmd = ['yum']
|
||||||
# If enabled, then yum will be tolerant of errors on the command line
|
# If enabled, then yum will be tolerant of errors on the command line
|
||||||
# with regard to packages.
|
# with regard to packages.
|
||||||
|
|||||||
@@ -19,9 +19,6 @@
|
|||||||
# You should have received a copy of the GNU General Public License
|
# You should have received a copy of the GNU General Public License
|
||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
from StringIO import StringIO
|
|
||||||
|
|
||||||
import csv
|
|
||||||
import os
|
import os
|
||||||
import pwd
|
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-nistp384-cert-v01@openssh.com",
|
||||||
"ecdsa-sha2-nistp521-cert-v01@openssh.com")
|
"ecdsa-sha2-nistp521-cert-v01@openssh.com")
|
||||||
|
|
||||||
|
|
||||||
class AuthKeyLine(object):
|
class AuthKeyLine(object):
|
||||||
def __init__(self, source, keytype=None, base64=None,
|
def __init__(self, source, keytype=None, base64=None,
|
||||||
comment=None, options=None):
|
comment=None, options=None):
|
||||||
@@ -141,14 +139,14 @@ class AuthKeyLineParser(object):
|
|||||||
ent = line.strip()
|
ent = line.strip()
|
||||||
try:
|
try:
|
||||||
(keytype, base64, comment) = parse_ssh_key(ent)
|
(keytype, base64, comment) = parse_ssh_key(ent)
|
||||||
except TypeError as e:
|
except TypeError:
|
||||||
(keyopts, remain) = self._extract_options(ent)
|
(keyopts, remain) = self._extract_options(ent)
|
||||||
if options is None:
|
if options is None:
|
||||||
options = keyopts
|
options = keyopts
|
||||||
|
|
||||||
try:
|
try:
|
||||||
(keytype, base64, comment) = parse_ssh_key(remain)
|
(keytype, base64, comment) = parse_ssh_key(remain)
|
||||||
except TypeError as e:
|
except TypeError:
|
||||||
return AuthKeyLine(src_line)
|
return AuthKeyLine(src_line)
|
||||||
|
|
||||||
return AuthKeyLine(src_line, keytype=keytype, base64=base64,
|
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")
|
fn = os.path.join("/proc/", str(pid), "environ")
|
||||||
try:
|
try:
|
||||||
contents = load_file(fn)
|
contents = load_file(fn)
|
||||||
toks = contents.split("\0")
|
toks = contents.split("\x00")
|
||||||
for tok in toks:
|
for tok in toks:
|
||||||
if tok == "":
|
if tok == "":
|
||||||
continue
|
continue
|
||||||
|
|||||||
@@ -17,13 +17,13 @@ from cloudinit import version
|
|||||||
# General information about the project.
|
# General information about the project.
|
||||||
project = 'Cloud-Init'
|
project = 'Cloud-Init'
|
||||||
|
|
||||||
# -- General configuration -----------------------------------------------------
|
# -- General configuration ----------------------------------------------------
|
||||||
|
|
||||||
# If your documentation needs a minimal Sphinx version, state it here.
|
# If your documentation needs a minimal Sphinx version, state it here.
|
||||||
#needs_sphinx = '1.0'
|
#needs_sphinx = '1.0'
|
||||||
|
|
||||||
# Add any Sphinx extension module names here, as strings. They can be extensions
|
# Add any Sphinx extension module names here, as strings. They can be
|
||||||
# coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
|
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
|
||||||
extensions = [
|
extensions = [
|
||||||
'sphinx.ext.intersphinx',
|
'sphinx.ext.intersphinx',
|
||||||
]
|
]
|
||||||
@@ -55,7 +55,7 @@ exclude_patterns = []
|
|||||||
# output. They are ignored by default.
|
# output. They are ignored by default.
|
||||||
show_authors = False
|
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
|
# The theme to use for HTML and HTML Help pages. See the documentation for
|
||||||
# a list of builtin themes.
|
# a list of builtin themes.
|
||||||
|
|||||||
@@ -183,6 +183,7 @@ class FilesystemMockingTestCase(ResourceUsingTestCase):
|
|||||||
setattr(mod, f, trap_func)
|
setattr(mod, f, trap_func)
|
||||||
self.patched_funcs.append((mod, f, func))
|
self.patched_funcs.append((mod, f, func))
|
||||||
|
|
||||||
|
|
||||||
def populate_dir(path, files):
|
def populate_dir(path, files):
|
||||||
os.makedirs(path)
|
os.makedirs(path)
|
||||||
for (name, content) in files.iteritems():
|
for (name, content) in files.iteritems():
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
from cloudinit import helpers
|
from cloudinit import helpers
|
||||||
from tests.unittests.helpers import populate_dir
|
|
||||||
from cloudinit.sources import DataSourceNoCloud
|
from cloudinit.sources import DataSourceNoCloud
|
||||||
from cloudinit import util
|
from cloudinit import util
|
||||||
|
from tests.unittests.helpers import populate_dir
|
||||||
|
|
||||||
from mocker import MockerTestCase
|
from mocker import MockerTestCase
|
||||||
import os
|
import os
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
from mocker import MockerTestCase
|
from mocker import MockerTestCase
|
||||||
|
|
||||||
from cloudinit import cloud
|
from cloudinit import cloud
|
||||||
from cloudinit import helpers
|
|
||||||
from cloudinit import util
|
from cloudinit import util
|
||||||
|
|
||||||
from cloudinit.config import cc_growpart
|
from cloudinit.config import cc_growpart
|
||||||
@@ -9,9 +8,7 @@ from cloudinit.config import cc_growpart
|
|||||||
import errno
|
import errno
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
import mocker
|
|
||||||
import re
|
import re
|
||||||
import stat
|
|
||||||
|
|
||||||
# growpart:
|
# growpart:
|
||||||
# mode: auto # off, on, auto, 'growpart', 'parted'
|
# mode: auto # off, on, auto, 'growpart', 'parted'
|
||||||
@@ -85,6 +82,7 @@ growpart disk partition
|
|||||||
Resize partition 1 on /dev/sda
|
Resize partition 1 on /dev/sda
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
class TestDisabled(MockerTestCase):
|
class TestDisabled(MockerTestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(TestDisabled, self).setUp()
|
super(TestDisabled, self).setUp()
|
||||||
@@ -106,6 +104,7 @@ class TestDisabled(MockerTestCase):
|
|||||||
|
|
||||||
self.handle(self.name, config, self.cloud_init, self.log, self.args)
|
self.handle(self.name, config, self.cloud_init, self.log, self.args)
|
||||||
|
|
||||||
|
|
||||||
class TestConfig(MockerTestCase):
|
class TestConfig(MockerTestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(TestConfig, self).setUp()
|
super(TestConfig, self).setUp()
|
||||||
@@ -125,9 +124,9 @@ class TestConfig(MockerTestCase):
|
|||||||
def test_no_resizers_auto_is_fine(self):
|
def test_no_resizers_auto_is_fine(self):
|
||||||
subp = self.mocker.replace(util.subp, passthrough=False)
|
subp = self.mocker.replace(util.subp, passthrough=False)
|
||||||
subp(['parted', '--help'], env={'LANG': 'C'})
|
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'})
|
subp(['growpart', '--help'], env={'LANG': 'C'})
|
||||||
self.mocker.result((HELP_GROWPART_NO_RESIZE,""))
|
self.mocker.result((HELP_GROWPART_NO_RESIZE, ""))
|
||||||
self.mocker.replay()
|
self.mocker.replay()
|
||||||
|
|
||||||
config = {'growpart': {'mode': 'auto'}}
|
config = {'growpart': {'mode': 'auto'}}
|
||||||
@@ -136,7 +135,7 @@ class TestConfig(MockerTestCase):
|
|||||||
def test_no_resizers_mode_growpart_is_exception(self):
|
def test_no_resizers_mode_growpart_is_exception(self):
|
||||||
subp = self.mocker.replace(util.subp, passthrough=False)
|
subp = self.mocker.replace(util.subp, passthrough=False)
|
||||||
subp(['growpart', '--help'], env={'LANG': 'C'})
|
subp(['growpart', '--help'], env={'LANG': 'C'})
|
||||||
self.mocker.result((HELP_GROWPART_NO_RESIZE,""))
|
self.mocker.result((HELP_GROWPART_NO_RESIZE, ""))
|
||||||
self.mocker.replay()
|
self.mocker.replay()
|
||||||
|
|
||||||
config = {'growpart': {'mode': "growpart"}}
|
config = {'growpart': {'mode': "growpart"}}
|
||||||
@@ -146,7 +145,7 @@ class TestConfig(MockerTestCase):
|
|||||||
def test_mode_auto_prefers_parted(self):
|
def test_mode_auto_prefers_parted(self):
|
||||||
subp = self.mocker.replace(util.subp, passthrough=False)
|
subp = self.mocker.replace(util.subp, passthrough=False)
|
||||||
subp(['parted', '--help'], env={'LANG': 'C'})
|
subp(['parted', '--help'], env={'LANG': 'C'})
|
||||||
self.mocker.result((HELP_PARTED_RESIZE,""))
|
self.mocker.result((HELP_PARTED_RESIZE, ""))
|
||||||
self.mocker.replay()
|
self.mocker.replay()
|
||||||
|
|
||||||
ret = cc_growpart.resizer_factory(mode="auto")
|
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)
|
self.handle(self.name, {}, self.cloud_init, self.log, self.args)
|
||||||
finally:
|
finally:
|
||||||
cc_growpart.RESIZERS = orig_resizers
|
cc_growpart.RESIZERS = orig_resizers
|
||||||
|
|
||||||
|
|
||||||
class TestResize(MockerTestCase):
|
class TestResize(MockerTestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
@@ -196,7 +195,7 @@ class TestResize(MockerTestCase):
|
|||||||
real_stat = os.stat
|
real_stat = os.stat
|
||||||
resize_calls = []
|
resize_calls = []
|
||||||
|
|
||||||
class myresizer():
|
class myresizer(object):
|
||||||
def resize(self, diskdev, partnum, partdev):
|
def resize(self, diskdev, partnum, partdev):
|
||||||
resize_calls.append((diskdev, partnum, partdev))
|
resize_calls.append((diskdev, partnum, partdev))
|
||||||
if partdev == "/dev/YYda2":
|
if partdev == "/dev/YYda2":
|
||||||
@@ -224,7 +223,7 @@ class TestResize(MockerTestCase):
|
|||||||
if f[0] == name:
|
if f[0] == name:
|
||||||
return f
|
return f
|
||||||
return None
|
return None
|
||||||
|
|
||||||
self.assertEqual(cc_growpart.RESIZE.NOCHANGE,
|
self.assertEqual(cc_growpart.RESIZE.NOCHANGE,
|
||||||
find("/dev/XXda1", resized)[1])
|
find("/dev/XXda1", resized)[1])
|
||||||
self.assertEqual(cc_growpart.RESIZE.CHANGED,
|
self.assertEqual(cc_growpart.RESIZE.CHANGED,
|
||||||
@@ -244,7 +243,8 @@ def simple_device_part_info(devpath):
|
|||||||
ret = re.search("([^0-9]*)([0-9]*)$", devpath)
|
ret = re.search("([^0-9]*)([0-9]*)$", devpath)
|
||||||
x = (ret.group(1), ret.group(2))
|
x = (ret.group(1), ret.group(2))
|
||||||
return x
|
return x
|
||||||
|
|
||||||
|
|
||||||
class Bunch:
|
class Bunch:
|
||||||
def __init__(self, **kwds):
|
def __init__(self, **kwds):
|
||||||
self.__dict__.update(kwds)
|
self.__dict__.update(kwds)
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
from unittest import TestCase
|
|
||||||
from cloudinit import ssh_util
|
from cloudinit import ssh_util
|
||||||
|
from unittest import TestCase
|
||||||
|
|
||||||
|
|
||||||
VALID_CONTENT = {
|
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'
|
'command="echo \'Please login as the user \"ubuntu\" rather than the'
|
||||||
'user \"root\".\';echo;sleep 10"')
|
'user \"root\".\';echo;sleep 10"')
|
||||||
|
|
||||||
|
|
||||||
class TestAuthKeyLineParser(TestCase):
|
class TestAuthKeyLineParser(TestCase):
|
||||||
def test_simple_parse(self):
|
def test_simple_parse(self):
|
||||||
# test key line with common 3 fields (keytype, base64, comment)
|
# test key line with common 3 fields (keytype, base64, comment)
|
||||||
@@ -61,7 +62,7 @@ class TestAuthKeyLineParser(TestCase):
|
|||||||
self.assertFalse(key.options)
|
self.assertFalse(key.options)
|
||||||
self.assertFalse(key.comment)
|
self.assertFalse(key.comment)
|
||||||
self.assertEqual(key.keytype, ktype)
|
self.assertEqual(key.keytype, ktype)
|
||||||
|
|
||||||
def test_parse_with_keyoptions(self):
|
def test_parse_with_keyoptions(self):
|
||||||
# test key line with options in it
|
# test key line with options in it
|
||||||
parser = ssh_util.AuthKeyLineParser()
|
parser = ssh_util.AuthKeyLineParser()
|
||||||
|
|||||||
Reference in New Issue
Block a user