mirror of
https://github.com/containers/podman.git
synced 2025-06-22 09:58:10 +08:00
Merge pull request #15066 from sstosh/checkpoint-samename
Fix: Restore a container which name is equal to a image name
This commit is contained in:
@ -93,12 +93,28 @@ func init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func restore(cmd *cobra.Command, args []string) error {
|
func restore(cmd *cobra.Command, args []string) error {
|
||||||
var errs utils.OutputErrors
|
var (
|
||||||
|
e error
|
||||||
|
errs utils.OutputErrors
|
||||||
|
)
|
||||||
podmanStart := time.Now()
|
podmanStart := time.Now()
|
||||||
if rootless.IsRootless() {
|
if rootless.IsRootless() {
|
||||||
return fmt.Errorf("restoring a container requires root")
|
return fmt.Errorf("restoring a container requires root")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check if the container exists (#15055)
|
||||||
|
exists := &entities.BoolReport{Value: false}
|
||||||
|
for _, ctr := range args {
|
||||||
|
exists, e = registry.ContainerEngine().ContainerExists(registry.GetContext(), ctr, entities.ContainerExistsOptions{})
|
||||||
|
if e != nil {
|
||||||
|
return e
|
||||||
|
}
|
||||||
|
if exists.Value {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if !exists.Value {
|
||||||
// Find out if this is an image
|
// Find out if this is an image
|
||||||
inspectOpts := entities.InspectOptions{}
|
inspectOpts := entities.InspectOptions{}
|
||||||
imgData, _, err := registry.ImageEngine().Inspect(context.Background(), args, inspectOpts)
|
imgData, _, err := registry.ImageEngine().Inspect(context.Background(), args, inspectOpts)
|
||||||
@ -121,6 +137,7 @@ func restore(cmd *cobra.Command, args []string) error {
|
|||||||
return fmt.Errorf("container image \"%s\" requires runtime: \"%s\"", imgData[i].ID, checkpointRuntimeName)
|
return fmt.Errorf("container image \"%s\" requires runtime: \"%s\"", imgData[i].ID, checkpointRuntimeName)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
notImport := (!restoreOptions.CheckpointImage && restoreOptions.Import == "")
|
notImport := (!restoreOptions.CheckpointImage && restoreOptions.Import == "")
|
||||||
|
|
||||||
|
@ -223,6 +223,26 @@ var _ = Describe("Podman checkpoint", func() {
|
|||||||
Expect(result).Should(Exit(0))
|
Expect(result).Should(Exit(0))
|
||||||
Expect(podmanTest.NumberOfContainersRunning()).To(Equal(1))
|
Expect(podmanTest.NumberOfContainersRunning()).To(Equal(1))
|
||||||
Expect(podmanTest.GetContainerStatus()).To(ContainSubstring("Up"))
|
Expect(podmanTest.GetContainerStatus()).To(ContainSubstring("Up"))
|
||||||
|
|
||||||
|
// Restore a container which name is equal to a image name (#15055)
|
||||||
|
localRunString = getRunString([]string{"--name", "alpine", "quay.io/libpod/alpine:latest", "top"})
|
||||||
|
session = podmanTest.Podman(localRunString)
|
||||||
|
session.WaitWithDefaultTimeout()
|
||||||
|
Expect(session).Should(Exit(0))
|
||||||
|
|
||||||
|
result = podmanTest.Podman([]string{"container", "checkpoint", "alpine"})
|
||||||
|
result.WaitWithDefaultTimeout()
|
||||||
|
|
||||||
|
Expect(result).Should(Exit(0))
|
||||||
|
Expect(podmanTest.NumberOfContainersRunning()).To(Equal(1))
|
||||||
|
Expect(podmanTest.GetContainerStatus()).To(ContainSubstring("Exited"))
|
||||||
|
|
||||||
|
result = podmanTest.Podman([]string{"container", "restore", "alpine"})
|
||||||
|
result.WaitWithDefaultTimeout()
|
||||||
|
|
||||||
|
Expect(result).Should(Exit(0))
|
||||||
|
Expect(podmanTest.NumberOfContainersRunning()).To(Equal(2))
|
||||||
|
Expect(podmanTest.GetContainerStatus()).To(ContainSubstring("Up"))
|
||||||
})
|
})
|
||||||
|
|
||||||
It("podman pause a checkpointed container by id", func() {
|
It("podman pause a checkpointed container by id", func() {
|
||||||
|
Reference in New Issue
Block a user