-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
one_host: Fix ID logic #8907
Merged
felixfontein
merged 4 commits into
ansible-collections:main
from
abakanovskii:one_host_1199
Oct 10, 2024
+38
−23
Merged
one_host: Fix ID logic #8907
Changes from 3 commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
bugfixes: | ||
- one_host - fix if statements for cases when ``ID=0`` (https://github.com/ansible-collections/community.general/issues/1199, https://github.com/ansible-collections/community.general/pull/8907). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Just to be on the safe side, have you checked whether the other
if
statements you are modifying do not fall under the same situation?Methods:
one.host.status()
one.host.delete()
one.host.update()
one.host.addhost()
Don't they also trigger exceptions when parameters are invalid?
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.
they are all almost the same in terms of error handling but it seems to me that other if statements look right
here are 2 examples for
![image](https://private-user-images.githubusercontent.com/79072457/371988796-9618ce09-c50f-48c8-9aee-93c878b99995.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzk0NjQyODYsIm5iZiI6MTczOTQ2Mzk4NiwicGF0aCI6Ii83OTA3MjQ1Ny8zNzE5ODg3OTYtOTYxOGNlMDktYzUwZi00OGM4LTlhZWUtOTNjODc4Yjk5OTk1LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMTMlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjEzVDE2MjYyNlomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTNjN2VhYTY0MmEzNWZlZGI1MTM5MmQ2MDQ5OTQ2OWU4NzhiM2MyNzNiMTg5ZjhiOTM0MjYyNjM2NzM3OWM0MGQmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0._gc080FMuIDPEw3MjvAAsj2gspcZejj2V57HlBjIF94)
one.host.status()
, 1 when running with no parameters, 2 when running with wrong parameterThere 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.
So, in that case, wouldn't it be good to add the
try-except
around them below as well?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.
Could you please show which if statemets are wrong as well? From my perspective other if statements look right
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.
I would not go as far as saying they are wrong, but the same way that you transformed the if statement into a try-except, maybe those could benefit from that as well - line numbers on your branch (right hand side):
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.
oops, I completely missed them, thanks!
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.
Beware that by using this, we are assuming that those calls will raise exceptions when failing (which makes sense, but not all developers write code that way). I would suggest you confirm that if you haven't yet.
Other than that, LGTM.
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.
yeah, it's too much IMO, no need to use it for every call :)
I simply do not use this module that much, so if one day I would need to use this module directly then might as well check if these are necessary