Page MenuHomePhabricator

Spicerack: allow cookbooks to abort execution from __init__
Closed, ResolvedPublic

Description

Sometimes cookbooks have a mode (enabled by CLI flags) that makes them print/list some information without performing any RW action.
In those cases is most often unnecessary to log to IRC/SAL and running the cookbook with the debug mode could trigger very noisy loggers and make the output less readable.

One way to solve this could be to offer a dedicated exception that the cookbooks could raise from their __init__ and that Spicerack could catch. In that case the cookbook will be considered "successful" and spicerack will make it exit cleanly without ever executing run() and hence without any start/end logging.

This will also cover and solve some of the use cases of T324655.

Details

Event Timeline

Volans triaged this task as Medium priority.
Restricted Application added a subscriber: Aklapper. · View Herald Transcript

Another use case for this is the sre.dns.admin cookbook.

sukhe@cumin1002:~$ sudo cookbook sre.dns.admin show
=> CURRENT STATE:
text-addrs: depooled in ulsfo
text-next: depooled in ulsfo
upload-addrs: depooled in ulsfo
ncredir-addrs: depooled in ulsfo
Exception raised while initializing the Cookbook sre.dns.admin:
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/spicerack/_menu.py", line 199, in run
    runner = self.instance.get_runner(args)
  File "/srv/deployment/spicerack/cookbooks/sre/dns/admin.py", line 47, in get_runner
    return DNSAdminRunner(args, self.spicerack)
  File "/srv/deployment/spicerack/cookbooks/sre/dns/admin.py", line 78, in __init__
    raise RuntimeError("show action called; outputting current admin_state. No changes were made.")
RuntimeError: show action called; outputting current admin_state. No changes were made.

show intentionally should not log to SAL so it would be nice to continue to be able to do so without raising RuntimeError.

Change #1105351 had a related patch set uploaded (by Volans; author: Volans):

[operations/software/spicerack@master] api: allow to abort before run()

https://gerrit.wikimedia.org/r/1105351

Change #1105351 merged by jenkins-bot:

[operations/software/spicerack@master] api: allow to abort before run()

https://gerrit.wikimedia.org/r/1105351