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
Handle OSError: file exists exception #26580
Conversation
The test
The test
The test
|
contrib/inventory/ec2.py
Outdated
try: | ||
os.makedirs(cache_dir) | ||
except(OSError): | ||
print('Cache directory already exists. Skipping the step...') |
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 don't think printing an informational message is that useful. Just pass
here instead
@@ -399,7 +399,10 @@ def read_settings(self): | |||
if self.boto_profile: | |||
cache_dir = os.path.join(cache_dir, 'profile_' + self.boto_profile) | |||
if not os.path.exists(cache_dir): |
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 check is now fairly pointless. If we're going to just try
/except
, no point checking it first.
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.
Done
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.
@cazorla19 It seems like you still need to remove this line.
I'm gonna close this as an outdated topic, even me completely lost the track of this issue |
SUMMARY
I appended the handling of situation where we run multiple inventory cache updates on one host from one user. It's not related to any issue in Github, but it's important anyway.
What's is the issue at all? Let's imagine that I'm running multiple Ansible playbooks on EC2 inventory at a time. There may be used just one node, but might be multiple, it depends on the CI choice. To have my cache fresh, I have to update this running
ec2.py --refresh-cache
command. When cache will become empty, multiple processes will try to create a new directory and will fail doing this simultaneously.My way to fix this is tested. Please, check the accordance to your code style and merge if everything's fine.
ISSUE TYPE
Bugfix Pull Request
COMPONENT NAME
contrib/inventory/ec2.py
ANSIBLE VERSION
ADDITIONAL INFORMATION
To reproduce the error, you can run multiple EC2 inventory update processes. I'm not sure how to make it reproduced every time, because process may try to create the directory anytime and then avoid concurrency issue.