Browse code

Fix flaky TestApiStatsNetworkStats test

It appears that on some systems apparmor gets in the way of libc.so.6
shared library being loaded - which means the ping fails.

To get around this if we run ping under `/lib64/ld-linux-x86-64.so.2`
then it works. So we only do this for linux and only if the first attempt
fails. If this 2nd attempt fails then we'll show the original error to
the user for debugging.

Also s/Output/CombinedOutput/ to help debugging in the future. It didn't
show the real error msg.

Signed-off-by: Doug Davis <dug@us.ibm.com>

Doug Davis authored on 2016/05/24 03:20:41
Showing 1 changed files
... ...
@@ -107,9 +107,22 @@ func (s *DockerSuite) TestApiStatsNetworkStats(c *check.C) {
107 107
 	if runtime.GOOS == "windows" {
108 108
 		countParam = "-n" // Ping count parameter is -n on Windows
109 109
 	}
110
-	pingout, err := exec.Command("ping", contIP, countParam, strconv.Itoa(numPings)).Output()
111
-	pingouts := string(pingout[:])
110
+	pingout, err := exec.Command("ping", contIP, countParam, strconv.Itoa(numPings)).CombinedOutput()
111
+	if err != nil && runtime.GOOS == "linux" {
112
+		// If it fails then try a work-around, but just for linux.
113
+		// If this fails too then go back to the old error for reporting.
114
+		//
115
+		// The ping will sometimes fail due to an apparmor issue where it
116
+		// denies access to the libc.so.6 shared library - running it
117
+		// via /lib64/ld-linux-x86-64.so.2 seems to work around it.
118
+		pingout2, err2 := exec.Command("/lib64/ld-linux-x86-64.so.2", "/bin/ping", contIP, "-c", strconv.Itoa(numPings)).CombinedOutput()
119
+		if err2 == nil {
120
+			pingout = pingout2
121
+			err = err2
122
+		}
123
+	}
112 124
 	c.Assert(err, checker.IsNil)
125
+	pingouts := string(pingout[:])
113 126
 	nwStatsPost := getNetworkStats(c, id)
114 127
 	for _, v := range nwStatsPost {
115 128
 		postRxPackets += v.RxPackets