Skip to content

Commit

Permalink
Merge pull request #7272 from vrothberg/issue-7271
Browse files Browse the repository at this point in the history
generate systemd: fix error handling
  • Loading branch information
openshift-merge-robot authored Aug 10, 2020
2 parents 162625f + 6865058 commit 5ba2184
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
5 changes: 3 additions & 2 deletions pkg/domain/infra/abi/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ func (ic *ContainerEngine) GenerateSystemd(ctx context.Context, nameOrID string,
if ctrErr == nil {
// Generate the unit for the container.
s, err := generate.ContainerUnit(ctr, options)
if err == nil {
return &entities.GenerateSystemdReport{Output: s}, nil
if err != nil {
return nil, err
}
return &entities.GenerateSystemdReport{Output: s}, nil
}

// If it's not a container, we either have a pod or garbage.
Expand Down
12 changes: 12 additions & 0 deletions test/e2e/generate_systemd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,18 @@ var _ = Describe("Podman generate systemd", func() {
Expect(session).To(ExitWithError())
})

It("podman generate systemd bad restart-policy value", func() {
session := podmanTest.Podman([]string{"create", "--name", "foobar", "alpine", "top"})
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(0))

session = podmanTest.Podman([]string{"generate", "systemd", "--restart-policy", "bogus", "foobar"})
session.WaitWithDefaultTimeout()
Expect(session).To(ExitWithError())
found, _ := session.ErrorGrepString("Error: bogus is not a valid restart policy")
Expect(found).Should(BeTrue())
})

It("podman generate systemd good timeout value", func() {
session := podmanTest.Podman([]string{"create", "--name", "foobar", "alpine", "top"})
session.WaitWithDefaultTimeout()
Expand Down

0 comments on commit 5ba2184

Please sign in to comment.