container_lifecycle - openconfig/featureprofiles GitHub Wiki
Verify the correct behaviour of gNOI.Containerz
when operating containers.
- Build the test and upgrade container as described below
- Pass the tarballs of the container the test as arguments.
The test container is available in the feature profile repository under
internal/cntrsrv
.
Start by entering in that directory and running the following commands:
$ 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.
$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
cntrsrv latest 8d786a6eebc8 3 minutes ago 21.4MB
Now export the container to a tarball.
$ docker save -o /tmp/cntrsrv.tar cntrsrv:latest
$ docker tag cntrsrv:latest cntrsrv:upgrade
$ docker save -o /tmp/cntrsrv-upgrade.tar cntrsrv:upgrade
$ docker rmi cntrsrv:latest
This is the tarball that will be used during tests.
The TestPlugins
test suite validates the lifecycle of containerz plugins, specifically using the vieux/docker-volume-sshfs
plugin as an example. To run these tests, you need to build the plugin's rootfs.tar.gz
tarball.
Follow these steps:
-
Clone the
docker-volume-sshfs
repository: If you haven't already, clone the repository from GitHub:git clone https://github.com/vieux/docker-volume-sshfs.git cd docker-volume-sshfs
-
Update the
Makefile
: Open theMakefile
in thedocker-volume-sshfs
directory and add the following target. This target is specifically designed to create arootfs.tar.gz
that includes theconfig.json
manifest at the root, as expected by thecontainerz
plugin system.# ... (other Makefile content) ... package-plugin-tarball: rootfs @echo "### Creating rootfs.tar.gz for containerz" @tar -czf rootfs.tar.gz -C ./plugin/rootfs . -C ../ config.json @echo "### rootfs.tar.gz created in project root." # ... (ensure there's a blank line after this if it's not the end of the file) ...
- The
-C ./plugin/rootfs .
part adds all files from theplugin/rootfs
directory to the archive. - The
-C ../ config.json
part adds theconfig.json
file (which is in the parent directory ofplugin/rootfs
, i.e., the project root) to the archive's root.
- The
-
Build the plugin tarball: Run the new make target from the root of the
docker-volume-sshfs
directory:make package-plugin-tarball
This command will create a
rootfs.tar.gz
file in thedocker-volume-sshfs
project root directory. -
Provide the path to the test: When running your Go tests, you'll need to provide the absolute path to this generated
rootfs.tar.gz
file using the--plugin_tar
flag. For example:go test -v ./feature/container/containerz/tests/container_lifecycle/... --plugin_tar=/path/to/your/docker-volume-sshfs/rootfs.tar.gz
Replace
/path/to/your/docker-volume-sshfs/
with the actual path to where you cloned and built the plugin. -
SSHFS Plugin Test: Runtime Configuration:
The
TestPlugin
test for thevieux/docker-volume-sshfs
plugin (CNTR-1.7) requires a runtime configuration JSON file that includes SSH credentials and specific options.A default configuration file,
test_sshfs_config.json
, is now provided in thetestdata/
directory (i.e., atfeature/container/containerz/tests/container_lifecycle/testdata/test_sshfs_config.json
). This file is pre-configured for a local SSH server setup with the following default environment variables:-
SSH_HOST
:localhost
-
SSH_USER
:testuser
-
SSH_PASSWORD
:testpass
-
SSHFS_OPTS
:allow_other,reconnect
Customization: If you want to customize your local SSH testing environment (e.g., with a different hostname, user, password, or SSH options), you can:
- Copy the provided
testdata/test_sshfs_config.json
to a new location. - Modify the
env
section in your copied file with your specific credentials and options. The file should still be based on the originalconfig.json
from thevieux/docker-volume-sshfs
plugin. - Update the test flag to point to your custom configuration file.
The JSON structure (like
description
,entrypoint
,interface
,mounts
, etc.) should mirror the originalconfig.json
from the plugin, with theenv
array modified as needed. The providedtest_sshfs_config.json
already includes these base settings along with the test-specific environment variables:By using this provided configuration file (or a customized version), you'll have the necessary runtime settings for the
vieux/docker-volume-sshfs
plugin, allowing theTestPlugin
(CNTR-1.7) to execute correctly. -
Using the
gnoi.Containerz
API
(reference implementation to be available
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.
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
.
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
.
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.
Validate the the DUT is capable of creating a volume, reading it back and removing it.
Using the same container started as part of CNTR-1.1, validate that the container can be upgraded to the new version of the image identified by a different tag than the current running container image.
This test validates the complete lifecycle of the vieux/docker-volume-sshfs
plugin on the DUT.
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
.
Subsequently, the plugin is stopped using gnoi.Containerz.StopPlugin
and removed with gnoi.Containerz.RemovePlugin
.
The below yaml defines the RPCs intended to be covered by this test.
rpcs:
gnoi:
containerz.Containerz.Deploy:
containerz.Containerz.StartContainer:
containerz.Containerz.StopContainer:
containerz.Containerz.Log:
containerz.Containerz.ListContainer:
containerz.Containerz.CreateVolume:
containerz.Containerz.RemoveVolume:
containerz.Containerz.ListVolume:
containerz.Containerz.UpdateContainer:
containerz.Containerz.StartPlugin:
containerz.Containerz.ListPlugins:
containerz.Containerz.StopPlugin:
containerz.Containerz.RemovePlugin: