github.com/containers/libpod@v1.9.4-0.20220419124438-4284fd425507/test/e2e/generate_systemd_test.go (about) 1 // +build !remoteclient 2 3 package integration 4 5 import ( 6 "os" 7 8 . "github.com/containers/libpod/test/utils" 9 . "github.com/onsi/ginkgo" 10 . "github.com/onsi/gomega" 11 ) 12 13 var _ = Describe("Podman generate systemd", func() { 14 var ( 15 tempdir string 16 err error 17 podmanTest *PodmanTestIntegration 18 ) 19 20 BeforeEach(func() { 21 tempdir, err = CreateTempDirInTempDir() 22 if err != nil { 23 os.Exit(1) 24 } 25 podmanTest = PodmanTestCreate(tempdir) 26 podmanTest.Setup() 27 podmanTest.SeedImages() 28 }) 29 30 AfterEach(func() { 31 podmanTest.Cleanup() 32 f := CurrentGinkgoTestDescription() 33 processTestResult(f) 34 35 }) 36 37 It("podman generate systemd on bogus container/pod", func() { 38 session := podmanTest.Podman([]string{"generate", "systemd", "foobar"}) 39 session.WaitWithDefaultTimeout() 40 Expect(session).To(ExitWithError()) 41 }) 42 43 It("podman generate systemd bad restart policy", func() { 44 session := podmanTest.Podman([]string{"generate", "systemd", "--restart-policy", "never", "foobar"}) 45 session.WaitWithDefaultTimeout() 46 Expect(session).To(ExitWithError()) 47 }) 48 49 It("podman generate systemd bad timeout value", func() { 50 session := podmanTest.Podman([]string{"generate", "systemd", "--time", "-1", "foobar"}) 51 session.WaitWithDefaultTimeout() 52 Expect(session).To(ExitWithError()) 53 }) 54 55 It("podman generate systemd good timeout value", func() { 56 session := podmanTest.Podman([]string{"create", "--name", "foobar", "alpine", "top"}) 57 session.WaitWithDefaultTimeout() 58 Expect(session.ExitCode()).To(Equal(0)) 59 60 session = podmanTest.Podman([]string{"generate", "systemd", "--time", "1234", "foobar"}) 61 session.WaitWithDefaultTimeout() 62 Expect(session.ExitCode()).To(Equal(0)) 63 64 found, _ := session.GrepString(" stop -t 1234 ") 65 Expect(found).To(BeTrue()) 66 }) 67 68 It("podman generate systemd", func() { 69 n := podmanTest.Podman([]string{"run", "--name", "nginx", "-dt", nginx}) 70 n.WaitWithDefaultTimeout() 71 Expect(n.ExitCode()).To(Equal(0)) 72 73 session := podmanTest.Podman([]string{"generate", "systemd", "nginx"}) 74 session.WaitWithDefaultTimeout() 75 Expect(session.ExitCode()).To(Equal(0)) 76 }) 77 78 It("podman generate systemd --files --name", func() { 79 n := podmanTest.Podman([]string{"run", "--name", "nginx", "-dt", nginx}) 80 n.WaitWithDefaultTimeout() 81 Expect(n.ExitCode()).To(Equal(0)) 82 83 session := podmanTest.Podman([]string{"generate", "systemd", "--files", "--name", "nginx"}) 84 session.WaitWithDefaultTimeout() 85 Expect(session.ExitCode()).To(Equal(0)) 86 87 for _, file := range session.OutputToStringArray() { 88 os.Remove(file) 89 } 90 91 found, _ := session.GrepString("/container-nginx.service") 92 Expect(found).To(BeTrue()) 93 }) 94 95 It("podman generate systemd with timeout", func() { 96 n := podmanTest.Podman([]string{"run", "--name", "nginx", "-dt", nginx}) 97 n.WaitWithDefaultTimeout() 98 Expect(n.ExitCode()).To(Equal(0)) 99 100 session := podmanTest.Podman([]string{"generate", "systemd", "--time", "5", "nginx"}) 101 session.WaitWithDefaultTimeout() 102 Expect(session.ExitCode()).To(Equal(0)) 103 104 found, _ := session.GrepString("podman stop -t 5") 105 Expect(found).To(BeTrue()) 106 }) 107 108 It("podman generate systemd pod --name", func() { 109 n := podmanTest.Podman([]string{"pod", "create", "--name", "foo"}) 110 n.WaitWithDefaultTimeout() 111 Expect(n.ExitCode()).To(Equal(0)) 112 113 n = podmanTest.Podman([]string{"create", "--pod", "foo", "--name", "foo-1", "alpine", "top"}) 114 n.WaitWithDefaultTimeout() 115 Expect(n.ExitCode()).To(Equal(0)) 116 117 n = podmanTest.Podman([]string{"create", "--pod", "foo", "--name", "foo-2", "alpine", "top"}) 118 n.WaitWithDefaultTimeout() 119 Expect(n.ExitCode()).To(Equal(0)) 120 121 session := podmanTest.Podman([]string{"generate", "systemd", "--time", "42", "--name", "foo"}) 122 session.WaitWithDefaultTimeout() 123 Expect(session.ExitCode()).To(Equal(0)) 124 125 // Grepping the output (in addition to unit tests) 126 found, _ := session.GrepString("# pod-foo.service") 127 Expect(found).To(BeTrue()) 128 129 found, _ = session.GrepString("Requires=container-foo-1.service container-foo-2.service") 130 Expect(found).To(BeTrue()) 131 132 found, _ = session.GrepString("# container-foo-1.service") 133 Expect(found).To(BeTrue()) 134 135 found, _ = session.GrepString(" start foo-1") 136 Expect(found).To(BeTrue()) 137 138 found, _ = session.GrepString("-infra") // infra container 139 Expect(found).To(BeTrue()) 140 141 found, _ = session.GrepString("# container-foo-2.service") 142 Expect(found).To(BeTrue()) 143 144 found, _ = session.GrepString(" stop -t 42 foo-2") 145 Expect(found).To(BeTrue()) 146 147 found, _ = session.GrepString("BindsTo=pod-foo.service") 148 Expect(found).To(BeTrue()) 149 150 found, _ = session.GrepString("PIDFile=") 151 Expect(found).To(BeTrue()) 152 153 found, _ = session.GrepString("/userdata/conmon.pid") 154 Expect(found).To(BeTrue()) 155 }) 156 157 It("podman generate systemd pod --name --files", func() { 158 n := podmanTest.Podman([]string{"pod", "create", "--name", "foo"}) 159 n.WaitWithDefaultTimeout() 160 Expect(n.ExitCode()).To(Equal(0)) 161 162 n = podmanTest.Podman([]string{"create", "--pod", "foo", "--name", "foo-1", "alpine", "top"}) 163 n.WaitWithDefaultTimeout() 164 Expect(n.ExitCode()).To(Equal(0)) 165 166 session := podmanTest.Podman([]string{"generate", "systemd", "--name", "--files", "foo"}) 167 session.WaitWithDefaultTimeout() 168 Expect(session.ExitCode()).To(Equal(0)) 169 170 for _, file := range session.OutputToStringArray() { 171 os.Remove(file) 172 } 173 174 found, _ := session.GrepString("/pod-foo.service") 175 Expect(found).To(BeTrue()) 176 177 found, _ = session.GrepString("/container-foo-1.service") 178 Expect(found).To(BeTrue()) 179 }) 180 181 It("podman generate systemd --new", func() { 182 n := podmanTest.Podman([]string{"create", "--name", "foo", "alpine", "top"}) 183 n.WaitWithDefaultTimeout() 184 Expect(n.ExitCode()).To(Equal(0)) 185 186 session := podmanTest.Podman([]string{"generate", "systemd", "-t", "42", "--name", "--new", "foo"}) 187 session.WaitWithDefaultTimeout() 188 Expect(session.ExitCode()).To(Equal(0)) 189 190 // Grepping the output (in addition to unit tests) 191 found, _ := session.GrepString("# container-foo.service") 192 Expect(found).To(BeTrue()) 193 194 found, _ = session.GrepString("stop --ignore --cidfile %t/%n-cid -t 42") 195 Expect(found).To(BeTrue()) 196 }) 197 198 It("podman generate systemd --new without explicit detaching param", func() { 199 n := podmanTest.Podman([]string{"create", "--name", "foo", "alpine", "top"}) 200 n.WaitWithDefaultTimeout() 201 Expect(n.ExitCode()).To(Equal(0)) 202 203 session := podmanTest.Podman([]string{"generate", "systemd", "--timeout", "42", "--name", "--new", "foo"}) 204 session.WaitWithDefaultTimeout() 205 Expect(session.ExitCode()).To(Equal(0)) 206 207 // Grepping the output (in addition to unit tests) 208 found, _ := session.GrepString("--cgroups=no-conmon -d") 209 Expect(found).To(BeTrue()) 210 }) 211 212 It("podman generate systemd --new with explicit detaching param in middle", func() { 213 n := podmanTest.Podman([]string{"create", "--name", "foo", "-d", "alpine", "top"}) 214 n.WaitWithDefaultTimeout() 215 Expect(n.ExitCode()).To(Equal(0)) 216 217 session := podmanTest.Podman([]string{"generate", "systemd", "--time", "42", "--name", "--new", "foo"}) 218 session.WaitWithDefaultTimeout() 219 Expect(session.ExitCode()).To(Equal(0)) 220 221 // Grepping the output (in addition to unit tests) 222 found, _ := session.GrepString("--name foo -d alpine top") 223 Expect(found).To(BeTrue()) 224 }) 225 226 It("podman generate systemd --new pod", func() { 227 n := podmanTest.Podman([]string{"pod", "create", "--name", "foo"}) 228 n.WaitWithDefaultTimeout() 229 Expect(n.ExitCode()).To(Equal(0)) 230 231 session := podmanTest.Podman([]string{"generate", "systemd", "--time", "42", "--name", "--new", "foo"}) 232 session.WaitWithDefaultTimeout() 233 Expect(session.ExitCode()).To(Equal(125)) 234 }) 235 236 })