github.com/AbhinandanKurakure/podman/v3@v3.4.10/test/e2e/volume_plugin_test.go (about) 1 package integration 2 3 import ( 4 "fmt" 5 "os" 6 "path/filepath" 7 8 . "github.com/containers/podman/v3/test/utils" 9 . "github.com/onsi/ginkgo" 10 . "github.com/onsi/gomega" 11 . "github.com/onsi/gomega/gexec" 12 ) 13 14 var _ = Describe("Podman volume plugins", func() { 15 var ( 16 tempdir string 17 err error 18 podmanTest *PodmanTestIntegration 19 ) 20 21 BeforeEach(func() { 22 tempdir, err = CreateTempDirInTempDir() 23 if err != nil { 24 os.Exit(1) 25 } 26 podmanTest = PodmanTestCreate(tempdir) 27 podmanTest.Setup() 28 podmanTest.SeedImages() 29 os.Setenv("CONTAINERS_CONF", "config/containers.conf") 30 SkipIfRemote("Volume plugins only supported as local") 31 SkipIfRootless("Root is required for volume plugin testing") 32 os.MkdirAll("/run/docker/plugins", 0755) 33 }) 34 35 AfterEach(func() { 36 podmanTest.CleanupVolume() 37 f := CurrentGinkgoTestDescription() 38 processTestResult(f) 39 os.Unsetenv("CONTAINERS_CONF") 40 }) 41 42 It("volume create with nonexistent plugin errors", func() { 43 session := podmanTest.Podman([]string{"volume", "create", "--driver", "notexist", "test_volume_name"}) 44 session.WaitWithDefaultTimeout() 45 Expect(session).To(ExitWithError()) 46 }) 47 48 It("volume create with not-running plugin does not error", func() { 49 session := podmanTest.Podman([]string{"volume", "create", "--driver", "testvol0", "test_volume_name"}) 50 session.WaitWithDefaultTimeout() 51 Expect(session).To(ExitWithError()) 52 }) 53 54 It("volume create and remove with running plugin succeeds", func() { 55 podmanTest.AddImageToRWStore(volumeTest) 56 57 pluginStatePath := filepath.Join(podmanTest.TempDir, "volumes") 58 os.Mkdir(pluginStatePath, 0755) 59 60 // Keep this distinct within tests to avoid multiple tests using the same plugin. 61 pluginName := "testvol1" 62 plugin := podmanTest.Podman([]string{"run", "--security-opt", "label=disable", "-v", "/run/docker/plugins:/run/docker/plugins", "-v", fmt.Sprintf("%v:%v", pluginStatePath, pluginStatePath), "-d", volumeTest, "--sock-name", pluginName, "--path", pluginStatePath}) 63 plugin.WaitWithDefaultTimeout() 64 Expect(plugin).Should(Exit(0)) 65 66 volName := "testVolume1" 67 create := podmanTest.Podman([]string{"volume", "create", "--driver", pluginName, volName}) 68 create.WaitWithDefaultTimeout() 69 Expect(create).Should(Exit(0)) 70 71 ls1 := podmanTest.Podman([]string{"volume", "ls", "-q"}) 72 ls1.WaitWithDefaultTimeout() 73 Expect(ls1).Should(Exit(0)) 74 arrOutput := ls1.OutputToStringArray() 75 Expect(len(arrOutput)).To(Equal(1)) 76 Expect(arrOutput[0]).To(ContainSubstring(volName)) 77 78 remove := podmanTest.Podman([]string{"volume", "rm", volName}) 79 remove.WaitWithDefaultTimeout() 80 Expect(remove).Should(Exit(0)) 81 82 ls2 := podmanTest.Podman([]string{"volume", "ls", "-q"}) 83 ls2.WaitWithDefaultTimeout() 84 Expect(ls2).Should(Exit(0)) 85 Expect(len(ls2.OutputToStringArray())).To(Equal(0)) 86 }) 87 88 It("volume inspect with running plugin succeeds", func() { 89 podmanTest.AddImageToRWStore(volumeTest) 90 91 pluginStatePath := filepath.Join(podmanTest.TempDir, "volumes") 92 os.Mkdir(pluginStatePath, 0755) 93 94 // Keep this distinct within tests to avoid multiple tests using the same plugin. 95 pluginName := "testvol2" 96 plugin := podmanTest.Podman([]string{"run", "--security-opt", "label=disable", "-v", "/run/docker/plugins:/run/docker/plugins", "-v", fmt.Sprintf("%v:%v", pluginStatePath, pluginStatePath), "-d", volumeTest, "--sock-name", pluginName, "--path", pluginStatePath}) 97 plugin.WaitWithDefaultTimeout() 98 Expect(plugin).Should(Exit(0)) 99 100 volName := "testVolume1" 101 create := podmanTest.Podman([]string{"volume", "create", "--driver", pluginName, volName}) 102 create.WaitWithDefaultTimeout() 103 Expect(create).Should(Exit(0)) 104 105 volInspect := podmanTest.Podman([]string{"volume", "inspect", "--format", "{{ .Driver }}", volName}) 106 volInspect.WaitWithDefaultTimeout() 107 Expect(volInspect).Should(Exit(0)) 108 Expect(volInspect.OutputToString()).To(ContainSubstring(pluginName)) 109 }) 110 111 It("remove plugin with stopped plugin succeeds", func() { 112 podmanTest.AddImageToRWStore(volumeTest) 113 114 pluginStatePath := filepath.Join(podmanTest.TempDir, "volumes") 115 os.Mkdir(pluginStatePath, 0755) 116 117 // Keep this distinct within tests to avoid multiple tests using the same plugin. 118 pluginName := "testvol3" 119 ctrName := "pluginCtr" 120 plugin := podmanTest.Podman([]string{"run", "--name", ctrName, "--security-opt", "label=disable", "-v", "/run/docker/plugins:/run/docker/plugins", "-v", fmt.Sprintf("%v:%v", pluginStatePath, pluginStatePath), "-d", volumeTest, "--sock-name", pluginName, "--path", pluginStatePath}) 121 plugin.WaitWithDefaultTimeout() 122 Expect(plugin).Should(Exit(0)) 123 124 volName := "testVolume1" 125 create := podmanTest.Podman([]string{"volume", "create", "--driver", pluginName, volName}) 126 create.WaitWithDefaultTimeout() 127 Expect(create).Should(Exit(0)) 128 129 ls1 := podmanTest.Podman([]string{"volume", "ls", "-q"}) 130 ls1.WaitWithDefaultTimeout() 131 Expect(ls1).Should(Exit(0)) 132 arrOutput := ls1.OutputToStringArray() 133 Expect(len(arrOutput)).To(Equal(1)) 134 Expect(arrOutput[0]).To(ContainSubstring(volName)) 135 136 stop := podmanTest.Podman([]string{"stop", "--timeout", "0", ctrName}) 137 stop.WaitWithDefaultTimeout() 138 Expect(stop).Should(Exit(0)) 139 140 // Remove should exit non-zero because missing plugin 141 remove := podmanTest.Podman([]string{"volume", "rm", volName}) 142 remove.WaitWithDefaultTimeout() 143 Expect(remove).To(ExitWithError()) 144 145 // But the volume should still be gone 146 ls2 := podmanTest.Podman([]string{"volume", "ls", "-q"}) 147 ls2.WaitWithDefaultTimeout() 148 Expect(ls2).Should(Exit(0)) 149 Expect(len(ls2.OutputToStringArray())).To(Equal(0)) 150 }) 151 152 It("use plugin in containers", func() { 153 podmanTest.AddImageToRWStore(volumeTest) 154 155 pluginStatePath := filepath.Join(podmanTest.TempDir, "volumes") 156 os.Mkdir(pluginStatePath, 0755) 157 158 // Keep this distinct within tests to avoid multiple tests using the same plugin. 159 pluginName := "testvol4" 160 plugin := podmanTest.Podman([]string{"run", "--security-opt", "label=disable", "-v", "/run/docker/plugins:/run/docker/plugins", "-v", fmt.Sprintf("%v:%v", pluginStatePath, pluginStatePath), "-d", volumeTest, "--sock-name", pluginName, "--path", pluginStatePath}) 161 plugin.WaitWithDefaultTimeout() 162 Expect(plugin).Should(Exit(0)) 163 164 volName := "testVolume1" 165 create := podmanTest.Podman([]string{"volume", "create", "--driver", pluginName, volName}) 166 create.WaitWithDefaultTimeout() 167 Expect(create).Should(Exit(0)) 168 169 ctr1 := podmanTest.Podman([]string{"run", "--security-opt", "label=disable", "-v", fmt.Sprintf("%v:/test", volName), ALPINE, "sh", "-c", "touch /test/testfile && echo helloworld > /test/testfile"}) 170 ctr1.WaitWithDefaultTimeout() 171 Expect(ctr1).Should(Exit(0)) 172 173 ctr2 := podmanTest.Podman([]string{"run", "--security-opt", "label=disable", "-v", fmt.Sprintf("%v:/test", volName), ALPINE, "cat", "/test/testfile"}) 174 ctr2.WaitWithDefaultTimeout() 175 Expect(ctr2).Should(Exit(0)) 176 Expect(ctr2.OutputToString()).To(ContainSubstring("helloworld")) 177 178 // HACK: `volume rm -f` is timing out trying to remove containers using the volume. 179 // Solution: remove them manually... 180 // TODO: fix this when I get back 181 rmAll := podmanTest.Podman([]string{"rm", "-af"}) 182 rmAll.WaitWithDefaultTimeout() 183 Expect(rmAll).Should(Exit(0)) 184 }) 185 })