mirror of
https://github.com/containers/podman.git
synced 2026-07-20 04:02:03 -04:00
This implements support for mounting and unmounting volumes backed by volume plugins. Support for actually retrieving plugins requires a pull request to land in containers.conf and then that to be vendored, and as such is not yet ready. Given this, this code is only compile tested. However, the code for everything past retrieving the plugin has been written - there is support for creating, removing, mounting, and unmounting volumes, which should allow full functionality once the c/common PR is merged. A major change is the signature of the MountPoint function for volumes, which now, by necessity, returns an error. Named volumes managed by a plugin do not have a mountpoint we control; instead, it is managed entirely by the plugin. As such, we need to cache the path in the DB, and calls to retrieve it now need to access the DB (and may fail as such). Notably absent is support for SELinux relabelling and chowning these volumes. Given that we don't manage the mountpoint for these volumes, I am extremely reluctant to try and modify it - we could easily break the plugin trying to chown or relabel it. Also, we had no less than *5* separate implementations of inspecting a volume floating around in pkg/infra/abi and pkg/api/handlers/libpod. And none of them used volume.Inspect(), the only correct way of inspecting volumes. Remove them all and consolidate to using the correct way. Compat API is likely still doing things the wrong way, but that is an issue for another day. Fixes #4304 Signed-off-by: Matthew Heon <matthew.heon@pm.me>
99 lines
3.7 KiB
Bash
99 lines
3.7 KiB
Bash
# -*- sh -*-
|
|
#
|
|
# volume-related tests
|
|
#
|
|
|
|
## create volume
|
|
t GET libpod/info 200
|
|
volumepath=$(jq -r ".store.volumePath" <<<"$output")
|
|
t POST libpod/volumes/create name=foo1 201 \
|
|
.Name=foo1 \
|
|
.Driver=local \
|
|
.Mountpoint=$volumepath/foo1/_data \
|
|
.CreatedAt~[0-9]\\{4\\}-[0-9]\\{2\\}-[0-9]\\{2\\}.* \
|
|
.Labels={} \
|
|
.Options={}
|
|
t POST libpod/volumes/create '' 201
|
|
t POST libpod/volumes/create \
|
|
'"Name":"foo2","Label":{"testlabel":"testonly"},"Options":{"type":"tmpfs","o":"nodev,noexec"}}' 201 \
|
|
.Name=foo2 \
|
|
.Labels.testlabel=testonly \
|
|
.Options.type=tmpfs \
|
|
.Options.o=nodev,noexec
|
|
t POST libpod/volumes/create \
|
|
'"Name":"foo3","Label":{"testlabel":""},"Options":{"type":"tmpfs","o":"nodev,noexec"}}' 201 \
|
|
.Name=foo3 \
|
|
.Labels.testlabel="" \
|
|
.Options.type=tmpfs \
|
|
.Options.o=nodev,noexec
|
|
t POST libpod/volumes/create \
|
|
'"Name":"foo4","Label":{"testlabel1":"testonly"},"Options":{"type":"tmpfs","o":"nodev,noexec"}}' 201 \
|
|
.Name=foo4 \
|
|
.Labels.testlabel1=testonly \
|
|
.Options.type=tmpfs \
|
|
.Options.o=nodev,noexec
|
|
|
|
# Negative test
|
|
# We have created a volume named "foo1"
|
|
t POST libpod/volumes/create name=foo1 500 \
|
|
.cause="volume already exists" \
|
|
.message~.* \
|
|
.response=500
|
|
|
|
## list volume
|
|
t GET libpod/volumes/json 200 \
|
|
.[0].Name~.* \
|
|
.[0].Mountpoint~.* \
|
|
.[0].CreatedAt~[0-9]\\{4\\}-[0-9]\\{2\\}-[0-9]\\{2\\}.*
|
|
# -G --data-urlencode 'filters={"name":["foo1"]}'
|
|
t GET libpod/volumes/json?filters=%7B%22name%22%3A%5B%22foo1%22%5D%7D 200 length=1 .[0].Name=foo1
|
|
# -G --data-urlencode 'filters={"name":["foo1","foo2"]}'
|
|
t GET libpod/volumes/json?filters=%7B%22name%22%3A%20%5B%22foo1%22%2C%20%22foo2%22%5D%7D 200 length=2 .[0].Name=foo1 .[1].Name=foo2
|
|
# -G --data-urlencode 'filters={"name":["nonexistent"]}'
|
|
t GET libpod/volumes/json?filters=%7B%22name%22%3A%5B%22nonexistent%22%5D%7D 200 length=0
|
|
# -G --data-urlencode 'filters={"label":["testlabel"]}'
|
|
t GET libpod/volumes/json?filters=%7B%22label%22:%5B%22testlabel%22%5D%7D 200 length=2
|
|
# -G --data-urlencode 'filters={"label":["testlabel=testonly"]}'
|
|
t GET libpod/volumes/json?filters=%7B%22label%22:%5B%22testlabel=testonly%22%5D%7D 200 length=1
|
|
# -G --data-urlencode 'filters={"label":["testlabel1=testonly"]}'
|
|
t GET libpod/volumes/json?filters=%7B%22label%22:%5B%22testlabel1=testonly%22%5D%7D 200 length=1
|
|
|
|
## inspect volume
|
|
t GET libpod/volumes/foo1/json 200 \
|
|
.Name=foo1 \
|
|
.Mountpoint=$volumepath/foo1/_data \
|
|
.CreatedAt~[0-9]\\{4\\}-[0-9]\\{2\\}-[0-9]\\{2\\}.*
|
|
t GET libpod/volumes/nonexistent/json 404 \
|
|
.cause="no such volume" \
|
|
.message~.* \
|
|
.response=404
|
|
|
|
## Remove volumes
|
|
t DELETE libpod/volumes/foo1 204
|
|
#After remove foo1 volume, this volume should not exist
|
|
t GET libpod/volumes/foo1/json 404
|
|
# Negative test
|
|
t DELETE libpod/volumes/foo1 404 \
|
|
.cause="no such volume" \
|
|
.message~.* \
|
|
.response=404
|
|
|
|
## Prune volumes with label matching 'testlabel1=testonly'
|
|
# -G --data-urlencode 'filters={"label":["testlabel1=testonly"]}'
|
|
t POST libpod/volumes/prune?filters=%7B%22label%22:%5B%22testlabel1=testonly%22%5D%7D "" 200
|
|
# -G --data-urlencode 'filters={"label":["testlabel1=testonly"]}'
|
|
t GET libpod/volumes/json?filters=%7B%22label%22:%5B%22testlabel1=testonly%22%5D%7D 200 length=0
|
|
|
|
## Prune volumes with label matching 'testlabel'
|
|
# -G --data-urlencode 'filters={"label":["testlabel"]}'
|
|
t POST libpod/volumes/prune?filters=%7B%22label%22:%5B%22testlabel%22%5D%7D "" 200
|
|
# -G --data-urlencode 'filters={"label":["testlabel"]}'
|
|
t GET libpod/volumes/json?filters=%7B%22label%22:%5B%22testlabel%22%5D%7D 200 length=0
|
|
|
|
## Prune volumes
|
|
t POST libpod/volumes/prune "" 200
|
|
#After prune volumes, there should be no volume existing
|
|
t GET libpod/volumes/json 200 length=0
|
|
|
|
# vim: filetype=sh
|