Skip to content

Commit

Permalink
Merge branch 'openconfig:main' into certz1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
priyacj authored Aug 1, 2024
2 parents 5db46da + 8510c98 commit 4ff016d
Show file tree
Hide file tree
Showing 17 changed files with 597 additions and 107 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

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
10 changes: 5 additions & 5 deletions feature/gribi/otg_tests/basic_encap_test/basic_encap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ const (
vrfEncapB = "ENCAP_TE_VRF_B"
ipv4PrefixLen = 30
ipv6PrefixLen = 126
trafficDuration = 30 * time.Second
trafficDuration = 15 * time.Second
nhg10ID = 10
nh201ID = 201
nh202ID = 202
Expand Down Expand Up @@ -364,23 +364,23 @@ func TestBasicEncap(t *testing.T) {
}{
{
name: fmt.Sprintf("Test1 IPv4 Traffic WCMP Encap dscp %d", dscpEncapA1),
pattr: packetAttr{dscp: dscpEncapA1, protocol: ipipProtocol},
pattr: packetAttr{dscp: dscpEncapA1, protocol: ipipProtocol, ttl: 99},
flows: []gosnappi.Flow{fa4.getFlow("ipv4", "ip4a1", dscpEncapA1)},
weights: wantWeights,
capturePorts: otgDstPorts,
validateEncapRatio: true,
},
{
name: fmt.Sprintf("Test2 IPv6 Traffic WCMP Encap dscp %d", dscpEncapA1),
pattr: packetAttr{dscp: dscpEncapA1, protocol: ipv6ipProtocol},
pattr: packetAttr{dscp: dscpEncapA1, protocol: ipv6ipProtocol, ttl: 99},
flows: []gosnappi.Flow{fa6.getFlow("ipv6", "ip6a1", dscpEncapA1)},
weights: wantWeights,
capturePorts: otgDstPorts,
validateEncapRatio: true,
},
{
name: fmt.Sprintf("Test3 IPinIP Traffic WCMP Encap dscp %d", dscpEncapA1),
pattr: packetAttr{dscp: dscpEncapA1, protocol: ipipProtocol},
pattr: packetAttr{dscp: dscpEncapA1, protocol: ipipProtocol, ttl: 99},
flows: []gosnappi.Flow{faIPinIP.getFlow("ipv4in4", "ip4in4a1", dscpEncapA1),
faIPinIP.getFlow("ipv6in4", "ip6in4a1", dscpEncapA1),
},
Expand All @@ -390,7 +390,7 @@ func TestBasicEncap(t *testing.T) {
},
{
name: fmt.Sprintf("No Match Dscp %d Traffic", dscpEncapNoMatch),
pattr: packetAttr{protocol: udpProtocol, dscp: dscpEncapNoMatch},
pattr: packetAttr{protocol: udpProtocol, dscp: dscpEncapNoMatch, ttl: 99},
flows: []gosnappi.Flow{fa4.getFlow("ipv4", "ip4nm", dscpEncapNoMatch)},
weights: noMatchWeight,
capturePorts: otgDstPorts[:1],
Expand Down
Loading

0 comments on commit 4ff016d

Please sign in to comment.