Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Start on a set of common callbacks #163

Closed

Conversation

jeremycline
Copy link
Member

@jeremycline jeremycline commented Apr 17, 2019

Move the printer callback into the "callbacks" module and add the callback requested in #155.

There are no tests yet because I wanted to get a bit of feedback on usage. @nirik, would the command ever need to see the message itself, or is this purely a way to trigger a command based on the topic alone? Would it ever be helpful to requeue the message and run the command again if it gets stuck while running or exits with some non-zero return code?

The current configuration options are:

  • command (string or list of strings): The arguments to launch the process
    as a string or list of strings.
  • shell (boolean): Whether or not to execute the command in a shell. Refer to the
    security considerations <https://docs.python.org/3/library/subprocess.html#security-considerations>_
    before setting this to true. Defaults to false.
  • timeout (integer): The length of time, in seconds, to wait on the command
    before halting the command and returning the message to the queue for later
    processing. Defaults to no timeout.

Would anything else be useful to configure here?

@codecov-io
Copy link

codecov-io commented Apr 17, 2019

Codecov Report

Merging #163 into master will decrease coverage by 0.52%.
The diff coverage is 63.15%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #163      +/-   ##
==========================================
- Coverage   95.68%   95.16%   -0.53%     
==========================================
  Files          13       15       +2     
  Lines        1343     1467     +124     
  Branches      166      197      +31     
==========================================
+ Hits         1285     1396     +111     
- Misses         43       56      +13     
  Partials       15       15
Impacted Files Coverage Δ
fedora_messaging/example.py 100% <100%> (ø) ⬆️
fedora_messaging/callbacks.py 58.82% <58.82%> (ø)
fedora_messaging/twisted/factory.py 94.15% <0%> (-1.33%) ⬇️
fedora_messaging/cli.py 92.91% <0%> (-1.29%) ⬇️
fedora_messaging/twisted/protocol.py 92.4% <0%> (-0.8%) ⬇️
fedora_messaging/twisted/service.py 96.9% <0%> (-0.7%) ⬇️
fedora_messaging/exceptions.py 92.68% <0%> (-0.5%) ⬇️
fedora_messaging/api.py 100% <0%> (ø) ⬆️
fedora_messaging/config.py 100% <0%> (ø) ⬆️
fedora_messaging/testing.py 100% <0%> (ø) ⬆️
... and 3 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update abd5301...a2be788. Read the comment docs.

Runs a configurable command when a message is received.

Fixes fedora-infra#155

Signed-off-by: Jeremy Cline <[email protected]>
@cverna cverna force-pushed the common-callbacks branch from 723217c to a2be788 Compare March 10, 2020 12:10
@cverna
Copy link
Contributor

cverna commented Mar 10, 2020

I think we should go with that for now, and based on the usage ask people to file RFEs. I have added a simple test case for the runner callback.

Do we need anything else to merge this PR ?

This commit add a simple test case for the runner callback.
It also disable the bandit security checks against the
subprocess call since the choice to use shell=True is left
to the user of the callback.

Signed-off-by: Clement Verna <[email protected]>
@cverna cverna force-pushed the common-callbacks branch from a2be788 to 821bdc1 Compare March 11, 2020 08:41
processing. Defaults to no timeout.
"""
try:
subprocess.check_call( # nosec
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need @puiterwijk 's approval to add the nosec tag. Can you follow up with him @cverna ?

with mock.patch("subprocess.check_call") as mock_subprocess:
callbacks.run(message)

mock_subprocess.assert_called_once_with("/bin/true", shell=False, timeout=None)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you also check that the Drop exception is raised when the command fails, and that the proper exception is raised when the command times out?

@abompard abompard changed the base branch from master to stable July 3, 2020 06:53
@abompard abompard changed the base branch from stable to develop November 26, 2021 10:28
@jeremycline
Copy link
Member Author

Seems likely I'm not going to finish this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants