From ad29f4faa6a5e1c52b7bbb57b008001468c705e1 Mon Sep 17 00:00:00 2001 From: Navid Yaghoobi Date: Fri, 10 Mar 2023 22:00:49 +1100 Subject: [PATCH] Container create error fix when selecting a volume Signed-off-by: Navid Yaghoobi --- pdcs/containers/create.go | 20 +++++++++++++++----- test/003-network.bats | 2 +- test/005-container.bats | 33 +++++++++++---------------------- test/README.md | 9 ++++----- 4 files changed, 31 insertions(+), 33 deletions(-) diff --git a/pdcs/containers/create.go b/pdcs/containers/create.go index 3246c38c2..412eb96a2 100644 --- a/pdcs/containers/create.go +++ b/pdcs/containers/create.go @@ -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. @@ -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 diff --git a/test/003-network.bats b/test/003-network.bats index f2734582b..cc3f7babe 100644 --- a/test/003-network.bats +++ b/test/003-network.bats @@ -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 diff --git a/test/005-container.bats b/test/005-container.bats index e86028cb5..1accf5c66 100644 --- a/test/005-container.bats +++ b/test/005-container.bats @@ -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 @@ -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" @@ -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" @@ -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" } @@ -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" @@ -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" diff --git a/test/README.md b/test/README.md index f089a0171..081690ba9 100644 --- a/test/README.md +++ b/test/README.md @@ -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