e2e-tests (1/4): Repackage gnmi-test-server and e2e test infrastructure#407
Draft
nikatza wants to merge 7 commits into
Draft
e2e-tests (1/4): Repackage gnmi-test-server and e2e test infrastructure#407nikatza wants to merge 7 commits into
e2e test infrastructure#407nikatza wants to merge 7 commits into
Conversation
d6f35e8 to
4f9dd88
Compare
4f9dd88 to
23777e1
Compare
e2e test infrastructuree2e test infrastructure
791563e to
090c7f3
Compare
2c34099 to
d481ab3
Compare
Extract gNMI server implementation into a reusable `testserver` package. This enables running later the server in-process, i.e., with envtest. No behavioral changes - this is a pure refactor to enable reuse. Signed-off-by: Pujol <enric.pujol@sap.com>
Add configurable options to NewTestServer: - WithGRPCPort(port) - specify gRPC port (default: random) - WithHTTPPort(port) - specify HTTP port (default: random) - WithBindAddress(addr) - specify bind address (default: 127.0.0.1) Add an HTTP API for inspecting and manipulating server state. This becomes useful during tests for initialization and validation. - GET /v1/state: return the current accumulated state as JSON - POST /v1/state: merge a JSON body into the state at the root level, e.g. to preload configuration into the server. The merge is shallow: top-level keys overwrite, nested objects are replaced - DELETE /v1/state: clear all state - POST /v1/clear: clear all state, for clients that cannot send DELETE - The /v1/state endpoint honors the X-HTTP-Method-Override header so clients restricted to GET/POST can still invoke DELETE - GetState()/ClearState() helper methods on Server Update main.go to use these options with the CLI flags, binding to 0.0.0.0 for pod deployments. Signed-off-by: Pujol <enric.pujol@sap.com>
gNMI/OpenConfig carries list keys in the path (e.g.
interface[name=eth0]) but stores them as child leaves inside the list
entry. A Set payload therefore often omits the key field, since it is
implied by the path.
State.Set now, for every keyed path element:
- locates the array entry whose key leaves match the path keys,
appending a new entry when none match, so repeated Sets to the
same key update in place instead of duplicating;
- materializes the key(s) as leaves inside the entry — for
intermediate elements directly into the buffer, and for the final
element into the value being written.
Without this, a subsequent keyed Get (which matches on the key leaves
via a gjson #(key=="val") query) would not find the entry.
Signed-off-by: Pujol <enric.pujol@sap.com>
Adds the WithNXOSBehavior() option, which enforces: - Stripping fields containing the DME_UNSET_PROPERTY_MARKER value when storing (the marker means "unset this field", not "store this literal string"). - Returning an empty TypedValue for non-existent paths, which triggers the client's ErrNil handling. Add a -nxos CLI flag to main.go to enable NXOS emulation mode. Signed-off-by: Pujol <enric.pujol@sap.com>
Cover JSON state manipulation in the gNMI test server: - list-key injection for final, intermediate, and deeply nested keyed path elements - in-place update vs. append semantics for keyed list entries - empty-path root merge and keyless nested writes - NX-OS DME unset-marker stripping - Set/Get round-trip via a keyed path query Add testify as a test dependency. Signed-off-by: Pujol <enric.pujol@sap.com>
- Update test/gnmi/Dockerfile for testserver package structure - Update test-e2e target to load the image into the kind cluster - Update Makefile / Makefile.maker.yaml build + license-scan config - Add gnmi-test-server.yaml deployment config - Update main Dockerfile Signed-off-by: Pujol <enric.pujol@sap.com>
Add common test infrastructure for e2e tests: test/e2e/testutil/helpers.go: - Run, Apply, ApplyWithPatch - kubectl command execution - CompareJSON, normalizeJSON - JSON comparison utilities - ExtractResourceIdentifier, WaitForCondition - resource helpers - Cert-manager and Prometheus operator install/uninstall - LoadImageToKindClusterWithName, GetProjectDir, UncommentCode test/e2e/testutil/provider.go: - Provider registry (NXOS, IOSXR) with factory functions - CoreResources and ConfigResources GVK lists - ResourcePluralName for CRD plural mappings - CreateTestDevice helper test/e2e/testutil/timeouts.go: - DefaultTimeout, LongTimeout, VeryLongTimeout constants test/e2e/e2e_test.go: - Add idempotent namespace creation (dry-run + apply) - Add --ignore-not-found to cleanup commands - Pre-delete gnmi-test-server pod before deploying Signed-off-by: Pujol <enric.pujol@sap.com>
Merging this branch will not change overall coverage
Coverage by fileChanged files (no unit tests)
Please note that the "Total", "Covered", and "Missed" counts above refer to code statements instead of lines of code. The value in brackets refers to the test coverage of that file in the old version of the code. Changed unit test files
|
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.
This PR refactors the gNMI test server into a reusable package and adds e2e test infrastructure.
Package gNMI test server into testserver package
Extract gNMI server implementation into a reusable testserver package. This enables running the server in-process with envtest, not just as a standalone container.
Add test server factory with functional opts and HTTP API
Add configurable options to NewTestServer(): WithGRPCPort(), WithHTTPPort(), WithBindAddress(). Add an HTTP API for inspecting and manipulating server state during tests — GET/POST/DELETE /v1/state for reading, merging, and clearing state.
Inject YANG list keys into stored state
When you Set a path like
/interfaces/interface[name=eth0]/config with {"mtu":1500}, the name=eth0 key lives in the path, not in the payload. But when you later Get that path, the lookup searches for a JSON object with "name":"eth0" inside it. Without this fix, Set stores{"mtu":1500}and Get can't find it. Now Set injects the key into the stored JSON:{"name":"eth0","mtu":1500}.Add NXOS behavior emulation
Adds
WithNXOSBehavior()option which strips fields containing the DME unset marker when storing, and returns empty TypedValue for non-existent paths. Enable via -nxos CLI flag.Add unit tests for State.Set
Cover JSON state manipulation: key injection for final/intermediate/nested keyed paths, in-place update vs append semantics, empty-path root merge, and NX-OS marker stripping.
Update build configuration
Update Dockerfile, Makefile targets (test-gnmi-unit), and deployment config for the new package structure.
Add shared e2e test utilities
Add common test infrastructure in test/e2e/testutil/: kubectl helpers, JSON comparison utilities, retry/polling functions, and centralized timeout constants.