Skip to content

Commit

Permalink
Merge pull request #4394 from vrothberg/fix-start
Browse files Browse the repository at this point in the history
container start: fix regression when using name
  • Loading branch information
openshift-merge-robot authored Oct 31, 2019
2 parents 5af166f + dc3e3af commit 1e750f7
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 14 deletions.
29 changes: 17 additions & 12 deletions pkg/adapter/containers.go
Original file line number Diff line number Diff line change
Expand Up @@ -656,20 +656,25 @@ func (r *LocalRuntime) Start(ctx context.Context, c *cliconfig.StartValues, sigP

return exitCode, nil
}
if ctrRunning {
fmt.Println(ctr.ID())
continue
}
// Handle non-attach start
// If the container is in a pod, also set to recursively start dependencies
if err := ctr.Start(ctx, ctr.PodID() != ""); err != nil {
if lastError != nil {
fmt.Fprintln(os.Stderr, lastError)
// Start the container if it's not running already.
if !ctrRunning {
// Handle non-attach start
// If the container is in a pod, also set to recursively start dependencies
if err := ctr.Start(ctx, ctr.PodID() != ""); err != nil {
if lastError != nil {
fmt.Fprintln(os.Stderr, lastError)
}
lastError = errors.Wrapf(err, "unable to start container %q", container)
continue
}
lastError = errors.Wrapf(err, "unable to start container %q", container)
continue
}
fmt.Println(ctr.ID())
// Check if the container is referenced by ID or by name and print
// it accordingly.
if strings.HasPrefix(ctr.ID(), container) {
fmt.Println(ctr.ID())
} else {
fmt.Println(container)
}
}
return exitCode, lastError
}
Expand Down
21 changes: 19 additions & 2 deletions test/e2e/start_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,32 @@ var _ = Describe("Podman start", func() {
session = podmanTest.Podman([]string{"container", "start", cid})
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(0))
Expect(session.OutputToString()).To(Equal(cid))
})

It("podman container start single container by short id", func() {
session := podmanTest.Podman([]string{"container", "create", "-d", ALPINE, "ls"})
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(0))
cid := session.OutputToString()
session = podmanTest.Podman([]string{"container", "start", cid[0:10]})
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(0))
Expect(session.OutputToString()).To(Equal(cid))
})

It("podman start single container by name", func() {
session := podmanTest.Podman([]string{"create", "-d", "--name", "foobar99", ALPINE, "ls"})
name := "foobar99"
session := podmanTest.Podman([]string{"create", "-d", "--name", name, ALPINE, "ls"})
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(0))
session = podmanTest.Podman([]string{"start", "foobar99"})
session = podmanTest.Podman([]string{"start", name})
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(0))
if podmanTest.RemoteTest {
Skip("Container-start name check doesn't work on remote client. It always returns the full ID.")
}
Expect(session.OutputToString()).To(Equal(name))
})

It("podman start multiple containers", func() {
Expand Down

0 comments on commit 1e750f7

Please sign in to comment.