I've added a function "utils.die(logger, msg)" that I'm going to be
moving things to instead of raise while I'm in the process of removing
print statements.
def die(logger, msg):
# log the exception once in the per-task log or the main
# log if this is not a background op.
try:
raise CX(msg)
except:
if logger is not None:
log_exc(logger)
else:
log_exc(main_logger)
# now re-raise it so the error can fail the operation
raise CX(msg)
The reason for this is that different task logs need to log their
exceptions (if any) in the individual task files as opposed to in the
main log, and there is not any global
try/catch logic in the actions or the API... this is normally done in
the web application or CLI.
This is not totally refined yet (just added for reposync so far), though
the intent is that the full traceback will be in the log file for any
utils.die() calls and that these will also
show up as the nicely formatted error messages we have today (no
traceback) in the web app or CLI, with a link to the logs, where relevant.
This may also eventually mean there is more logic in the die call later,
TBD.
It's a little weird, but it's all in the course of implementing our
system of being able to run things in the background or the foreground
and have them log (conditionally) to the correct place.
For example, added distributions should go to the main log, but import
is a background task, so added distributions added during the import go
to the main log.
Perhaps this can be a little cleaner but it is a start.
Next week, we'll work on removing the remaining print calls throughout
the actions and also cleaning up the exception handling.
For trying this all out, download a new checkout of cobbler-devel, run
"make webtest" to make sure the new daemon is running, and run the test
program:
#!/usr/bin/python
import xmlrpclib
import time
s = xmlrpclib.Server("http://127.0.0.1/cobbler_api")
token = s.login("testing","testing")
# task1 = s.background_sync(token)
task2 = s.background_reposync(["r1","r2"], 3, token)
# new function names are subject to change until released
#print s.get_task_status(task1)
while True:
print s.get_task_status(task2)
time.sleep(1)
While that is running, issue the following 3 times:
sudo pkill reposync
sudo pkill reposync
sudo pkill reposync
You should see the task status move to "failed"
If you look in the logfile /var/log/cobbler/tasks/0.log, you should see
the exception.
(In the above example, I've briefly commented out the code to also try a
background sync, which ends up being so instanteous in my environment
there is little point in backgrounding it, but it is true that folks
could have post-sync triggers installed that fire off other actions).
Obviously in addition to all of this cleanup and making the CLI be
remoted we also have to make tasks show up in the web app so you can see
the results of the task that you kick off, as well as list tasks (and if
there's a task queue, which there currently is not one implemented/needed).
--Michael
Show replies by date