Skip to content

Commit

Permalink
Use random IP addresses during checkpoint/restore tests
Browse files Browse the repository at this point in the history
This tries to reduce CI errors which might happen due to parallel CI
runs which all are using the same IP addresses. Using random addresses
should reduce the possibility of parallel tests using the same IP address.

Signed-off-by: Adrian Reber <areber@redhat.com>
  • Loading branch information
adrianreber committed Jul 9, 2019
1 parent edc7f52 commit d0f540e
Showing 1 changed file with 45 additions and 20 deletions.
65 changes: 45 additions & 20 deletions test/e2e/checkpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,29 @@
package integration

import (
"math/rand"
"net"
"os"
"os/exec"
"strconv"
"time"

"github.com/containers/libpod/pkg/criu"
. "github.com/containers/libpod/test/utils"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)

func getRunString(input []string) []string {
// To avoid IP collisions of initialize random seed for random IP addresses
rand.Seed(time.Now().UnixNano())
ip3 := strconv.Itoa(rand.Intn(230) + GinkgoParallelNode())
ip4 := strconv.Itoa(rand.Intn(230) + GinkgoParallelNode())
// CRIU does not work with seccomp correctly on RHEL7 : seccomp=unconfined
runString := []string{"run", "-it", "--security-opt", "seccomp=unconfined", "-d", "--ip", "10.88." + ip3 + "." + ip4}
return append(runString, input...)
}

var _ = Describe("Podman checkpoint", func() {
var (
tempdir string
Expand Down Expand Up @@ -49,7 +62,6 @@ var _ = Describe("Podman checkpoint", func() {
if hostInfo.Distribution == "fedora" && hostInfo.Version < "29" {
Skip("Checkpoint/Restore with SELinux only works on Fedora >= 29")
}

})

AfterEach(func() {
Expand All @@ -72,8 +84,8 @@ var _ = Describe("Podman checkpoint", func() {
})

It("podman checkpoint a running container by id", func() {
// CRIU does not work with seccomp correctly on RHEL7
session := podmanTest.Podman([]string{"run", "-it", "--security-opt", "seccomp=unconfined", "-d", ALPINE, "top"})
localRunString := getRunString([]string{ALPINE, "top"})
session := podmanTest.Podman(localRunString)
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(0))
cid := session.OutputToString()
Expand All @@ -94,7 +106,8 @@ var _ = Describe("Podman checkpoint", func() {
})

It("podman checkpoint a running container by name", func() {
session := podmanTest.Podman([]string{"run", "-it", "--security-opt", "seccomp=unconfined", "--name", "test_name", "-d", ALPINE, "top"})
localRunString := getRunString([]string{"--name", "test_name", ALPINE, "top"})
session := podmanTest.Podman(localRunString)
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(0))

Expand All @@ -114,7 +127,8 @@ var _ = Describe("Podman checkpoint", func() {
})

It("podman pause a checkpointed container by id", func() {
session := podmanTest.Podman([]string{"run", "-it", "--security-opt", "seccomp=unconfined", "-d", ALPINE, "top"})
localRunString := getRunString([]string{ALPINE, "top"})
session := podmanTest.Podman(localRunString)
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(0))
cid := session.OutputToString()
Expand Down Expand Up @@ -151,11 +165,13 @@ var _ = Describe("Podman checkpoint", func() {
})

It("podman checkpoint latest running container", func() {
session1 := podmanTest.Podman([]string{"run", "-it", "--security-opt", "seccomp=unconfined", "--name", "first", "-d", ALPINE, "top"})
localRunString := getRunString([]string{"--name", "first", ALPINE, "top"})
session1 := podmanTest.Podman(localRunString)
session1.WaitWithDefaultTimeout()
Expect(session1.ExitCode()).To(Equal(0))

session2 := podmanTest.Podman([]string{"run", "-it", "--security-opt", "seccomp=unconfined", "--name", "second", "-d", ALPINE, "top"})
localRunString = getRunString([]string{"--name", "second", ALPINE, "top"})
session2 := podmanTest.Podman(localRunString)
session2.WaitWithDefaultTimeout()
Expect(session2.ExitCode()).To(Equal(0))

Expand Down Expand Up @@ -186,11 +202,13 @@ var _ = Describe("Podman checkpoint", func() {
})

It("podman checkpoint all running container", func() {
session1 := podmanTest.Podman([]string{"run", "-it", "--security-opt", "seccomp=unconfined", "--name", "first", "-d", ALPINE, "top"})
localRunString := getRunString([]string{"--name", "first", ALPINE, "top"})
session1 := podmanTest.Podman(localRunString)
session1.WaitWithDefaultTimeout()
Expect(session1.ExitCode()).To(Equal(0))

session2 := podmanTest.Podman([]string{"run", "-it", "--security-opt", "seccomp=unconfined", "--name", "second", "-d", ALPINE, "top"})
localRunString = getRunString([]string{"--name", "second", ALPINE, "top"})
session2 := podmanTest.Podman(localRunString)
session2.WaitWithDefaultTimeout()
Expect(session2.ExitCode()).To(Equal(0))

Expand Down Expand Up @@ -221,7 +239,8 @@ var _ = Describe("Podman checkpoint", func() {
})

It("podman checkpoint container with established tcp connections", func() {
session := podmanTest.Podman([]string{"run", "-it", "--security-opt", "seccomp=unconfined", "-d", redis})
localRunString := getRunString([]string{redis})
session := podmanTest.Podman(localRunString)
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(0))

Expand Down Expand Up @@ -275,7 +294,8 @@ var _ = Describe("Podman checkpoint", func() {
})

It("podman checkpoint with --leave-running", func() {
session := podmanTest.Podman([]string{"run", "-it", "--security-opt", "seccomp=unconfined", "-d", ALPINE, "top"})
localRunString := getRunString([]string{ALPINE, "top"})
session := podmanTest.Podman(localRunString)
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(0))
cid := session.OutputToString()
Expand Down Expand Up @@ -312,7 +332,8 @@ var _ = Describe("Podman checkpoint", func() {
})

It("podman checkpoint and restore container with same IP", func() {
session := podmanTest.Podman([]string{"run", "-it", "--security-opt", "seccomp=unconfined", "--name", "test_name", "-d", ALPINE, "top"})
localRunString := getRunString([]string{"--name", "test_name", ALPINE, "top"})
session := podmanTest.Podman(localRunString)
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(0))

Expand Down Expand Up @@ -355,8 +376,10 @@ var _ = Describe("Podman checkpoint", func() {
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(0))
Expect(podmanTest.NumberOfContainersRunning()).To(Equal(1))
cid := session.OutputToString()
fileName := "/tmp/checkpoint-" + cid + ".tar.gz"

result := podmanTest.Podman([]string{"container", "checkpoint", "-l", "-e", "/tmp/checkpoint.tar.gz"})
result := podmanTest.Podman([]string{"container", "checkpoint", "-l", "-e", fileName})
result.WaitWithDefaultTimeout()

Expect(result.ExitCode()).To(Equal(0))
Expand All @@ -369,15 +392,15 @@ var _ = Describe("Podman checkpoint", func() {
Expect(result.ExitCode()).To(Equal(0))
Expect(podmanTest.NumberOfContainersRunning()).To(Equal(0))

result = podmanTest.Podman([]string{"container", "restore", "-i", "/tmp/checkpoint.tar.gz"})
result = podmanTest.Podman([]string{"container", "restore", "-i", fileName})
result.WaitWithDefaultTimeout()

Expect(result.ExitCode()).To(Equal(0))
Expect(podmanTest.NumberOfContainersRunning()).To(Equal(1))
Expect(podmanTest.GetContainerStatus()).To(ContainSubstring("Up"))

// Restore container a second time with different name
result = podmanTest.Podman([]string{"container", "restore", "-i", "/tmp/checkpoint.tar.gz", "-n", "restore_again"})
result = podmanTest.Podman([]string{"container", "restore", "-i", fileName, "-n", "restore_again"})
result.WaitWithDefaultTimeout()

Expect(result.ExitCode()).To(Equal(0))
Expand All @@ -390,27 +413,29 @@ var _ = Describe("Podman checkpoint", func() {
Expect(podmanTest.NumberOfContainersRunning()).To(Equal(0))

// Remove exported checkpoint
os.Remove("/tmp/checkpoint.tar.gz")
os.Remove(fileName)
})

It("podman checkpoint and run exec in restored container", func() {
// Start the container
session := podmanTest.Podman([]string{"run", "-it", "--rm", "-d", ALPINE, "top"})
localRunString := getRunString([]string{"--rm", ALPINE, "top"})
session := podmanTest.Podman(localRunString)
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(0))
Expect(podmanTest.NumberOfContainersRunning()).To(Equal(1))
cid := session.OutputToString()
fileName := "/tmp/checkpoint-" + cid + ".tar.gz"

// Checkpoint the container
result := podmanTest.Podman([]string{"container", "checkpoint", "-l", "-e", "/tmp/checkpoint.tar.gz"})
result := podmanTest.Podman([]string{"container", "checkpoint", "-l", "-e", fileName})
result.WaitWithDefaultTimeout()

Expect(result.ExitCode()).To(Equal(0))
Expect(podmanTest.NumberOfContainersRunning()).To(Equal(0))
Expect(podmanTest.NumberOfContainers()).To(Equal(0))

// Restore the container
result = podmanTest.Podman([]string{"container", "restore", "-i", "/tmp/checkpoint.tar.gz"})
result = podmanTest.Podman([]string{"container", "restore", "-i", fileName})
result.WaitWithDefaultTimeout()

Expect(result.ExitCode()).To(Equal(0))
Expand All @@ -429,6 +454,6 @@ var _ = Describe("Podman checkpoint", func() {
Expect(result.OutputToString()).To(ContainSubstring(cid))

// Remove exported checkpoint
os.Remove("/tmp/checkpoint.tar.gz")
os.Remove(fileName)
})
})

0 comments on commit d0f540e

Please sign in to comment.