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

Improve error handling for missing Provider configurations #283

Merged
merged 1 commit into from
Apr 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
Unreleased
-------------------------
* [Enhancement] Add better error handling for missing Provider configuration.
* [Enhancement] Add support for Python 3.12.

Version 7.9.1 (2024-02-14)
Expand Down
3 changes: 3 additions & 0 deletions hastexo/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ def init(name):
return OpenstackProvider(name, config, sleep_seconds)
elif provider_type == "gcloud":
return GcloudProvider(name, config, sleep_seconds)
else:
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it's suboptimal that we end up with the same exception type with the same message in two different code paths, as it complicates troubleshooting. Thoughts?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm, perhaps yes. I updated the error message now.

raise ProviderException(
f"Configuration missing for provider: {name}")

def __init__(self, name, config, sleep):
self.name = name
Expand Down
6 changes: 6 additions & 0 deletions tests/unit/test_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,12 @@ def test_init(self):
self.assertNotEqual(provider.heat_c, None)
self.assertNotEqual(provider.nova_c, None)

def test_init_missing_configuration(self):
self.settings["providers"].pop(self.provider_name)

with self.assertRaises(ProviderException):
Provider.init(self.provider_name)

def test_generate_ssh_keys(self):
provider = Provider.init(self.provider_name)

Expand Down
Loading