mirror of https://github.com/containers/podman.git
Merge pull request #3750 from baude/portreporting
fix port early return
This commit is contained in:
commit
09cedd152d
|
@ -48,8 +48,8 @@ func init() {
|
||||||
|
|
||||||
func portCmd(c *cliconfig.PortValues) error {
|
func portCmd(c *cliconfig.PortValues) error {
|
||||||
var (
|
var (
|
||||||
userProto, containerName string
|
userProto string
|
||||||
userPort int
|
userPort int
|
||||||
)
|
)
|
||||||
args := c.InputArgs
|
args := c.InputArgs
|
||||||
|
|
||||||
|
@ -106,6 +106,7 @@ func portCmd(c *cliconfig.PortValues) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
var found bool
|
||||||
// Iterate mappings
|
// Iterate mappings
|
||||||
for _, v := range portmappings {
|
for _, v := range portmappings {
|
||||||
hostIP := v.HostIP
|
hostIP := v.HostIP
|
||||||
|
@ -125,12 +126,14 @@ func portCmd(c *cliconfig.PortValues) error {
|
||||||
if v.ContainerPort == int32(userPort) {
|
if v.ContainerPort == int32(userPort) {
|
||||||
if userProto == "" || userProto == v.Protocol {
|
if userProto == "" || userProto == v.Protocol {
|
||||||
fmt.Printf("%s:%d\n", hostIP, v.HostPort)
|
fmt.Printf("%s:%d\n", hostIP, v.HostPort)
|
||||||
|
found = true
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
return errors.Errorf("No public port '%d' published for %s", userPort, containerName)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if !found && port != "" {
|
||||||
|
return errors.Errorf("failed to find published port '%d'", userPort)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|
|
@ -105,4 +105,42 @@ var _ = Describe("Podman port", func() {
|
||||||
result.WaitWithDefaultTimeout()
|
result.WaitWithDefaultTimeout()
|
||||||
Expect(result.ExitCode()).To(Equal(0))
|
Expect(result.ExitCode()).To(Equal(0))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
It("podman port nginx by name", func() {
|
||||||
|
session, cid := podmanTest.RunNginxWithHealthCheck("portcheck")
|
||||||
|
Expect(session.ExitCode()).To(Equal(0))
|
||||||
|
|
||||||
|
if err := podmanTest.RunHealthCheck(cid); err != nil {
|
||||||
|
Fail(err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
result := podmanTest.Podman([]string{"port", "portcheck"})
|
||||||
|
result.WaitWithDefaultTimeout()
|
||||||
|
Expect(result.ExitCode()).To(Equal(0))
|
||||||
|
result.LineInOuputStartsWith("80/tcp -> 0.0.0.0:")
|
||||||
|
})
|
||||||
|
|
||||||
|
It("podman port multiple ports", func() {
|
||||||
|
// Acquire and release locks
|
||||||
|
lock1 := GetPortLock("5000")
|
||||||
|
defer lock1.Unlock()
|
||||||
|
lock2 := GetPortLock("5001")
|
||||||
|
defer lock2.Unlock()
|
||||||
|
|
||||||
|
setup := podmanTest.Podman([]string{"run", "-dt", "-p", "5000:5000", "-p", "5001:5001", ALPINE, "top"})
|
||||||
|
setup.WaitWithDefaultTimeout()
|
||||||
|
Expect(setup.ExitCode()).To(BeZero())
|
||||||
|
|
||||||
|
// Check that the first port was honored
|
||||||
|
result1 := podmanTest.Podman([]string{"port", "-l", "5000"})
|
||||||
|
result1.WaitWithDefaultTimeout()
|
||||||
|
Expect(result1.ExitCode()).To(BeZero())
|
||||||
|
Expect(result1.LineInOuputStartsWith("0.0.0.0:5000"))
|
||||||
|
|
||||||
|
// Check that the second port was honored
|
||||||
|
result2 := podmanTest.Podman([]string{"port", "-l", "5001"})
|
||||||
|
result2.WaitWithDefaultTimeout()
|
||||||
|
Expect(result2.ExitCode()).To(BeZero())
|
||||||
|
Expect(result2.LineInOuputStartsWith("0.0.0.0:5001"))
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue