github.com/AbhinandanKurakure/podman/v3@v3.4.10/test/e2e/checkpoint_test.go (about) 1 package integration 2 3 import ( 4 "fmt" 5 "net" 6 "os" 7 "os/exec" 8 "strings" 9 "time" 10 11 "github.com/containers/podman/v3/pkg/checkpoint/crutils" 12 "github.com/containers/podman/v3/pkg/criu" 13 . "github.com/containers/podman/v3/test/utils" 14 "github.com/containers/podman/v3/utils" 15 . "github.com/onsi/ginkgo" 16 . "github.com/onsi/gomega" 17 . "github.com/onsi/gomega/gexec" 18 ) 19 20 func getRunString(input []string) []string { 21 // CRIU does not work with seccomp correctly on RHEL7 : seccomp=unconfined 22 runString := []string{"run", "-it", "--security-opt", "seccomp=unconfined", "-d", "--ip", GetRandomIPAddress()} 23 return append(runString, input...) 24 } 25 26 var _ = Describe("Podman checkpoint", func() { 27 var ( 28 tempdir string 29 err error 30 podmanTest *PodmanTestIntegration 31 ) 32 33 BeforeEach(func() { 34 SkipIfRemote("checkpoint not supported in remote mode") 35 SkipIfRootless("checkpoint not supported in rootless mode") 36 tempdir, err = CreateTempDirInTempDir() 37 if err != nil { 38 os.Exit(1) 39 } 40 podmanTest = PodmanTestCreate(tempdir) 41 podmanTest.Setup() 42 podmanTest.SeedImages() 43 // Check if the runtime implements checkpointing. Currently only 44 // runc's checkpoint/restore implementation is supported. 45 cmd := exec.Command(podmanTest.OCIRuntime, "checkpoint", "--help") 46 if err := cmd.Start(); err != nil { 47 Skip("OCI runtime does not support checkpoint/restore") 48 } 49 if err := cmd.Wait(); err != nil { 50 Skip("OCI runtime does not support checkpoint/restore") 51 } 52 53 if !criu.CheckForCriu(criu.MinCriuVersion) { 54 Skip("CRIU is missing or too old.") 55 } 56 // Only Fedora 29 and newer has a new enough selinux-policy and 57 // container-selinux package to support CRIU in correctly 58 // restoring threaded processes 59 hostInfo := podmanTest.Host 60 if hostInfo.Distribution == "fedora" && hostInfo.Version < "29" { 61 Skip("Checkpoint/Restore with SELinux only works on Fedora >= 29") 62 } 63 }) 64 65 AfterEach(func() { 66 podmanTest.Cleanup() 67 f := CurrentGinkgoTestDescription() 68 processTestResult(f) 69 70 }) 71 72 It("podman checkpoint bogus container", func() { 73 session := podmanTest.Podman([]string{"container", "checkpoint", "foobar"}) 74 session.WaitWithDefaultTimeout() 75 Expect(session).To(ExitWithError()) 76 }) 77 78 It("podman restore bogus container", func() { 79 session := podmanTest.Podman([]string{"container", "restore", "foobar"}) 80 session.WaitWithDefaultTimeout() 81 Expect(session).To(ExitWithError()) 82 }) 83 84 It("podman checkpoint a running container by id", func() { 85 localRunString := getRunString([]string{ALPINE, "top"}) 86 session := podmanTest.Podman(localRunString) 87 session.WaitWithDefaultTimeout() 88 Expect(session).Should(Exit(0)) 89 cid := session.OutputToString() 90 91 result := podmanTest.Podman([]string{"container", "checkpoint", cid}) 92 result.WaitWithDefaultTimeout() 93 94 Expect(result).Should(Exit(0)) 95 Expect(podmanTest.NumberOfContainersRunning()).To(Equal(0)) 96 Expect(podmanTest.GetContainerStatus()).To(ContainSubstring("Exited")) 97 98 inspect := podmanTest.Podman([]string{"inspect", cid}) 99 inspect.WaitWithDefaultTimeout() 100 Expect(inspect).Should(Exit(0)) 101 inspectOut := inspect.InspectContainerToJSON() 102 Expect(inspectOut[0].State.Checkpointed).To(BeTrue()) 103 104 result = podmanTest.Podman([]string{"container", "restore", cid}) 105 result.WaitWithDefaultTimeout() 106 107 Expect(result).Should(Exit(0)) 108 Expect(podmanTest.NumberOfContainersRunning()).To(Equal(1)) 109 Expect(podmanTest.GetContainerStatus()).To(ContainSubstring("Up")) 110 }) 111 112 It("podman checkpoint a running container by name", func() { 113 localRunString := getRunString([]string{"--name", "test_name", ALPINE, "top"}) 114 session := podmanTest.Podman(localRunString) 115 session.WaitWithDefaultTimeout() 116 Expect(session).Should(Exit(0)) 117 118 result := podmanTest.Podman([]string{"container", "checkpoint", "test_name"}) 119 result.WaitWithDefaultTimeout() 120 121 Expect(result).Should(Exit(0)) 122 Expect(podmanTest.NumberOfContainersRunning()).To(Equal(0)) 123 Expect(podmanTest.GetContainerStatus()).To(ContainSubstring("Exited")) 124 125 result = podmanTest.Podman([]string{"container", "restore", "test_name"}) 126 result.WaitWithDefaultTimeout() 127 128 Expect(result).Should(Exit(0)) 129 Expect(podmanTest.NumberOfContainersRunning()).To(Equal(1)) 130 Expect(podmanTest.GetContainerStatus()).To(ContainSubstring("Up")) 131 }) 132 133 It("podman pause a checkpointed container by id", func() { 134 localRunString := getRunString([]string{ALPINE, "top"}) 135 session := podmanTest.Podman(localRunString) 136 session.WaitWithDefaultTimeout() 137 Expect(session).Should(Exit(0)) 138 cid := session.OutputToString() 139 140 result := podmanTest.Podman([]string{"container", "checkpoint", cid}) 141 result.WaitWithDefaultTimeout() 142 143 Expect(result).Should(Exit(0)) 144 Expect(podmanTest.NumberOfContainersRunning()).To(Equal(0)) 145 Expect(podmanTest.GetContainerStatus()).To(ContainSubstring("Exited")) 146 147 result = podmanTest.Podman([]string{"pause", cid}) 148 result.WaitWithDefaultTimeout() 149 150 Expect(result).Should(Exit(125)) 151 Expect(podmanTest.NumberOfContainersRunning()).To(Equal(0)) 152 Expect(podmanTest.GetContainerStatus()).To(ContainSubstring("Exited")) 153 154 result = podmanTest.Podman([]string{"container", "restore", cid}) 155 result.WaitWithDefaultTimeout() 156 Expect(result).Should(Exit(0)) 157 Expect(podmanTest.NumberOfContainersRunning()).To(Equal(1)) 158 159 result = podmanTest.Podman([]string{"rm", cid}) 160 result.WaitWithDefaultTimeout() 161 Expect(result).Should(Exit(2)) 162 Expect(podmanTest.NumberOfContainersRunning()).To(Equal(1)) 163 164 result = podmanTest.Podman([]string{"rm", "-f", cid}) 165 result.WaitWithDefaultTimeout() 166 Expect(result).Should(Exit(0)) 167 Expect(podmanTest.NumberOfContainersRunning()).To(Equal(0)) 168 169 }) 170 171 It("podman checkpoint latest running container", func() { 172 localRunString := getRunString([]string{"--name", "first", ALPINE, "top"}) 173 session1 := podmanTest.Podman(localRunString) 174 session1.WaitWithDefaultTimeout() 175 Expect(session1).Should(Exit(0)) 176 177 localRunString = getRunString([]string{"--name", "second", ALPINE, "top"}) 178 session2 := podmanTest.Podman(localRunString) 179 session2.WaitWithDefaultTimeout() 180 Expect(session2).Should(Exit(0)) 181 182 result := podmanTest.Podman([]string{"container", "checkpoint", "-l"}) 183 result.WaitWithDefaultTimeout() 184 185 Expect(result).Should(Exit(0)) 186 Expect(podmanTest.NumberOfContainersRunning()).To(Equal(1)) 187 188 ps := podmanTest.Podman([]string{"ps", "-q", "--no-trunc"}) 189 ps.WaitWithDefaultTimeout() 190 Expect(ps).Should(Exit(0)) 191 Expect(ps.LineInOutputContains(session1.OutputToString())).To(BeTrue()) 192 Expect(ps.LineInOutputContains(session2.OutputToString())).To(BeFalse()) 193 194 result = podmanTest.Podman([]string{"container", "restore", "-l"}) 195 result.WaitWithDefaultTimeout() 196 197 Expect(result).Should(Exit(0)) 198 Expect(podmanTest.NumberOfContainersRunning()).To(Equal(2)) 199 Expect(podmanTest.GetContainerStatus()).To(ContainSubstring("Up")) 200 Expect(podmanTest.GetContainerStatus()).To(Not(ContainSubstring("Exited"))) 201 202 result = podmanTest.Podman([]string{"rm", "-fa"}) 203 result.WaitWithDefaultTimeout() 204 Expect(result).Should(Exit(0)) 205 Expect(podmanTest.NumberOfContainersRunning()).To(Equal(0)) 206 }) 207 208 It("podman checkpoint all running container", func() { 209 localRunString := getRunString([]string{"--name", "first", ALPINE, "top"}) 210 session1 := podmanTest.Podman(localRunString) 211 session1.WaitWithDefaultTimeout() 212 Expect(session1).Should(Exit(0)) 213 214 localRunString = getRunString([]string{"--name", "second", ALPINE, "top"}) 215 session2 := podmanTest.Podman(localRunString) 216 session2.WaitWithDefaultTimeout() 217 Expect(session2).Should(Exit(0)) 218 219 result := podmanTest.Podman([]string{"container", "checkpoint", "-a"}) 220 result.WaitWithDefaultTimeout() 221 222 Expect(result).Should(Exit(0)) 223 Expect(podmanTest.NumberOfContainersRunning()).To(Equal(0)) 224 225 ps := podmanTest.Podman([]string{"ps", "-q", "--no-trunc"}) 226 ps.WaitWithDefaultTimeout() 227 Expect(ps).Should(Exit(0)) 228 Expect(ps.LineInOutputContains(session1.OutputToString())).To(BeFalse()) 229 Expect(ps.LineInOutputContains(session2.OutputToString())).To(BeFalse()) 230 231 result = podmanTest.Podman([]string{"container", "restore", "-a"}) 232 result.WaitWithDefaultTimeout() 233 234 Expect(result).Should(Exit(0)) 235 Expect(podmanTest.NumberOfContainersRunning()).To(Equal(2)) 236 Expect(podmanTest.GetContainerStatus()).To(ContainSubstring("Up")) 237 Expect(podmanTest.GetContainerStatus()).To(Not(ContainSubstring("Exited"))) 238 239 result = podmanTest.Podman([]string{"rm", "-fa"}) 240 result.WaitWithDefaultTimeout() 241 Expect(result).Should(Exit(0)) 242 Expect(podmanTest.NumberOfContainersRunning()).To(Equal(0)) 243 }) 244 245 It("podman checkpoint container with established tcp connections", func() { 246 // Broken on Ubuntu. 247 SkipIfNotFedora() 248 localRunString := getRunString([]string{redis}) 249 session := podmanTest.Podman(localRunString) 250 session.WaitWithDefaultTimeout() 251 Expect(session).Should(Exit(0)) 252 cid := session.OutputToString() 253 if !WaitContainerReady(podmanTest, cid, "Ready to accept connections", 20, 1) { 254 Fail("Container failed to get ready") 255 } 256 257 IP := podmanTest.Podman([]string{"inspect", "-l", "--format={{.NetworkSettings.IPAddress}}"}) 258 IP.WaitWithDefaultTimeout() 259 Expect(IP).Should(Exit(0)) 260 261 // Open a network connection to the redis server 262 conn, err := net.DialTimeout("tcp4", IP.OutputToString()+":6379", time.Duration(3)*time.Second) 263 Expect(err).To(BeNil()) 264 265 // This should fail as the container has established TCP connections 266 result := podmanTest.Podman([]string{"container", "checkpoint", "-l"}) 267 result.WaitWithDefaultTimeout() 268 269 Expect(result).Should(Exit(125)) 270 Expect(podmanTest.NumberOfContainersRunning()).To(Equal(1)) 271 Expect(podmanTest.GetContainerStatus()).To(ContainSubstring("Up")) 272 273 // Now it should work thanks to "--tcp-established" 274 result = podmanTest.Podman([]string{"container", "checkpoint", "-l", "--tcp-established"}) 275 result.WaitWithDefaultTimeout() 276 277 Expect(result).Should(Exit(0)) 278 Expect(podmanTest.NumberOfContainersRunning()).To(Equal(0)) 279 Expect(podmanTest.GetContainerStatus()).To(ContainSubstring("Exited")) 280 281 // Restore should fail as the checkpoint image contains established TCP connections 282 result = podmanTest.Podman([]string{"container", "restore", "-l"}) 283 result.WaitWithDefaultTimeout() 284 285 Expect(result).Should(Exit(125)) 286 Expect(podmanTest.NumberOfContainersRunning()).To(Equal(0)) 287 Expect(podmanTest.GetContainerStatus()).To(ContainSubstring("Exited")) 288 289 // Now it should work thanks to "--tcp-established" 290 result = podmanTest.Podman([]string{"container", "restore", "-l", "--tcp-established"}) 291 result.WaitWithDefaultTimeout() 292 293 Expect(result).Should(Exit(0)) 294 Expect(podmanTest.NumberOfContainersRunning()).To(Equal(1)) 295 Expect(podmanTest.GetContainerStatus()).To(ContainSubstring("Up")) 296 297 result = podmanTest.Podman([]string{"rm", "-fa"}) 298 result.WaitWithDefaultTimeout() 299 Expect(result).Should(Exit(0)) 300 Expect(podmanTest.NumberOfContainersRunning()).To(Equal(0)) 301 302 conn.Close() 303 }) 304 305 It("podman checkpoint with --leave-running", func() { 306 localRunString := getRunString([]string{ALPINE, "top"}) 307 session := podmanTest.Podman(localRunString) 308 session.WaitWithDefaultTimeout() 309 Expect(session).Should(Exit(0)) 310 cid := session.OutputToString() 311 312 // Checkpoint container, but leave it running 313 result := podmanTest.Podman([]string{"container", "checkpoint", "--leave-running", cid}) 314 result.WaitWithDefaultTimeout() 315 316 Expect(result).Should(Exit(0)) 317 // Make sure it is still running 318 Expect(podmanTest.NumberOfContainersRunning()).To(Equal(1)) 319 Expect(podmanTest.GetContainerStatus()).To(ContainSubstring("Up")) 320 321 // Stop the container 322 result = podmanTest.Podman([]string{"container", "stop", cid}) 323 result.WaitWithDefaultTimeout() 324 325 Expect(result).Should(Exit(0)) 326 Expect(podmanTest.NumberOfContainersRunning()).To(Equal(0)) 327 Expect(podmanTest.GetContainerStatus()).To(ContainSubstring("Exited")) 328 329 // Restore the stopped container from the previous checkpoint 330 result = podmanTest.Podman([]string{"container", "restore", cid}) 331 result.WaitWithDefaultTimeout() 332 333 Expect(result).Should(Exit(0)) 334 Expect(podmanTest.NumberOfContainersRunning()).To(Equal(1)) 335 Expect(podmanTest.GetContainerStatus()).To(ContainSubstring("Up")) 336 337 result = podmanTest.Podman([]string{"rm", "-fa"}) 338 result.WaitWithDefaultTimeout() 339 Expect(result).Should(Exit(0)) 340 Expect(podmanTest.NumberOfContainersRunning()).To(Equal(0)) 341 }) 342 343 It("podman checkpoint and restore container with same IP", func() { 344 localRunString := getRunString([]string{"--name", "test_name", ALPINE, "top"}) 345 session := podmanTest.Podman(localRunString) 346 session.WaitWithDefaultTimeout() 347 Expect(session).Should(Exit(0)) 348 349 IPBefore := podmanTest.Podman([]string{"inspect", "-l", "--format={{.NetworkSettings.IPAddress}}"}) 350 IPBefore.WaitWithDefaultTimeout() 351 Expect(IPBefore).Should(Exit(0)) 352 353 MACBefore := podmanTest.Podman([]string{"inspect", "-l", "--format={{.NetworkSettings.MacAddress}}"}) 354 MACBefore.WaitWithDefaultTimeout() 355 Expect(MACBefore).Should(Exit(0)) 356 357 result := podmanTest.Podman([]string{"container", "checkpoint", "test_name"}) 358 result.WaitWithDefaultTimeout() 359 360 Expect(result).Should(Exit(0)) 361 Expect(podmanTest.NumberOfContainersRunning()).To(Equal(0)) 362 Expect(podmanTest.GetContainerStatus()).To(ContainSubstring("Exited")) 363 364 result = podmanTest.Podman([]string{"container", "restore", "test_name"}) 365 result.WaitWithDefaultTimeout() 366 367 IPAfter := podmanTest.Podman([]string{"inspect", "-l", "--format={{.NetworkSettings.IPAddress}}"}) 368 IPAfter.WaitWithDefaultTimeout() 369 Expect(IPAfter).Should(Exit(0)) 370 371 MACAfter := podmanTest.Podman([]string{"inspect", "-l", "--format={{.NetworkSettings.MacAddress}}"}) 372 MACAfter.WaitWithDefaultTimeout() 373 Expect(MACAfter).Should(Exit(0)) 374 375 // Check that IP address did not change between checkpointing and restoring 376 Expect(IPBefore.OutputToString()).To(Equal(IPAfter.OutputToString())) 377 378 // Check that MAC address did not change between checkpointing and restoring 379 Expect(MACBefore.OutputToString()).To(Equal(MACAfter.OutputToString())) 380 381 Expect(result).Should(Exit(0)) 382 Expect(podmanTest.NumberOfContainersRunning()).To(Equal(1)) 383 Expect(podmanTest.GetContainerStatus()).To(ContainSubstring("Up")) 384 385 result = podmanTest.Podman([]string{"rm", "-fa"}) 386 result.WaitWithDefaultTimeout() 387 Expect(result).Should(Exit(0)) 388 Expect(podmanTest.NumberOfContainersRunning()).To(Equal(0)) 389 }) 390 391 // This test does the same steps which are necessary for migrating 392 // a container from one host to another 393 It("podman checkpoint container with export (migration)", func() { 394 localRunString := getRunString([]string{"--rm", ALPINE, "top"}) 395 session := podmanTest.Podman(localRunString) 396 session.WaitWithDefaultTimeout() 397 Expect(session).Should(Exit(0)) 398 Expect(podmanTest.NumberOfContainersRunning()).To(Equal(1)) 399 cid := session.OutputToString() 400 fileName := "/tmp/checkpoint-" + cid + ".tar.gz" 401 402 result := podmanTest.Podman([]string{"container", "checkpoint", "-l", "-e", fileName}) 403 result.WaitWithDefaultTimeout() 404 405 // As the container has been started with '--rm' it will be completely 406 // cleaned up after checkpointing. 407 Expect(result).Should(Exit(0)) 408 Expect(podmanTest.NumberOfContainersRunning()).To(Equal(0)) 409 Expect(podmanTest.NumberOfContainers()).To(Equal(0)) 410 411 // Restore container the first time with different name. 412 // Using '--ignore-static-ip' as for parallel test runs 413 // each containers gets a random IP address via '--ip'. 414 // '--ignore-static-ip' tells the restore to use the next 415 // available IP address. 416 // First restore the container with a new name/ID to make 417 // sure nothing in the restored container depends on the 418 // original container. 419 result = podmanTest.Podman([]string{"container", "restore", "-i", fileName, "-n", "restore_again", "--ignore-static-ip"}) 420 result.WaitWithDefaultTimeout() 421 422 Expect(result).Should(Exit(0)) 423 Expect(podmanTest.NumberOfContainersRunning()).To(Equal(1)) 424 Expect(podmanTest.GetContainerStatus()).To(ContainSubstring("Up")) 425 426 result = podmanTest.Podman([]string{"container", "restore", "-i", fileName}) 427 result.WaitWithDefaultTimeout() 428 429 Expect(result).Should(Exit(0)) 430 Expect(podmanTest.NumberOfContainersRunning()).To(Equal(2)) 431 Expect(podmanTest.GetContainerStatus()).To(ContainSubstring("Up")) 432 433 result = podmanTest.Podman([]string{"rm", "-fa"}) 434 result.WaitWithDefaultTimeout() 435 Expect(result).Should(Exit(0)) 436 Expect(podmanTest.NumberOfContainersRunning()).To(Equal(0)) 437 Expect(podmanTest.NumberOfContainers()).To(Equal(0)) 438 439 // Remove exported checkpoint 440 os.Remove(fileName) 441 }) 442 // This test does the same steps which are necessary for migrating 443 // a container from one host to another 444 It("podman checkpoint container with export and different compression algorithms", func() { 445 localRunString := getRunString([]string{"--rm", ALPINE, "top"}) 446 session := podmanTest.Podman(localRunString) 447 session.WaitWithDefaultTimeout() 448 Expect(session).Should(Exit(0)) 449 Expect(podmanTest.NumberOfContainersRunning()).To(Equal(1)) 450 cid := session.OutputToString() 451 fileName := "/tmp/checkpoint-" + cid + ".tar" 452 453 // Checkpoint with the default algorithm 454 result := podmanTest.Podman([]string{"container", "checkpoint", "-l", "-e", fileName}) 455 result.WaitWithDefaultTimeout() 456 457 // As the container has been started with '--rm' it will be completely 458 // cleaned up after checkpointing. 459 Expect(result).Should(Exit(0)) 460 Expect(podmanTest.NumberOfContainersRunning()).To(Equal(0)) 461 Expect(podmanTest.NumberOfContainers()).To(Equal(0)) 462 463 // Restore container 464 result = podmanTest.Podman([]string{"container", "restore", "-i", fileName}) 465 result.WaitWithDefaultTimeout() 466 467 Expect(result).Should(Exit(0)) 468 Expect(podmanTest.NumberOfContainersRunning()).To(Equal(1)) 469 Expect(podmanTest.GetContainerStatus()).To(ContainSubstring("Up")) 470 471 // Checkpoint with the zstd algorithm 472 result = podmanTest.Podman([]string{"container", "checkpoint", "-l", "-e", fileName, "--compress", "zstd"}) 473 result.WaitWithDefaultTimeout() 474 475 // As the container has been started with '--rm' it will be completely 476 // cleaned up after checkpointing. 477 Expect(result).Should(Exit(0)) 478 Expect(podmanTest.NumberOfContainersRunning()).To(Equal(0)) 479 Expect(podmanTest.NumberOfContainers()).To(Equal(0)) 480 481 // Restore container 482 result = podmanTest.Podman([]string{"container", "restore", "-i", fileName}) 483 result.WaitWithDefaultTimeout() 484 485 Expect(result).Should(Exit(0)) 486 Expect(podmanTest.NumberOfContainersRunning()).To(Equal(1)) 487 Expect(podmanTest.GetContainerStatus()).To(ContainSubstring("Up")) 488 489 // Checkpoint with the none algorithm 490 result = podmanTest.Podman([]string{"container", "checkpoint", "-l", "-e", fileName, "-c", "none"}) 491 result.WaitWithDefaultTimeout() 492 493 // As the container has been started with '--rm' it will be completely 494 // cleaned up after checkpointing. 495 Expect(result).Should(Exit(0)) 496 Expect(podmanTest.NumberOfContainersRunning()).To(Equal(0)) 497 Expect(podmanTest.NumberOfContainers()).To(Equal(0)) 498 499 // Restore container 500 result = podmanTest.Podman([]string{"container", "restore", "-i", fileName}) 501 result.WaitWithDefaultTimeout() 502 503 Expect(result).Should(Exit(0)) 504 Expect(podmanTest.NumberOfContainersRunning()).To(Equal(1)) 505 Expect(podmanTest.GetContainerStatus()).To(ContainSubstring("Up")) 506 507 // Checkpoint with the gzip algorithm 508 result = podmanTest.Podman([]string{"container", "checkpoint", "-l", "-e", fileName, "-c", "gzip"}) 509 result.WaitWithDefaultTimeout() 510 511 // As the container has been started with '--rm' it will be completely 512 // cleaned up after checkpointing. 513 Expect(result).Should(Exit(0)) 514 Expect(podmanTest.NumberOfContainersRunning()).To(Equal(0)) 515 Expect(podmanTest.NumberOfContainers()).To(Equal(0)) 516 517 // Restore container 518 result = podmanTest.Podman([]string{"container", "restore", "-i", fileName}) 519 result.WaitWithDefaultTimeout() 520 521 Expect(result).Should(Exit(0)) 522 Expect(podmanTest.NumberOfContainersRunning()).To(Equal(1)) 523 Expect(podmanTest.GetContainerStatus()).To(ContainSubstring("Up")) 524 525 // Checkpoint with the non-existing algorithm 526 result = podmanTest.Podman([]string{"container", "checkpoint", "-l", "-e", fileName, "-c", "non-existing"}) 527 result.WaitWithDefaultTimeout() 528 529 Expect(result).Should(Exit(125)) 530 Expect(podmanTest.NumberOfContainersRunning()).To(Equal(1)) 531 Expect(podmanTest.NumberOfContainers()).To(Equal(1)) 532 533 result = podmanTest.Podman([]string{"rm", "-fa"}) 534 result.WaitWithDefaultTimeout() 535 Expect(result).Should(Exit(0)) 536 Expect(podmanTest.NumberOfContainersRunning()).To(Equal(0)) 537 Expect(podmanTest.NumberOfContainers()).To(Equal(0)) 538 539 // Remove exported checkpoint 540 os.Remove(fileName) 541 }) 542 543 It("podman checkpoint and restore container with root file-system changes", func() { 544 // Start the container 545 localRunString := getRunString([]string{"--rm", ALPINE, "top"}) 546 session := podmanTest.Podman(localRunString) 547 session.WaitWithDefaultTimeout() 548 Expect(session).Should(Exit(0)) 549 Expect(podmanTest.NumberOfContainersRunning()).To(Equal(1)) 550 cid := session.OutputToString() 551 fileName := "/tmp/checkpoint-" + cid + ".tar.gz" 552 553 // Change the container's root file-system 554 result := podmanTest.Podman([]string{"exec", "-l", "/bin/sh", "-c", "echo test" + cid + "test > /test.output"}) 555 result.WaitWithDefaultTimeout() 556 Expect(result).Should(Exit(0)) 557 558 result = podmanTest.Podman([]string{"exec", "-l", "/bin/sh", "-c", "rm /etc/motd"}) 559 result.WaitWithDefaultTimeout() 560 Expect(result).Should(Exit(0)) 561 562 result = podmanTest.Podman([]string{"diff", "-l"}) 563 result.WaitWithDefaultTimeout() 564 Expect(result).Should(Exit(0)) 565 Expect(result.OutputToString()).To(ContainSubstring("C /etc")) 566 Expect(result.OutputToString()).To(ContainSubstring("A /test.output")) 567 Expect(result.OutputToString()).To(ContainSubstring("D /etc/motd")) 568 Expect(len(result.OutputToStringArray())).To(Equal(3)) 569 570 // Checkpoint the container 571 result = podmanTest.Podman([]string{"container", "checkpoint", "-l", "-e", fileName}) 572 result.WaitWithDefaultTimeout() 573 574 Expect(result).Should(Exit(0)) 575 Expect(podmanTest.NumberOfContainersRunning()).To(Equal(0)) 576 Expect(podmanTest.NumberOfContainers()).To(Equal(0)) 577 578 // Restore the container 579 result = podmanTest.Podman([]string{"container", "restore", "-i", fileName}) 580 result.WaitWithDefaultTimeout() 581 582 Expect(result).Should(Exit(0)) 583 Expect(podmanTest.NumberOfContainersRunning()).To(Equal(1)) 584 Expect(podmanTest.NumberOfContainers()).To(Equal(1)) 585 Expect(podmanTest.GetContainerStatus()).To(ContainSubstring("Up")) 586 587 // Verify the changes to the container's root file-system 588 result = podmanTest.Podman([]string{"exec", "-l", "cat", "/test.output"}) 589 result.WaitWithDefaultTimeout() 590 Expect(result).Should(Exit(0)) 591 Expect(result.OutputToString()).To(ContainSubstring("test" + cid + "test")) 592 593 result = podmanTest.Podman([]string{"diff", "-l"}) 594 result.WaitWithDefaultTimeout() 595 Expect(result).Should(Exit(0)) 596 Expect(result.OutputToString()).To(ContainSubstring("C /etc")) 597 Expect(result.OutputToString()).To(ContainSubstring("A /test.output")) 598 Expect(result.OutputToString()).To(ContainSubstring("D /etc/motd")) 599 Expect(len(result.OutputToStringArray())).To(Equal(3)) 600 601 // Remove exported checkpoint 602 os.Remove(fileName) 603 }) 604 It("podman checkpoint and restore container with root file-system changes using --ignore-rootfs during restore", func() { 605 // Start the container 606 localRunString := getRunString([]string{"--rm", ALPINE, "top"}) 607 session := podmanTest.Podman(localRunString) 608 session.WaitWithDefaultTimeout() 609 Expect(session).Should(Exit(0)) 610 Expect(podmanTest.NumberOfContainersRunning()).To(Equal(1)) 611 cid := session.OutputToString() 612 fileName := "/tmp/checkpoint-" + cid + ".tar.gz" 613 614 // Change the container's root file-system 615 result := podmanTest.Podman([]string{"exec", "-l", "/bin/sh", "-c", "echo test" + cid + "test > /test.output"}) 616 result.WaitWithDefaultTimeout() 617 Expect(result).Should(Exit(0)) 618 619 // Checkpoint the container 620 result = podmanTest.Podman([]string{"container", "checkpoint", "-l", "-e", fileName}) 621 result.WaitWithDefaultTimeout() 622 623 Expect(result).Should(Exit(0)) 624 Expect(podmanTest.NumberOfContainersRunning()).To(Equal(0)) 625 Expect(podmanTest.NumberOfContainers()).To(Equal(0)) 626 627 // Restore the container 628 result = podmanTest.Podman([]string{"container", "restore", "--ignore-rootfs", "-i", fileName}) 629 result.WaitWithDefaultTimeout() 630 631 Expect(result).Should(Exit(0)) 632 Expect(podmanTest.NumberOfContainersRunning()).To(Equal(1)) 633 Expect(podmanTest.NumberOfContainers()).To(Equal(1)) 634 Expect(podmanTest.GetContainerStatus()).To(ContainSubstring("Up")) 635 636 // Verify the changes to the container's root file-system 637 result = podmanTest.Podman([]string{"exec", "-l", "cat", "/test.output"}) 638 result.WaitWithDefaultTimeout() 639 Expect(result).Should(Exit(1)) 640 Expect(result.ErrorToString()).To(ContainSubstring("cat: can't open '/test.output': No such file or directory")) 641 642 // Remove exported checkpoint 643 os.Remove(fileName) 644 }) 645 It("podman checkpoint and restore container with root file-system changes using --ignore-rootfs during checkpoint", func() { 646 // Start the container 647 localRunString := getRunString([]string{"--rm", ALPINE, "top"}) 648 session := podmanTest.Podman(localRunString) 649 session.WaitWithDefaultTimeout() 650 Expect(session).Should(Exit(0)) 651 Expect(podmanTest.NumberOfContainersRunning()).To(Equal(1)) 652 cid := session.OutputToString() 653 fileName := "/tmp/checkpoint-" + cid + ".tar.gz" 654 655 // Change the container's root file-system 656 result := podmanTest.Podman([]string{"exec", "-l", "/bin/sh", "-c", "echo test" + cid + "test > /test.output"}) 657 result.WaitWithDefaultTimeout() 658 Expect(result).Should(Exit(0)) 659 660 // Checkpoint the container 661 result = podmanTest.Podman([]string{"container", "checkpoint", "--ignore-rootfs", "-l", "-e", fileName}) 662 result.WaitWithDefaultTimeout() 663 664 Expect(result).Should(Exit(0)) 665 Expect(podmanTest.NumberOfContainersRunning()).To(Equal(0)) 666 Expect(podmanTest.NumberOfContainers()).To(Equal(0)) 667 668 // Restore the container 669 result = podmanTest.Podman([]string{"container", "restore", "-i", fileName}) 670 result.WaitWithDefaultTimeout() 671 672 Expect(result).Should(Exit(0)) 673 Expect(podmanTest.NumberOfContainersRunning()).To(Equal(1)) 674 Expect(podmanTest.NumberOfContainers()).To(Equal(1)) 675 Expect(podmanTest.GetContainerStatus()).To(ContainSubstring("Up")) 676 677 // Verify the changes to the container's root file-system 678 result = podmanTest.Podman([]string{"exec", "-l", "cat", "/test.output"}) 679 result.WaitWithDefaultTimeout() 680 Expect(result).Should(Exit(1)) 681 Expect(result.ErrorToString()).To(ContainSubstring("cat: can't open '/test.output': No such file or directory")) 682 683 // Remove exported checkpoint 684 os.Remove(fileName) 685 }) 686 687 It("podman checkpoint and run exec in restored container", func() { 688 // Start the container 689 localRunString := getRunString([]string{"--rm", ALPINE, "top"}) 690 session := podmanTest.Podman(localRunString) 691 session.WaitWithDefaultTimeout() 692 Expect(session).Should(Exit(0)) 693 Expect(podmanTest.NumberOfContainersRunning()).To(Equal(1)) 694 cid := session.OutputToString() 695 fileName := "/tmp/checkpoint-" + cid + ".tar.gz" 696 697 // Checkpoint the container 698 result := podmanTest.Podman([]string{"container", "checkpoint", "-l", "-e", fileName}) 699 result.WaitWithDefaultTimeout() 700 701 Expect(result).Should(Exit(0)) 702 Expect(podmanTest.NumberOfContainersRunning()).To(Equal(0)) 703 Expect(podmanTest.NumberOfContainers()).To(Equal(0)) 704 705 // Restore the container 706 result = podmanTest.Podman([]string{"container", "restore", "-i", fileName}) 707 result.WaitWithDefaultTimeout() 708 709 Expect(result).Should(Exit(0)) 710 Expect(podmanTest.NumberOfContainersRunning()).To(Equal(1)) 711 Expect(podmanTest.NumberOfContainers()).To(Equal(1)) 712 Expect(podmanTest.GetContainerStatus()).To(ContainSubstring("Up")) 713 714 // Exec in the container 715 result = podmanTest.Podman([]string{"exec", "-l", "/bin/sh", "-c", "echo " + cid + " > /test.output"}) 716 result.WaitWithDefaultTimeout() 717 Expect(result).Should(Exit(0)) 718 719 result = podmanTest.Podman([]string{"exec", "-l", "cat", "/test.output"}) 720 result.WaitWithDefaultTimeout() 721 Expect(result).Should(Exit(0)) 722 Expect(result.OutputToString()).To(ContainSubstring(cid)) 723 724 // Remove exported checkpoint 725 os.Remove(fileName) 726 }) 727 728 It("podman checkpoint a container started with --rm", func() { 729 // Start the container 730 localRunString := getRunString([]string{"--rm", ALPINE, "top"}) 731 session := podmanTest.Podman(localRunString) 732 session.WaitWithDefaultTimeout() 733 cid := session.OutputToString() 734 Expect(podmanTest.NumberOfContainersRunning()).To(Equal(1)) 735 736 // Checkpoint the container - this should fail as it was started with --rm 737 result := podmanTest.Podman([]string{"container", "checkpoint", "-l"}) 738 result.WaitWithDefaultTimeout() 739 Expect(result).To(ExitWithError()) 740 Expect(result.ErrorToString()).To(ContainSubstring("cannot checkpoint containers that have been started with '--rm'")) 741 742 // Checkpointing with --export should still work 743 fileName := "/tmp/checkpoint-" + cid + ".tar.gz" 744 745 result = podmanTest.Podman([]string{"container", "checkpoint", "-l", "-e", fileName}) 746 result.WaitWithDefaultTimeout() 747 748 // As the container has been started with '--rm' it will be completely 749 // cleaned up after checkpointing. 750 Expect(result).Should(Exit(0)) 751 Expect(podmanTest.NumberOfContainersRunning()).To(Equal(0)) 752 Expect(podmanTest.NumberOfContainers()).To(Equal(0)) 753 754 result = podmanTest.Podman([]string{"container", "restore", "-i", fileName}) 755 result.WaitWithDefaultTimeout() 756 757 Expect(result).Should(Exit(0)) 758 Expect(podmanTest.NumberOfContainersRunning()).To(Equal(1)) 759 Expect(podmanTest.GetContainerStatus()).To(ContainSubstring("Up")) 760 761 result = podmanTest.Podman([]string{"rm", "-fa"}) 762 result.WaitWithDefaultTimeout() 763 Expect(result).Should(Exit(0)) 764 Expect(podmanTest.NumberOfContainersRunning()).To(Equal(0)) 765 Expect(podmanTest.NumberOfContainers()).To(Equal(0)) 766 767 // Remove exported checkpoint 768 os.Remove(fileName) 769 }) 770 771 It("podman checkpoint a container with volumes", func() { 772 session := podmanTest.Podman([]string{ 773 "build", "-f", "build/basicalpine/Containerfile.volume", "-t", "test-cr-volume", 774 }) 775 session.WaitWithDefaultTimeout() 776 Expect(session).Should(Exit(0)) 777 778 // Start the container 779 localRunString := getRunString([]string{ 780 "--rm", 781 "-v", "/volume1", 782 "-v", "my-test-vol:/volume2", 783 "test-cr-volume", 784 "top", 785 }) 786 session = podmanTest.Podman(localRunString) 787 session.WaitWithDefaultTimeout() 788 Expect(session).Should(Exit(0)) 789 Expect(podmanTest.NumberOfContainersRunning()).To(Equal(1)) 790 791 cid := session.OutputToString() 792 793 // Add file in volume0 794 result := podmanTest.Podman([]string{ 795 "exec", "-l", "/bin/sh", "-c", "echo " + cid + " > /volume0/test.output", 796 }) 797 result.WaitWithDefaultTimeout() 798 Expect(result).Should(Exit(0)) 799 800 // Add file in volume1 801 result = podmanTest.Podman([]string{ 802 "exec", "-l", "/bin/sh", "-c", "echo " + cid + " > /volume1/test.output", 803 }) 804 result.WaitWithDefaultTimeout() 805 Expect(result).Should(Exit(0)) 806 807 // Add file in volume2 808 result = podmanTest.Podman([]string{ 809 "exec", "-l", "/bin/sh", "-c", "echo " + cid + " > /volume2/test.output", 810 }) 811 result.WaitWithDefaultTimeout() 812 Expect(result).Should(Exit(0)) 813 814 checkpointFileName := "/tmp/checkpoint-" + cid + ".tar.gz" 815 816 // Checkpoint the container 817 result = podmanTest.Podman([]string{"container", "checkpoint", "-l", "-e", checkpointFileName}) 818 result.WaitWithDefaultTimeout() 819 Expect(result).Should(Exit(0)) 820 Expect(podmanTest.NumberOfContainersRunning()).To(Equal(0)) 821 Expect(podmanTest.NumberOfContainers()).To(Equal(0)) 822 823 // Restore container should fail because named volume still exists 824 result = podmanTest.Podman([]string{"container", "restore", "-i", checkpointFileName}) 825 result.WaitWithDefaultTimeout() 826 Expect(result).To(ExitWithError()) 827 Expect(result.ErrorToString()).To(ContainSubstring( 828 "volume with name my-test-vol already exists. Use --ignore-volumes to not restore content of volumes", 829 )) 830 831 // Remove named volume 832 session = podmanTest.Podman([]string{"volume", "rm", "my-test-vol"}) 833 session.WaitWithDefaultTimeout() 834 Expect(session).Should(Exit(0)) 835 836 // Restoring container 837 result = podmanTest.Podman([]string{"container", "restore", "-i", checkpointFileName}) 838 result.WaitWithDefaultTimeout() 839 Expect(result).Should(Exit(0)) 840 Expect(podmanTest.NumberOfContainersRunning()).To(Equal(1)) 841 Expect(podmanTest.NumberOfContainers()).To(Equal(1)) 842 Expect(podmanTest.GetContainerStatus()).To(ContainSubstring("Up")) 843 844 // Validate volume0 content 845 result = podmanTest.Podman([]string{"exec", "-l", "cat", "/volume0/test.output"}) 846 result.WaitWithDefaultTimeout() 847 Expect(result).Should(Exit(0)) 848 Expect(result.OutputToString()).To(ContainSubstring(cid)) 849 850 // Validate volume1 content 851 result = podmanTest.Podman([]string{"exec", "-l", "cat", "/volume1/test.output"}) 852 result.WaitWithDefaultTimeout() 853 Expect(result).Should(Exit(0)) 854 Expect(result.OutputToString()).To(ContainSubstring(cid)) 855 856 // Validate volume2 content 857 result = podmanTest.Podman([]string{"exec", "-l", "cat", "/volume2/test.output"}) 858 result.WaitWithDefaultTimeout() 859 Expect(result).Should(Exit(0)) 860 Expect(result.OutputToString()).To(ContainSubstring(cid)) 861 862 // Remove exported checkpoint 863 os.Remove(checkpointFileName) 864 }) 865 866 It("podman checkpoint container with --pre-checkpoint", func() { 867 if !strings.Contains(podmanTest.OCIRuntime, "runc") { 868 Skip("Test only works on runc 1.0-rc3 or higher.") 869 } 870 localRunString := getRunString([]string{ALPINE, "top"}) 871 session := podmanTest.Podman(localRunString) 872 session.WaitWithDefaultTimeout() 873 Expect(session).Should(Exit(0)) 874 cid := session.OutputToString() 875 876 result := podmanTest.Podman([]string{"container", "checkpoint", "-P", cid}) 877 result.WaitWithDefaultTimeout() 878 879 Expect(result).Should(Exit(0)) 880 Expect(podmanTest.NumberOfContainersRunning()).To(Equal(1)) 881 Expect(podmanTest.GetContainerStatus()).To(ContainSubstring("Up")) 882 883 result = podmanTest.Podman([]string{"container", "checkpoint", "--with-previous", cid}) 884 result.WaitWithDefaultTimeout() 885 886 Expect(result).Should(Exit(0)) 887 Expect(podmanTest.NumberOfContainersRunning()).To(Equal(0)) 888 Expect(podmanTest.GetContainerStatus()).To(ContainSubstring("Exited")) 889 890 result = podmanTest.Podman([]string{"container", "restore", cid}) 891 result.WaitWithDefaultTimeout() 892 893 Expect(result).Should(Exit(0)) 894 Expect(podmanTest.NumberOfContainersRunning()).To(Equal(1)) 895 Expect(podmanTest.GetContainerStatus()).To(ContainSubstring("Up")) 896 }) 897 898 It("podman checkpoint container with --pre-checkpoint and export (migration)", func() { 899 if !strings.Contains(podmanTest.OCIRuntime, "runc") { 900 Skip("Test only works on runc 1.0-rc3 or higher.") 901 } 902 localRunString := getRunString([]string{ALPINE, "top"}) 903 session := podmanTest.Podman(localRunString) 904 session.WaitWithDefaultTimeout() 905 Expect(session).Should(Exit(0)) 906 cid := session.OutputToString() 907 preCheckpointFileName := "/tmp/pre-checkpoint-" + cid + ".tar.gz" 908 checkpointFileName := "/tmp/checkpoint-" + cid + ".tar.gz" 909 910 result := podmanTest.Podman([]string{"container", "checkpoint", "-P", "-e", preCheckpointFileName, cid}) 911 result.WaitWithDefaultTimeout() 912 913 Expect(result).Should(Exit(0)) 914 Expect(podmanTest.NumberOfContainersRunning()).To(Equal(1)) 915 Expect(podmanTest.GetContainerStatus()).To(ContainSubstring("Up")) 916 917 result = podmanTest.Podman([]string{"container", "checkpoint", "--with-previous", "-e", checkpointFileName, cid}) 918 result.WaitWithDefaultTimeout() 919 920 Expect(result).Should(Exit(0)) 921 Expect(podmanTest.NumberOfContainersRunning()).To(Equal(0)) 922 Expect(podmanTest.GetContainerStatus()).To(ContainSubstring("Exited")) 923 924 result = podmanTest.Podman([]string{"rm", "-f", cid}) 925 result.WaitWithDefaultTimeout() 926 Expect(result).Should(Exit(0)) 927 Expect(podmanTest.NumberOfContainersRunning()).To(Equal(0)) 928 929 result = podmanTest.Podman([]string{"container", "restore", "-i", checkpointFileName, "--import-previous", preCheckpointFileName}) 930 result.WaitWithDefaultTimeout() 931 932 Expect(result).Should(Exit(0)) 933 Expect(podmanTest.NumberOfContainersRunning()).To(Equal(1)) 934 Expect(podmanTest.GetContainerStatus()).To(ContainSubstring("Up")) 935 936 os.Remove(checkpointFileName) 937 os.Remove(preCheckpointFileName) 938 }) 939 940 It("podman checkpoint and restore container with different port mappings", func() { 941 randomPort, err := utils.GetRandomPort() 942 Expect(err).ShouldNot(HaveOccurred()) 943 localRunString := getRunString([]string{"-p", fmt.Sprintf("%d:6379", randomPort), "--rm", redis}) 944 session := podmanTest.Podman(localRunString) 945 session.WaitWithDefaultTimeout() 946 Expect(session).Should(Exit(0)) 947 cid := session.OutputToString() 948 fileName := "/tmp/checkpoint-" + cid + ".tar.gz" 949 950 if !WaitContainerReady(podmanTest, cid, "Ready to accept connections", 20, 1) { 951 Fail("Container failed to get ready") 952 } 953 954 fmt.Fprintf(os.Stderr, "Trying to connect to redis server at localhost:%d", randomPort) 955 // Open a network connection to the redis server via initial port mapping 956 conn, err := net.DialTimeout("tcp4", fmt.Sprintf("localhost:%d", randomPort), time.Duration(3)*time.Second) 957 Expect(err).ShouldNot(HaveOccurred()) 958 conn.Close() 959 960 // Checkpoint the container 961 result := podmanTest.Podman([]string{"container", "checkpoint", "-l", "-e", fileName}) 962 result.WaitWithDefaultTimeout() 963 964 // As the container has been started with '--rm' it will be completely 965 // cleaned up after checkpointing. 966 Expect(result).Should(Exit(0)) 967 Expect(podmanTest.NumberOfContainersRunning()).To(Equal(0)) 968 Expect(podmanTest.NumberOfContainers()).To(Equal(0)) 969 970 // Restore container with different port mapping 971 newRandomPort, err := utils.GetRandomPort() 972 Expect(err).ShouldNot(HaveOccurred()) 973 result = podmanTest.Podman([]string{"container", "restore", "-p", fmt.Sprintf("%d:6379", newRandomPort), "-i", fileName}) 974 result.WaitWithDefaultTimeout() 975 976 Expect(result).Should(Exit(0)) 977 Expect(podmanTest.NumberOfContainersRunning()).To(Equal(1)) 978 Expect(podmanTest.GetContainerStatus()).To(ContainSubstring("Up")) 979 980 // Open a network connection to the redis server via initial port mapping 981 // This should fail 982 conn, err = net.DialTimeout("tcp4", fmt.Sprintf("localhost:%d", randomPort), time.Duration(3)*time.Second) 983 Expect(err.Error()).To(ContainSubstring("connection refused")) 984 // Open a network connection to the redis server via new port mapping 985 fmt.Fprintf(os.Stderr, "Trying to reconnect to redis server at localhost:%d", newRandomPort) 986 conn, err = net.DialTimeout("tcp4", fmt.Sprintf("localhost:%d", newRandomPort), time.Duration(3)*time.Second) 987 Expect(err).ShouldNot(HaveOccurred()) 988 conn.Close() 989 990 result = podmanTest.Podman([]string{"rm", "-fa"}) 991 result.WaitWithDefaultTimeout() 992 Expect(result).Should(Exit(0)) 993 Expect(podmanTest.NumberOfContainersRunning()).To(Equal(0)) 994 Expect(podmanTest.NumberOfContainers()).To(Equal(0)) 995 996 // Remove exported checkpoint 997 os.Remove(fileName) 998 }) 999 1000 namespaceCombination := []string{ 1001 "cgroup,ipc,net,uts,pid", 1002 "cgroup,ipc,net,uts", 1003 "cgroup,ipc,net", 1004 "cgroup,ipc", 1005 "ipc,net,uts,pid", 1006 "ipc,net,uts", 1007 "ipc,net", 1008 "net,uts,pid", 1009 "net,uts", 1010 "uts,pid", 1011 } 1012 for _, share := range namespaceCombination { 1013 testName := fmt.Sprintf( 1014 "podman checkpoint and restore container out of and into pod (%s)", 1015 share, 1016 ) 1017 It(testName, func() { 1018 if !criu.CheckForCriu(criu.PodCriuVersion) { 1019 Skip("CRIU is missing or too old.") 1020 } 1021 if !crutils.CRRuntimeSupportsPodCheckpointRestore(podmanTest.OCIRuntime) { 1022 Skip("runtime does not support pod restore") 1023 } 1024 // Create a pod 1025 session := podmanTest.Podman([]string{ 1026 "pod", 1027 "create", 1028 "--share", 1029 share, 1030 }) 1031 session.WaitWithDefaultTimeout() 1032 Expect(session).To(Exit(0)) 1033 podID := session.OutputToString() 1034 1035 session = podmanTest.Podman([]string{ 1036 "run", 1037 "-d", 1038 "--rm", 1039 "--pod", 1040 podID, 1041 ALPINE, 1042 "top", 1043 }) 1044 session.WaitWithDefaultTimeout() 1045 Expect(session).To(Exit(0)) 1046 cid := session.OutputToString() 1047 1048 fileName := "/tmp/checkpoint-" + cid + ".tar.gz" 1049 1050 // Checkpoint the container 1051 result := podmanTest.Podman([]string{ 1052 "container", 1053 "checkpoint", 1054 "-e", 1055 fileName, 1056 cid, 1057 }) 1058 result.WaitWithDefaultTimeout() 1059 1060 // As the container has been started with '--rm' it will be completely 1061 // cleaned up after checkpointing. 1062 Expect(result).To(Exit(0)) 1063 Expect(podmanTest.NumberOfContainersRunning()).To(Equal(1)) 1064 Expect(podmanTest.NumberOfContainers()).To(Equal(1)) 1065 1066 // Remove the pod and create a new pod 1067 result = podmanTest.Podman([]string{ 1068 "pod", 1069 "rm", 1070 podID, 1071 }) 1072 result.WaitWithDefaultTimeout() 1073 Expect(result).To(Exit(0)) 1074 1075 // First create a pod with different shared namespaces. 1076 // Restore should fail 1077 1078 wrongShare := share[:strings.LastIndex(share, ",")] 1079 1080 session = podmanTest.Podman([]string{ 1081 "pod", 1082 "create", 1083 "--share", 1084 wrongShare, 1085 }) 1086 session.WaitWithDefaultTimeout() 1087 Expect(session).To(Exit(0)) 1088 podID = session.OutputToString() 1089 1090 // Restore container with different port mapping 1091 result = podmanTest.Podman([]string{ 1092 "container", 1093 "restore", 1094 "--pod", 1095 podID, 1096 "-i", 1097 fileName, 1098 }) 1099 result.WaitWithDefaultTimeout() 1100 Expect(result).To(Exit(125)) 1101 Expect(result.ErrorToString()).To(ContainSubstring("does not share the")) 1102 1103 // Remove the pod and create a new pod 1104 result = podmanTest.Podman([]string{ 1105 "pod", 1106 "rm", 1107 podID, 1108 }) 1109 result.WaitWithDefaultTimeout() 1110 Expect(result).To(Exit(0)) 1111 1112 session = podmanTest.Podman([]string{ 1113 "pod", 1114 "create", 1115 "--share", 1116 share, 1117 }) 1118 session.WaitWithDefaultTimeout() 1119 Expect(session).To(Exit(0)) 1120 podID = session.OutputToString() 1121 1122 // Restore container with different port mapping 1123 result = podmanTest.Podman([]string{ 1124 "container", 1125 "restore", 1126 "--pod", 1127 podID, 1128 "-i", 1129 fileName, 1130 }) 1131 result.WaitWithDefaultTimeout() 1132 1133 Expect(result).To(Exit(0)) 1134 Expect(podmanTest.NumberOfContainersRunning()).To(Equal(2)) 1135 Expect(podmanTest.GetContainerStatus()).To(ContainSubstring("Up")) 1136 1137 result = podmanTest.Podman([]string{ 1138 "rm", 1139 "-f", 1140 result.OutputToString(), 1141 }) 1142 result.WaitWithDefaultTimeout() 1143 Expect(result).To(Exit(0)) 1144 Expect(podmanTest.NumberOfContainersRunning()).To(Equal(1)) 1145 Expect(podmanTest.NumberOfContainers()).To(Equal(1)) 1146 1147 result = podmanTest.Podman([]string{ 1148 "pod", 1149 "rm", 1150 "-fa", 1151 }) 1152 result.WaitWithDefaultTimeout() 1153 Expect(result).To(Exit(0)) 1154 1155 // Remove exported checkpoint 1156 os.Remove(fileName) 1157 }) 1158 } 1159 })