Visitar URL original
Report unsupported GCP machine types as a user error by arpitjain099 · Pull Request #30 · ncbi/elastic-blast · GitHub
Skip to content

Report unsupported GCP machine types as a user error - #30

Open
arpitjain099 wants to merge 1 commit into
ncbi:masterfrom
arpitjain099:fix/unsupported-machine-type
Open

arpitjain099 wants to merge 1 commit into
ncbi:masterfrom
arpitjain099:fix/unsupported-machine-type

Conversation

@arpitjain099

Copy link
Copy Markdown

Requesting a real GCP machine type that ElasticBLAST has not catalogued gives an uncaught KeyError traceback rather than the friendly message the code clearly intends:

>>> tuner.gcp_get_mem_limit("c2d-standard-4")
KeyError: 'c2d-standard'

gcp_traits.get_machine_properties matches the type against ([^-]+-[^-]+)-([0-9]+) and then indexes GCP_MACHINES[series]. A well formed type from a series that is not in that dict (c2d, t2d, n4, c3, and the other newer families) matches the regex, so it never reaches the else branch that raises NotImplementedError; it dies on the dict lookup instead. Both user-facing callers, tuner.gcp_get_mem_limit and elb_config.get_instance_props, catch only NotImplementedError, so the KeyError escapes to the user during config validation.

I left the low-level function alone on purpose. tests/gcp_traits/test_gcp_traits.py::test_not_found asserts that get_machine_properties("n1-nonstandard-32") raises KeyError, so that behavior is part of the tested contract. Widening the two callers to except (NotImplementedError, KeyError) is the smaller change and keeps that test passing.

Added a test that asserts c2d-standard-4, t2d-standard-8 and n4-standard-16 raise UserReportError with INPUT_ERROR. It fails before the change with KeyError: 'c2d-standard' and passes after. tests/tuner tests/gcp_traits tests/base tests/elb_config run 74 passed with the fix in place.

get_machine_properties raises KeyError for a well formed machine type
whose series is not in GCP_MACHINES (c2d, t2d, n4, c3 and so on), since
those match the regex and never reach the NotImplementedError branch.
Both user-facing callers only caught NotImplementedError, so the user
saw a bare KeyError traceback instead of the intended message. The
low-level function is unchanged, so the existing test_not_found still
holds.

Signed-off-by: Arpit Jain <arpitjain099@gmail.com>
@christiam

Copy link
Copy Markdown
Collaborator

Thanks! We'll look into incorporating this into the next release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants