Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Checkpoint/Restore test fixes #11955

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 19 additions & 11 deletions test/e2e/checkpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ import (
"os"
"os/exec"
"strings"
"time"

"github.com/containers/podman/v3/pkg/checkpoint/crutils"
"github.com/containers/podman/v3/pkg/criu"
. "github.com/containers/podman/v3/test/utils"
"github.com/containers/podman/v3/utils"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
. "github.com/onsi/gomega/gexec"
Expand Down Expand Up @@ -933,18 +935,23 @@ var _ = Describe("Podman checkpoint", func() {
})

It("podman checkpoint and restore container with different port mappings", func() {
localRunString := getRunString([]string{"-p", "1234:6379", "--rm", redis})
randomPort, err := utils.GetRandomPort()
Expect(err).ShouldNot(HaveOccurred())
localRunString := getRunString([]string{"-p", fmt.Sprintf("%d:6379", randomPort), "--rm", redis})
session := podmanTest.Podman(localRunString)
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(0))
cid := session.OutputToString()
fileName := "/tmp/checkpoint-" + cid + ".tar.gz"

// Open a network connection to the redis server via initial port mapping
conn, err := net.Dial("tcp", "localhost:1234")
if err != nil {
os.Exit(1)
if !WaitContainerReady(podmanTest, cid, "Ready to accept connections", 20, 1) {
Fail("Container failed to get ready")
}

fmt.Fprintf(os.Stderr, "Trying to connect to redis server at localhost:%d", randomPort)
// Open a network connection to the redis server via initial port mapping
conn, err := net.DialTimeout("tcp4", fmt.Sprintf("localhost:%d", randomPort), time.Duration(3)*time.Second)
Expect(err).ShouldNot(HaveOccurred())
conn.Close()

// Checkpoint the container
Expand All @@ -958,7 +965,9 @@ var _ = Describe("Podman checkpoint", func() {
Expect(podmanTest.NumberOfContainers()).To(Equal(0))

// Restore container with different port mapping
result = podmanTest.Podman([]string{"container", "restore", "-p", "1235:6379", "-i", fileName})
newRandomPort, err := utils.GetRandomPort()
Expect(err).ShouldNot(HaveOccurred())
result = podmanTest.Podman([]string{"container", "restore", "-p", fmt.Sprintf("%d:6379", newRandomPort), "-i", fileName})
result.WaitWithDefaultTimeout()

Expect(result).Should(Exit(0))
Expand All @@ -967,13 +976,12 @@ var _ = Describe("Podman checkpoint", func() {

// Open a network connection to the redis server via initial port mapping
// This should fail
conn, err = net.Dial("tcp", "localhost:1234")
conn, err = net.DialTimeout("tcp4", fmt.Sprintf("localhost:%d", randomPort), time.Duration(3)*time.Second)
Expect(err.Error()).To(ContainSubstring("connection refused"))
// Open a network connection to the redis server via new port mapping
conn, err = net.Dial("tcp", "localhost:1235")
if err != nil {
os.Exit(1)
}
fmt.Fprintf(os.Stderr, "Trying to reconnect to redis server at localhost:%d", newRandomPort)
conn, err = net.DialTimeout("tcp4", fmt.Sprintf("localhost:%d", newRandomPort), time.Duration(3)*time.Second)
Expect(err).ShouldNot(HaveOccurred())
conn.Close()

result = podmanTest.Podman([]string{"rm", "-t", "0", "-fa"})
Expand Down