aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cmd/podman/create.go30
-rw-r--r--cmd/podman/ps.go45
-rw-r--r--libpod/runtime_img.go28
-rw-r--r--test/podman_import.bats102
4 files changed, 70 insertions, 135 deletions
diff --git a/cmd/podman/create.go b/cmd/podman/create.go
index 80cb7f432..e0825566a 100644
--- a/cmd/podman/create.go
+++ b/cmd/podman/create.go
@@ -370,10 +370,13 @@ func exposedPorts(c *cli.Context, imageExposedPorts map[string]struct{}) (map[na
// default container runtime data out of it. imageData returns the data
// to the caller. Example Data: Entrypoint, Env, WorkingDir, Labels ...
func imageData(c *cli.Context, runtime *libpod.Runtime, image string) (string, string, *libpod.ImageData, error) {
- var err error
+ var (
+ err error
+ imageName, imageID string
+ )
// Deal with the image after all the args have been checked
createImage := runtime.NewImage(image)
- createImage.LocalName, _ = createImage.GetLocalImageName()
+ imageName, imageID, _ = createImage.GetLocalImageName()
if createImage.LocalName == "" {
// The image wasnt found by the user input'd name or its fqname
// Pull the image
@@ -384,31 +387,14 @@ func imageData(c *cli.Context, runtime *libpod.Runtime, image string) (string, s
createImage.Pull(writer)
}
- var imageName string
- if createImage.LocalName != "" {
- nameIsID, err := runtime.IsImageID(createImage.LocalName)
- if err != nil {
- return "", "", nil, err
- }
- if nameIsID {
- // If the input from the user is an ID, then we need to get the image
- // name for cstorage
- createImage.LocalName, err = createImage.GetNameByID()
- if err != nil {
- return "", "", nil, err
- }
- }
- imageName = createImage.LocalName
- } else {
+ createImage.LocalName = imageName
+ if imageName == "" {
imageName, err = createImage.GetFQName()
+ _, imageID, _ = createImage.GetLocalImageName()
}
if err != nil {
return "", "", nil, err
}
- imageID, err := createImage.GetImageID()
- if err != nil {
- return "", "", nil, err
- }
storageImage, err := runtime.GetImage(imageName)
if err != nil {
return "", "", nil, errors.Wrapf(err, "error getting storage image %q", image)
diff --git a/cmd/podman/ps.go b/cmd/podman/ps.go
index ef5d40c43..be6c5aef5 100644
--- a/cmd/podman/ps.go
+++ b/cmd/podman/ps.go
@@ -396,23 +396,38 @@ func (p *psTemplateParams) headerMap() map[string]string {
// getTemplateOutput returns the modified container information
func getTemplateOutput(containers []*libpod.Container, opts psOptions) ([]psTemplateParams, error) {
- var psOutput []psTemplateParams
- var status string
+ var (
+ psOutput []psTemplateParams
+ status, ctrID string
+ conConfig *libpod.ContainerConfig
+ conState libpod.ContainerStatus
+ err error
+ exitCode int32
+ pid int
+ )
+
for _, ctr := range containers {
- ctrID := ctr.ID()
- conConfig := ctr.Config()
- conState, err := ctr.State()
- if err != nil {
- return psOutput, errors.Wrapf(err, "unable to obtain container state")
- }
- exitCode, err := ctr.ExitCode()
- if err != nil {
- return psOutput, errors.Wrapf(err, "unable to obtain container exit code")
- }
- pid, err := ctr.PID()
- if err != nil {
- return psOutput, errors.Wrapf(err, "unable to obtain container pid")
+ batchErr := ctr.Batch(func(c *libpod.Container) error {
+ ctrID = c.ID()
+ conConfig = c.Config()
+ conState, err = c.State()
+ if err != nil {
+ return errors.Wrapf(err, "unable to obtain container state")
+ }
+ exitCode, err = c.ExitCode()
+ if err != nil {
+ return errors.Wrapf(err, "unable to obtain container exit code")
+ }
+ pid, err = c.PID()
+ if err != nil {
+ return errors.Wrapf(err, "unable to obtain container pid")
+ }
+ return nil
+ })
+ if batchErr != nil {
+ return nil, err
}
+
runningFor := units.HumanDuration(time.Since(conConfig.CreatedTime))
createdAt := runningFor + " ago"
imageName := conConfig.RootfsImageName
diff --git a/libpod/runtime_img.go b/libpod/runtime_img.go
index 671e08c19..882174856 100644
--- a/libpod/runtime_img.go
+++ b/libpod/runtime_img.go
@@ -342,27 +342,23 @@ func getTags(nameInput string) (reference.NamedTagged, bool, error) {
return tagged, isTagged, nil
}
-// GetLocalImageName returns the name of the image if it is local.
-// It will return an empty string and error if not found.
-func (k *Image) GetLocalImageName() (string, error) {
- _, err := k.runtime.GetImage(k.Name)
+// GetLocalImageName returns the name of the image if it is local as well
+// as the image's ID. It will return an empty strings and error if not found.
+func (k *Image) GetLocalImageName() (string, string, error) {
+ localImage, err := k.runtime.GetImage(k.Name)
if err == nil {
k.LocalName = k.Name
- return k.Name, nil
+ return k.Name, localImage.ID, nil
}
localImages, err := k.runtime.GetImages(&ImageFilterParams{})
if err != nil {
- return "", errors.Wrapf(err, "unable to find local images")
+ return "", "", errors.Wrapf(err, "unable to find local images")
}
_, isTagged, err := getTags(k.Name)
if err != nil {
- return "", err
+ return "", "", err
}
for _, image := range localImages {
- if strings.HasPrefix(image.ID, k.Name) {
- k.ID = image.ID
- return image.ID, nil
- }
for _, name := range image.Names {
imgRef, err := reference.Parse(name)
if err != nil {
@@ -382,22 +378,22 @@ func (k *Image) GetLocalImageName() (string, error) {
if imageName == k.Name {
k.LocalName = name
- return name, nil
+ return name, image.ID, nil
}
imageSplit := strings.Split(imageName, "/")
baseName := imageSplit[len(imageSplit)-1]
if baseName == k.Name {
k.LocalName = name
- return name, nil
+ return name, image.ID, nil
}
}
}
- return "", errors.Wrapf(storage.ErrImageUnknown, "unable to find image locally")
+ return "", "", errors.Wrapf(storage.ErrImageUnknown, "unable to find image locally")
}
// HasLatest determines if we have the latest image local
func (k *Image) HasLatest() (bool, error) {
- localName, err := k.GetLocalImageName()
+ localName, _, err := k.GetLocalImageName()
if err != nil {
return false, err
}
@@ -434,7 +430,7 @@ func (k *Image) Pull(writer io.Writer) error {
func (k *Image) Remove(force bool) (string, error) {
if k.LocalName == "" {
// This populates the images local name
- _, err := k.GetLocalImageName()
+ _, _, err := k.GetLocalImageName()
if err != nil {
return "", errors.Wrapf(err, "unable to find %s locally", k.Name)
}
diff --git a/test/podman_import.bats b/test/podman_import.bats
index 6303141c9..69c704a68 100644
--- a/test/podman_import.bats
+++ b/test/podman_import.bats
@@ -2,8 +2,6 @@
load helpers
-IMAGE="redis:alpine"
-
function teardown() {
cleanup_test
}
@@ -13,133 +11,73 @@ function setup() {
}
@test "podman import with source and reference" {
- skip "Test needs to be converted to podman run bash -c"
- start_crio
- run bash -c crioctl pod run bash -c --config "$TESTDATA"/sandbox_config.json
- echo "$output"
- [ "$status" -eq 0 ]
- pod_id="$output"
- run bash -c crioctl image pull "$IMAGE"
- echo "$output"
- [ "$status" -eq 0 ]
- run bash -c crioctl ctr create --config "$TESTDATA"/container_config.json --pod "$pod_id"
+ run bash -c "${PODMAN_BINARY} ${PODMAN_OPTIONS} run -d $ALPINE sleep 60"
echo "$output"
[ "$status" -eq 0 ]
ctr_id="$output"
- run bash -c ${PODMAN_BINARY} ${PODMAN_OPTIONS} export -o container.tar "$ctr_id"
- echo "$output"
- [ "$status" -eq 0 ]
- run bash -c ${PODMAN_BINARY} ${PODMAN_OPTIONS} import container.tar imported-image
+ run bash -cp "${PODMAN_BINARY} ${PODMAN_OPTIONS} export -o container.tar $ctr_id"
echo "$output"
[ "$status" -eq 0 ]
- run bash -c ${PODMAN_BINARY} ${PODMAN_OPTIONS} images
+ run bash -c "${PODMAN_BINARY} ${PODMAN_OPTIONS} import container.tar imported-image"
echo "$output"
[ "$status" -eq 0 ]
- images="$output"
- run bash -c grep "imported-image" <<< "$images"
+ run bash -c "${PODMAN_BINARY} ${PODMAN_OPTIONS} images"
echo "$output"
[ "$status" -eq 0 ]
- cleanup_ctrs
- cleanup_pods
- stop_crio
+ [[ "$output" == *"imported-image"* ]]
rm -f container.tar
}
@test "podman import without reference" {
- skip "Test needs to be converted to podman run bash -c"
- start_crio
- run bash -c crioctl pod run bash -c --config "$TESTDATA"/sandbox_config.json
- echo "$output"
- [ "$status" -eq 0 ]
- pod_id="$output"
- run bash -c crioctl image pull "$IMAGE"
- echo "$output"
- [ "$status" -eq 0 ]
- run bash -c crioctl ctr create --config "$TESTDATA"/container_config.json --pod "$pod_id"
+ run bash -c "${PODMAN_BINARY} ${PODMAN_OPTIONS} run -d $ALPINE sleep 60"
echo "$output"
[ "$status" -eq 0 ]
ctr_id="$output"
- run bash -c ${PODMAN_BINARY} ${PODMAN_OPTIONS} export -o container.tar "$ctr_id"
- echo "$output"
- [ "$status" -eq 0 ]
- run bash -c ${PODMAN_BINARY} ${PODMAN_OPTIONS} import container.tar
+ run bash -c "${PODMAN_BINARY} ${PODMAN_OPTIONS} export -o container.tar $ctr_id"
echo "$output"
[ "$status" -eq 0 ]
- run bash -c ${PODMAN_BINARY} ${PODMAN_OPTIONS} images
+ run bash -c "${PODMAN_BINARY} ${PODMAN_OPTIONS} import container.tar"
echo "$output"
[ "$status" -eq 0 ]
- images="$output"
- run bash -c grep "<none>" <<< "$images"
+ run bash -c "${PODMAN_BINARY} ${PODMAN_OPTIONS} images"
echo "$output"
[ "$status" -eq 0 ]
- cleanup_ctrs
- cleanup_pods
- stop_crio
+ [[ "$output" == *"<none>"* ]]
rm -f container.tar
}
@test "podman import with message flag" {
- skip "Test needs to be converted to podman run bash -c"
- start_crio
- run bash -c crioctl pod run bash -c --config "$TESTDATA"/sandbox_config.json
- echo "$output"
- [ "$status" -eq 0 ]
- pod_id="$output"
- run bash -c crioctl image pull "$IMAGE"
- echo "$output"
- [ "$status" -eq 0 ]
- run bash -c crioctl ctr create --config "$TESTDATA"/container_config.json --pod "$pod_id"
+ run bash -c "${PODMAN_BINARY} ${PODMAN_OPTIONS} run -d $ALPINE sleep 60"
echo "$output"
[ "$status" -eq 0 ]
ctr_id="$output"
- run bash -c ${PODMAN_BINARY} ${PODMAN_OPTIONS} export -o container.tar "$ctr_id"
- echo "$output"
- [ "$status" -eq 0 ]
- run bash -c ${PODMAN_BINARY} ${PODMAN_OPTIONS} import --message "importing container test message" container.tar imported-image
+ run bash -c "${PODMAN_BINARY} ${PODMAN_OPTIONS} export -o container.tar $ctr_id"
echo "$output"
[ "$status" -eq 0 ]
- run bash -c ${PODMAN_BINARY} ${PODMAN_OPTIONS} history imported-image
+ run bash -c "${PODMAN_BINARY} ${PODMAN_OPTIONS} import --message 'importing container test message' container.tar imported-image"
echo "$output"
[ "$status" -eq 0 ]
- history="$output"
- run bash -c grep "importing container test message" <<< "$history"
+ run bash -c "${PODMAN_BINARY} ${PODMAN_OPTIONS} history imported-image"
echo "$output"
[ "$status" -eq 0 ]
- cleanup_ctrs
- cleanup_pods
- stop_crio
+ [[ "$output" == *"importing container test message"* ]]
rm -f container.tar
}
@test "podman import with change flag" {
- skip "Test needs to be converted to podman run bash -c"
- start_crio
- run bash -c crioctl pod run bash -c --config "$TESTDATA"/sandbox_config.json
- echo "$output"
- [ "$status" -eq 0 ]
- pod_id="$output"
- run bash -c crioctl image pull "$IMAGE"
- echo "$output"
- [ "$status" -eq 0 ]
- run bash -c crioctl ctr create --config "$TESTDATA"/container_config.json --pod "$pod_id"
+ run bash -c "${PODMAN_BINARY} ${PODMAN_OPTIONS} run -d $ALPINE sleep 60"
echo "$output"
[ "$status" -eq 0 ]
ctr_id="$output"
- run bash -c ${PODMAN_BINARY} ${PODMAN_OPTIONS} export -o container.tar "$ctr_id"
- echo "$output"
- [ "$status" -eq 0 ]
- run bash -c ${PODMAN_BINARY} ${PODMAN_OPTIONS} import --change "CMD=/bin/bash" container.tar imported-image
+ run bash -c "${PODMAN_BINARY} ${PODMAN_OPTIONS} export -o container.tar $ctr_id"
echo "$output"
[ "$status" -eq 0 ]
- run bash -c ${PODMAN_BINARY} ${PODMAN_OPTIONS} inspect imported-image
+ run bash -c "${PODMAN_BINARY} ${PODMAN_OPTIONS} import --change 'CMD=/bin/bash' container.tar imported-image"
echo "$output"
[ "$status" -eq 0 ]
- inspect="$output"
- run bash -c grep "/bin/bash" <<< "$inspect"
+ run bash -c "${PODMAN_BINARY} ${PODMAN_OPTIONS} inspect imported-image"
echo "$output"
[ "$status" -eq 0 ]
- cleanup_ctrs
- cleanup_pods
- stop_crio
+ [[ "$output" == *"/bin/bash"* ]]
rm -f container.tar
}