mirror of
https://github.com/containers/podman.git
synced 2025-06-22 09:58:10 +08:00
Add support for network ids
The network ID is not stored. It is just the sha256 hash from the network name. There is a risk of a potential hash collision. However it's very unlikely and even if we hit this it will complain that more than network with this ID exists. The main benefit is that the compat api can have proper network ID support. Also this adds the support for `podman network ls --format "{{.ID}}"` and `--filter id=<ID>`. It also ensures that we can do network rm <ID> and network inspect <ID>. Since we use a hash this commit is backwards compatible even for already existing networks. Signed-off-by: Paul Holzinger <paul.holzinger@web.de>
This commit is contained in:
@ -135,6 +135,40 @@ var _ = Describe("Podman network", func() {
|
||||
Expect(session.LineInOutputContains(name)).To(BeFalse())
|
||||
})
|
||||
|
||||
It("podman network ID test", func() {
|
||||
net := "networkIDTest"
|
||||
// the network id should be the sha256 hash of the network name
|
||||
netID := "6073aefe03cdf8f29be5b23ea9795c431868a3a22066a6290b187691614fee84"
|
||||
session := podmanTest.Podman([]string{"network", "create", net})
|
||||
session.WaitWithDefaultTimeout()
|
||||
defer podmanTest.removeCNINetwork(net)
|
||||
Expect(session.ExitCode()).To(BeZero())
|
||||
|
||||
session = podmanTest.Podman([]string{"network", "ls", "--format", "{{.Name}} {{.ID}}", "--filter", "id=" + netID})
|
||||
session.WaitWithDefaultTimeout()
|
||||
Expect(session.ExitCode()).To(BeZero())
|
||||
Expect(session.OutputToString()).To(ContainSubstring(net + " " + netID[:12]))
|
||||
|
||||
session = podmanTest.Podman([]string{"network", "ls", "--format", "{{.Name}} {{.ID}}", "--filter", "id=" + netID[10:50], "--no-trunc"})
|
||||
session.WaitWithDefaultTimeout()
|
||||
Expect(session.ExitCode()).To(BeZero())
|
||||
Expect(session.OutputToString()).To(ContainSubstring(net + " " + netID))
|
||||
|
||||
session = podmanTest.Podman([]string{"network", "inspect", netID[:40]})
|
||||
session.WaitWithDefaultTimeout()
|
||||
Expect(session.ExitCode()).To(BeZero())
|
||||
Expect(session.OutputToString()).To(ContainSubstring(net))
|
||||
|
||||
session = podmanTest.Podman([]string{"network", "inspect", netID[1:]})
|
||||
session.WaitWithDefaultTimeout()
|
||||
Expect(session.ExitCode()).ToNot(BeZero())
|
||||
Expect(session.ErrorToString()).To(ContainSubstring("no such network"))
|
||||
|
||||
session = podmanTest.Podman([]string{"network", "rm", netID})
|
||||
session.WaitWithDefaultTimeout()
|
||||
Expect(session.ExitCode()).To(BeZero())
|
||||
})
|
||||
|
||||
rm_func := func(rm string) {
|
||||
It(fmt.Sprintf("podman network %s no args", rm), func() {
|
||||
session := podmanTest.Podman([]string{"network", rm})
|
||||
|
Reference in New Issue
Block a user