mirror of
https://github.com/containers/podman.git
synced 2025-11-29 01:28:22 +08:00
Add cdi-spec-dir option to top level options.
This commit adds new --cdi-spec-dir global option. This option is used to add additional CDI spec paths. Signed-off-by: Micah Chambers (eos) <mchambers@anduril.com> Signed-off-by: Jan Kaluza <jkaluza@redhat.com>
This commit is contained in:
committed by
Jan Kaluza
parent
a36276f5ad
commit
dce36131ae
@@ -3,19 +3,29 @@
|
||||
package integration
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/fs"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
. "github.com/containers/podman/v5/test/utils"
|
||||
. "github.com/onsi/ginkgo/v2"
|
||||
. "github.com/onsi/gomega"
|
||||
)
|
||||
|
||||
func createContainersConfFileWithDevices(pTest *PodmanTestIntegration, devices string) {
|
||||
func createContainersConfFileWithDevices(pTest *PodmanTestIntegration, devices string, cdiSpecDirs []string) {
|
||||
configPath := filepath.Join(pTest.TempDir, "containers.conf")
|
||||
containersConf := []byte(fmt.Sprintf("[containers]\ndevices = [%s]\n", devices))
|
||||
if len(cdiSpecDirs) > 0 {
|
||||
quoted := make([]string, len(cdiSpecDirs))
|
||||
for i, dir := range cdiSpecDirs {
|
||||
quoted[i] = fmt.Sprintf("%q", dir)
|
||||
}
|
||||
containersConf = append(containersConf, []byte(fmt.Sprintf("[engine]\ncdi_spec_dirs = [%s]\n", strings.Join(quoted, ", ")))...)
|
||||
}
|
||||
err := os.WriteFile(configPath, containersConf, os.ModePerm)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
@@ -103,7 +113,7 @@ var _ = Describe("Podman run device", func() {
|
||||
It("podman run CDI device test", func() {
|
||||
SkipIfRootless("Rootless will not be able to create files/folders in /etc")
|
||||
cdiDir := "/etc/cdi"
|
||||
if _, err := os.Stat(cdiDir); os.IsNotExist(err) {
|
||||
if _, err := os.Stat(cdiDir); errors.Is(err, fs.ErrNotExist) {
|
||||
Expect(os.MkdirAll(cdiDir, os.ModePerm)).To(Succeed())
|
||||
}
|
||||
defer os.RemoveAll(cdiDir)
|
||||
@@ -116,7 +126,26 @@ var _ = Describe("Podman run device", func() {
|
||||
session.WaitWithDefaultTimeout()
|
||||
Expect(session).Should(ExitCleanly())
|
||||
|
||||
createContainersConfFileWithDevices(podmanTest, "\"vendor.com/device=myKmsg\"")
|
||||
createContainersConfFileWithDevices(podmanTest, "\"vendor.com/device=myKmsg\"", []string{})
|
||||
session = podmanTest.Podman([]string{"run", "-q", "--security-opt", "label=disable", ALPINE, "test", "-c", "/dev/kmsg1"})
|
||||
session.WaitWithDefaultTimeout()
|
||||
Expect(session).Should(ExitCleanly())
|
||||
})
|
||||
|
||||
It("podman run CDI device test with --cdi-spec-dir", func() {
|
||||
SkipIfRemote("The --cdi-spec-dir only works locally.")
|
||||
cdiDir := podmanTest.TempDir + "/cdi"
|
||||
Expect(os.MkdirAll(cdiDir, os.ModePerm)).To(Succeed())
|
||||
|
||||
cmd := exec.Command("cp", "cdi/device.json", cdiDir)
|
||||
err = cmd.Run()
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
session := podmanTest.Podman([]string{"run", "--cdi-spec-dir", cdiDir, "-q", "--security-opt", "label=disable", "--device", "vendor.com/device=myKmsg", ALPINE, "test", "-c", "/dev/kmsg1"})
|
||||
session.WaitWithDefaultTimeout()
|
||||
Expect(session).Should(ExitCleanly())
|
||||
|
||||
createContainersConfFileWithDevices(podmanTest, "\"vendor.com/device=myKmsg\"", []string{cdiDir})
|
||||
session = podmanTest.Podman([]string{"run", "-q", "--security-opt", "label=disable", ALPINE, "test", "-c", "/dev/kmsg1"})
|
||||
session.WaitWithDefaultTimeout()
|
||||
Expect(session).Should(ExitCleanly())
|
||||
|
||||
Reference in New Issue
Block a user