Skip to content

Commit 798a0d4

Browse files
test: add fake gnmi server to allow for local emulation
1 parent 3e98cbf commit 798a0d4

File tree

4 files changed

+95
-0
lines changed

4 files changed

+95
-0
lines changed

test/gnmi/.gitignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# SPDX-FileCopyrightText: 2025 SAP SE or an SAP affiliate company and IronCore contributors
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
*
5+
!.gitignore
6+
!Dockerfile
7+
!README.md
8+
!config.pb.txt

test/gnmi/Dockerfile

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# syntax=docker/dockerfile:1
2+
# SPDX-FileCopyrightText: 2025 SAP SE or an SAP affiliate company and IronCore contributors
3+
# SPDX-License-Identifier: Apache-2.0
4+
5+
ARG GO_VERSION=1.24
6+
ARG ALPINE_VERSION=3.22
7+
8+
FROM --platform=${BUILDPLATFORM:-linux/amd64} golang:${GO_VERSION}-alpine${ALPINE_VERSION} AS build
9+
10+
ARG TARGETOS
11+
ARG TARGETARCH
12+
13+
# Clone the openconfig/gnmi repository containing the fake server
14+
RUN apk add --no-cache --no-progress git && \
15+
git clone --depth=1 --filter=blob:none https://github.com/openconfig/gnmi.git /go/src/github.com/openconfig/gnmi && \
16+
apk del --no-cache --no-progress apk-tools alpine-keys alpine-release libc-utils
17+
18+
# Switch into workspace
19+
WORKDIR /go/src/github.com/openconfig/gnmi
20+
21+
# Install dependencies
22+
RUN --mount=type=cache,target=/go/pkg/mod \
23+
go mod download -x && \
24+
go mod tidy
25+
26+
# Build the application into a static executable while removing the symbol table and debugging information
27+
RUN --mount=type=cache,target=/go/pkg/mod \
28+
--mount=type=cache,target=/root/.cache/go-build \
29+
CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -ldflags="-s -w" -o ./build/server ./testing/fake/gnmi/cmd/fake_server
30+
31+
FROM alpine:${ALPINE_VERSION}
32+
33+
# Switch into workspace
34+
WORKDIR /app
35+
36+
# Copy executable from build
37+
COPY --from=build /go/src/github.com/openconfig/gnmi/build/server /app/
38+
39+
# Start the server application
40+
CMD ["/app/server", "--config=/config.pb.txt", "--text", "--port=9339", "--server_crt=/cert.pem", "--server_key=/key.pem", "--allow_no_client_auth", "--logtostderr"]

test/gnmi/README.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Fake GNMI Test Server
2+
3+
This is a fake GNMI server that can be used to test GNMI clients.
4+
5+
Server Configuration can be found [`config.pb.txt`](./config.pb.txt), bootstrapped from [gen_fake_config](https://github.com/openconfig/gnmi/tree/master/testing/fake/gnmi/cmd/gen_fake_config).
6+
7+
## Prerequisites
8+
9+
- [Docker](https://docs.docker.com/get-docker/)
10+
- [OpenSSL](https://www.openssl.org/)
11+
12+
## Build
13+
14+
All the commands below should be executed in the directory containing this `README.md` file.
15+
16+
Generate a x509 certificate and private key for the server:
17+
18+
```sh
19+
openssl req -x509 -sha256 -newkey rsa:2048 -keyout key.pem -out cert.pem -days 365 -nodes -subj "/O=SAP SE/OU=GCID PlusOne/CN=localhost" -addext "subjectAltName = DNS:localhost"
20+
```
21+
22+
Build the fake GNMI server:
23+
24+
```sh
25+
docker build -t ghcr.io/ironcore-dev/gnmi-test-server .
26+
```
27+
28+
## Run
29+
30+
Run the fake GNMI server:
31+
32+
```sh
33+
docker run -d -p 9339:9339 -v $(pwd)/config.pb.txt:/config.pb.txt -v $(pwd)/key.pem:/key.pem -v $(pwd)/cert.pem:/cert.pem ghcr.io/ironcore-dev/gnmi-test-server
34+
```

test/gnmi/config.pb.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
target: "targetclient"
2+
seed: 12345
3+
values: {
4+
path: "openconfig"
5+
path: "parent"
6+
path: "child"
7+
path: "state"
8+
repeat: 3
9+
string_value: {
10+
value: "value1"
11+
}
12+
}
13+
client_type: GRPC_GNMI

0 commit comments

Comments
 (0)