abrt / retrace-server

Application for remote coredump analysis
GNU General Public License v2.0
40 stars 30 forks source link

retrace: Fix Traceback if getgrpnam() fails and fail task if chgrp fails #479

Closed DaveWysochanskiRH closed 1 year ago

DaveWysochanskiRH commented 1 year ago

If AuthGroup is set in the config but getgrnam() fails for some reason (such as a network or server error) the below Traceback will occur. Fix this by catching KeyError and handling the same as with OSError in chgrp.

Also if chrgrp fails, we don't want to continue so raise an exception here which should fail the task.

Traceback (most recent call last): File "/usr/lib/python3.6/site-packages/retrace/retrace_worker.py", line 1102, in start errors = task.download_remote() File "/usr/lib/python3.6/site-packages/retrace/retrace.py", line 1199, in download_remote self.set_md5sum("\n".join(md5sums)+"\n") File "/usr/lib/python3.6/site-packages/retrace/retrace.py", line 1439, in set_md5sum self.set(RetraceTask.MD5SUM_FILE, value) File "/usr/lib/python3.6/site-packages/retrace/retrace.py", line 785, in set self.chgrp(key) File "/usr/lib/python3.6/site-packages/retrace/retrace.py", line 766, in chgrp gr = grp.getgrnam(CONFIG["AuthGroup"]) KeyError: "getgrnam(): name not found: 'my-auth-group'"

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/usr/bin/retrace-server-worker", line 85, in worker.start(kernelver=kernelver, arch=cmdline.arch) File "/usr/lib/python3.6/site-packages/retrace/retrace_worker.py", line 1138, in start self._fail() File "/usr/lib/python3.6/site-packages/retrace/retrace_worker.py", line 171, in _fail task.set_status(STATUS_FAIL) File "/usr/lib/python3.6/site-packages/retrace/retrace.py", line 932, in set_status self.set_atomic(RetraceTask.STATUS_FILE, "%d" % statuscode) File "/usr/lib/python3.6/site-packages/retrace/retrace.py", line 806, in set_atomic self.chgrp(key) File "/usr/lib/python3.6/site-packages/retrace/retrace.py", line 766, in chgrp gr = grp.getgrnam(CONFIG["AuthGroup"]) KeyError: "getgrnam(): name not found: 'my-auth-group'"

Signed-off-by: Dave Wysochanski dwysocha@redhat.com

DaveWysochanskiRH commented 1 year ago

It may be a little risky to fail the task if chgrp fails so we may want to stick with 'pass' on the exception handler. However, I'm not sure what will happen as far as usability of the task, and in my instance I'd prefer to fail it as I doubt the task is usable. Still testing this patch though.

codecov-commenter commented 1 year ago

Codecov Report

Merging #479 (c04f7c0) into master (0c3382c) will decrease coverage by 0.00%. The diff coverage is 0.00%.

@@            Coverage Diff             @@
##           master     #479      +/-   ##
==========================================
- Coverage   21.97%   21.96%   -0.01%     
==========================================
  Files          18       18              
  Lines        2853     2863      +10     
==========================================
+ Hits          627      629       +2     
- Misses       2226     2234       +8     
Flag Coverage Δ
unittests 21.96% <0.00%> (-0.01%) :arrow_down:

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
src/retrace/retrace.py 17.09% <0.00%> (ø)
src/retrace/hooks/config.py 76.74% <0.00%> (-7.04%) :arrow_down:
src/retrace/retrace_worker.py 6.53% <0.00%> (-0.04%) :arrow_down:

:mega: We’re building smart automated test selection to slash your CI/CD build times. Learn more

DaveWysochanskiRH commented 1 year ago

Haven't seen any issues with this patch so far.