github.com/hanks177/podman/v4@v4.1.3-0.20220613032544-16d90015bc83/test/e2e/generate_systemd_test.go (about) 1 package integration 2 3 import ( 4 "io/ioutil" 5 "os" 6 7 . "github.com/hanks177/podman/v4/test/utils" 8 . "github.com/onsi/ginkgo" 9 . "github.com/onsi/gomega" 10 . "github.com/onsi/gomega/gexec" 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 }) 28 29 AfterEach(func() { 30 podmanTest.Cleanup() 31 f := CurrentGinkgoTestDescription() 32 processTestResult(f) 33 34 }) 35 36 It("podman generate systemd on bogus container/pod", func() { 37 session := podmanTest.Podman([]string{"generate", "systemd", "foobar"}) 38 session.WaitWithDefaultTimeout() 39 Expect(session).To(ExitWithError()) 40 }) 41 42 It("podman generate systemd bad restart policy", func() { 43 session := podmanTest.Podman([]string{"generate", "systemd", "--restart-policy", "never", "foobar"}) 44 session.WaitWithDefaultTimeout() 45 Expect(session).To(ExitWithError()) 46 }) 47 48 It("podman generate systemd bad timeout value", func() { 49 session := podmanTest.Podman([]string{"generate", "systemd", "--time", "-1", "foobar"}) 50 session.WaitWithDefaultTimeout() 51 Expect(session).To(ExitWithError()) 52 }) 53 54 It("podman generate systemd bad restart-policy value", func() { 55 session := podmanTest.Podman([]string{"create", "--name", "foobar", "alpine", "top"}) 56 session.WaitWithDefaultTimeout() 57 Expect(session).Should(Exit(0)) 58 59 session = podmanTest.Podman([]string{"generate", "systemd", "--restart-policy", "bogus", "foobar"}) 60 session.WaitWithDefaultTimeout() 61 Expect(session).To(ExitWithError()) 62 Expect(session.ErrorToString()).To(ContainSubstring("bogus is not a valid restart policy")) 63 }) 64 65 It("podman generate systemd with --no-header=true", func() { 66 session := podmanTest.Podman([]string{"create", "--name", "foobar", "alpine", "top"}) 67 session.WaitWithDefaultTimeout() 68 Expect(session).Should(Exit(0)) 69 70 session = podmanTest.Podman([]string{"generate", "systemd", "foobar", "--no-header=true"}) 71 session.WaitWithDefaultTimeout() 72 Expect(session).Should(Exit(0)) 73 74 Expect(session.OutputToString()).NotTo(ContainSubstring("autogenerated by")) 75 }) 76 77 It("podman generate systemd with --no-header", func() { 78 session := podmanTest.Podman([]string{"create", "--name", "foobar", "alpine", "top"}) 79 session.WaitWithDefaultTimeout() 80 Expect(session).Should(Exit(0)) 81 82 session = podmanTest.Podman([]string{"generate", "systemd", "foobar", "--no-header"}) 83 session.WaitWithDefaultTimeout() 84 Expect(session).Should(Exit(0)) 85 86 Expect(session.OutputToString()).NotTo(ContainSubstring("autogenerated by")) 87 }) 88 89 It("podman generate systemd with --no-header=false", func() { 90 session := podmanTest.Podman([]string{"create", "--name", "foobar", "alpine", "top"}) 91 session.WaitWithDefaultTimeout() 92 Expect(session).Should(Exit(0)) 93 94 session = podmanTest.Podman([]string{"generate", "systemd", "foobar", "--no-header=false"}) 95 session.WaitWithDefaultTimeout() 96 Expect(session).Should(Exit(0)) 97 98 Expect(session.OutputToString()).To(ContainSubstring("autogenerated by")) 99 }) 100 101 It("podman generate systemd good timeout value", func() { 102 session := podmanTest.Podman([]string{"create", "--name", "foobar", "alpine", "top"}) 103 session.WaitWithDefaultTimeout() 104 Expect(session).Should(Exit(0)) 105 106 session = podmanTest.Podman([]string{"generate", "systemd", "--time", "1234", "foobar"}) 107 session.WaitWithDefaultTimeout() 108 Expect(session).Should(Exit(0)) 109 Expect(session.OutputToString()).To(ContainSubstring("TimeoutStopSec=1294")) 110 Expect(session.OutputToString()).To(ContainSubstring(" stop -t 1234 ")) 111 }) 112 113 It("podman generate systemd", func() { 114 n := podmanTest.Podman([]string{"run", "--name", "nginx", "-dt", nginx}) 115 n.WaitWithDefaultTimeout() 116 Expect(n).Should(Exit(0)) 117 118 session := podmanTest.Podman([]string{"generate", "systemd", "nginx"}) 119 session.WaitWithDefaultTimeout() 120 Expect(session).Should(Exit(0)) 121 122 // The podman commands in the unit should not contain the root flags 123 Expect(session.OutputToString()).ToNot(ContainSubstring(" --runroot")) 124 }) 125 126 It("podman generate systemd --files --name", func() { 127 n := podmanTest.Podman([]string{"run", "--name", "nginx", "-dt", nginx}) 128 n.WaitWithDefaultTimeout() 129 Expect(n).Should(Exit(0)) 130 131 session := podmanTest.Podman([]string{"generate", "systemd", "--files", "--name", "nginx"}) 132 session.WaitWithDefaultTimeout() 133 Expect(session).Should(Exit(0)) 134 135 for _, file := range session.OutputToStringArray() { 136 os.Remove(file) 137 } 138 Expect(session.OutputToString()).To(ContainSubstring("/container-nginx.service")) 139 }) 140 141 It("podman generate systemd with timeout", func() { 142 n := podmanTest.Podman([]string{"run", "--name", "nginx", "-dt", nginx}) 143 n.WaitWithDefaultTimeout() 144 Expect(n).Should(Exit(0)) 145 146 session := podmanTest.Podman([]string{"generate", "systemd", "--time", "5", "nginx"}) 147 session.WaitWithDefaultTimeout() 148 Expect(session).Should(Exit(0)) 149 Expect(session.OutputToString()).To(ContainSubstring("TimeoutStopSec=65")) 150 Expect(session.OutputToString()).ToNot(ContainSubstring("TimeoutStartSec=")) 151 Expect(session.OutputToString()).To(ContainSubstring("podman stop -t 5")) 152 153 session = podmanTest.Podman([]string{"generate", "systemd", "--stop-timeout", "5", "--start-timeout", "123", "nginx"}) 154 session.WaitWithDefaultTimeout() 155 Expect(session).Should(Exit(0)) 156 Expect(session.OutputToString()).To(ContainSubstring("TimeoutStartSec=123")) 157 Expect(session.OutputToString()).To(ContainSubstring("TimeoutStopSec=65")) 158 Expect(session.OutputToString()).To(ContainSubstring("podman stop -t 5")) 159 }) 160 161 It("podman generate systemd with user-defined dependencies", func() { 162 n := podmanTest.Podman([]string{"run", "--name", "nginx", "-dt", nginx}) 163 n.WaitWithDefaultTimeout() 164 Expect(n).Should(Exit(0)) 165 166 session := podmanTest.Podman([]string{"generate", "systemd", "--wants", "foobar.service", "nginx"}) 167 session.WaitWithDefaultTimeout() 168 Expect(session).Should(Exit(0)) 169 170 // The generated systemd unit should contain the User-defined Wants option 171 Expect(session.OutputToString()).To(ContainSubstring("# User-defined dependencies")) 172 Expect(session.OutputToString()).To(ContainSubstring("Wants=foobar.service")) 173 174 session = podmanTest.Podman([]string{"generate", "systemd", "--after", "foobar.service", "nginx"}) 175 session.WaitWithDefaultTimeout() 176 Expect(session).Should(Exit(0)) 177 178 // The generated systemd unit should contain the User-defined After option 179 Expect(session.OutputToString()).To(ContainSubstring("# User-defined dependencies")) 180 Expect(session.OutputToString()).To(ContainSubstring("After=foobar.service")) 181 182 session = podmanTest.Podman([]string{"generate", "systemd", "--requires", "foobar.service", "nginx"}) 183 session.WaitWithDefaultTimeout() 184 Expect(session).Should(Exit(0)) 185 186 // The generated systemd unit should contain the User-defined Requires option 187 Expect(session.OutputToString()).To(ContainSubstring("# User-defined dependencies")) 188 Expect(session.OutputToString()).To(ContainSubstring("Requires=foobar.service")) 189 190 session = podmanTest.Podman([]string{ 191 "generate", "systemd", 192 "--wants", "foobar.service", "--wants", "barfoo.service", 193 "--after", "foobar.service", "--after", "barfoo.service", 194 "--requires", "foobar.service", "--requires", "barfoo.service", "nginx"}) 195 session.WaitWithDefaultTimeout() 196 Expect(session).Should(Exit(0)) 197 198 // The generated systemd unit should contain the User-defined Want, After, Requires options 199 Expect(session.OutputToString()).To(ContainSubstring("# User-defined dependencies")) 200 Expect(session.OutputToString()).To(ContainSubstring("Wants=foobar.service barfoo.service")) 201 Expect(session.OutputToString()).To(ContainSubstring("After=foobar.service barfoo.service")) 202 Expect(session.OutputToString()).To(ContainSubstring("Requires=foobar.service barfoo.service")) 203 }) 204 205 It("podman generate systemd pod --name", func() { 206 n := podmanTest.Podman([]string{"pod", "create", "--name", "foo"}) 207 n.WaitWithDefaultTimeout() 208 Expect(n).Should(Exit(0)) 209 210 n = podmanTest.Podman([]string{"create", "--pod", "foo", "--name", "foo-1", "alpine", "top"}) 211 n.WaitWithDefaultTimeout() 212 Expect(n).Should(Exit(0)) 213 214 n = podmanTest.Podman([]string{"create", "--pod", "foo", "--name", "foo-2", "alpine", "top"}) 215 n.WaitWithDefaultTimeout() 216 Expect(n).Should(Exit(0)) 217 218 session := podmanTest.Podman([]string{"generate", "systemd", "--time", "42", "--name", "foo"}) 219 session.WaitWithDefaultTimeout() 220 Expect(session).Should(Exit(0)) 221 222 // Grepping the output (in addition to unit tests) 223 Expect(session.OutputToString()).To(ContainSubstring("# pod-foo.service")) 224 Expect(session.OutputToString()).To(ContainSubstring("Requires=container-foo-1.service container-foo-2.service")) 225 Expect(session.OutputToString()).To(ContainSubstring("# container-foo-1.service")) 226 Expect(session.OutputToString()).To(ContainSubstring(" start foo-1")) 227 Expect(session.OutputToString()).To(ContainSubstring("-infra")) // infra container 228 Expect(session.OutputToString()).To(ContainSubstring("# container-foo-2.service")) 229 Expect(session.OutputToString()).To(ContainSubstring(" stop -t 42 foo-2")) 230 Expect(session.OutputToString()).To(ContainSubstring("BindsTo=pod-foo.service")) 231 Expect(session.OutputToString()).To(ContainSubstring("PIDFile=")) 232 Expect(session.OutputToString()).To(ContainSubstring("/userdata/conmon.pid")) 233 234 // The podman commands in the unit should not contain the root flags 235 Expect(session.OutputToString()).ToNot(ContainSubstring(" --runroot")) 236 }) 237 238 It("podman generate systemd pod --name --files", func() { 239 n := podmanTest.Podman([]string{"pod", "create", "--name", "foo"}) 240 n.WaitWithDefaultTimeout() 241 Expect(n).Should(Exit(0)) 242 243 n = podmanTest.Podman([]string{"create", "--pod", "foo", "--name", "foo-1", "alpine", "top"}) 244 n.WaitWithDefaultTimeout() 245 Expect(n).Should(Exit(0)) 246 247 session := podmanTest.Podman([]string{"generate", "systemd", "--name", "--files", "foo"}) 248 session.WaitWithDefaultTimeout() 249 Expect(session).Should(Exit(0)) 250 251 for _, file := range session.OutputToStringArray() { 252 os.Remove(file) 253 } 254 255 Expect(session.OutputToString()).To(ContainSubstring("/pod-foo.service")) 256 Expect(session.OutputToString()).To(ContainSubstring("/container-foo-1.service")) 257 }) 258 259 It("podman generate systemd pod with user-defined dependencies", func() { 260 n := podmanTest.Podman([]string{"pod", "create", "--name", "foo"}) 261 n.WaitWithDefaultTimeout() 262 Expect(n).Should(Exit(0)) 263 264 n = podmanTest.Podman([]string{"create", "--pod", "foo", "--name", "foo-1", "alpine", "top"}) 265 n.WaitWithDefaultTimeout() 266 Expect(n).Should(Exit(0)) 267 268 session := podmanTest.Podman([]string{"generate", "systemd", "--name", "--wants", "foobar.service", "foo"}) 269 session.WaitWithDefaultTimeout() 270 Expect(session).Should(Exit(0)) 271 272 // The generated systemd unit should contain the User-defined Wants option 273 Expect(session.OutputToString()).To(ContainSubstring("# User-defined dependencies")) 274 Expect(session.OutputToString()).To(ContainSubstring("Wants=foobar.service")) 275 276 session = podmanTest.Podman([]string{"generate", "systemd", "--name", "--after", "foobar.service", "foo"}) 277 session.WaitWithDefaultTimeout() 278 Expect(session).Should(Exit(0)) 279 280 // The generated systemd unit should contain the User-defined After option 281 Expect(session.OutputToString()).To(ContainSubstring("# User-defined dependencies")) 282 Expect(session.OutputToString()).To(ContainSubstring("After=foobar.service")) 283 284 session = podmanTest.Podman([]string{"generate", "systemd", "--name", "--requires", "foobar.service", "foo"}) 285 session.WaitWithDefaultTimeout() 286 Expect(session).Should(Exit(0)) 287 288 // The generated systemd unit should contain the User-defined Requires option 289 Expect(session.OutputToString()).To(ContainSubstring("# User-defined dependencies")) 290 Expect(session.OutputToString()).To(ContainSubstring("Requires=foobar.service")) 291 292 session = podmanTest.Podman([]string{ 293 "generate", "systemd", "--name", 294 "--wants", "foobar.service", "--wants", "barfoo.service", 295 "--after", "foobar.service", "--after", "barfoo.service", 296 "--requires", "foobar.service", "--requires", "barfoo.service", "foo"}) 297 session.WaitWithDefaultTimeout() 298 Expect(session).Should(Exit(0)) 299 300 // The generated systemd unit should contain the User-defined Want, After, Requires options 301 Expect(session.OutputToString()).To(ContainSubstring("# User-defined dependencies")) 302 Expect(session.OutputToString()).To(ContainSubstring("Wants=foobar.service barfoo.service")) 303 Expect(session.OutputToString()).To(ContainSubstring("After=foobar.service barfoo.service")) 304 Expect(session.OutputToString()).To(ContainSubstring("Requires=foobar.service barfoo.service")) 305 }) 306 307 It("podman generate systemd --new --name foo", func() { 308 n := podmanTest.Podman([]string{"create", "--name", "foo", "alpine", "top"}) 309 n.WaitWithDefaultTimeout() 310 Expect(n).Should(Exit(0)) 311 312 session := podmanTest.Podman([]string{"generate", "systemd", "-t", "42", "--name", "--new", "foo"}) 313 session.WaitWithDefaultTimeout() 314 Expect(session).Should(Exit(0)) 315 316 // Grepping the output (in addition to unit tests) 317 Expect(session.OutputToString()).To(ContainSubstring("# container-foo.service")) 318 Expect(session.OutputToString()).To(ContainSubstring(" --replace ")) 319 if !IsRemote() { 320 // The podman commands in the unit should contain the root flags if generate systemd --new is used 321 Expect(session.OutputToString()).To(ContainSubstring(" --runroot")) 322 } 323 }) 324 325 It("podman generate systemd --new --name=foo", func() { 326 n := podmanTest.Podman([]string{"create", "--name=foo", "alpine", "top"}) 327 n.WaitWithDefaultTimeout() 328 Expect(n).Should(Exit(0)) 329 330 session := podmanTest.Podman([]string{"generate", "systemd", "-t", "42", "--name", "--new", "foo"}) 331 session.WaitWithDefaultTimeout() 332 Expect(session).Should(Exit(0)) 333 334 // Grepping the output (in addition to unit tests) 335 Expect(session.OutputToString()).To(ContainSubstring("# container-foo.service")) 336 Expect(session.OutputToString()).To(ContainSubstring(" --replace ")) 337 }) 338 339 It("podman generate systemd --new without explicit detaching param", func() { 340 n := podmanTest.Podman([]string{"create", "--name", "foo", "alpine", "top"}) 341 n.WaitWithDefaultTimeout() 342 Expect(n).Should(Exit(0)) 343 344 session := podmanTest.Podman([]string{"generate", "systemd", "--time", "42", "--name", "--new", "foo"}) 345 session.WaitWithDefaultTimeout() 346 Expect(session).Should(Exit(0)) 347 348 // Grepping the output (in addition to unit tests) 349 Expect(session.OutputToString()).To(ContainSubstring(" -d ")) 350 }) 351 352 It("podman generate systemd --new with explicit detaching param in middle", func() { 353 n := podmanTest.Podman([]string{"create", "--name", "foo", "alpine", "top"}) 354 n.WaitWithDefaultTimeout() 355 Expect(n).Should(Exit(0)) 356 357 session := podmanTest.Podman([]string{"generate", "systemd", "--time", "42", "--name", "--new", "foo"}) 358 session.WaitWithDefaultTimeout() 359 Expect(session).Should(Exit(0)) 360 361 // Grepping the output (in addition to unit tests) 362 Expect(session.OutputToString()).To(ContainSubstring("--name foo alpine top")) 363 }) 364 365 It("podman generate systemd --new pod", func() { 366 n := podmanTest.Podman([]string{"pod", "create", "--name", "foo"}) 367 n.WaitWithDefaultTimeout() 368 Expect(n).Should(Exit(0)) 369 370 session := podmanTest.Podman([]string{"generate", "systemd", "--time", "42", "--name", "--new", "foo"}) 371 session.WaitWithDefaultTimeout() 372 Expect(session).Should(Exit(0)) 373 Expect(session.OutputToString()).To(ContainSubstring(" pod create ")) 374 }) 375 376 It("podman generate systemd --restart-sec 15 --name foo", func() { 377 n := podmanTest.Podman([]string{"pod", "create", "--name", "foo"}) 378 n.WaitWithDefaultTimeout() 379 Expect(n).Should(Exit(0)) 380 381 session := podmanTest.Podman([]string{"generate", "systemd", "--restart-sec", "15", "--name", "foo"}) 382 session.WaitWithDefaultTimeout() 383 Expect(session).Should(Exit(0)) 384 385 // Grepping the output (in addition to unit tests) 386 Expect(session.OutputToString()).To(ContainSubstring("RestartSec=15")) 387 }) 388 389 It("podman generate systemd --new=false pod", func() { 390 n := podmanTest.Podman([]string{"pod", "create", "--name", "foo"}) 391 n.WaitWithDefaultTimeout() 392 Expect(n).Should(Exit(0)) 393 394 session := podmanTest.Podman([]string{"generate", "systemd", "--time", "42", "--name", "--new=false", "foo"}) 395 session.WaitWithDefaultTimeout() 396 Expect(session).Should(Exit(0)) 397 Expect(session.OutputToString()).NotTo(ContainSubstring(" pod create ")) 398 }) 399 400 It("podman generate systemd --new=true pod", func() { 401 n := podmanTest.Podman([]string{"pod", "create", "--name", "foo"}) 402 n.WaitWithDefaultTimeout() 403 Expect(n).Should(Exit(0)) 404 405 session := podmanTest.Podman([]string{"generate", "systemd", "--time", "42", "--name", "--new=true", "foo"}) 406 session.WaitWithDefaultTimeout() 407 Expect(session).Should(Exit(0)) 408 Expect(session.OutputToString()).To(ContainSubstring(" pod create ")) 409 }) 410 411 It("podman generate systemd --container-prefix con", func() { 412 n := podmanTest.Podman([]string{"create", "--name", "foo", "alpine", "top"}) 413 n.WaitWithDefaultTimeout() 414 Expect(n).Should(Exit(0)) 415 416 session := podmanTest.Podman([]string{"generate", "systemd", "--name", "--container-prefix", "con", "foo"}) 417 session.WaitWithDefaultTimeout() 418 Expect(session).Should(Exit(0)) 419 420 // Grepping the output (in addition to unit tests) 421 Expect(session.OutputToString()).To(ContainSubstring("# con-foo.service")) 422 423 }) 424 425 It("podman generate systemd --container-prefix ''", func() { 426 n := podmanTest.Podman([]string{"create", "--name", "foo", "alpine", "top"}) 427 n.WaitWithDefaultTimeout() 428 Expect(n).Should(Exit(0)) 429 430 session := podmanTest.Podman([]string{"generate", "systemd", "--name", "--container-prefix", "", "foo"}) 431 session.WaitWithDefaultTimeout() 432 Expect(session).Should(Exit(0)) 433 434 // Grepping the output (in addition to unit tests) 435 Expect(session.OutputToString()).To(ContainSubstring("# foo.service")) 436 437 }) 438 439 It("podman generate systemd --separator _", func() { 440 n := podmanTest.Podman([]string{"create", "--name", "foo", "alpine", "top"}) 441 n.WaitWithDefaultTimeout() 442 Expect(n).Should(Exit(0)) 443 444 session := podmanTest.Podman([]string{"generate", "systemd", "--name", "--separator", "_", "foo"}) 445 session.WaitWithDefaultTimeout() 446 Expect(session).Should(Exit(0)) 447 448 // Grepping the output (in addition to unit tests) 449 Expect(session.OutputToString()).To(ContainSubstring("# container_foo.service")) 450 }) 451 452 It("podman generate systemd pod --pod-prefix p", func() { 453 n := podmanTest.Podman([]string{"pod", "create", "--name", "foo"}) 454 n.WaitWithDefaultTimeout() 455 Expect(n).Should(Exit(0)) 456 457 n = podmanTest.Podman([]string{"create", "--pod", "foo", "--name", "foo-1", "alpine", "top"}) 458 n.WaitWithDefaultTimeout() 459 Expect(n).Should(Exit(0)) 460 461 n = podmanTest.Podman([]string{"create", "--pod", "foo", "--name", "foo-2", "alpine", "top"}) 462 n.WaitWithDefaultTimeout() 463 Expect(n).Should(Exit(0)) 464 465 session := podmanTest.Podman([]string{"generate", "systemd", "--pod-prefix", "p", "--name", "foo"}) 466 session.WaitWithDefaultTimeout() 467 Expect(session).Should(Exit(0)) 468 469 // Grepping the output (in addition to unit tests) 470 Expect(session.OutputToString()).To(ContainSubstring("# p-foo.service")) 471 Expect(session.OutputToString()).To(ContainSubstring("Requires=container-foo-1.service container-foo-2.service")) 472 Expect(session.OutputToString()).To(ContainSubstring("# container-foo-1.service")) 473 Expect(session.OutputToString()).To(ContainSubstring("BindsTo=p-foo.service")) 474 }) 475 476 It("podman generate systemd pod --pod-prefix p --container-prefix con --separator _ change all prefixes/separator", func() { 477 n := podmanTest.Podman([]string{"pod", "create", "--name", "foo"}) 478 n.WaitWithDefaultTimeout() 479 Expect(n).Should(Exit(0)) 480 481 n = podmanTest.Podman([]string{"create", "--pod", "foo", "--name", "foo-1", "alpine", "top"}) 482 n.WaitWithDefaultTimeout() 483 Expect(n).Should(Exit(0)) 484 485 n = podmanTest.Podman([]string{"create", "--pod", "foo", "--name", "foo-2", "alpine", "top"}) 486 n.WaitWithDefaultTimeout() 487 Expect(n).Should(Exit(0)) 488 489 session := podmanTest.Podman([]string{"generate", "systemd", "--container-prefix", "con", "--pod-prefix", "p", "--separator", "_", "--name", "foo"}) 490 session.WaitWithDefaultTimeout() 491 Expect(session).Should(Exit(0)) 492 493 // Grepping the output (in addition to unit tests) 494 Expect(session.OutputToString()).To(ContainSubstring("# p_foo.service")) 495 Expect(session.OutputToString()).To(ContainSubstring("Requires=con_foo-1.service con_foo-2.service")) 496 Expect(session.OutputToString()).To(ContainSubstring("# con_foo-1.service")) 497 Expect(session.OutputToString()).To(ContainSubstring("# con_foo-2.service")) 498 Expect(session.OutputToString()).To(ContainSubstring("BindsTo=p_foo.service")) 499 }) 500 501 It("podman generate systemd pod --pod-prefix '' --container-prefix '' --separator _ change all prefixes/separator", func() { 502 n := podmanTest.Podman([]string{"pod", "create", "--name", "foo"}) 503 n.WaitWithDefaultTimeout() 504 Expect(n).Should(Exit(0)) 505 506 n = podmanTest.Podman([]string{"create", "--pod", "foo", "--name", "foo-1", "alpine", "top"}) 507 n.WaitWithDefaultTimeout() 508 Expect(n).Should(Exit(0)) 509 510 n = podmanTest.Podman([]string{"create", "--pod", "foo", "--name", "foo-2", "alpine", "top"}) 511 n.WaitWithDefaultTimeout() 512 Expect(n).Should(Exit(0)) 513 514 // test systemd generate with empty pod prefix 515 session1 := podmanTest.Podman([]string{"generate", "systemd", "--pod-prefix", "", "--name", "foo"}) 516 session1.WaitWithDefaultTimeout() 517 Expect(session1).Should(Exit(0)) 518 519 // Grepping the output (in addition to unit tests) 520 Expect(session1.OutputToString()).To(ContainSubstring("# foo.service")) 521 Expect(session1.OutputToString()).To(ContainSubstring("Requires=container-foo-1.service container-foo-2.service")) 522 Expect(session1.OutputToString()).To(ContainSubstring("# container-foo-1.service")) 523 Expect(session1.OutputToString()).To(ContainSubstring("BindsTo=foo.service")) 524 525 // test systemd generate with empty container and pod prefix 526 session2 := podmanTest.Podman([]string{"generate", "systemd", "--container-prefix", "", "--pod-prefix", "", "--separator", "_", "--name", "foo"}) 527 session2.WaitWithDefaultTimeout() 528 Expect(session2).Should(Exit(0)) 529 530 // Grepping the output (in addition to unit tests) 531 Expect(session2.OutputToString()).To(ContainSubstring("# foo.service")) 532 Expect(session2.OutputToString()).To(ContainSubstring("Requires=foo-1.service foo-2.service")) 533 Expect(session2.OutputToString()).To(ContainSubstring("# foo-1.service")) 534 Expect(session2.OutputToString()).To(ContainSubstring("# foo-2.service")) 535 Expect(session2.OutputToString()).To(ContainSubstring("BindsTo=foo.service")) 536 537 }) 538 539 It("podman generate systemd pod with containers --new", func() { 540 tmpDir, err := ioutil.TempDir("", "") 541 Expect(err).To(BeNil()) 542 tmpFile := tmpDir + "podID" 543 defer os.RemoveAll(tmpDir) 544 545 n := podmanTest.Podman([]string{"pod", "create", "--pod-id-file", tmpFile, "--name", "foo"}) 546 n.WaitWithDefaultTimeout() 547 Expect(n).Should(Exit(0)) 548 549 n = podmanTest.Podman([]string{"create", "--pod", "foo", "--name", "foo-1", "alpine", "top"}) 550 n.WaitWithDefaultTimeout() 551 Expect(n).Should(Exit(0)) 552 553 n = podmanTest.Podman([]string{"create", "--pod", "foo", "--name", "foo-2", "alpine", "top"}) 554 n.WaitWithDefaultTimeout() 555 Expect(n).Should(Exit(0)) 556 557 session := podmanTest.Podman([]string{"generate", "systemd", "--new", "--name", "foo"}) 558 session.WaitWithDefaultTimeout() 559 Expect(session).Should(Exit(0)) 560 561 // Grepping the output (in addition to unit tests) 562 Expect(session.OutputToString()).To(ContainSubstring("# pod-foo.service")) 563 Expect(session.OutputToString()).To(ContainSubstring("Requires=container-foo-1.service container-foo-2.service")) 564 Expect(session.OutputToString()).To(ContainSubstring("BindsTo=pod-foo.service")) 565 Expect(session.OutputToString()).To(ContainSubstring("pod create --infra-conmon-pidfile %t/pod-foo.pid --pod-id-file %t/pod-foo.pod-id --name foo")) 566 Expect(session.OutputToString()).To(ContainSubstring("ExecStartPre=/bin/rm -f %t/pod-foo.pid %t/pod-foo.pod-id")) 567 Expect(session.OutputToString()).To(ContainSubstring("pod stop --ignore --pod-id-file %t/pod-foo.pod-id -t 10")) 568 Expect(session.OutputToString()).To(ContainSubstring("pod rm --ignore -f --pod-id-file %t/pod-foo.pod-id")) 569 }) 570 571 It("podman generate systemd --format json", func() { 572 n := podmanTest.Podman([]string{"create", "--name", "foo", ALPINE}) 573 n.WaitWithDefaultTimeout() 574 Expect(n).Should(Exit(0)) 575 576 session := podmanTest.Podman([]string{"generate", "systemd", "--format", "json", "foo"}) 577 session.WaitWithDefaultTimeout() 578 Expect(session).Should(Exit(0)) 579 Expect(session.OutputToString()).To(BeValidJSON()) 580 }) 581 582 It("podman generate systemd --new create command with double curly braces", func() { 583 SkipIfInContainer("journald inside a container doesn't work") 584 // Regression test for #9034 585 session := podmanTest.Podman([]string{"create", "--name", "foo", "--log-driver=journald", "--log-opt=tag={{.Name}}", ALPINE}) 586 session.WaitWithDefaultTimeout() 587 Expect(session).Should(Exit(0)) 588 589 session = podmanTest.Podman([]string{"generate", "systemd", "--new", "foo"}) 590 session.WaitWithDefaultTimeout() 591 Expect(session).Should(Exit(0)) 592 Expect(session.OutputToString()).To(ContainSubstring(" --log-opt=tag={{.Name}} ")) 593 594 session = podmanTest.Podman([]string{"pod", "create", "--name", "pod", "--label", "key={{someval}}"}) 595 session.WaitWithDefaultTimeout() 596 Expect(session).Should(Exit(0)) 597 598 session = podmanTest.Podman([]string{"generate", "systemd", "--new", "pod"}) 599 session.WaitWithDefaultTimeout() 600 Expect(session).Should(Exit(0)) 601 Expect(session.OutputToString()).To(ContainSubstring(" --label key={{someval}}")) 602 }) 603 })