Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

libpod, event: generate a valid event on container rename operation #13677

Merged
merged 1 commit into from
Mar 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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