Skip to content

Commit

Permalink
Merge pull request #13677 from flouthoc/rename-event
Browse files Browse the repository at this point in the history
libpod, event: generate a valid event on container `rename` operation
  • Loading branch information
openshift-merge-robot authored Mar 28, 2022
2 parents e1699d8 + 82ed99b commit ffe87c0
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 0 deletions.
2 changes: 2 additions & 0 deletions libpod/events/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,8 @@ const (
Refresh Status = "refresh"
// Remove ...
Remove Status = "remove"
// Rename indicates that a container was renamed
Rename Status = "rename"
// Renumber indicates that lock numbers were reallocated at user
// request.
Renumber Status = "renumber"
Expand Down
2 changes: 2 additions & 0 deletions libpod/events/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,8 @@ func StringToStatus(name string) (Status, error) {
return Refresh, nil
case Remove.String():
return Remove, nil
case Rename.String():
return Rename, nil
case Renumber.String():
return Renumber, nil
case Restart.String():
Expand Down
1 change: 1 addition & 0 deletions libpod/runtime_ctr.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ func (r *Runtime) RenameContainer(ctx context.Context, ctr *Container, newName s
return nil, err
}

ctr.newContainerEvent(events.Rename)
return ctr, nil
}

Expand Down
17 changes: 17 additions & 0 deletions test/e2e/rename_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,23 @@ var _ = Describe("podman rename", func() {
Expect(ps.OutputToString()).To(ContainSubstring(newName))
})

It("Successfully rename a created container and test event generated", func() {
ctrName := "testCtr"
ctr := podmanTest.Podman([]string{"create", "--name", ctrName, ALPINE, "top"})
ctr.WaitWithDefaultTimeout()
Expect(ctr).Should(Exit(0))

newName := "aNewName"
rename := podmanTest.Podman([]string{"rename", ctrName, newName})
rename.WaitWithDefaultTimeout()
Expect(rename).Should(Exit(0))

result := podmanTest.Podman([]string{"events", "--stream=false", "--filter", "container=aNewName"})
result.WaitWithDefaultTimeout()
Expect(result).Should(Exit(0))
Expect(result.OutputToString()).To(ContainSubstring("rename"))
})

It("Successfully rename a running container", func() {
ctrName := "testCtr"
ctr := podmanTest.Podman([]string{"run", "-d", "--name", ctrName, ALPINE, "top"})
Expand Down

0 comments on commit ffe87c0

Please sign in to comment.