Skip to content

Commit

Permalink
Merge pull request #14370 from umohnani8/todo
Browse files Browse the repository at this point in the history
Fix podman pod unpause TODO
  • Loading branch information
openshift-ci[bot] authored Jul 5, 2022
2 parents 39fc5d1 + 65d511c commit cf74739
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 10 deletions.
10 changes: 10 additions & 0 deletions cmd/podman/common/completion.go
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,16 @@ func AutocompletePodsRunning(cmd *cobra.Command, args []string, toComplete strin
return getPods(cmd, toComplete, completeDefault, "running", "degraded")
}

// AutoCompletePodsPause - Autocomplete only paused pod names
// When a pod has a few containers paused, that ends up in degraded state
// So autocomplete degraded pod names as well
func AutoCompletePodsPause(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
if !validCurrentCmdLine(cmd, args, toComplete) {
return nil, cobra.ShellCompDirectiveNoFileComp
}
return getPods(cmd, toComplete, completeDefault, "paused", "degraded")
}

// AutocompleteForKube - Autocomplete all Podman objects supported by kube generate.
func AutocompleteForKube(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
if !validCurrentCmdLine(cmd, args, toComplete) {
Expand Down
6 changes: 2 additions & 4 deletions cmd/podman/pods/unpause.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@ var (
Args: func(cmd *cobra.Command, args []string) error {
return validate.CheckAllLatestAndIDFile(cmd, args, false, "")
},
// TODO have a function which shows only pods which could be unpaused
// for now show all
ValidArgsFunction: common.AutocompletePods,
ValidArgsFunction: common.AutoCompletePodsPause,
Example: `podman pod unpause podID1 podID2
podman pod unpause --all
podman pod unpause --latest`,
Expand All @@ -43,7 +41,7 @@ func init() {
Parent: podCmd,
})
flags := unpauseCommand.Flags()
flags.BoolVarP(&unpauseOptions.All, "all", "a", false, "Pause all running pods")
flags.BoolVarP(&unpauseOptions.All, "all", "a", false, "Unpause all running pods")
validate.AddLatestFlag(unpauseCommand, &unpauseOptions.Latest)
}

Expand Down
8 changes: 8 additions & 0 deletions pkg/domain/infra/abi/pods.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,14 @@ func (ic *ContainerEngine) PodUnpause(ctx context.Context, namesOrIds []string,
return nil, err
}
for _, p := range pods {
status, err := p.GetPodStatus()
if err != nil {
return nil, err
}
// If the pod is not paused or degraded, there is no need to attempt an unpause on it
if status != define.PodStatePaused && status != define.PodStateDegraded {
continue
}
report := entities.PodUnpauseReport{Id: p.ID()}
errs, err := p.Unpause(ctx)
if err != nil && !errors.Is(err, define.ErrPodPartialFail) {
Expand Down
4 changes: 4 additions & 0 deletions pkg/domain/infra/tunnel/pods.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ func (ic *ContainerEngine) PodUnpause(ctx context.Context, namesOrIds []string,
}
reports := make([]*entities.PodUnpauseReport, 0, len(foundPods))
for _, p := range foundPods {
// If the pod is not paused or degraded, there is no need to attempt an unpause on it
if p.Status != define.PodStatePaused && p.Status != define.PodStateDegraded {
continue
}
response, err := pods.Unpause(ic.ClientCtx, p.Id, nil)
if err != nil {
report := entities.PodUnpauseReport{
Expand Down
47 changes: 41 additions & 6 deletions test/e2e/pod_pause_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ var _ = Describe("Podman pod pause", func() {
Expect(result).Should(Exit(0))
})

It("podman pod pause a running pod by id", func() {
It("pause a running pod by id", func() {
_, ec, podid := podmanTest.CreatePod(nil)
Expect(ec).To(Equal(0))

Expand All @@ -73,26 +73,32 @@ var _ = Describe("Podman pod pause", func() {

result = podmanTest.Podman([]string{"pod", "unpause", podid})
result.WaitWithDefaultTimeout()

Expect(podmanTest.NumberOfContainersRunning()).To(Equal(1))
})

It("podman unpause a running pod by id", func() {
It("unpause a paused pod by id", func() {
_, ec, podid := podmanTest.CreatePod(nil)
Expect(ec).To(Equal(0))

session := podmanTest.RunTopContainerInPod("", podid)
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(0))

result := podmanTest.Podman([]string{"pod", "unpause", podid})
result := podmanTest.Podman([]string{"pod", "pause", podid})
result.WaitWithDefaultTimeout()
Expect(result).Should(Exit(0))
Expect(result.OutputToStringArray()).Should(HaveLen(1))
Expect(podmanTest.NumberOfContainersRunning()).To(Equal(0))
Expect(podmanTest.GetContainerStatus()).To(Equal(pausedState))

result = podmanTest.Podman([]string{"pod", "unpause", podid})
result.WaitWithDefaultTimeout()
Expect(result).Should(Exit(0))
Expect(result.OutputToStringArray()).Should(HaveLen(1))
Expect(podmanTest.NumberOfContainersRunning()).To(Equal(1))
})

It("podman pod pause a running pod by name", func() {
It("unpause a paused pod by name", func() {
_, ec, _ := podmanTest.CreatePod(map[string][]string{"--name": {"test1"}})
Expect(ec).To(Equal(0))

Expand All @@ -102,13 +108,42 @@ var _ = Describe("Podman pod pause", func() {

result := podmanTest.Podman([]string{"pod", "pause", "test1"})
result.WaitWithDefaultTimeout()

Expect(result).Should(Exit(0))
Expect(result.OutputToStringArray()).Should(HaveLen(1))
Expect(podmanTest.NumberOfContainersRunning()).To(Equal(0))
Expect(podmanTest.GetContainerStatus()).To(Equal(pausedState))

result = podmanTest.Podman([]string{"pod", "unpause", "test1"})
result.WaitWithDefaultTimeout()
Expect(result).Should(Exit(0))
Expect(result.OutputToStringArray()).Should(HaveLen(1))
Expect(podmanTest.NumberOfContainersRunning()).To(Equal(1))
})

It("unpause --all", func() {
_, ec, podid1 := podmanTest.CreatePod(nil)
Expect(ec).To(Equal(0))
_, ec, podid2 := podmanTest.CreatePod(nil)
Expect(ec).To(Equal(0))

session := podmanTest.RunTopContainerInPod("", podid1)
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(0))
session = podmanTest.RunTopContainerInPod("", podid2)
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(0))

result := podmanTest.Podman([]string{"pod", "pause", podid1})
result.WaitWithDefaultTimeout()
Expect(result).Should(Exit(0))
Expect(result.OutputToStringArray()).Should(HaveLen(1))
Expect(podmanTest.NumberOfContainersRunning()).To(Equal(1))
Expect(podmanTest.GetContainerStatus()).To(ContainSubstring(pausedState))

result = podmanTest.Podman([]string{"pod", "unpause", "--all"})
result.WaitWithDefaultTimeout()
Expect(result).Should(Exit(0))
Expect(result.OutputToStringArray()).Should(HaveLen(1))
Expect(podmanTest.NumberOfContainersRunning()).To(Equal(2))
})
})

0 comments on commit cf74739

Please sign in to comment.