cloud-init-dev team mailing list archive
-
cloud-init-dev team
-
Mailing list archive
-
Message #00867
[Merge] lp:~harlowja/cloud-init/cloud-init-flake8-fixups into lp:cloud-init
Joshua Harlow has proposed merging lp:~harlowja/cloud-init/cloud-init-flake8-fixups into lp:cloud-init.
Requested reviews:
cloud init development team (cloud-init-dev)
For more details, see:
https://code.launchpad.net/~harlowja/cloud-init/cloud-init-flake8-fixups/+merge/294548
--
Your team cloud init development team is requested to review the proposed merge of lp:~harlowja/cloud-init/cloud-init-flake8-fixups into lp:cloud-init.
=== modified file 'cloudinit/config/cc_apt_configure.py'
--- cloudinit/config/cc_apt_configure.py 2016-03-03 22:20:10 +0000
+++ cloudinit/config/cc_apt_configure.py 2016-05-12 18:09:03 +0000
@@ -207,20 +207,20 @@
ks = ent['keyserver']
try:
ent['key'] = getkeybyid(ent['keyid'], ks)
- except:
+ except Exception:
errorlist.append([source, "failed to get key from %s" % ks])
continue
if 'key' in ent:
try:
util.subp(('apt-key', 'add', '-'), ent['key'])
- except:
+ except Exception:
errorlist.append([source, "failed add key"])
try:
contents = "%s\n" % (source)
util.write_file(ent['filename'], contents, omode="ab")
- except:
+ except Exception:
errorlist.append([source,
"failed write to file %s" % ent['filename']])
=== modified file 'cloudinit/config/cc_bootcmd.py'
--- cloudinit/config/cc_bootcmd.py 2015-02-10 21:33:11 +0000
+++ cloudinit/config/cc_bootcmd.py 2016-05-12 18:09:03 +0000
@@ -38,7 +38,7 @@
content = util.shellify(cfg["bootcmd"])
tmpf.write(util.encode_text(content))
tmpf.flush()
- except:
+ except Exception:
util.logexc(log, "Failed to shellify bootcmd")
raise
@@ -49,6 +49,6 @@
env['INSTANCE_ID'] = str(iid)
cmd = ['/bin/sh', tmpf.name]
util.subp(cmd, env=env, capture=False)
- except:
+ except Exception:
util.logexc(log, "Failed to run bootcmd module %s", name)
raise
=== modified file 'cloudinit/config/cc_disk_setup.py'
--- cloudinit/config/cc_disk_setup.py 2016-04-04 19:02:00 +0000
+++ cloudinit/config/cc_disk_setup.py 2016-05-12 18:09:03 +0000
@@ -198,7 +198,7 @@
d_type = ""
try:
d_type = device_type(name)
- except:
+ except Exception:
LOG.warn("Query against device %s failed" % name)
return False
=== modified file 'cloudinit/config/cc_emit_upstart.py'
--- cloudinit/config/cc_emit_upstart.py 2015-03-16 17:20:26 +0000
+++ cloudinit/config/cc_emit_upstart.py 2016-05-12 18:09:03 +0000
@@ -20,8 +20,8 @@
import os
+from cloudinit import log as logging
from cloudinit.settings import PER_ALWAYS
-from cloudinit import log as logging
from cloudinit import util
frequency = PER_ALWAYS
=== modified file 'cloudinit/config/cc_fan.py'
--- cloudinit/config/cc_fan.py 2015-10-09 16:39:23 +0000
+++ cloudinit/config/cc_fan.py 2016-05-12 18:09:03 +0000
@@ -37,8 +37,8 @@
"""
from cloudinit import log as logging
+from cloudinit.settings import PER_INSTANCE
from cloudinit import util
-from cloudinit.settings import PER_INSTANCE
LOG = logging.getLogger(__name__)
=== modified file 'cloudinit/config/cc_final_message.py'
--- cloudinit/config/cc_final_message.py 2016-03-04 06:45:58 +0000
+++ cloudinit/config/cc_final_message.py 2016-05-12 18:09:03 +0000
@@ -66,7 +66,7 @@
try:
contents = "%s - %s - v. %s\n" % (uptime, ts, cver)
util.write_file(boot_fin_fn, contents)
- except:
+ except Exception:
util.logexc(log, "Failed to write boot finished file %s", boot_fin_fn)
if cloud.datasource.is_disconnected:
=== modified file 'cloudinit/config/cc_grub_dpkg.py'
--- cloudinit/config/cc_grub_dpkg.py 2016-03-04 06:45:58 +0000
+++ cloudinit/config/cc_grub_dpkg.py 2016-05-12 18:09:03 +0000
@@ -69,5 +69,5 @@
try:
util.subp(['debconf-set-selections'], dconf_sel)
- except:
+ except Exception:
util.logexc(log, "Failed to run debconf-set-selections for grub-dpkg")
=== modified file 'cloudinit/config/cc_keys_to_console.py'
--- cloudinit/config/cc_keys_to_console.py 2016-03-03 22:20:10 +0000
+++ cloudinit/config/cc_keys_to_console.py 2016-05-12 18:09:03 +0000
@@ -57,6 +57,6 @@
(stdout, _stderr) = util.subp(cmd)
util.multi_log("%s\n" % (stdout.strip()),
stderr=False, console=True)
- except:
+ except Exception:
log.warn("Writing keys to the system console failed!")
raise
=== modified file 'cloudinit/config/cc_lxd.py'
--- cloudinit/config/cc_lxd.py 2016-04-11 19:08:08 +0000
+++ cloudinit/config/cc_lxd.py 2016-05-12 18:09:03 +0000
@@ -111,7 +111,7 @@
data = "\n".join(["set %s %s" % (k, v)
for k, v in debconf.items()]) + "\n"
util.subp(['debconf-communicate'], data)
- except:
+ except Exception:
util.logexc(log, "Failed to run '%s' for lxd with" % dconf_comm)
# Remove the existing configuration file (forces re-generation)
=== modified file 'cloudinit/config/cc_mounts.py'
--- cloudinit/config/cc_mounts.py 2016-03-03 22:20:10 +0000
+++ cloudinit/config/cc_mounts.py 2016-05-12 18:09:03 +0000
@@ -244,7 +244,7 @@
LOG.debug("swap file %s already in use.", fname)
return fname
LOG.debug("swap file %s existed, but not in /proc/swaps", fname)
- except:
+ except Exception:
LOG.warn("swap file %s existed. Error reading /proc/swaps", fname)
return fname
@@ -379,7 +379,7 @@
toks = WS.split(line)
if toks[3].find(comment) != -1:
continue
- except:
+ except Exception:
pass
fstab_lines.append(line)
@@ -390,16 +390,16 @@
if needswap:
try:
util.subp(("swapon", "-a"))
- except:
+ except Exception:
util.logexc(log, "Activating swap via 'swapon -a' failed")
for d in dirs:
try:
util.ensure_dir(d)
- except:
+ except Exception:
util.logexc(log, "Failed to make '%s' config-mount", d)
try:
util.subp(("mount", "-a"))
- except:
+ except Exception:
util.logexc(log, "Activating mounts via 'mount -a' failed")
=== modified file 'cloudinit/config/cc_phone_home.py'
--- cloudinit/config/cc_phone_home.py 2016-04-13 16:35:50 +0000
+++ cloudinit/config/cc_phone_home.py 2016-05-12 18:09:03 +0000
@@ -65,7 +65,7 @@
tries = ph_cfg.get('tries')
try:
tries = int(tries)
- except:
+ except Exception:
tries = 10
util.logexc(log, "Configuration entry 'tries' is not an integer, "
"using %s instead", tries)
@@ -87,7 +87,7 @@
for (n, path) in pubkeys.items():
try:
all_keys[n] = util.load_file(path)
- except:
+ except Exception:
util.logexc(log, "%s: failed to open, can not phone home that "
"data!", path)
@@ -117,6 +117,6 @@
util.read_file_or_url(url, data=real_submit_keys,
retries=tries, sec_between=3,
ssl_details=util.fetch_ssl_details(cloud.paths))
- except:
+ except Exception:
util.logexc(log, "Failed to post phone home data to %s in %s tries",
url, tries)
=== modified file 'cloudinit/config/cc_rightscale_userdata.py'
--- cloudinit/config/cc_rightscale_userdata.py 2015-06-29 14:58:59 +0000
+++ cloudinit/config/cc_rightscale_userdata.py 2016-05-12 18:09:03 +0000
@@ -52,7 +52,7 @@
def handle(name, _cfg, cloud, log, _args):
try:
ud = cloud.get_userdata_raw()
- except:
+ except Exception:
log.debug("Failed to get raw userdata in module %s", name)
return
@@ -63,7 +63,7 @@
"did not find %s in parsed"
" raw userdata"), name, MY_HOOKNAME)
return
- except:
+ except Exception:
util.logexc(log, "Failed to parse query string %s into a dictionary",
ud)
raise
=== modified file 'cloudinit/config/cc_runcmd.py'
--- cloudinit/config/cc_runcmd.py 2015-01-27 19:24:22 +0000
+++ cloudinit/config/cc_runcmd.py 2016-05-12 18:09:03 +0000
@@ -34,5 +34,5 @@
try:
content = util.shellify(cmd)
util.write_file(out_fn, content, 0o700)
- except:
+ except Exception:
util.logexc(log, "Failed to shellify %s into file %s", cmd, out_fn)
=== modified file 'cloudinit/config/cc_scripts_per_boot.py'
--- cloudinit/config/cc_scripts_per_boot.py 2012-06-21 16:12:16 +0000
+++ cloudinit/config/cc_scripts_per_boot.py 2016-05-12 18:09:03 +0000
@@ -35,7 +35,7 @@
runparts_path = os.path.join(cloud.get_cpath(), 'scripts', SCRIPT_SUBDIR)
try:
util.runparts(runparts_path)
- except:
+ except Exception:
log.warn("Failed to run module %s (%s in %s)",
name, SCRIPT_SUBDIR, runparts_path)
raise
=== modified file 'cloudinit/config/cc_scripts_per_instance.py'
--- cloudinit/config/cc_scripts_per_instance.py 2012-06-21 16:12:16 +0000
+++ cloudinit/config/cc_scripts_per_instance.py 2016-05-12 18:09:03 +0000
@@ -35,7 +35,7 @@
runparts_path = os.path.join(cloud.get_cpath(), 'scripts', SCRIPT_SUBDIR)
try:
util.runparts(runparts_path)
- except:
+ except Exception:
log.warn("Failed to run module %s (%s in %s)",
name, SCRIPT_SUBDIR, runparts_path)
raise
=== modified file 'cloudinit/config/cc_scripts_per_once.py'
--- cloudinit/config/cc_scripts_per_once.py 2012-06-21 16:12:16 +0000
+++ cloudinit/config/cc_scripts_per_once.py 2016-05-12 18:09:03 +0000
@@ -35,7 +35,7 @@
runparts_path = os.path.join(cloud.get_cpath(), 'scripts', SCRIPT_SUBDIR)
try:
util.runparts(runparts_path)
- except:
+ except Exception:
log.warn("Failed to run module %s (%s in %s)",
name, SCRIPT_SUBDIR, runparts_path)
raise
=== modified file 'cloudinit/config/cc_scripts_user.py'
--- cloudinit/config/cc_scripts_user.py 2012-06-21 16:12:16 +0000
+++ cloudinit/config/cc_scripts_user.py 2016-05-12 18:09:03 +0000
@@ -36,7 +36,7 @@
runparts_path = os.path.join(cloud.get_ipath_cur(), SCRIPT_SUBDIR)
try:
util.runparts(runparts_path)
- except:
+ except Exception:
log.warn("Failed to run module %s (%s in %s)",
name, SCRIPT_SUBDIR, runparts_path)
raise
=== modified file 'cloudinit/config/cc_scripts_vendor.py'
--- cloudinit/config/cc_scripts_vendor.py 2014-01-15 22:13:24 +0000
+++ cloudinit/config/cc_scripts_vendor.py 2016-05-12 18:09:03 +0000
@@ -37,7 +37,7 @@
try:
util.runparts(runparts_path, exe_prefix=prefix)
- except:
+ except Exception:
log.warn("Failed to run module %s (%s in %s)",
name, SCRIPT_SUBDIR, runparts_path)
raise
=== modified file 'cloudinit/config/cc_seed_random.py'
--- cloudinit/config/cc_seed_random.py 2016-03-08 02:31:25 +0000
+++ cloudinit/config/cc_seed_random.py 2016-05-12 18:09:03 +0000
@@ -24,8 +24,8 @@
from six import BytesIO
+from cloudinit import log as logging
from cloudinit.settings import PER_INSTANCE
-from cloudinit import log as logging
from cloudinit import util
frequency = PER_INSTANCE
=== modified file 'cloudinit/config/cc_set_passwords.py'
--- cloudinit/config/cc_set_passwords.py 2016-03-14 18:24:27 +0000
+++ cloudinit/config/cc_set_passwords.py 2016-05-12 18:09:03 +0000
@@ -155,7 +155,7 @@
cmd = filter(None, cmd) # Remove empty arguments
util.subp(cmd)
log.debug("Restarted the ssh daemon")
- except:
+ except Exception:
util.logexc(log, "Restarting of the ssh daemon failed")
if len(errors):
=== modified file 'cloudinit/config/cc_snappy.py'
--- cloudinit/config/cc_snappy.py 2015-09-15 17:53:36 +0000
+++ cloudinit/config/cc_snappy.py 2016-05-12 18:09:03 +0000
@@ -47,12 +47,12 @@
"""
from cloudinit import log as logging
+from cloudinit.settings import PER_INSTANCE
from cloudinit import util
-from cloudinit.settings import PER_INSTANCE
import glob
+import os
import tempfile
-import os
LOG = logging.getLogger(__name__)
=== modified file 'cloudinit/config/cc_ssh.py'
--- cloudinit/config/cc_ssh.py 2016-03-03 22:20:10 +0000
+++ cloudinit/config/cc_ssh.py 2016-05-12 18:09:03 +0000
@@ -57,7 +57,7 @@
for f in glob.glob(key_pth):
try:
util.del_file(f)
- except:
+ except Exception:
util.logexc(log, "Failed deleting key file %s", f)
if "ssh_keys" in cfg:
@@ -78,7 +78,7 @@
with util.SeLinuxGuard("/etc/ssh", recursive=True):
util.subp(cmd, capture=False)
log.debug("Generated a key for %s from %s", pair[0], pair[1])
- except:
+ except Exception:
util.logexc(log, "Failed generated a key for %s from %s",
pair[0], pair[1])
else:
@@ -122,7 +122,7 @@
keys.extend(cfgkeys)
apply_credentials(keys, user, disable_root, disable_root_opts)
- except:
+ except Exception:
util.logexc(log, "Applying ssh credentials failed!")
=== modified file 'cloudinit/config/cc_ssh_import_id.py'
--- cloudinit/config/cc_ssh_import_id.py 2014-09-10 18:32:37 +0000
+++ cloudinit/config/cc_ssh_import_id.py 2016-05-12 18:09:03 +0000
@@ -52,14 +52,14 @@
else:
try:
import_ids = user_cfg['ssh_import_id']
- except:
+ except Exception:
log.debug("User %s is not configured for ssh_import_id", user)
continue
try:
import_ids = util.uniq_merge(import_ids)
import_ids = [str(i) for i in import_ids]
- except:
+ except Exception:
log.debug("User %s is not correctly configured for ssh_import_id",
user)
continue
=== modified file 'cloudinit/config/cc_ubuntu_init_switch.py'
--- cloudinit/config/cc_ubuntu_init_switch.py 2014-10-24 01:02:37 +0000
+++ cloudinit/config/cc_ubuntu_init_switch.py 2016-05-12 18:09:03 +0000
@@ -40,10 +40,10 @@
mechanism you've used to switch the init system.
"""
+from cloudinit.distros import ubuntu
+from cloudinit import log as logging
from cloudinit.settings import PER_INSTANCE
-from cloudinit import log as logging
from cloudinit import util
-from cloudinit.distros import ubuntu
import os
import time
=== modified file 'cloudinit/distros/__init__.py'
--- cloudinit/distros/__init__.py 2016-04-06 15:23:47 +0000
+++ cloudinit/distros/__init__.py 2016-05-12 18:09:03 +0000
@@ -50,8 +50,8 @@
LOG = logging.getLogger(__name__)
+@six.add_metaclass(abc.ABCMeta)
class Distro(object):
- __metaclass__ = abc.ABCMeta
usr_lib_exec = "/usr/lib"
hosts_fn = "/etc/hosts"
@@ -97,7 +97,7 @@
try:
res = os.lstat('/run/systemd/system')
return stat.S_ISDIR(res.st_mode)
- except:
+ except Exception:
return False
@abc.abstractmethod
=== modified file 'cloudinit/distros/debian.py'
--- cloudinit/distros/debian.py 2016-04-15 16:02:51 +0000
+++ cloudinit/distros/debian.py 2016-05-12 18:09:03 +0000
@@ -25,8 +25,8 @@
from cloudinit import distros
from cloudinit import helpers
from cloudinit import log as logging
+from cloudinit import net
from cloudinit import util
-from cloudinit import net
from cloudinit.distros.parsers.hostname import HostnameConf
@@ -221,7 +221,7 @@
msg = "removed %s with known contents" % path
else:
msg = (bmsg + " '%s' exists with user configured content." % path)
- except:
+ except Exception:
msg = bmsg + " %s exists, but could not be read." % path
LOG.warn(msg)
=== modified file 'cloudinit/handlers/__init__.py'
--- cloudinit/handlers/__init__.py 2015-04-16 21:00:19 +0000
+++ cloudinit/handlers/__init__.py 2016-05-12 18:09:03 +0000
@@ -71,8 +71,8 @@
key=(lambda e: 0 - len(e)))
+@six.add_metaclass(abc.ABCMeta)
class Handler(object):
- __metaclass__ = abc.ABCMeta
def __init__(self, frequency, version=2):
self.handler_version = version
@@ -118,7 +118,7 @@
mod.handle_part(data, content_type, filename, payload)
else:
raise ValueError("Unknown module version %s" % (mod_ver))
- except:
+ except Exception:
util.logexc(LOG, "Failed calling handler %s (%s, %s, %s) with "
"frequency %s", mod, content_type, filename, mod_ver,
frequency)
@@ -157,7 +157,7 @@
# register if it fails starting.
handlers.register(mod, initialized=True)
pdata['handlercount'] = curcount + 1
- except:
+ except Exception:
util.logexc(LOG, "Failed at registering python file: %s (part "
"handler %s)", modfname, curcount)
=== modified file 'cloudinit/handlers/cloud_config.py'
--- cloudinit/handlers/cloud_config.py 2015-01-21 22:56:53 +0000
+++ cloudinit/handlers/cloud_config.py 2016-05-12 18:09:03 +0000
@@ -158,6 +158,6 @@
for i in ("\n", "\r", "\t"):
filename = filename.replace(i, " ")
self.file_names.append(filename.strip())
- except:
+ except Exception:
util.logexc(LOG, "Failed at merging in cloud config part from %s",
filename)
=== modified file 'cloudinit/handlers/upstart_job.py'
--- cloudinit/handlers/upstart_job.py 2015-01-21 22:56:53 +0000
+++ cloudinit/handlers/upstart_job.py 2016-05-12 18:09:03 +0000
@@ -80,7 +80,7 @@
return False
try:
(version_out, _err) = util.subp(["initctl", "version"])
- except:
+ except Exception:
util.logexc(LOG, "initctl version failed")
return False
=== modified file 'cloudinit/helpers.py'
--- cloudinit/helpers.py 2016-04-29 15:23:08 +0000
+++ cloudinit/helpers.py 2016-05-12 18:09:03 +0000
@@ -86,7 +86,7 @@
name = canon_sem_name(name)
try:
yield self._acquire(name, freq)
- except:
+ except Exception:
if clear_on_fail:
self.clear(name, freq)
raise
@@ -219,7 +219,7 @@
ds_cfg = self._ds.get_config_obj()
if ds_cfg and isinstance(ds_cfg, (dict)):
d_cfgs.append(ds_cfg)
- except:
+ except Exception:
util.logexc(LOG, "Failed loading of datasource config object "
"from %s", self._ds)
return d_cfgs
@@ -230,7 +230,7 @@
e_fn = os.environ[CFG_ENV_NAME]
try:
e_cfgs.append(util.read_conf(e_fn))
- except:
+ except Exception:
util.logexc(LOG, 'Failed loading of env. config from %s',
e_fn)
return e_cfgs
@@ -251,7 +251,7 @@
if cc_fn and os.path.isfile(cc_fn):
try:
i_cfgs.append(util.read_conf(cc_fn))
- except:
+ except Exception:
util.logexc(LOG, 'Failed loading of cloud-config from %s',
cc_fn)
return i_cfgs
@@ -268,7 +268,7 @@
for c_fn in self._fns:
try:
cfgs.append(util.read_conf(c_fn))
- except:
+ except Exception:
util.logexc(LOG, "Failed loading of configuration from %s",
c_fn)
=== modified file 'cloudinit/net/__init__.py'
--- cloudinit/net/__init__.py 2016-04-15 20:21:05 +0000
+++ cloudinit/net/__init__.py 2016-05-12 18:09:03 +0000
@@ -26,9 +26,9 @@
import shlex
from cloudinit import log as logging
+from cloudinit.net import network_state
+from cloudinit.net.udev import generate_udev_rule
from cloudinit import util
-from .udev import generate_udev_rule
-from . import network_state
LOG = logging.getLogger(__name__)
@@ -40,16 +40,16 @@
"pointtopoint", "media", "mtu", "hostname", "leasehours", "leasetime",
"vendor", "client", "bootfile", "server", "hwaddr", "provider", "frame",
"netnum", "endpoint", "local", "ttl",
- ]
+]
NET_CONFIG_COMMANDS = [
"pre-up", "up", "post-up", "down", "pre-down", "post-down",
- ]
+]
NET_CONFIG_BRIDGE_OPTIONS = [
"bridge_ageing", "bridge_bridgeprio", "bridge_fd", "bridge_gcinit",
"bridge_hello", "bridge_maxage", "bridge_maxwait", "bridge_stp",
- ]
+]
DEFAULT_PRIMARY_INTERFACE = 'eth0'
@@ -399,9 +399,7 @@
def render_persistent_net(network_state):
- ''' Given state, emit udev rules to map
- mac to ifname
- '''
+ '''Given state, emit udev rules to map mac to ifname.'''
content = ""
interfaces = network_state.get('interfaces')
for iface in interfaces.values():
@@ -465,7 +463,7 @@
def render_route(route, indent=""):
- """ When rendering routes for an iface, in some cases applying a route
+ """When rendering routes for an iface, in some cases applying a route
may result in the route command returning non-zero which produces
some confusing output for users manually using ifup/ifdown[1]. To
that end, we will optionally include an '|| true' postfix to each
@@ -530,7 +528,7 @@
def render_interfaces(network_state):
- ''' Given state, emit etc/network/interfaces content '''
+ '''Given state, emit etc/network/interfaces content.'''
content = ""
interfaces = network_state.get('interfaces')
=== modified file 'cloudinit/net/network_state.py'
--- cloudinit/net/network_state.py 2016-03-23 16:05:22 +0000
+++ cloudinit/net/network_state.py 2016-05-12 18:09:03 +0000
@@ -36,7 +36,7 @@
return network_state
-class NetworkState:
+class NetworkState(object):
def __init__(self, version=NETWORK_STATE_VERSION, config=None):
self.version = version
self.config = config
@@ -53,7 +53,7 @@
def get_command_handlers(self):
METHOD_PREFIX = 'handle_'
methods = filter(lambda x: callable(getattr(self, x)) and
- x.startswith(METHOD_PREFIX), dir(self))
+ x.startswith(METHOD_PREFIX), dir(self))
handlers = {}
for m in methods:
key = m.replace(METHOD_PREFIX, '')
@@ -379,8 +379,9 @@
if __name__ == '__main__':
+ import random
import sys
- import random
+
from cloudinit import net
def load_config(nc):
=== modified file 'cloudinit/net/udev.py'
--- cloudinit/net/udev.py 2016-03-10 21:37:30 +0000
+++ cloudinit/net/udev.py 2016-05-12 18:09:03 +0000
@@ -48,7 +48,7 @@
compose_udev_equality('DRIVERS', '?*'),
compose_udev_attr_equality('address', mac),
compose_udev_setting('NAME', interface),
- ])
+ ])
return '%s\n' % rule
# vi: ts=4 expandtab syntax=python
=== modified file 'cloudinit/netinfo.py'
--- cloudinit/netinfo.py 2015-01-21 22:56:53 +0000
+++ cloudinit/netinfo.py 2016-05-12 18:09:03 +0000
@@ -20,10 +20,11 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
-import cloudinit.util as util
-from cloudinit.log import logging
import re
+from cloudinit import log as logging
+from cloudinit import util
+
from prettytable import PrettyTable
LOG = logging.getLogger()
@@ -163,7 +164,7 @@
def getgateway():
try:
routes = route_info()
- except:
+ except Exception:
pass
else:
for r in routes.get('ipv4', []):
=== modified file 'cloudinit/reporting/handlers.py'
--- cloudinit/reporting/handlers.py 2015-09-17 19:56:51 +0000
+++ cloudinit/reporting/handlers.py 2016-05-12 18:09:03 +0000
@@ -4,9 +4,9 @@
import json
import six
-from ..registry import DictRegistry
-from .. import (url_helper, util)
-from .. import log as logging
+from cloudinit import log as logging
+from cloudinit.registry import DictRegistry
+from cloudinit import (url_helper, util)
LOG = logging.getLogger(__name__)
@@ -36,7 +36,7 @@
input_level = level
try:
level = getattr(logging, level.upper())
- except:
+ except Exception:
LOG.warn("invalid level '%s', using WARN", input_level)
level = logging.WARN
self.level = level
@@ -81,7 +81,7 @@
self.endpoint, data=json.dumps(event.as_dict()),
timeout=self.timeout,
retries=self.retries, ssl_details=self.ssl_details)
- except:
+ except Exception:
LOG.warn("failed posting event: %s" % event.as_string())
=== modified file 'cloudinit/sources/DataSourceAzure.py'
--- cloudinit/sources/DataSourceAzure.py 2016-03-24 16:51:31 +0000
+++ cloudinit/sources/DataSourceAzure.py 2016-05-12 18:09:03 +0000
@@ -27,11 +27,12 @@
from xml.dom import minidom
+from cloudinit.sources.helpers.azure import get_metadata_from_fabric
+
from cloudinit import log as logging
from cloudinit.settings import PER_ALWAYS
from cloudinit import sources
from cloudinit import util
-from cloudinit.sources.helpers.azure import get_metadata_from_fabric
LOG = logging.getLogger(__name__)
@@ -40,7 +41,8 @@
AGENT_START = ['service', 'walinuxagent', 'start']
BOUNCE_COMMAND = [
'sh', '-xc',
- "i=$interface; x=0; ifdown $i || x=$?; ifup $i || x=$?; exit $x"]
+ "i=$interface; x=0; ifdown $i || x=$?; ifup $i || x=$?; exit $x"
+]
BUILTIN_DS_CONFIG = {
'agent_command': AGENT_START,
@@ -51,7 +53,7 @@
'policy': True,
'command': BOUNCE_COMMAND,
'hostname_command': 'hostname',
- },
+ },
'disk_aliases': {'ephemeral0': '/dev/sdb'},
}
@@ -60,7 +62,7 @@
'ephemeral0': {'table_type': 'gpt',
'layout': [100],
'overwrite': True},
- },
+ },
'fs_setup': [{'filesystem': 'ext4',
'device': 'ephemeral0.1',
'replace_fs': 'ntfs'}],
@@ -312,7 +314,7 @@
file_count = 0
try:
file_count = util.mount_cb(device, count_files)
- except:
+ except Exception:
return None
LOG.debug("fabric prepared ephmeral0.1 has %s files on it", file_count)
=== modified file 'cloudinit/sources/DataSourceBigstep.py'
--- cloudinit/sources/DataSourceBigstep.py 2016-03-07 12:30:08 +0000
+++ cloudinit/sources/DataSourceBigstep.py 2016-05-12 18:09:03 +0000
@@ -4,13 +4,13 @@
# Author: Alexandru Sirbu <alexandru.sirbu@xxxxxxxxxxx>
#
+import errno
import json
-import errno
from cloudinit import log as logging
from cloudinit import sources
+from cloudinit import url_helper
from cloudinit import util
-from cloudinit import url_helper
LOG = logging.getLogger(__name__)
=== modified file 'cloudinit/sources/DataSourceCloudSigma.py'
--- cloudinit/sources/DataSourceCloudSigma.py 2016-04-12 16:57:50 +0000
+++ cloudinit/sources/DataSourceCloudSigma.py 2016-05-12 18:09:03 +0000
@@ -19,10 +19,11 @@
import os
import re
+from cloudinit.cs_utils import Cepko
+
from cloudinit import log as logging
from cloudinit import sources
from cloudinit import util
-from cloudinit.cs_utils import Cepko
LOG = logging.getLogger(__name__)
@@ -77,7 +78,7 @@
try:
server_context = self.cepko.all().result
server_meta = server_context['meta']
- except:
+ except Exception:
# TODO: check for explicit "config on", and then warn
# but since no explicit config is available now, just debug.
LOG.debug("CloudSigma: Unable to read from serial port")
=== modified file 'cloudinit/sources/DataSourceCloudStack.py'
--- cloudinit/sources/DataSourceCloudStack.py 2016-04-28 15:33:43 +0000
+++ cloudinit/sources/DataSourceCloudStack.py 2016-05-12 18:09:03 +0000
@@ -25,14 +25,15 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import os
-import time
from socket import inet_ntoa
from struct import pack
+import time
from cloudinit import ec2_utils as ec2
from cloudinit import log as logging
+from cloudinit import sources
from cloudinit import url_helper as uhelp
-from cloudinit import sources, util
+from cloudinit import util
LOG = logging.getLogger(__name__)
=== modified file 'cloudinit/sources/DataSourceDigitalOcean.py'
--- cloudinit/sources/DataSourceDigitalOcean.py 2016-03-04 06:45:58 +0000
+++ cloudinit/sources/DataSourceDigitalOcean.py 2016-05-12 18:09:03 +0000
@@ -14,10 +14,10 @@
# 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 cloudinit import ec2_utils
from cloudinit import log as logging
+from cloudinit import sources
from cloudinit import util
-from cloudinit import sources
-from cloudinit import ec2_utils
import functools
=== modified file 'cloudinit/sources/DataSourceGCE.py'
--- cloudinit/sources/DataSourceGCE.py 2015-07-22 12:06:34 +0000
+++ cloudinit/sources/DataSourceGCE.py 2016-05-12 18:09:03 +0000
@@ -18,9 +18,9 @@
from base64 import b64decode
from cloudinit import log as logging
-from cloudinit import util
from cloudinit import sources
from cloudinit import url_helper
+from cloudinit import util
LOG = logging.getLogger(__name__)
@@ -71,7 +71,7 @@
index = public_key.index(':')
if index > 0:
return public_key[(index + 1):]
- except:
+ except Exception:
return public_key
def get_data(self):
=== modified file 'cloudinit/sources/DataSourceNoCloud.py'
--- cloudinit/sources/DataSourceNoCloud.py 2016-04-12 15:54:31 +0000
+++ cloudinit/sources/DataSourceNoCloud.py 2016-05-12 18:09:03 +0000
@@ -61,7 +61,7 @@
if parse_cmdline_data(self.cmdline_id, md):
found.append("cmdline")
mydata = _merge_new_seed(mydata, {'meta-data': md})
- except:
+ except Exception:
util.logexc(LOG, "Unable to parse command line data")
return False
@@ -288,7 +288,7 @@
continue
try:
(k, v) = item.split("=", 1)
- except:
+ except Exception:
k = item
v = None
if k in s2l:
=== modified file 'cloudinit/sources/DataSourceOVF.py'
--- cloudinit/sources/DataSourceOVF.py 2016-03-29 18:38:47 +0000
+++ cloudinit/sources/DataSourceOVF.py 2016-05-12 18:09:03 +0000
@@ -30,13 +30,20 @@
from cloudinit import log as logging
from cloudinit import sources
from cloudinit import util
-from .helpers.vmware.imc.config import Config
-from .helpers.vmware.imc.config_file import ConfigFile
-from .helpers.vmware.imc.config_nic import NicConfigurator
-from .helpers.vmware.imc.guestcust_event import GuestCustEventEnum
-from .helpers.vmware.imc.guestcust_state import GuestCustStateEnum
-from .helpers.vmware.imc.guestcust_error import GuestCustErrorEnum
-from .helpers.vmware.imc.guestcust_util import (
+
+from cloudinit.sources.helpers.vmware.imc.config \
+ import Config
+from cloudinit.sources.helpers.vmware.imc.config_file \
+ import ConfigFile
+from cloudinit.sources.helpers.vmware.imc.config_nic \
+ import NicConfigurator
+from cloudinit.sources.helpers.vmware.imc.guestcust_event \
+ import GuestCustEventEnum
+from cloudinit.sources.helpers.vmware.imc.guestcust_state \
+ import GuestCustStateEnum
+from cloudinit.sourceshelpers.vmware.imc.guestcust_error \
+ import GuestCustErrorEnum
+from cloudinit.sourceshelpers.vmware.imc.guestcust_util import (
set_customization_status,
get_nics_to_enable,
enable_nics
@@ -262,7 +269,7 @@
elif prop == "user-data":
try:
ud = base64.decodestring(val)
- except:
+ except Exception:
ud = val
return (md, ud, cfg)
@@ -277,7 +284,7 @@
try:
contents = util.load_file(full_fn)
return (fname, contents)
- except:
+ except Exception:
util.logexc(LOG, "Failed loading ovf file %s", full_fn)
return (None, False)
=== modified file 'cloudinit/sources/__init__.py'
--- cloudinit/sources/__init__.py 2016-04-04 16:31:28 +0000
+++ cloudinit/sources/__init__.py 2016-05-12 18:09:03 +0000
@@ -45,10 +45,9 @@
pass
+@six.add_metaclass(abc.ABCMeta)
class DataSource(object):
- __metaclass__ = abc.ABCMeta
-
def __init__(self, sys_cfg, distro, paths, ud_proc=None):
self.sys_cfg = sys_cfg
self.distro = distro
=== modified file 'cloudinit/sources/helpers/azure.py'
--- cloudinit/sources/helpers/azure.py 2016-02-16 22:00:29 +0000
+++ cloudinit/sources/helpers/azure.py 2016-05-12 18:09:03 +0000
@@ -5,6 +5,7 @@
import struct
import tempfile
import time
+
from contextlib import contextmanager
from xml.etree import ElementTree
=== modified file 'cloudinit/sources/helpers/openstack.py'
--- cloudinit/sources/helpers/openstack.py 2016-03-23 19:17:10 +0000
+++ cloudinit/sources/helpers/openstack.py 2016-05-12 18:09:03 +0000
@@ -145,8 +145,8 @@
return device
+@six.add_metaclass(abc.ABCMeta)
class BaseReader(object):
- __metaclass__ = abc.ABCMeta
def __init__(self, base_path):
self.base_path = base_path
@@ -475,7 +475,7 @@
def convert_vendordata_json(data, recurse=True):
- """ data: a loaded json *object* (strings, arrays, dicts).
+ """data: a loaded json *object* (strings, arrays, dicts).
return something suitable for cloudinit vendordata_raw.
if data is:
=== modified file 'cloudinit/sources/helpers/vmware/imc/boot_proto.py'
--- cloudinit/sources/helpers/vmware/imc/boot_proto.py 2016-01-20 02:24:54 +0000
+++ cloudinit/sources/helpers/vmware/imc/boot_proto.py 2016-05-12 18:09:03 +0000
@@ -18,7 +18,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
-class BootProtoEnum:
+class BootProtoEnum(object):
"""Specifies the NIC Boot Settings."""
DHCP = 'dhcp'
=== modified file 'cloudinit/sources/helpers/vmware/imc/config.py'
--- cloudinit/sources/helpers/vmware/imc/config.py 2016-01-20 02:24:54 +0000
+++ cloudinit/sources/helpers/vmware/imc/config.py 2016-05-12 18:09:03 +0000
@@ -20,7 +20,7 @@
from .nic import Nic
-class Config:
+class Config(object):
"""
Stores the Contents specified in the Customization
Specification file.
=== modified file 'cloudinit/sources/helpers/vmware/imc/config_nic.py'
--- cloudinit/sources/helpers/vmware/imc/config_nic.py 2016-03-11 19:29:15 +0000
+++ cloudinit/sources/helpers/vmware/imc/config_nic.py 2016-05-12 18:09:03 +0000
@@ -26,7 +26,7 @@
logger = logging.getLogger(__name__)
-class NicConfigurator:
+class NicConfigurator(object):
def __init__(self, nics):
"""
Initialize the Nic Configurator
=== modified file 'cloudinit/sources/helpers/vmware/imc/config_source.py'
--- cloudinit/sources/helpers/vmware/imc/config_source.py 2016-01-05 20:05:11 +0000
+++ cloudinit/sources/helpers/vmware/imc/config_source.py 2016-05-12 18:09:03 +0000
@@ -18,6 +18,6 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
-class ConfigSource:
+class ConfigSource(object):
"""Specifies a source for the Config Content."""
pass
=== modified file 'cloudinit/sources/helpers/vmware/imc/guestcust_error.py'
--- cloudinit/sources/helpers/vmware/imc/guestcust_error.py 2016-03-08 20:41:08 +0000
+++ cloudinit/sources/helpers/vmware/imc/guestcust_error.py 2016-05-12 18:09:03 +0000
@@ -18,7 +18,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
-class GuestCustErrorEnum:
+class GuestCustErrorEnum(object):
"""Specifies different errors of Guest Customization engine"""
GUESTCUST_ERROR_SUCCESS = 0
=== modified file 'cloudinit/sources/helpers/vmware/imc/guestcust_event.py'
--- cloudinit/sources/helpers/vmware/imc/guestcust_event.py 2016-03-08 20:41:08 +0000
+++ cloudinit/sources/helpers/vmware/imc/guestcust_event.py 2016-05-12 18:09:03 +0000
@@ -18,7 +18,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
-class GuestCustEventEnum:
+class GuestCustEventEnum(object):
"""Specifies different types of Guest Customization Events"""
GUESTCUST_EVENT_CUSTOMIZE_FAILED = 100
=== modified file 'cloudinit/sources/helpers/vmware/imc/guestcust_state.py'
--- cloudinit/sources/helpers/vmware/imc/guestcust_state.py 2016-03-08 20:41:08 +0000
+++ cloudinit/sources/helpers/vmware/imc/guestcust_state.py 2016-05-12 18:09:03 +0000
@@ -18,7 +18,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
-class GuestCustStateEnum:
+class GuestCustStateEnum(object):
"""Specifies different states of Guest Customization engine"""
GUESTCUST_STATE_RUNNING = 4
=== modified file 'cloudinit/sources/helpers/vmware/imc/guestcust_util.py'
--- cloudinit/sources/helpers/vmware/imc/guestcust_util.py 2016-03-11 21:29:28 +0000
+++ cloudinit/sources/helpers/vmware/imc/guestcust_util.py 2016-05-12 18:09:03 +0000
@@ -23,8 +23,8 @@
from cloudinit import util
+from .guestcust_event import GuestCustEventEnum
from .guestcust_state import GuestCustStateEnum
-from .guestcust_event import GuestCustEventEnum
logger = logging.getLogger(__name__)
=== modified file 'cloudinit/sources/helpers/vmware/imc/ipv4_mode.py'
--- cloudinit/sources/helpers/vmware/imc/ipv4_mode.py 2016-01-20 02:24:54 +0000
+++ cloudinit/sources/helpers/vmware/imc/ipv4_mode.py 2016-05-12 18:09:03 +0000
@@ -18,7 +18,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
-class Ipv4ModeEnum:
+class Ipv4ModeEnum(object):
"""
The IPv4 configuration mode which directly represents the user's goal.
=== modified file 'cloudinit/sources/helpers/vmware/imc/nic_base.py'
--- cloudinit/sources/helpers/vmware/imc/nic_base.py 2016-01-20 02:24:54 +0000
+++ cloudinit/sources/helpers/vmware/imc/nic_base.py 2016-05-12 18:09:03 +0000
@@ -18,7 +18,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
-class NicBase:
+class NicBase(object):
"""
Define what are expected of each nic.
The following properties should be provided in an implementation class.
@@ -93,7 +93,7 @@
raise NotImplementedError('Check constraints on properties')
-class StaticIpv4Base:
+class StaticIpv4Base(object):
"""
Define what are expected of a static IPv4 setting
The following properties should be provided in an implementation class.
@@ -124,7 +124,7 @@
raise NotImplementedError('Ipv4 GATEWAY')
-class StaticIpv6Base:
+class StaticIpv6Base(object):
"""Define what are expected of a static IPv6 setting
The following properties should be provided in an implementation class.
"""
=== modified file 'cloudinit/stages.py'
--- cloudinit/stages.py 2016-04-15 16:16:14 +0000
+++ cloudinit/stages.py 2016-05-12 18:09:03 +0000
@@ -44,10 +44,10 @@
from cloudinit import importer
from cloudinit import log as logging
from cloudinit import net
+from cloudinit.reporting import events
from cloudinit import sources
from cloudinit import type_utils
from cloudinit import util
-from cloudinit.reporting import events
LOG = logging.getLogger(__name__)
@@ -483,7 +483,7 @@
c_handlers.initialized.remove(mod)
try:
handlers.call_end(mod, data, frequency)
- except:
+ except Exception:
util.logexc(LOG, "Failed to finalize handler: %s", mod)
try:
=== modified file 'cloudinit/url_helper.py'
--- cloudinit/url_helper.py 2016-03-03 22:20:10 +0000
+++ cloudinit/url_helper.py 2016-05-12 18:09:03 +0000
@@ -28,8 +28,9 @@
from email.utils import parsedate
from functools import partial
+
+import oauthlib.oauth1 as oauth1
from requests import exceptions
-import oauthlib.oauth1 as oauth1
from six.moves.urllib.parse import (
urlparse, urlunparse,
@@ -61,7 +62,7 @@
SSL_ENABLED = True
if _REQ_VER >= LooseVersion('0.7.0') and _REQ_VER < LooseVersion('1.0.0'):
CONFIG_ENABLED = True
-except:
+except ImportError:
pass
=== modified file 'cloudinit/user_data.py'
--- cloudinit/user_data.py 2015-04-16 21:00:19 +0000
+++ cloudinit/user_data.py 2016-05-12 18:09:03 +0000
@@ -178,7 +178,7 @@
payload = util.load_yaml(msg.get_payload(decode=True))
if payload:
payload_idx = payload.get('launch-index')
- except:
+ except Exception:
pass
# Header overrides contents, for now (?) or the other way around?
if header_idx is not None:
=== modified file 'cloudinit/util.py'
--- cloudinit/util.py 2016-03-24 19:30:03 +0000
+++ cloudinit/util.py 2016-05-12 18:09:03 +0000
@@ -288,7 +288,7 @@
try:
child_cb(*args, **kwargs)
os._exit(0)
- except:
+ except Exception:
logexc(LOG, "Failed forking and calling callback %s",
type_utils.obj_name(child_cb))
os._exit(1)
@@ -472,7 +472,7 @@
try:
toks = [x for x in toks if int(x) < 256 and int(x) >= 0]
- except:
+ except Exception:
return False
return len(toks) == 4
@@ -1210,7 +1210,7 @@
else:
try:
cmdline = load_file("/proc/cmdline").strip()
- except:
+ except Exception:
cmdline = ""
PROC_CMDLINE = cmdline
@@ -1380,7 +1380,7 @@
if not os.path.exists(target_fn):
try:
(key, url, content) = get_cmdline_url()
- except:
+ except Exception:
logexc(LOG, "Failed fetching command line url")
return
try:
@@ -1391,7 +1391,7 @@
elif key and not content:
LOG.debug(("Command line key %s with url"
" %s had no contents"), key, url)
- except:
+ except Exception:
logexc(LOG, "Failed writing url content to %s", target_fn)
@@ -1449,7 +1449,7 @@
mp = m.group(2)
fstype = m.group(3)
opts = m.group(4)
- except:
+ except Exception:
continue
# If the name of the mount point contains spaces these
# can be escaped as '\040', so undo that..
@@ -1575,7 +1575,7 @@
def time_rfc2822():
try:
ts = time.strftime("%a, %d %b %Y %H:%M:%S %z", time.gmtime())
- except:
+ except Exception:
ts = "??"
return ts
@@ -1601,7 +1601,7 @@
bootup = buf.value
uptime_str = now - bootup
- except:
+ except Exception:
logexc(LOG, "Unable to read uptime using method: %s" % method)
return uptime_str
@@ -2055,7 +2055,7 @@
tmsg += " (N/A)"
try:
logfunc(msg + tmsg)
- except:
+ except Exception:
pass
return ret
=== modified file 'test-requirements.txt'
--- test-requirements.txt 2015-02-10 20:32:32 +0000
+++ test-requirements.txt 2016-05-12 18:09:03 +0000
@@ -1,7 +1,8 @@
httpretty>=0.7.1
mock
nose
-pep8==1.5.7
+pep8>=1.5.7
pyflakes
contextlib2
setuptools
+flake8>=2.5.4
=== modified file 'tox.ini'
--- tox.ini 2016-03-04 06:45:58 +0000
+++ tox.ini 2016-05-12 18:09:03 +0000
@@ -30,3 +30,8 @@
pyflakes
setenv =
LC_ALL = C
+
+[flake8]
+
+ignore=H404,H405,H105,H301,H104,H403,H101
+exclude = .venv,.tox,dist,doc,*egg,.git,build,tools,tests