Conversation
Validate the 'target' argument passed to gNMIclient() so that malformed inputs fail fast with a clear gNMIException instead of producing confusing errors deep inside connect()/gRPC. Checks added: - target must be a (host, port) tuple/list of length 2 - host must be a non-empty string - port must be an int or numeric string in the range 1-65535 (skipped for unix domain socket targets, where the port is unused) Adds tests/test_10_target_validation.py covering valid and invalid target inputs; no device connectivity required.
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What
Adds validation of the
targetargument ingNMIclient.__init__so malformed inputs fail fast with a cleargNMIException, instead of causing confusing errors later insideconnect()/gRPC (e.g. silently indexing into a string if a plain string is passed instead of a(host, port)tuple).Validation added
targetmust be a tuple/list of exactly 2 elements:(host, port)hostmust be a non-empty stringportmust be an int or numeric string in the range 1-65535unix:<path>targets, the port is unused and therefore not validatedTesting
tests/test_10_target_validation.py(14 new unit tests, no device required) covering valid targets (IPv4, IPv6, FQDN, unix socket, list form) and invalid targets (wrong type, wrong length, empty host, non-string host, non-numeric port, out-of-range port, boolean port).test_00,test_01,test_10): 34 passed.flake8/pylinton the changed file; no new warnings introduced.Happy to adjust the validation rules or error messages based on feedback.