Skip to content

Commit 7dba57c

Browse files
authored
Rename test image and make tarball path overridable (#4826)
* Rename test image and make tarball path overridable * make plugin and upgrade [ath overridable as well * make only mandatory tar paths overridable * Avoid get in func name * Add empty canonical oc section in readme to satisfy validator
1 parent ddcc27a commit 7dba57c

File tree

4 files changed

+44
-22
lines changed

4 files changed

+44
-22
lines changed

feature/container/containerz/tests/container_lifecycle/README.md

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,24 +20,24 @@ Start by entering in that directory and running the following commands:
2020
$ cd internal/cntrsrv
2121
$ go mod vendor
2222
$ CGO_ENABLED=0 go build .
23-
$ docker build -f build/Dockerfile.local -t cntrsrv:latest .
23+
$ docker build -f build/Dockerfile.local -t cntrsrv_image:latest .
2424
```
2525

2626
At this point you will have a container image build for the test container.
2727

2828
```shell
2929
$ docker images
30-
REPOSITORY TAG IMAGE ID CREATED SIZE
31-
cntrsrv latest 8d786a6eebc8 3 minutes ago 21.4MB
30+
REPOSITORY TAG IMAGE ID CREATED SIZE
31+
cntrsrv_image latest 8d786a6eebc8 3 minutes ago 21.4MB
3232
```
3333

3434
Now export the container to a tarball.
3535

3636
```shell
37-
$ docker save -o /tmp/cntrsrv.tar cntrsrv:latest
38-
$ docker tag cntrsrv:latest cntrsrv:upgrade
39-
$ docker save -o /tmp/cntrsrv-upgrade.tar cntrsrv:upgrade
40-
$ docker rmi cntrsrv:latest
37+
$ docker save -o /tmp/cntrsrv.tar cntrsrv_image:latest
38+
$ docker tag cntrsrv_image:latest cntrsrv_image:upgrade
39+
$ docker save -o /tmp/cntrsrv-upgrade.tar cntrsrv_image:upgrade
40+
$ docker rmi cntrsrv_image:latest
4141
```
4242

4343
This is the tarball that will be used during tests.
@@ -150,6 +150,13 @@ This test validates the complete lifecycle of the `vieux/docker-volume-sshfs` pl
150150
Using the tarball from 'Build docker volume sshfs plugin tarball', the test installs and activates the plugin via `gnoi.Containerz.StartPlugin`, then verifies its presence and state using `gnoi.Containerz.ListPlugins`.
151151
Subsequently, the plugin is stopped using `gnoi.Containerz.StopPlugin` and removed with `gnoi.Containerz.RemovePlugin`.
152152

153+
## Canonical OC
154+
155+
<!-- This test does not require any specific OpenConfig configuration, so this section is empty to satisfy the validator. -->
156+
```json
157+
{}
158+
```
159+
153160
## OpenConfig Path and RPC Coverage
154161

155162
The below yaml defines the RPCs intended to be covered by this test.

feature/container/containerz/tests/container_lifecycle/containerz_test.go

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,21 @@ var (
2727
containerUpgradeTar = flag.String("container_upgrade_tar", "/tmp/cntrsrv-upgrade.tar", "The container tarball to upgrade to.")
2828
pluginTar = flag.String("plugin_tar", "/tmp/rootfs.tar.gz", "The plugin tarball (e.g., for vieux/docker-volume-sshfs rootfs.tar.gz).")
2929
pluginConfig = flag.String("plugin_config", "testdata/test_sshfs_config.json", "The plugin config.")
30+
// These can be overridden for internal testing behavior using init().
31+
containerTarPath = func(t *testing.T) string {
32+
return *containerTar
33+
}
34+
containerUpgradeTarPath = func(t *testing.T) string {
35+
return *containerUpgradeTar
36+
}
37+
pluginTarPath = func(t *testing.T) string {
38+
return *pluginTar
39+
}
3040
)
3141

3242
const (
3343
instanceName = "test-instance"
34-
imageName = "cntrsrv"
44+
imageName = "cntrsrv_image"
3545
)
3646

3747
func TestMain(m *testing.M) {
@@ -44,7 +54,7 @@ func startContainer(ctx context.Context, t *testing.T) (*client.Client, func())
4454
t.Helper()
4555
dut := ondatra.DUT(t, "dut")
4656
opts := containerztest.StartContainerOptions{
47-
TarPath: *containerTar,
57+
TarPath: containerTarPath(t),
4858
RemoveExistingImage: false,
4959
PollForRunningState: false,
5060
PollInterval: 5 * time.Second,
@@ -64,7 +74,7 @@ func TestDeployAndStartContainer(t *testing.T) {
6474
InstanceName: instanceName,
6575
ImageName: imageName,
6676
ImageTag: "latest",
67-
TarPath: *containerTar,
77+
TarPath: containerTarPath(t),
6878
Command: "./cntrsrv",
6979
Ports: []string{"60061:60061"},
7080
RemoveExistingImage: true,
@@ -225,7 +235,7 @@ func TestRetrieveLogs(t *testing.T) {
225235
InstanceName: stoppedInstanceName,
226236
ImageName: localImageName,
227237
ImageTag: "latest",
228-
TarPath: *containerTar,
238+
TarPath: containerTarPath(t),
229239
Command: "./cntrsrv",
230240
Ports: []string{"60062:60062"},
231241
RemoveExistingImage: false,
@@ -577,7 +587,7 @@ func TestUpgrade(t *testing.T) {
577587
defer cleanup()
578588
defer cli.RemoveImage(ctx, imageName, "upgrade", true)
579589

580-
progCh, err := cli.PushImage(ctx, imageName, "upgrade", *containerUpgradeTar, false)
590+
progCh, err := cli.PushImage(ctx, imageName, "upgrade", containerUpgradeTarPath(t), false)
581591
if err != nil {
582592
t.Fatalf("unable to push image %s:upgrade: %v", imageName, err)
583593
}
@@ -727,8 +737,8 @@ func TestPlugins(t *testing.T) {
727737
)
728738

729739
// Check if the plugin tarball exists (as it's needed for config extraction).
730-
if _, err := os.Stat(*pluginTar); os.IsNotExist(err) {
731-
t.Fatalf("Plugin tarball %q not found. Build it from vieux/docker-volume-sshfs and specify path using --plugin_tar.", *pluginTar)
740+
if _, err := os.Stat(pluginTarPath(t)); os.IsNotExist(err) {
741+
t.Fatalf("Plugin tarball %q not found. Build it from vieux/docker-volume-sshfs and specify path using --plugin_tar.", pluginTarPath(t))
732742
}
733743

734744
t.Run("SuccessfulPluginCompleteLifecycle", func(t *testing.T) {
@@ -751,7 +761,7 @@ func TestPlugins(t *testing.T) {
751761
}()
752762

753763
// Push the plugin image for this specific test case.
754-
if err := pushPluginImage(ctx, t, cli, *pluginTar, pluginName, pluginImageTag); err != nil {
764+
if err := pushPluginImage(ctx, t, cli, pluginTarPath(t), pluginName, pluginImageTag); err != nil {
755765
t.Fatalf("Failed to push plugin image %s:%s: %v", pluginName, pluginImageTag, err)
756766
}
757767

@@ -849,7 +859,7 @@ func TestPlugins(t *testing.T) {
849859
}()
850860

851861
// Push the plugin image for this specific test case.
852-
if err := pushPluginImage(ctx, t, cli, *pluginTar, pluginName, pluginImageTag); err != nil {
862+
if err := pushPluginImage(ctx, t, cli, pluginTarPath(t), pluginName, pluginImageTag); err != nil {
853863
t.Fatalf("Failed to push plugin image %s:%s for StartAlreadyStartedInstance: %v", pluginName, pluginImageTag, err)
854864
}
855865

feature/container/networking/tests/container_connectivity/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,21 +19,21 @@ Start by entering in that directory and running the following commands:
1919
$ cd internal/cntrsrv
2020
$ go mod vendor
2121
$ CGO_ENABLED=0 go build .
22-
$ docker build -f build/Dockerfile.local -t cntrsrv:latest .
22+
$ docker build -f build/Dockerfile.local -t cntrsrv_image:latest .
2323
```
2424

2525
At this point you will have a container image build for the test container.
2626

2727
```shell
2828
$ docker images
29-
REPOSITORY TAG IMAGE ID CREATED SIZE
30-
cntrsrv latest 8d786a6eebc8 3 minutes ago 21.4MB
29+
REPOSITORY TAG IMAGE ID CREATED SIZE
30+
cntrsrv_image latest 8d786a6eebc8 3 minutes ago 21.4MB
3131
```
3232

3333
Now export the container to a tarball.
3434

3535
```shell
36-
$ docker save -o /tmp/cntrsrv.tar cntrsrv:latest
36+
$ docker save -o /tmp/cntrsrv.tar cntrsrv_image:latest
3737
```
3838

3939
This is the tarball that will be used during tests.

feature/container/networking/tests/container_connectivity/cntr_test.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,15 @@ func TestMain(m *testing.M) {
4747

4848
var (
4949
containerTar = flag.String("container_tar", "/tmp/cntrsrv.tar", "The container tarball to deploy.")
50+
// containerTarPath returns the path to the container tarball.
51+
// This can be overridden for internal testing behavior using init().
52+
containerTarPath = func(t *testing.T) string {
53+
return *containerTar
54+
}
5055
)
5156

5257
const (
53-
imageName = "cntrsrv"
58+
imageName = "cntrsrv_image"
5459
instanceName = "cntr-test-conn"
5560
cntrPort = 60061
5661
)
@@ -64,7 +69,7 @@ func setupContainer(t *testing.T, dut *ondatra.DUTDevice) func() {
6469
ImageName: imageName,
6570
InstanceName: instanceName,
6671
Command: fmt.Sprintf("./cntrsrv --port=%d", cntrPort),
67-
TarPath: *containerTar,
72+
TarPath: containerTarPath(t),
6873
Network: "host",
6974
PollForRunningState: true,
7075
}

0 commit comments

Comments
 (0)