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_image:latest .At this point you will have a container image build for the test container.
$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
cntrsrv_image latest 8d786a6eebc8 3 minutes ago 21.4MBNow export the container to a tarball.
$ docker save -o /tmp/cntrsrv.tar cntrsrv_image:latest
$ docker tag cntrsrv_image:latest cntrsrv_image:upgrade
$ docker save -o /tmp/cntrsrv-upgrade.tar cntrsrv_image:upgrade
$ docker rmi cntrsrv_image:latestThis 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-sshfsrepository: 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 theMakefilein thedocker-volume-sshfsdirectory and add the following target. This target is specifically designed to create arootfs.tar.gzthat includes theconfig.jsonmanifest at the root, as expected by thecontainerzplugin 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/rootfsdirectory to the archive. - The
-C ../ config.jsonpart adds theconfig.jsonfile (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-sshfsdirectory:make package-plugin-tarball
This command will create a
rootfs.tar.gzfile in thedocker-volume-sshfsproject 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.gzfile using the--plugin_tarflag. For example:go test -v ./feature/container/containerz/tests/container_lifecycle/... --plugin_tar=/path/to/your/docker-volume-sshfs/rootfs.tar.gzReplace
/path/to/your/docker-volume-sshfs/with the actual path to where you cloned and built the plugin. -
SSHFS Plugin Test: Runtime Configuration:
The
TestPlugintest for thevieux/docker-volume-sshfsplugin (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.jsonto a new location. - Modify the
envsection in your copied file with your specific credentials and options. The file should still be based on the originalconfig.jsonfrom thevieux/docker-volume-sshfsplugin. - Update the test flag to point to your custom configuration file.
The JSON structure (like
description,entrypoint,interface,mounts, etc.) should mirror the originalconfig.jsonfrom the plugin, with theenvarray modified as needed. The providedtest_sshfs_config.jsonalready 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-sshfsplugin, 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: