Skip to content

Commit

Permalink
check that the container is running
Browse files Browse the repository at this point in the history
  • Loading branch information
alshabib committed Jan 19, 2025
1 parent aa94d16 commit 59065de
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@ and removing it.
## CNTR-1.6: Upgrade a container on the DUT.

Using the same container started as part of CNTR-1.1, validate that the container
can upgraded.
can be upgraded to the new version of the image identified by a different tag
than the current running container image.

## OpenConfig Path and RPC Coverage

Expand All @@ -126,4 +127,4 @@ rpcs:
containerz.Containerz.RemoveVolume:
containerz.Containerz.ListVolume:
containerz.Containerz.UpgradeContainer:
```
```
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@ import (
"context"
"crypto/tls"
"flag"
"testing"
"time"

"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"
"github.com/openconfig/containerz/client"
cpb "github.com/openconfig/featureprofiles/internal/cntrsrv/proto/cntr"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials"
"google.golang.org/grpc/credentials/insecure"
"testing"
"time"
)

var (
Expand Down Expand Up @@ -40,7 +41,7 @@ func containerzClient(ctx context.Context, t *testing.T) *client.Client {
func startContainer(ctx context.Context, t *testing.T) *client.Client {
cli := containerzClient(ctx, t)

progCh, err := cli.PushImage(ctx, "cntrsrv", "latest", *containerTar)
progCh, err := cli.PushImage(ctx, "cntrsrv", "latest", *containerTar, false)
if err != nil {
t.Fatalf("unable to push image: %v", err)
}
Expand All @@ -61,11 +62,27 @@ func startContainer(ctx context.Context, t *testing.T) *client.Client {
t.Fatalf("unable to start container: %v", err)
}

// wait for cntr container to come up.
time.Sleep(5 * time.Second)
t.Logf("Started %s", ret)
for i := 0; i < 5; i++ {
ch, err := cli.ListContainer(ctx, true, 0, map[string][]string{
"name": []string{instanceName},
})
if err != nil {
t.Fatalf("unable to list container state for %s", instanceName)
}

for info := range ch {
if info.State == "RUNNING" {
t.Logf("Started %s", ret)
return cli
}
}
// wait for cntr container to come up.
time.Sleep(5 * time.Second)
}

t.Fatalf("unable to start %s", instanceName)

return cli
return nil
}

func stopContainer(ctx context.Context, t *testing.T, cli *client.Client) {
Expand Down Expand Up @@ -162,6 +179,8 @@ func TestStopContainer(t *testing.T) {
}
}

// TestVolumes checks that volumes can be created or removed, it does not test
// if they can actually be used.
func TestVolumes(t *testing.T) {
ctx := context.Background()
cli := containerzClient(ctx, t)
Expand Down Expand Up @@ -206,7 +225,7 @@ func TestUpgrade(t *testing.T) {
cli := startContainer(ctx, t)
defer stopContainer(ctx, t, cli)

progCh, err := cli.PushImage(ctx, "cntrsrv", "upgrade", *containerUpgradeTar)
progCh, err := cli.PushImage(ctx, "cntrsrv", "upgrade", *containerUpgradeTar, false)
if err != nil {
t.Fatalf("unable to push image: %v", err)
}
Expand All @@ -222,8 +241,7 @@ func TestUpgrade(t *testing.T) {
}
}

_, err = cli.UpdateContainer(ctx, "cntrsrv", "upgrade", "./cntrsrv", instanceName, false, client.WithPorts([]string{"60061:60061"}))
if err != nil {
if _, err := cli.UpdateContainer(ctx, "cntrsrv", "upgrade", "./cntrsrv", instanceName, false, client.WithPorts([]string{"60061:60061"})); err != nil {
t.Errorf("unable to upgrade container: %v", err)
}

Expand Down

0 comments on commit 59065de

Please sign in to comment.