Browse code

28722: List of containers with networkID filter is not working

Signed-off-by: dattatrayakumbhar04 <dattatraya.kumbhar@gslab.com>

dattatrayakumbhar04 authored on 2016/11/23 05:02:46
Showing 2 changed files
... ...
@@ -504,7 +504,7 @@ func includeContainerInList(container *container.Container, ctx *listContext) it
504 504
 				if nw.EndpointSettings == nil {
505 505
 					continue
506 506
 				}
507
-				if nw.NetworkID == value {
507
+				if strings.HasPrefix(nw.NetworkID, value) {
508 508
 					return networkExist
509 509
 				}
510 510
 			}
... ...
@@ -877,6 +877,23 @@ func (s *DockerSuite) TestPsListContainersFilterNetwork(c *check.C) {
877 877
 	containerOut = strings.TrimSpace(string(out))
878 878
 
879 879
 	c.Assert(containerOut, checker.Contains, "onbridgenetwork")
880
+
881
+	// Filter by partial network ID
882
+	partialnwID := string(nwID[0:4])
883
+
884
+	out, _ = dockerCmd(c, "ps", "--filter", "network="+partialnwID)
885
+	containerOut = strings.TrimSpace(string(out))
886
+
887
+	lines = strings.Split(containerOut, "\n")
888
+	// skip header
889
+	lines = lines[1:]
890
+
891
+	// ps output should have only one container
892
+	c.Assert(lines, checker.HasLen, 1)
893
+
894
+	// Making sure onbridgenetwork is on the output
895
+	c.Assert(containerOut, checker.Contains, "onbridgenetwork", check.Commentf("Missing the container on network\n"))
896
+
880 897
 }
881 898
 
882 899
 func (s *DockerSuite) TestPsByOrder(c *check.C) {