Skip to content

Commit

Permalink
Merge pull request #259 from containers/container_create_error
Browse files Browse the repository at this point in the history
Container create error fix when selecting a volume
  • Loading branch information
navidys authored Mar 10, 2023
2 parents 8ad97a1 + ad29f4f commit f1ac545
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 33 deletions.
20 changes: 15 additions & 5 deletions pdcs/containers/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,15 @@ import (
"net"

"github.com/containers/common/libnetwork/types"
// nolint:gci
"github.com/containers/podman-tui/pdcs/registry"
"github.com/containers/podman-tui/pdcs/utils"
"github.com/containers/podman/v4/pkg/bindings/containers"
"github.com/containers/podman/v4/pkg/bindings/volumes"
"github.com/containers/podman/v4/pkg/domain/entities"
"github.com/containers/podman/v4/pkg/specgen"
"github.com/containers/podman/v4/pkg/specgenutil"
"github.com/pkg/errors"
"github.com/rs/zerolog/log"

"github.com/containers/podman-tui/pdcs/registry"
"github.com/containers/podman-tui/pdcs/utils"
)

// CreateOptions container create options.
Expand Down Expand Up @@ -86,7 +85,18 @@ func Create(opts CreateOptions) ([]string, error) { // nolint:cyclop
}

if opts.Volume != "" {
createOptions.Volume = []string{opts.Volume}
// get volume path
volFilter := make(map[string][]string)
volFilter["name"] = []string{opts.Volume}

volResponse, err := volumes.List(conn, new(volumes.ListOptions).WithFilters(volFilter))
if err != nil {
return warningResponse, err
}

if len(volResponse) > 0 {
createOptions.Volume = []string{volResponse[0].Mountpoint}
}
}

createOptions.ImageVolume = opts.ImageVolume
Expand Down
2 changes: 1 addition & 1 deletion test/003-network.bats
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ load helpers_tui
# select prune command from network commands dialog
# confirm the operation on warnings dialog
podman_tui_set_view "networks"
podman_tui_select_volume_cmd "prune"
podman_tui_select_network_cmd "prune"
podman_tui_send_inputs "Enter"
sleep 2

Expand Down
33 changes: 11 additions & 22 deletions test/005-container.bats
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ load helpers_tui

podman network create $TEST_CONTAINER_NETWORK_NAME || echo done
podman volume create $TEST_CONTAINER_VOLUME_NAME || echo done
podman pod create --name $TEST_CONTAINER_POD_NAME || echo done
podman pod create --name $TEST_CONTAINER_POD_NAME --network $TEST_CONTAINER_NETWORK_NAME --publish $TEST_CONTAINER_PORT || echo done
sleep 2

# get required pod, image, network and volume index for number of KeyDown stroke
Expand All @@ -46,26 +46,13 @@ load helpers_tui
podman_tui_send_inputs "Down"
podman_tui_select_item $pod_index
podman_tui_send_inputs "Enter" "Tab"
podman_tui_send_inputs $TEST_LABEL "Tab" "Tab" "Tab" "Tab"
podman_tui_send_inputs $TEST_LABEL "Tab" "Tab" "Tab"
sleep 1

# switch to "network settings" create view
# select network from dropdown widget
podman_tui_send_inputs "Down" "Down" "Tab"
podman_tui_send_inputs "Tab" "Tab" "Tab" "Down"
podman_tui_select_item $net_index
podman_tui_send_inputs "Enter"
podman_tui_send_inputs "Tab" "Tab"
sleep 1

# switch to "ports settings" create view
# fillout "publish ports" field
podman_tui_send_inputs "Tab" "Down" "Tab"
podman_tui_send_inputs $TEST_CONTAINER_PORT "Tab" "Tab" "Tab" "Tab" "Tab"
podman_tui_send_inputs "Tab"
sleep 1

# switch to "security options" create view
podman_tui_send_inputs "Down" "Tab"
podman_tui_send_inputs "Down" "Down" "Down" "Down" "Tab"
podman_tui_send_inputs "Tab" "Tab" "Tab" "Tab" "Tab"
podman_tui_send_inputs "Space" "Tab" "Tab" "Tab"

Expand Down Expand Up @@ -98,6 +85,7 @@ load helpers_tui
cnt_security_opt=$(podman container inspect ${TEST_CONTAINER_NAME} --format "{{ json .HostConfig.SecurityOpt }}")

assert "$cnt_pod_name" =~ "$TEST_CONTAINER_POD_NAME" "expected container pod: $TEST_CONTAINER_POD_NAME"

assert "$cnt_mounts" =~ "$TEST_CONTAINER_VOLUME_NAME" "expected container volume: $TEST_CONTAINER_VOLUME_NAME"
assert "$cnt_image_name" =~ "$httpd_image" "expected container image name: $httpd_image"
assert "$cnt_ports" =~ "$cnt_port_str" "expected container port: $cnt_port_str"
Expand All @@ -118,9 +106,10 @@ load helpers_tui
podman_tui_select_container_cmd "commit"

podman_tui_send_inputs $TEST_CONTAINER_COMMIT_IMAGE_NAME
podman_tui_send_inputs Tab Tab Tab Tab Tab Tab Tab
podman_tui_send_inputs Tab Enter
sleep 5
podman_tui_send_inputs Tab Tab Tab Tab
podman_tui_send_inputs Tab Tab Tab Tab
podman_tui_send_inputs Enter
sleep 10
run_helper podman image ls ${TEST_CONTAINER_COMMIT_IMAGE_NAME} --format "{{ .Repository }}"
assert "$output" =~ "localhost/${TEST_CONTAINER_COMMIT_IMAGE_NAME}" "expected image"
}
Expand Down Expand Up @@ -174,7 +163,7 @@ load helpers_tui
# switch to containers view
# selec restore command from container commands dialog
# filleout information
# go to restire button and Enter
# go to restore button and Enter

podman_tui_set_view "containers"
podman_tui_select_container_cmd "restore"
Expand Down Expand Up @@ -390,7 +379,7 @@ load helpers_tui
podman_tui_select_item $container_index
podman_tui_select_container_cmd "prune"
podman_tui_send_inputs "Enter"
sleep 3
sleep 10

run_helper podman container ls --all --filter "name=${TEST_CONTAINER_NAME}$" --noheading
assert "$output" == "" "expected $TEST_CONTAINER_NAME to be removed"
Expand Down
9 changes: 4 additions & 5 deletions test/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,13 @@
To run the tests locally in your sandbox, you can use one of these methods:

```shell
$ make binary # build podman-tui binary
$ sudo podman system reset # to reset all previous configuration
$ sudo make test-functionality # run all the tests
$ sudo bats test/001-image.bats # runs just the specified test
$ make binary # build podman-tui binary
$ sudo podman system reset # to reset all previous configuration
$ sudo systemctl restart podman.socket # restart podman socket
$ sudo make test-functionality # run all the tests
```

## Requirements
- switch user to `root` account before running the tests
- use provided Vagrant file to create clean VM sandbox (optional).
- if you are not in root directory of the project, be sure `PODMAN_TUI` variable is set
- access to repository to pull busybox and httpd image
Expand Down

0 comments on commit f1ac545

Please sign in to comment.