stdevel / katprep

Python toolkit for automating system maintenance and generating patch reports along with Foreman/Katello and Red Hat Satellite 6.x
GNU General Public License v3.0
35 stars 6 forks source link

Verifying maintenance not possible #104

Open stdevel opened 5 years ago

stdevel commented 5 years ago

Describe the bug Verifying maintenance is currently not possible as katprep_maintenane crashes:

TypeError: object of type 'NoneType' has no len()

To Reproduce Steps to reproduce the behavior:

  1. Prepare maintenance
  2. Run katprep_maintenance *.json verify
  3. See error

Expected behavior Maintenance should be verified.

Screenshots If applicable, add screenshots to help explain your problem.

Environment (please complete the following information):

Additional context Stacktrace:

$ katprep_maintenance -C pass.auth errata-snapshot-report-xxx.json -I pinkepank verify
Authentication container password:
INFO:katprep_maintenance:This is just a SIMULATION - no changes will be made.
INFO:katprep_maintenance:Snapshot for host 'pinkepank.loc' found.
INFO:katprep_maintenance:Downtime for host 'pinkepank.loc' found.
Traceback (most recent call last):
  File "/home/cstan/.local/bin/katprep_maintenance", line 9, in <module>
    load_entry_point('katprep==0.5.0', 'console_scripts', 'katprep_maintenance')()
  File "/home/cstan/katprep/katprep/maintenance.py", line 885, in cli
    main(options, args)
  File "/home/cstan/katprep/katprep/maintenance.py", line 864, in main
    options.func(options, options.func)
  File "/home/cstan/katprep/katprep/maintenance.py", line 447, in verify
    if len(crit_services) > 0:
TypeError: object of type 'NoneType' has no len()
okin commented 5 years ago

Change proposal: If you make use of Pythons Truth Value Testing the critical code can be simplified:

if len(crit_services) > 0:

Can be written as:

if crit_services:

The length check can be omitted in the same way on most occasions until the length is indeed required. The benefit of this is that a returned None will not result in errors.