Skip to content

Add target validation to gNMIclient constructor - #178

Open
G-Go-p wants to merge 1 commit into
akarneliuk:masterfrom
G-Go-p:feature/target-validation
Open

G-Go-p wants to merge 1 commit into
akarneliuk:masterfrom
G-Go-p:feature/target-validation

Conversation

@G-Go-p

@G-Go-p G-Go-p commented Jul 27, 2026

Copy link
Copy Markdown

What

Adds validation of the target argument in gNMIclient.__init__ so malformed inputs fail fast with a clear gNMIException, instead of causing confusing errors later inside connect()/gRPC (e.g. silently indexing into a string if a plain string is passed instead of a (host, port) tuple).

Validation added

  • target must be a tuple/list of exactly 2 elements: (host, port)
  • host must be a non-empty string
  • port must be an int or numeric string in the range 1-65535
  • For unix:<path> targets, the port is unused and therefore not validated

Testing

  • Added 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).
  • Ran the full device-independent unit test suite locally (test_00, test_01, test_10): 34 passed.
  • Ran flake8/pylint on the changed file; no new warnings introduced.

Happy to adjust the validation rules or error messages based on feedback.

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.
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.

1 participant