Skip to content

Commit 5afe4cd

Browse files
Joshua Powerssmoser
authored andcommitted
pylint: fix all logging warnings
This will change all instances of LOG.warn to LOG.warning as warn is now a deprecated method. It will also make sure any logging uses lazy logging by passing string format arguments as function parameters.
1 parent 33816e9 commit 5afe4cd

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+239
-202
lines changed

.pylintrc

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,29 @@ jobs=4
66

77
[MESSAGES CONTROL]
88

9-
# Errors only
10-
disable=C, F, I, R, W
9+
# Errors and warings with some filtered:
10+
# W0105(pointless-string-statement)
11+
# W0107(unnecessary-pass)
12+
# W0201(attribute-defined-outside-init)
13+
# W0212(protected-access)
14+
# W0221(arguments-differ)
15+
# W0222(signature-differs)
16+
# W0223(abstract-method)
17+
# W0231(super-init-not-called)
18+
# W0311(bad-indentation)
19+
# W0511(fixme)
20+
# W0602(global-variable-not-assigned)
21+
# W0603(global-statement)
22+
# W0611(unused-import)
23+
# W0612(unused-variable)
24+
# W0613(unused-argument)
25+
# W0621(redefined-outer-name)
26+
# W0622(redefined-builtin)
27+
# W0631(undefined-loop-variable)
28+
# W0703(broad-except)
29+
# W1401(anomalous-backslash-in-string)
30+
31+
disable=C, F, I, R, W0105, W0107, W0201, W0212, W0221, W0222, W0223, W0231, W0311, W0511, W0602, W0603, W0611, W0612, W0613, W0621, W0622, W0631, W0703, W1401
1132

1233

1334
[REPORTS]
@@ -25,7 +46,7 @@ reports=no
2546
# (useful for modules/projects where namespaces are manipulated during runtime
2647
# and thus existing member attributes cannot be deduced by static analysis. It
2748
# supports qualified module names, as well as Unix pattern matching.
28-
ignored-modules=six.moves,pkg_resources
49+
ignored-modules=six.moves,pkg_resources,httplib,http.client
2950

3051
# List of class names for which member attributes should not be checked (useful
3152
# for classes with dynamically set attributes). This supports the use of

cloudinit/cloud.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ def run(self, name, functor, args, freq=None, clear_on_fail=False):
5656
def get_template_filename(self, name):
5757
fn = self.paths.template_tpl % (name)
5858
if not os.path.isfile(fn):
59-
LOG.warn("No template found at %s for template named %s", fn, name)
59+
LOG.warning("No template found at %s for template named %s",
60+
fn, name)
6061
return None
6162
return fn
6263

cloudinit/cmd/main.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,8 @@ def main_init(name, args):
405405
errfmt_orig = errfmt
406406
(outfmt, errfmt) = util.get_output_cfg(mods.cfg, name)
407407
if outfmt_orig != outfmt or errfmt_orig != errfmt:
408-
LOG.warn("Stdout, stderr changing to (%s, %s)", outfmt, errfmt)
408+
LOG.warning("Stdout, stderr changing to (%s, %s)",
409+
outfmt, errfmt)
409410
(outfmt, errfmt) = util.fixup_output(mods.cfg, name)
410411
except Exception:
411412
util.logexc(LOG, "Failed to re-adjust output redirection!")
@@ -427,15 +428,15 @@ def di_report_warn(datasource, cfg):
427428

428429
dicfg = cfg.get('di_report', {})
429430
if not isinstance(dicfg, dict):
430-
LOG.warn("di_report config not a dictionary: %s", dicfg)
431+
LOG.warning("di_report config not a dictionary: %s", dicfg)
431432
return
432433

433434
dslist = dicfg.get('datasource_list')
434435
if dslist is None:
435-
LOG.warn("no 'datasource_list' found in di_report.")
436+
LOG.warning("no 'datasource_list' found in di_report.")
436437
return
437438
elif not isinstance(dslist, list):
438-
LOG.warn("di_report/datasource_list not a list: %s", dslist)
439+
LOG.warning("di_report/datasource_list not a list: %s", dslist)
439440
return
440441

441442
# ds.__module__ is like cloudinit.sources.DataSourceName
@@ -444,8 +445,8 @@ def di_report_warn(datasource, cfg):
444445
if modname.startswith(sources.DS_PREFIX):
445446
modname = modname[len(sources.DS_PREFIX):]
446447
else:
447-
LOG.warn("Datasource '%s' came from unexpected module '%s'.",
448-
datasource, modname)
448+
LOG.warning("Datasource '%s' came from unexpected module '%s'.",
449+
datasource, modname)
449450

450451
if modname in dslist:
451452
LOG.debug("used datasource '%s' from '%s' was in di_report's list: %s",
@@ -571,10 +572,10 @@ def main_single(name, args):
571572
mod_args,
572573
mod_freq)
573574
if failures:
574-
LOG.warn("Ran %s but it failed!", mod_name)
575+
LOG.warning("Ran %s but it failed!", mod_name)
575576
return 1
576577
elif not which_ran:
577-
LOG.warn("Did not run %s, does it exist?", mod_name)
578+
LOG.warning("Did not run %s, does it exist?", mod_name)
578579
return 1
579580
else:
580581
# Guess it worked

cloudinit/config/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def fixup_module(mod, def_freq=PER_INSTANCE):
3737
else:
3838
freq = mod.frequency
3939
if freq and freq not in FREQUENCIES:
40-
LOG.warn("Module %s has an unknown frequency %s", mod, freq)
40+
LOG.warning("Module %s has an unknown frequency %s", mod, freq)
4141
if not hasattr(mod, 'distros'):
4242
setattr(mod, 'distros', [])
4343
if not hasattr(mod, 'osfamilies'):

cloudinit/config/cc_apt_configure.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -347,8 +347,8 @@ def dpkg_reconfigure(packages, target=None):
347347
unhandled.append(pkg)
348348

349349
if len(unhandled):
350-
LOG.warn("The following packages were installed and preseeded, "
351-
"but cannot be unconfigured: %s", unhandled)
350+
LOG.warning("The following packages were installed and preseeded, "
351+
"but cannot be unconfigured: %s", unhandled)
352352

353353
if len(to_config):
354354
util.subp(['dpkg-reconfigure', '--frontend=noninteractive'] +
@@ -441,15 +441,15 @@ def rename_apt_lists(new_mirrors, target=None):
441441
os.rename(filename, newname)
442442
except OSError:
443443
# since this is a best effort task, warn with but don't fail
444-
LOG.warn("Failed to rename apt list:", exc_info=True)
444+
LOG.warning("Failed to rename apt list:", exc_info=True)
445445

446446

447447
def mirror_to_placeholder(tmpl, mirror, placeholder):
448448
"""mirror_to_placeholder
449449
replace the specified mirror in a template with a placeholder string
450450
Checks for existance of the expected mirror and warns if not found"""
451451
if mirror not in tmpl:
452-
LOG.warn("Expected mirror '%s' not found in: %s", mirror, tmpl)
452+
LOG.warning("Expected mirror '%s' not found in: %s", mirror, tmpl)
453453
return tmpl.replace(mirror, placeholder)
454454

455455

@@ -525,7 +525,8 @@ def generate_sources_list(cfg, release, mirrors, cloud):
525525
if not template_fn:
526526
template_fn = cloud.get_template_filename('sources.list')
527527
if not template_fn:
528-
LOG.warn("No template found, not rendering /etc/apt/sources.list")
528+
LOG.warning("No template found, "
529+
"not rendering /etc/apt/sources.list")
529530
return
530531
tmpl = util.load_file(template_fn)
531532

cloudinit/config/cc_disk_setup.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ def update_fs_setup_devices(disk_setup, tformer):
181181
# update it with the response from 'tformer'
182182
for definition in disk_setup:
183183
if not isinstance(definition, dict):
184-
LOG.warn("entry in disk_setup not a dict: %s", definition)
184+
LOG.warning("entry in disk_setup not a dict: %s", definition)
185185
continue
186186

187187
origname = definition.get('device')
@@ -279,7 +279,7 @@ def is_device_valid(name, partition=False):
279279
try:
280280
d_type = device_type(name)
281281
except Exception:
282-
LOG.warn("Query against device %s failed" % name)
282+
LOG.warning("Query against device %s failed", name)
283283
return False
284284

285285
if partition and d_type == 'part':
@@ -372,7 +372,7 @@ def find_device_node(device, fs_type=None, label=None, valid_targets=None,
372372
if not raw_device_used:
373373
return (device, False)
374374

375-
LOG.warn("Failed to find device during available device search.")
375+
LOG.warning("Failed to find device during available device search.")
376376
return (None, False)
377377

378378

@@ -638,7 +638,7 @@ def purge_disk(device):
638638
if d['type'] not in ["disk", "crypt"]:
639639
wipefs_cmd = [WIPEFS_CMD, "--all", "/dev/%s" % d['name']]
640640
try:
641-
LOG.info("Purging filesystem on /dev/%s" % d['name'])
641+
LOG.info("Purging filesystem on /dev/%s", d['name'])
642642
util.subp(wipefs_cmd)
643643
except Exception:
644644
raise Exception("Failed FS purge of /dev/%s" % d['name'])
@@ -700,7 +700,7 @@ def exec_mkpart_gpt(device, layout):
700700
[SGDISK_CMD,
701701
'-t', '{}:{}'.format(index, partition_type), device])
702702
except Exception:
703-
LOG.warn("Failed to partition device %s" % device)
703+
LOG.warning("Failed to partition device %s", device)
704704
raise
705705

706706
read_parttbl(device)
@@ -736,7 +736,7 @@ def mkpart(device, definition):
736736
# ensure that we get a real device rather than a symbolic link
737737
device = os.path.realpath(device)
738738

739-
LOG.debug("Checking values for %s definition" % device)
739+
LOG.debug("Checking values for %s definition", device)
740740
overwrite = definition.get('overwrite', False)
741741
layout = definition.get('layout', False)
742742
table_type = definition.get('table_type', 'mbr')
@@ -766,15 +766,15 @@ def mkpart(device, definition):
766766

767767
LOG.debug("Checking if device is safe to partition")
768768
if not overwrite and (is_disk_used(device) or is_filesystem(device)):
769-
LOG.debug("Skipping partitioning on configured device %s" % device)
769+
LOG.debug("Skipping partitioning on configured device %s", device)
770770
return
771771

772772
LOG.debug("Checking for device size")
773773
device_size = get_hdd_size(table_type, device)
774774

775775
LOG.debug("Calculating partition layout")
776776
part_definition = get_partition_layout(table_type, device_size, layout)
777-
LOG.debug(" Layout is: %s" % part_definition)
777+
LOG.debug(" Layout is: %s", part_definition)
778778

779779
LOG.debug("Creating partition table on %s", device)
780780
exec_mkpart(table_type, device, part_definition)
@@ -799,7 +799,7 @@ def lookup_force_flag(fs):
799799
if fs.lower() in flags:
800800
return flags[fs]
801801

802-
LOG.warn("Force flag for %s is unknown." % fs)
802+
LOG.warning("Force flag for %s is unknown.", fs)
803803
return ''
804804

805805

@@ -858,7 +858,7 @@ def mkfs(fs_cfg):
858858
LOG.debug("Device %s has required file system", device)
859859
return
860860
else:
861-
LOG.warn("Destroying filesystem on %s", device)
861+
LOG.warning("Destroying filesystem on %s", device)
862862

863863
else:
864864
LOG.debug("Device %s is cleared for formating", device)
@@ -883,14 +883,14 @@ def mkfs(fs_cfg):
883883
return
884884

885885
if not reuse and fs_replace and device:
886-
LOG.debug("Replacing file system on %s as instructed." % device)
886+
LOG.debug("Replacing file system on %s as instructed.", device)
887887

888888
if not device:
889889
LOG.debug("No device aviable that matches request. "
890890
"Skipping fs creation for %s", fs_cfg)
891891
return
892892
elif not partition or str(partition).lower() == 'none':
893-
LOG.debug("Using the raw device to place filesystem %s on" % label)
893+
LOG.debug("Using the raw device to place filesystem %s on", label)
894894

895895
else:
896896
LOG.debug("Error in device identification handling.")
@@ -901,7 +901,7 @@ def mkfs(fs_cfg):
901901

902902
# Make sure the device is defined
903903
if not device:
904-
LOG.warn("Device is not known: %s", device)
904+
LOG.warning("Device is not known: %s", device)
905905
return
906906

907907
# Check that we can create the FS
@@ -923,8 +923,8 @@ def mkfs(fs_cfg):
923923
mkfs_cmd = util.which("mk%s" % fs_type)
924924

925925
if not mkfs_cmd:
926-
LOG.warn("Cannot create fstype '%s'. No mkfs.%s command", fs_type,
927-
fs_type)
926+
LOG.warning("Cannot create fstype '%s'. No mkfs.%s command",
927+
fs_type, fs_type)
928928
return
929929

930930
fs_cmd = [mkfs_cmd, device]

cloudinit/config/cc_fan.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def run(cmd, msg):
6464
try:
6565
return util.subp(cmd, capture=True)
6666
except util.ProcessExecutionError as e:
67-
LOG.warn("failed: %s (%s): %s", service, cmd, e)
67+
LOG.warning("failed: %s (%s): %s", service, cmd, e)
6868
return False
6969

7070
stop_failed = not run(cmds['stop'], msg='stop %s' % service)
@@ -74,7 +74,7 @@ def run(cmd, msg):
7474

7575
ret = run(cmds['start'], msg='start %s' % service)
7676
if ret and stop_failed:
77-
LOG.warn("success: %s started", service)
77+
LOG.warning("success: %s started", service)
7878

7979
if 'enable' in cmds:
8080
ret = run(cmds['enable'], msg='enable %s' % service)

cloudinit/config/cc_mounts.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -216,8 +216,9 @@ def suggested_swapsize(memsize=None, maxsize=None, fsys=None):
216216
else:
217217
pinfo[k] = v
218218

219-
LOG.debug("suggest %(size)s swap for %(mem)s memory with '%(avail)s'"
220-
" disk given max=%(max_in)s [max=%(max)s]'" % pinfo)
219+
LOG.debug("suggest %s swap for %s memory with '%s'"
220+
" disk given max=%s [max=%s]'", pinfo['size'], pinfo['mem'],
221+
pinfo['avail'], pinfo['max_in'], pinfo['max'])
221222
return size
222223

223224

@@ -266,7 +267,7 @@ def handle_swapcfg(swapcfg):
266267
return None or (filename, size)
267268
"""
268269
if not isinstance(swapcfg, dict):
269-
LOG.warn("input for swap config was not a dict.")
270+
LOG.warning("input for swap config was not a dict.")
270271
return None
271272

272273
fname = swapcfg.get('filename', '/swap.img')
@@ -289,7 +290,8 @@ def handle_swapcfg(swapcfg):
289290
return fname
290291
LOG.debug("swap file %s existed, but not in /proc/swaps", fname)
291292
except Exception:
292-
LOG.warn("swap file %s existed. Error reading /proc/swaps", fname)
293+
LOG.warning("swap file %s existed. Error reading /proc/swaps",
294+
fname)
293295
return fname
294296

295297
try:
@@ -300,7 +302,7 @@ def handle_swapcfg(swapcfg):
300302
return setup_swapfile(fname=fname, size=size, maxsize=maxsize)
301303

302304
except Exception as e:
303-
LOG.warn("failed to setup swap: %s", e)
305+
LOG.warning("failed to setup swap: %s", e)
304306

305307
return None
306308

cloudinit/config/cc_resolv_conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def generate_resolv_conf(template_fn, params, target_fname="/etc/resolv.conf"):
7777
params['options'] = {}
7878

7979
params['flags'] = flags
80-
LOG.debug("Writing resolv.conf from template %s" % template_fn)
80+
LOG.debug("Writing resolv.conf from template %s", template_fn)
8181
templater.render_to_file(template_fn, target_fname, params)
8282

8383

cloudinit/config/cc_rsyslog.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,8 @@ def apply_rsyslog_changes(configs, def_fname, cfg_dir):
252252
for cur_pos, ent in enumerate(configs):
253253
if isinstance(ent, dict):
254254
if "content" not in ent:
255-
LOG.warn("No 'content' entry in config entry %s", cur_pos + 1)
255+
LOG.warning("No 'content' entry in config entry %s",
256+
cur_pos + 1)
256257
continue
257258
content = ent['content']
258259
filename = ent.get("filename", def_fname)
@@ -262,7 +263,7 @@ def apply_rsyslog_changes(configs, def_fname, cfg_dir):
262263

263264
filename = filename.strip()
264265
if not filename:
265-
LOG.warn("Entry %s has an empty filename", cur_pos + 1)
266+
LOG.warning("Entry %s has an empty filename", cur_pos + 1)
266267
continue
267268

268269
filename = os.path.join(cfg_dir, filename)
@@ -389,7 +390,7 @@ def remotes_to_rsyslog_cfg(remotes, header=None, footer=None):
389390
try:
390391
lines.append(str(parse_remotes_line(line, name=name)))
391392
except ValueError as e:
392-
LOG.warn("failed loading remote %s: %s [%s]", name, line, e)
393+
LOG.warning("failed loading remote %s: %s [%s]", name, line, e)
393394
if footer is not None:
394395
lines.append(footer)
395396
return '\n'.join(lines) + "\n"

0 commit comments

Comments
 (0)