Skip to content

Commit

Permalink
Adding Containerz CNTR-1.1 test (#3121)
Browse files Browse the repository at this point in the history
  • Loading branch information
alshabib authored Jul 31, 2024
1 parent f0c6d02 commit c206e2c
Show file tree
Hide file tree
Showing 9 changed files with 276 additions and 54 deletions.
30 changes: 0 additions & 30 deletions feature/container/containerz/README.md

This file was deleted.

113 changes: 113 additions & 0 deletions feature/container/containerz/tests/container_lifecycle/README.md
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:
```
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

View workflow job for this annotation

GitHub Actions / Static Analysis

don't use an underscore in package name

Check failure on line 1 in feature/container/containerz/tests/container_lifecycle/containerz_test.go

View workflow job for this annotation

GitHub Actions / Static Analysis

don't use an underscore in package name

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)
}

}
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
11 changes: 6 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ require (
github.com/grpc-ecosystem/go-grpc-middleware v1.4.0
github.com/kr/pretty v0.3.1
github.com/open-traffic-generator/snappi/gosnappi v1.3.0
github.com/openconfig/containerz v0.0.0-20240620162940-e0bf23af17d6
github.com/openconfig/entity-naming v0.0.0-20230912181021-7ac806551a31
github.com/openconfig/gnmi v0.11.0
github.com/openconfig/gnoi v0.4.0
github.com/openconfig/gnoi v0.4.1-0.20240501161656-1d16819bab6a
github.com/openconfig/gnoigo v0.0.0-20240320202954-ebd033e3542c
github.com/openconfig/gnsi v1.4.5
github.com/openconfig/gocloser v0.0.0-20220310182203-c6c950ed3b0b
Expand All @@ -44,11 +45,11 @@ require (
golang.org/x/exp v0.0.0-20240325151524-a685a6edb6d8
golang.org/x/text v0.14.0
google.golang.org/api v0.162.0
google.golang.org/grpc v1.63.0
google.golang.org/protobuf v1.33.0
google.golang.org/grpc v1.63.2
google.golang.org/protobuf v1.34.1
gopkg.in/yaml.v2 v2.4.0
gopkg.in/yaml.v3 v3.0.1
k8s.io/klog/v2 v2.100.1
k8s.io/klog/v2 v2.120.1
)

require (
Expand Down Expand Up @@ -153,7 +154,7 @@ require (
golang.org/x/mod v0.16.0 // indirect
golang.org/x/net v0.23.0 // indirect
golang.org/x/sync v0.6.0 // indirect
golang.org/x/sys v0.18.0 // indirect
golang.org/x/sys v0.20.0 // indirect
golang.org/x/term v0.18.0 // indirect
golang.org/x/time v0.5.0 // indirect
golang.org/x/tools v0.19.0 // indirect
Expand Down
26 changes: 14 additions & 12 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1366,7 +1366,6 @@ github.com/go-kit/log v0.1.0/go.mod h1:zbhenjAZHb184qTLMA9ZjW7ThYL0H2mk7Q6pNt4vb
github.com/go-latex/latex v0.0.0-20210118124228-b3d85cf34e07/go.mod h1:CO1AlKB2CSIqUrmQPqA0gdRIlnLEY0gK5JGjh37zN5U=
github.com/go-latex/latex v0.0.0-20210823091927-c0d11ff05a81/go.mod h1:SX0U8uGpxhq9o2S/CELCSUxEWWAuoCUcVCQWv7G2OCk=
github.com/go-logfmt/logfmt v0.5.0/go.mod h1:wCYkCAKZfumFQihp8CzCvQ3paCTfi41vtzG1KdI/P7A=
github.com/go-logr/logr v1.2.0/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
github.com/go-logr/logr v1.2.4/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
github.com/go-logr/logr v1.3.0/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
Expand Down Expand Up @@ -1638,15 +1637,17 @@ github.com/open-traffic-generator/snappi/gosnappi v1.3.0 h1:6SFSuZLTuncLW1xMcBG5
github.com/open-traffic-generator/snappi/gosnappi v1.3.0/go.mod h1:CaE4nisXftNXdXWvTSqb4eiW2WMFIXkJsH5rqPoipcg=
github.com/openconfig/attestz v0.2.0 h1:VuksFIG1OlGnRuUpdTFAkMyAY59ITvyLbp4AtiTXV64=
github.com/openconfig/attestz v0.2.0/go.mod h1:byY6H68zm3VXmQHEb4O4OZtRtFyHEjkmzrvIljYc79Y=
github.com/openconfig/containerz v0.0.0-20240620162940-e0bf23af17d6 h1:4SPV//llewH/1v5l3+ogzUubksBGSeI+hHLXTAw2T1A=
github.com/openconfig/containerz v0.0.0-20240620162940-e0bf23af17d6/go.mod h1:Byu9uT5Yyz8XEKv9eUBcWqAoUADVvfmN8m+BGqTQPoc=
github.com/openconfig/entity-naming v0.0.0-20230912181021-7ac806551a31 h1:K/9O+J20+liIof8WjquMydnebD0N1U9ItjhJYF6H4hg=
github.com/openconfig/entity-naming v0.0.0-20230912181021-7ac806551a31/go.mod h1:ZRUrfwYYY+pLaOoWPad3p/8J4LLQcSqtXhBCkD2pXJc=
github.com/openconfig/gnmi v0.0.0-20200414194230-1597cc0f2600/go.mod h1:M/EcuapNQgvzxo1DDXHK4tx3QpYM/uG4l591v33jG2A=
github.com/openconfig/gnmi v0.0.0-20200508230933-d19cebf5e7be/go.mod h1:M/EcuapNQgvzxo1DDXHK4tx3QpYM/uG4l591v33jG2A=
github.com/openconfig/gnmi v0.10.0/go.mod h1:Y9os75GmSkhHw2wX8sMsxfI7qRGAEcDh8NTa5a8vj6E=
github.com/openconfig/gnmi v0.11.0 h1:H7pLIb/o3xObu3+x0Fv9DCK7TH3FUh7mNwbYe+34hFw=
github.com/openconfig/gnmi v0.11.0/go.mod h1:9oJSQPPCpNvfMRj8e4ZoLVAw4wL8HyxXbiDlyuexCGU=
github.com/openconfig/gnoi v0.4.0 h1:jbYXRMNmmvA8ZFv2FBLrYoxA1MFSui4tEui+8LAWyVc=
github.com/openconfig/gnoi v0.4.0/go.mod h1:0d3/bgooXM/je6jI+fb7+9Iky8R8k6zSFG19xRYTRso=
github.com/openconfig/gnoi v0.4.1-0.20240501161656-1d16819bab6a h1:wDllmsI9aUalYMF3Z0VQa2GZv8hcaHYfZsSNJARuUfk=
github.com/openconfig/gnoi v0.4.1-0.20240501161656-1d16819bab6a/go.mod h1:QVnt7KL8l6WphIfLuHHpgZfNO+MoXE610gSLOLV9VcI=
github.com/openconfig/gnoigo v0.0.0-20240320202954-ebd033e3542c h1:egPgBUBDn0XEtbz0CvE+Bh/I/3iTzwzMq5/rmtPJdQs=
github.com/openconfig/gnoigo v0.0.0-20240320202954-ebd033e3542c/go.mod h1:Se/HklUcFVcCGB66khgYouiesLRPoa4UL1ovvmE/68k=
github.com/openconfig/gnpsi v0.3.2 h1:+bl1bXMOTrWOcGydWB+8wGgvxlgvL8Y6joAiWFU5sog=
Expand Down Expand Up @@ -1755,8 +1756,8 @@ github.com/sirikothe/gotextfsm v1.0.1-0.20200816110946-6aa2cfd355e4 h1:FHUL2HofY
github.com/sirikothe/gotextfsm v1.0.1-0.20200816110946-6aa2cfd355e4/go.mod h1:CJYqpTg9u5VPCoD0VEl9E68prCIiWQD8m457k098DdQ=
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
github.com/sirupsen/logrus v1.7.0/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
github.com/sirupsen/logrus v1.9.0 h1:trlNQbNUG3OdDrDil03MCb1H2o9nJ1x4/5LYw7byDE0=
github.com/sirupsen/logrus v1.9.0/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
github.com/skeema/knownhosts v1.2.1 h1:SHWdIUa82uGZz+F+47k8SY4QhhI291cXCpopT1lK2AQ=
github.com/skeema/knownhosts v1.2.1/go.mod h1:xYbVRSPxqBZFrdmDyMmsOs+uX1UZC3nTN3ThzgDxUwo=
github.com/sourcegraph/conc v0.3.0 h1:OQTbbt6P72L20UqAkXXuLOj79LfEanQ+YQFNpLA9ySo=
Expand Down Expand Up @@ -2191,8 +2192,8 @@ golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.14.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.16.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4=
golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.20.0 h1:Od9JTbYCk261bKm4M/mw7AklTlFYIa0bIp9BgSm1S8Y=
golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.1.0/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
Expand Down Expand Up @@ -2680,8 +2681,8 @@ google.golang.org/grpc v1.59.0/go.mod h1:aUPDwccQo6OTjy7Hct4AfBPD1GptF4fyUjIkQ9Y
google.golang.org/grpc v1.60.0/go.mod h1:OlCHIeLYqSSsLi6i49B5QGdzaMZK9+M7LXN2FKz4eGM=
google.golang.org/grpc v1.60.1/go.mod h1:OlCHIeLYqSSsLi6i49B5QGdzaMZK9+M7LXN2FKz4eGM=
google.golang.org/grpc v1.62.1/go.mod h1:IWTG0VlJLCh1SkC58F7np9ka9mx/WNkjl4PGJaiq+QE=
google.golang.org/grpc v1.63.0 h1:WjKe+dnvABXyPJMD7KDNLxtoGk5tgk+YFWN6cBWjZE8=
google.golang.org/grpc v1.63.0/go.mod h1:WAX/8DgncnokcFUldAxq7GeB5DXHDbMF+lLvDomNkRA=
google.golang.org/grpc v1.63.2 h1:MUeiw1B2maTVZthpU5xvASfTh3LDbxHd6IJ6QQVU+xM=
google.golang.org/grpc v1.63.2/go.mod h1:WAX/8DgncnokcFUldAxq7GeB5DXHDbMF+lLvDomNkRA=
google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.1.0/go.mod h1:6Kw0yEErY5E/yWrBtf03jp27GLLJujG4z/JK95pnjjw=
google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=
google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0=
Expand All @@ -2702,8 +2703,9 @@ google.golang.org/protobuf v1.29.1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqw
google.golang.org/protobuf v1.30.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
google.golang.org/protobuf v1.32.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGmI=
google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
google.golang.org/protobuf v1.34.1 h1:9ddQBjfCyZPOHPUiPxpYESBLc+T8P3E+Vo4IbKZgFWg=
google.golang.org/protobuf v1.34.1/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
Expand Down Expand Up @@ -2744,8 +2746,8 @@ k8s.io/apimachinery v0.26.3 h1:dQx6PNETJ7nODU3XPtrwkfuubs6w7sX0M8n61zHIV/k=
k8s.io/apimachinery v0.26.3/go.mod h1:ats7nN1LExKHvJ9TmwootT00Yz05MuYqPXEXaVeOy5I=
k8s.io/client-go v0.26.3 h1:k1UY+KXfkxV2ScEL3gilKcF7761xkYsSD6BC9szIu8s=
k8s.io/client-go v0.26.3/go.mod h1:ZPNu9lm8/dbRIPAgteN30RSXea6vrCpFvq+MateTUuQ=
k8s.io/klog/v2 v2.100.1 h1:7WCHKK6K8fNhTqfBhISHQ97KrnJNFZMcQvKp7gP/tmg=
k8s.io/klog/v2 v2.100.1/go.mod h1:y1WjHnz7Dj687irZUWR/WLkLc5N1YHtjLdmgWjndZn0=
k8s.io/klog/v2 v2.120.1 h1:QXU6cPEOIslTGvZaXvFWiP9VKyeet3sawzTOvdXb4Vw=
k8s.io/klog/v2 v2.120.1/go.mod h1:3Jpz1GvMt720eyJH1ckRHK1EDfpxISzJ7I9OYgaDtPE=
k8s.io/kube-openapi v0.0.0-20230308215209-15aac26d736a h1:gmovKNur38vgoWfGtP5QOGNOA7ki4n6qNYoFAgMlNvg=
k8s.io/kube-openapi v0.0.0-20230308215209-15aac26d736a/go.mod h1:y5VtZWM9sHHc2ZodIH/6SHzXj+TPU5USoA8lcIeKEKY=
k8s.io/utils v0.0.0-20230313181309-38a27ef9d749 h1:xMMXJlJbsU8w3V5N2FLDQ8YgU8s1EoULdbQBcAeNJkY=
Expand Down
5 changes: 5 additions & 0 deletions internal/cntrsrv/build/Dockerfile.local
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FROM alpine:3.16

COPY cntrsrv /

CMD ["./cntrsrv"]
Loading

0 comments on commit c206e2c

Please sign in to comment.