mirror of
https://github.com/containers/podman.git
synced 2025-05-20 00:27:03 +08:00
podman volume export/import: give better error
When the volume does not exist we should output an error stating so and not some generic one. Fixes #14411 Signed-off-by: Paul Holzinger <pholzing@redhat.com>
This commit is contained in:
@ -8,6 +8,7 @@ import (
|
|||||||
"github.com/containers/podman/v4/cmd/podman/common"
|
"github.com/containers/podman/v4/cmd/podman/common"
|
||||||
"github.com/containers/podman/v4/cmd/podman/registry"
|
"github.com/containers/podman/v4/cmd/podman/registry"
|
||||||
"github.com/containers/podman/v4/pkg/domain/entities"
|
"github.com/containers/podman/v4/pkg/domain/entities"
|
||||||
|
"github.com/containers/podman/v4/pkg/errorhandling"
|
||||||
"github.com/containers/podman/v4/utils"
|
"github.com/containers/podman/v4/utils"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
@ -58,10 +59,13 @@ func export(cmd *cobra.Command, args []string) error {
|
|||||||
return errors.New("expects output path, use --output=[path]")
|
return errors.New("expects output path, use --output=[path]")
|
||||||
}
|
}
|
||||||
inspectOpts.Type = common.VolumeType
|
inspectOpts.Type = common.VolumeType
|
||||||
volumeData, _, err := containerEngine.VolumeInspect(ctx, args, inspectOpts)
|
volumeData, errs, err := containerEngine.VolumeInspect(ctx, args, inspectOpts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
if len(errs) > 0 {
|
||||||
|
return errorhandling.JoinErrors(errs)
|
||||||
|
}
|
||||||
if len(volumeData) < 1 {
|
if len(volumeData) < 1 {
|
||||||
return errors.New("no volume data found")
|
return errors.New("no volume data found")
|
||||||
}
|
}
|
||||||
|
@ -8,6 +8,7 @@ import (
|
|||||||
"github.com/containers/podman/v4/cmd/podman/parse"
|
"github.com/containers/podman/v4/cmd/podman/parse"
|
||||||
"github.com/containers/podman/v4/cmd/podman/registry"
|
"github.com/containers/podman/v4/cmd/podman/registry"
|
||||||
"github.com/containers/podman/v4/pkg/domain/entities"
|
"github.com/containers/podman/v4/pkg/domain/entities"
|
||||||
|
"github.com/containers/podman/v4/pkg/errorhandling"
|
||||||
"github.com/containers/podman/v4/utils"
|
"github.com/containers/podman/v4/utils"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
@ -60,10 +61,14 @@ func importVol(cmd *cobra.Command, args []string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
inspectOpts.Type = common.VolumeType
|
inspectOpts.Type = common.VolumeType
|
||||||
volumeData, _, err := containerEngine.VolumeInspect(ctx, volumes, inspectOpts)
|
inspectOpts.Type = common.VolumeType
|
||||||
|
volumeData, errs, err := containerEngine.VolumeInspect(ctx, volumes, inspectOpts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
if len(errs) > 0 {
|
||||||
|
return errorhandling.JoinErrors(errs)
|
||||||
|
}
|
||||||
if len(volumeData) < 1 {
|
if len(volumeData) < 1 {
|
||||||
return errors.New("no volume data found")
|
return errors.New("no volume data found")
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
% podman-volume-import(1)
|
% podman-volume-import(1)
|
||||||
|
|
||||||
## NAME
|
## NAME
|
||||||
podman\-volume\-import - Import tarball contents into a podman volume
|
podman\-volume\-import - Import tarball contents into an existing podman volume
|
||||||
|
|
||||||
## SYNOPSIS
|
## SYNOPSIS
|
||||||
**podman volume import** *volume* [*source*]
|
**podman volume import** *volume* [*source*]
|
||||||
@ -11,9 +11,9 @@ podman\-volume\-import - Import tarball contents into a podman volume
|
|||||||
**podman volume import** imports the contents of a tarball into the podman volume's mount point.
|
**podman volume import** imports the contents of a tarball into the podman volume's mount point.
|
||||||
**podman volume import** can consume piped input when using `-` as source path.
|
**podman volume import** can consume piped input when using `-` as source path.
|
||||||
|
|
||||||
Note: Following command is not supported by podman-remote.
|
The given volume must already exist and will not be created by podman volume import.
|
||||||
|
|
||||||
**podman volume import VOLUME [SOURCE]**
|
Note: Following command is not supported by podman-remote.
|
||||||
|
|
||||||
#### **--help**
|
#### **--help**
|
||||||
|
|
||||||
|
@ -16,7 +16,7 @@ podman volume is a set of subcommands that manage volumes.
|
|||||||
| create | [podman-volume-create(1)](podman-volume-create.1.md) | Create a new volume. |
|
| create | [podman-volume-create(1)](podman-volume-create.1.md) | Create a new volume. |
|
||||||
| exists | [podman-volume-exists(1)](podman-volume-exists.1.md) | Check if the given volume exists. |
|
| exists | [podman-volume-exists(1)](podman-volume-exists.1.md) | Check if the given volume exists. |
|
||||||
| export | [podman-volume-export(1)](podman-volume-export.1.md) | Exports volume to external tar. |
|
| export | [podman-volume-export(1)](podman-volume-export.1.md) | Exports volume to external tar. |
|
||||||
| import | [podman-volume-import(1)](podman-volume-import.1.md) | Import tarball contents into a podman volume. |
|
| import | [podman-volume-import(1)](podman-volume-import.1.md) | Import tarball contents into an existing podman volume. |
|
||||||
| inspect | [podman-volume-inspect(1)](podman-volume-inspect.1.md) | Get detailed information on one or more volumes. |
|
| inspect | [podman-volume-inspect(1)](podman-volume-inspect.1.md) | Get detailed information on one or more volumes. |
|
||||||
| ls | [podman-volume-ls(1)](podman-volume-ls.1.md) | List all the available volumes. |
|
| ls | [podman-volume-ls(1)](podman-volume-ls.1.md) | List all the available volumes. |
|
||||||
| mount | [podman-volume-mount(1)](podman-volume-mount.1.md) | Mount a volume filesystem. |
|
| mount | [podman-volume-mount(1)](podman-volume-mount.1.md) | Mount a volume filesystem. |
|
||||||
|
@ -110,15 +110,24 @@ var _ = Describe("Podman volume create", func() {
|
|||||||
Expect(session.OutputToString()).To(ContainSubstring("hello"))
|
Expect(session.OutputToString()).To(ContainSubstring("hello"))
|
||||||
})
|
})
|
||||||
|
|
||||||
It("podman import volume should fail", func() {
|
It("podman import/export volume should fail", func() {
|
||||||
// try import on volume or source which does not exists
|
// try import on volume or source which does not exists
|
||||||
if podmanTest.RemoteTest {
|
SkipIfRemote("Volume export check does not work with a remote client")
|
||||||
Skip("Volume export check does not work with a remote client")
|
|
||||||
}
|
|
||||||
|
|
||||||
session := podmanTest.Podman([]string{"volume", "import", "notfound", "notfound.tar"})
|
session := podmanTest.Podman([]string{"volume", "import", "notfound", "notfound.tar"})
|
||||||
session.WaitWithDefaultTimeout()
|
session.WaitWithDefaultTimeout()
|
||||||
Expect(session).To(ExitWithError())
|
Expect(session).To(ExitWithError())
|
||||||
|
Expect(session.ErrorToString()).To(ContainSubstring("open notfound.tar: no such file or directory"))
|
||||||
|
|
||||||
|
session = podmanTest.Podman([]string{"volume", "import", "notfound", "-"})
|
||||||
|
session.WaitWithDefaultTimeout()
|
||||||
|
Expect(session).To(ExitWithError())
|
||||||
|
Expect(session.ErrorToString()).To(ContainSubstring("no such volume notfound"))
|
||||||
|
|
||||||
|
session = podmanTest.Podman([]string{"volume", "export", "notfound"})
|
||||||
|
session.WaitWithDefaultTimeout()
|
||||||
|
Expect(session).To(ExitWithError())
|
||||||
|
Expect(session.ErrorToString()).To(ContainSubstring("no such volume notfound"))
|
||||||
})
|
})
|
||||||
|
|
||||||
It("podman create volume with bad volume option", func() {
|
It("podman create volume with bad volume option", func() {
|
||||||
|
Reference in New Issue
Block a user