OpenSCAP / openscap-daemon

Manages continuous scans of your infrastructure
https://www.open-scap.org/tools/openscap-daemon
GNU Lesser General Public License v2.1
106 stars 32 forks source link

container/remediate.py: fix traceback caused by empty items in build_output_generator #133

Closed matusmarhefka closed 6 years ago

matusmarhefka commented 6 years ago

Remediation script tracebacks which prevents remediation of a container image to finish successfully.

The traceback:

Remediating target 2779c0f20c2df6b700858dbddd9f21f08b2c6cd3f0a1f79a847d1b711660454a.
Step 1/3 : FROM 2779c0f20c2df6b700858dbddd9f21f08b2c6cd3f0a1f79a847d1b711660454a
 ---> 2779c0f20c2d
Step 2/3 : COPY fix.sh /
 ---> 9705a5fb8614
Removing intermediate container 2e97d4e7132d
Step 3/3 : RUN chmod +x /fix.sh; /fix.sh ; yum clean all
 ---> Running in ec6e5e935b11
Traceback (most recent call last):
  File "/etc/atomic.d/scripts/remediate.py", line 154, in <module>
    remediate(args.id, args.results_dir)
  File "/etc/atomic.d/scripts/remediate.py", line 129, in remediate
    sys.stdout.write(item_dict["stream"])
KeyError: 'stream'

The issue is that the latest docker low-level API returns a generator for the build output with an empty item which is not handled in remediate.py script.

The issue is reported in the RHBZ#1550948

pep8speaks commented 6 years ago

Hello @matusmarhefka! Thanks for submitting the PR.

Line 79:47: E225 missing whitespace around operator Line 151:80: E501 line too long (80 > 79 characters)

jan-cerny commented 6 years ago

@matusmarhefka Thank you very much for your patch. Nice catch!