-
Notifications
You must be signed in to change notification settings - Fork 158
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding Containerz CNTR-1.1 test #3121
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 | ||
|
||
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()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this address correct? When the test is running on a DUT, I think we would need to dial the DUT address? |
||
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.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should the default address here not be the address of the DUT per the comment below too?