-
Notifications
You must be signed in to change notification settings - Fork 62
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
update hvac error handling (Open todo) #391
update hvac error handling (Open todo) #391
Conversation
Small note on this pr, I have no clue how to fully and properly run the pytest tests. I'm constantly getting the error that there's a relative import that's missing even though it's clearly there.
I'm probably doing something simply stupid but if anyone can get me up to speed with that, that'll be amazing cause I want to properly test everything, especially with the new modules being build. just for debugging purposes, I'm currently running |
Hi @mathijswesterhof , welcome and thank you for putting up this PR. In ansible collection, we don't really run The first step is to ensure that your checkout directory structure is correct. Your repository should be checked out in this structure: This structure is important! Then, from the root of the collection:
Units will run their tests across all supported python versions (within the container). For faster local testing you can choose a single python version like so:
For more detailed information, please see our Contributor guide. Let me know if you still need assistance running tests locally, or if the documentation there can be improved. I will have to look over this PR more deeply when I have some more time. I'm traveling now so I will be slower to respond and review for the next several weeks, but I will at least try to approve the CI for new commits while I'm away. I strongly recommend getting set up to run the tests locally so that you can get much faster feedback on your changes. Thank you! |
94bca51
to
77fa4e1
Compare
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #391 +/- ##
========================================
Coverage 99.21% 99.21%
========================================
Files 109 110 +1
Lines 6203 5767 -436
Branches 1184 1088 -96
========================================
- Hits 6154 5722 -432
+ Misses 39 36 -3
+ Partials 10 9 -1 Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
@briantist I finally had some spare time to put into this again. sorry for the insane long delay. I added some base tests for a few questions:
|
I don't think you can trigger codecov locally because you'd need a token to upload coverage reports to it, but don't worry about that. To be honest, I never run coverage locally, I make sure the tests pass locally and then let CI do it with coverage so we can get the nice reports from codecov. I realize that's not so good when it's your first contribution and you have to wait for me to approve each run, you can do a lot from a single online coverage report since you can browse it and see all the missed lines so easily. This comment gets edited/updated each time coverage runs, or you can go to the report directly: https://app.codecov.io/gh/ansible-collections/community.hashi_vault/pull/391 Do note it takes a little time for codecov to process the uploaded reports after they are sent.
I will have to defer these questions until I can give this a proper thorough review. I am incredibly short on time lately so I will try to get back to this as soon as I can. |
…cceed add test for hashivaultplugin to test exception forward to ansible
@briantist any updates? |
for now it's probably fine to keep them where they are, we can come back to that if it seems like they'd be better moved
I think they mostly get tested in integration implicitly via the integration tests for the plugins and modules that use them. The units help a lot with test cases that are hard to replicate in integration. |
It might be good to start migrating plugins and modules to use this method. Could you do one plugin and one module and push those up so that I can review? It would be good to (roughly) have each plugin and module be in its own commit, but not strictly necessary. Thanks again for your work on this, sorry for the delays. |
2862d21
to
b8e3f66
Compare
Not sure why this one failed on the CI - LI, but main is also failing (https://github.com/ansible-collections/community.hashi_vault/actions/runs/9528624007) Updated the KV modules and Lookups to use the I have also removed the test that runs over the import try/except with the I'm still doubting if it is neater to add:
to the |
yeah the local integration tests have been failing, nothing to do with your changes, I need to get around to fixing that separately.
I don't have a strong opinion (yet) but one way that method could be advantageous is in unit tests; it makes it easier to mock or wrap in the modules. As you said:
that makes sense, but with a method we could more easily add a test to enforce that modules are actually calling the method, like: get_hvac = mock.Mock(wraps=helper.get_hvac)
# ...
get_hvac.assert_called_once() (something like that) disclaimer: I haven't given it deep thought yet, feel free to play around with the different implementations |
@mathijswesterhof the devel failures are not related to this, that needs to be fixed separately for the repo.
Unfortunately I don't think it'll be possible. It's an incredibly busy time for me and I have far less time for this than I have in the past, hoping it eases up but looking at my week ahead it feels unlikely I'll be able to take a look before then, we'll see though. |
@briantist any update? |
The CI for the repo has been fixed, so let's get a new CI run after you update your branch |
…e test accordingly
faf3c5c
to
e945703
Compare
@briantist it seems like all checks are successful (apart from the codecov upload timeout) and there are no instances of the import anymore. |
193dd9a
to
8e8c7df
Compare
32aecf5
to
17bb721
Compare
…should not be triggered and could do with an empty mock
#455 |
@briantist checks have re-run and everything is green again :D |
@briantist can you give me an update on roughly when you can review this? then i can get going with the implementation of the policies and roles routes. |
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.
@mathijswesterhof thanks very much for your work on this, sticking with it, and your patience with my dwindling availability. It looks great and I really appreciate your work!
Re: my previous requested change I went ahead and just committed that myself, please review and be sure to pull on your end if you'll be making any other changes. If it all looks good to you then we can merge (as long as my change didn't mess up the tests).
@briantist I agree with the changes you've made, I think I messed this up along the way with the various experiments I did on making it look nice and trying to optimize the different components. |
SUMMARY
This pull request addresses the hashi_vault_common module. In specific, the handling of the HVAC import. In the current situation the import is tried and if failed the exception is handled by setting
HAS_HVAC
to false. this state is later not used to signal the missing lib to the user.This pull request fixes this by raising an HVAC specific error which in turn is picked up by the modules that use the common module.
The reason for raising the custom exception is that the module and plugin utils both make use of this class and both have their own error handling service (being; plugins via AnsibleError and modules via the fail handler of the AnsibleModule class)
Note that
I'm not sure if I can confidently remove all the HVAC import try-catch blocks, but based on this change it is a lot easier to write an adapter that can be used for all current modules and future modules significantly reducing duplicated code.
ISSUE TYPE
COMPONENT NAME
ADDITIONAL INFORMATION
Implementing the following change will have a positive effect in replcated code, some examples below for some widely used modules: vault_login
vault_list
before
after