-
Notifications
You must be signed in to change notification settings - Fork 157
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding Containerz CNTR-1.1 test (#3121)
- Loading branch information
Showing
9 changed files
with
276 additions
and
54 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
113 changes: 113 additions & 0 deletions
113
feature/container/containerz/tests/container_lifecycle/README.md
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
# CNTR-1: Basic container lifecycle via `gnoi.Containerz`. | ||
|
||
## Summary | ||
|
||
Verify the correct behaviour of `gNOI.Containerz` when operating containers. | ||
|
||
## Procedure | ||
|
||
This step only applies if the reference implementation of containerz is being | ||
tested. | ||
|
||
Start by pulling the reference implementation: | ||
|
||
```shell | ||
$ git clone [email protected]:openconfig/containerz.git | ||
``` | ||
|
||
Then `cd` into the containerz directory and build containerz: | ||
|
||
```shell | ||
$ cd containerz | ||
$ go build . | ||
``` | ||
|
||
Finally start containerz: | ||
|
||
```shell | ||
$ ./containerz start | ||
``` | ||
|
||
You should see the following output: | ||
|
||
```shell | ||
$ ./containerz start | ||
I0620 12:02:57.408496 3615908 janitor.go:33] janitor-starting | ||
I0620 12:02:57.408547 3615908 janitor.go:36] janitor-started | ||
I0620 12:02:57.408583 3615908 server.go:167] server-start | ||
I0620 12:02:57.408595 3615908 server.go:170] Starting up on Containerz server, listening on: [::]:19999 | ||
I0620 12:02:57.408608 3615908 server.go:171] server-ready | ||
``` | ||
|
||
### Build Test Container | ||
|
||
The test container is available in the feature profile repository under | ||
`internal/cntrsrv`. | ||
|
||
Start by entering in that directory and running the following commands: | ||
|
||
```shell | ||
$ cd internal/cntrsrv | ||
$ go mod vendor | ||
$ CGO_ENABLED=0 go build . | ||
$ docker build -f build/Dockerfile.local -t cntrsrv:latest . | ||
``` | ||
|
||
At this point you will have a container image build for the test container. | ||
|
||
```shell | ||
$ docker images | ||
REPOSITORY TAG IMAGE ID CREATED SIZE | ||
cntrsrv latest 8d786a6eebc8 3 minutes ago 21.4MB | ||
``` | ||
|
||
Now export the container to a tarball. | ||
|
||
```shell | ||
$ docker save -o /tmp/cntrsrv.tar cntrsrv:latest | ||
$ docker rmi cntrsrv:latest | ||
``` | ||
|
||
This is the tarball that will be used during tests. | ||
|
||
## CNTR-1.1: Deploy and Start a Container | ||
|
||
Using the | ||
[`gnoi.Containerz`](https://github.com/openconfig/gnoi/tree/main/containerz) API | ||
(reference implementation to be available | ||
[`openconfig/containerz`](https://github.com/openconfig/containerz), deploy a | ||
container to the DUT. Using `gnoi.Containerz` start the container. | ||
|
||
The container should expose a simple health API. The test succeeds if is | ||
possible to connect to the container via the gRPC API to determine its health. | ||
|
||
## CNTR-1.2: Retrieve a running container's logs. | ||
|
||
Using the container started as part of CNTR-1.1, retrieve the logs from the | ||
container and ensure non-zero contents are returned when using | ||
`gnoi.Containerz.Log`. | ||
|
||
## CNTR-1.3: List the running containers on a DUT | ||
|
||
Using the container started as part of CNTR-1.1, validate that the container is | ||
included in the listed set of containers when calling `gnoi.Containerz.List`. | ||
|
||
## CNTR-1.4: Stop a container running on a DUT. | ||
|
||
Using the container started as part of CNTR-1.2, validate that the container can | ||
be stopped, and is subsequently no longer listed in the `gnoi.Containerz.List` | ||
API. | ||
|
||
## OpenConfig Path and RPC Coverage | ||
|
||
The below yaml defines the RPCs intended to be covered by this test. | ||
|
||
```yaml | ||
rpcs: | ||
gnoi: | ||
containerz.Containerz.Deploy: | ||
containerz.Containerz.StartContainer: | ||
containerz.Containerz.StopContainer: | ||
containerz.Containerz.Log: | ||
containerz.Containerz.ListContainer: | ||
``` |
66 changes: 66 additions & 0 deletions
66
feature/container/containerz/tests/container_lifecycle/containerz_test.go
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package container_lifecycle | ||
Check failure on line 1 in feature/container/containerz/tests/container_lifecycle/containerz_test.go GitHub Actions / Static Analysis
|
||
|
||
import ( | ||
"context" | ||
"crypto/tls" | ||
"flag" | ||
"testing" | ||
|
||
"github.com/openconfig/containerz/client" | ||
cpb "github.com/openconfig/featureprofiles/internal/cntrsrv/proto/cntr" | ||
"google.golang.org/grpc" | ||
"google.golang.org/grpc/credentials" | ||
) | ||
|
||
var ( | ||
containerTar = flag.String("container_tar", "/tmp/cntrsrv.tar", "The container tarball to deploy.") | ||
containerzAddr = flag.String("containerz_addr", "localhost:19999", "containerz server address") | ||
) | ||
|
||
// TestDeployAndStartContainer implements CNTR-1.1 validating that it is | ||
// possible deploy and start a container via containerz. | ||
func TestDeployAndStartContainer(t *testing.T) { | ||
ctx, cancel := context.WithCancel(context.Background()) | ||
defer cancel() | ||
|
||
cli, err := client.NewClient(ctx, *containerzAddr) | ||
if err != nil { | ||
t.Fatalf("unable to dial containerz: %v", err) | ||
} | ||
|
||
progCh, err := cli.PushImage(ctx, "cntrsrv", "latest", *containerTar) | ||
if err != nil { | ||
t.Fatalf("unable to push image: %v", err) | ||
} | ||
|
||
for prog := range progCh { | ||
switch { | ||
case prog.Error != nil: | ||
t.Fatalf("failed to push image: %v", err) | ||
case prog.Finished: | ||
t.Logf("Pushed %s/%s\n", prog.Image, prog.Tag) | ||
default: | ||
t.Logf(" %d bytes pushed", prog.BytesReceived) | ||
} | ||
} | ||
|
||
ret, err := cli.StartContainer(ctx, "cntrsrv", "latest", "./cntrsrv", "test-instance", client.WithPorts([]string{"60061:60061"})) | ||
if err != nil { | ||
t.Fatalf("unable to start container: %v", err) | ||
} | ||
t.Logf("Started %s", ret) | ||
|
||
tlsc := credentials.NewTLS(&tls.Config{ | ||
InsecureSkipVerify: true, // NOLINT | ||
}) | ||
conn, err := grpc.DialContext(ctx, "localhost:60061", grpc.WithTransportCredentials(tlsc), grpc.WithBlock()) | ||
if err != nil { | ||
t.Fatalf("Failed to dial cntrsrv, %v", err) | ||
} | ||
|
||
cntrCli := cpb.NewCntrClient(conn) | ||
if _, err = cntrCli.Ping(ctx, &cpb.PingRequest{}); err != nil { | ||
t.Errorf("unable to reach cntrsrv: %v", err) | ||
} | ||
|
||
} |
7 changes: 7 additions & 0 deletions
7
feature/container/containerz/tests/container_lifecycle/metadata.textproto
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# proto-file: github.com/openconfig/featureprofiles/proto/metadata.proto | ||
# proto-message: Metadata | ||
|
||
uuid: "a477c97d-c895-4af3-9c97-9327bf86d517" | ||
plan_id: "CNTR-1" | ||
description: "Basic container lifecycle via `gnoi.Containerz`." | ||
testbed: TESTBED_DUT_ATE_2LINKS |
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
FROM alpine:3.16 | ||
|
||
COPY cntrsrv / | ||
|
||
CMD ["./cntrsrv"] |
Oops, something went wrong.