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
Add foreman callback plugin #17141
Add foreman callback plugin #17141
Conversation
from datetime import datetime | ||
from collections import defaultdict | ||
import json | ||
import requests |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We try to avoid the requests library as it has many issues across older versions and even major incompatibilities across it's own versions, look at using the ansible open_url/fetch_url functions instead.
@bcoca thanks for having a look at this PR. I think I addressed your concerns except for the python-requests removal. I'm happy to switch to open_url / fetch_url but I can't see how to get the current behaviour (allow to specify X509 certificate, key and CA) without reimplementing parts of requests myself or did I miss somthing in the *_url functions? |
Hi, anything I can do to move this further? I'd like to stick to requests since we need client certificates for authentication against foreman but if it's a must have to use the *_url functions I can copy over the necessary code. |
if you insist on requests i would specify version and handle either it being missing or of insufficient/incompatible version. The API of that library has changed in backwards incompatible ways. |
@bcoca thanks for your patience! I've added the check for requests. We're using very few parts of the requests API so I did not add any checks yet. I've tried several versions 2.10.0, 2.7.0, 2.4 and it worked there. |
Tests on shippable failed because this PR branch was created before shippable was enabled. If you rebase the branch the tests will pass, although in this case the tests will just no-op since there are no tests for this plugin. |
c7cca1f
to
cd62d54
Compare
@mattclay I rebased but the tests still fail. |
@agx Look at the console log here for the test failure: https://app.shippable.com/runs/57c7b815236da20f00dc7638/35/console The error is: 2016-09-01 05:12:52 == Missing from future import (absolute_import, division, print_function) == |
b020daa
to
81611b8
Compare
On Thu, Sep 01, 2016 at 12:10:31AM -0700, Matt Clay wrote:
Thanks, I also fixed another failure but the current one does not look
Just repin? |
81611b8
to
b2841d1
Compare
@agx, still, you need to specify requests versions, many machines come with <2.0 installed and I know it does not work because the API changed in incompatible ways. |
b2841d1
to
4dbec48
Compare
On Mon, Sep 05, 2016 at 04:20:02PM -0700, Brian Coca wrote:
Fixed now. Cheking for >= 2.0. |
@mattclay Tests are failing again but I don't think this is caused by the change: 2016-09-06 05:52:30 ERROR! Unexpected Exception: 'ascii' codec can't decode byte 0xc3 in position 95: ordinal not in range(128) @bcoca Check for requests is now there (I noticed that no other code that uses requests checks for the version. Should we move this to common code and add checks as well in a follow up commit?) |
@agx The error is due to the non-ascii character in your name. Removing it eliminates the error. Here's the full traceback:
The @abadger: This looks like a python 3 compatibility issue we'll need to address. |
installed CAs or to a path pointing to a CA bundle. Set to '0' | ||
to disable certificate checking. | ||
|
||
""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This docstring should be used for the CallbackModule
class instead of the module.
|
||
|
||
class CallbackModule(CallbackBase): | ||
""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The various CALLBACK_
prefixed class attributes are missing. Take a look at the other callbacks for an example. In particular, this is needed:
CALLBACK_NEEDS_WHITELIST = True
imp on python3 issue should be fixed. Reading the file as bytes instead of text and passing it to imp allows imp to properly find the encoding. You'll need to rebase to pick up that change. |
4dbec48
to
9fd3816
Compare
@mattclay Thanks for looking into the testsuite! I've addressed your comments. One thing I noticed: As soon as I add any of the CALLBACK_* variables to the callback, the callback won't be invoked anymore whith:
while it still gets invoked fine with a playbook:
Is this intentional? |
@agx Yes. Callbacks included with Ansible must be enabled by setting the For your plugin, you would use: Without this whitelisting, all callbacks shipped with Ansible would be used when running ansible-playbook. |
@mattclay I know I have to whitelist the plugin (and I do so via ansible.cfg) but it only gets run with ansible-playbook not with ansible -msetup ... This isn't a bug in the plugin itself but looks rather like a behaviour change between plugins using CALLBACK_ and those that dont. |
@agx You need to set |
@mattclay ahh...thanks for the hint. Yes, with |
data["_type"] = "ansible" | ||
data["_timestamp"] = datetime.now().strftime(self.TIME_FORMAT) | ||
data = json.dumps(data) | ||
facts_json = self.FACTS_FORMAT % dict(host=host, data=data) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not use json.dumps
to create facts_json
?
metrics["time"] = {"total": int(time.time()) - self.start_time} | ||
self.items[host] = [] | ||
|
||
report_json = self.REPORT_FORMAT % dict(host=host, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not use json.dumps
to create report_json
?
On Fri, Sep 16, 2016 at 02:21:11PM -0700, Matt Clay wrote:
I think the idea here was to have the format facts should be posted
but I think the current form is better readable.
Same here. |
@mattclay I removed the hand built json making the code more compact. Anything else I can do to get this merged? |
On Sun, Oct 02, 2016 at 09:13:04PM -0700, Brian Coca wrote:
Thanks! |
ISSUE TYPE
COMPONENT NAME
plugins/callback/foreman.py
ANSIBLE VERSION
SUMMARY
Add a callback to report facts and reports to the foreman: