From 94d057130461b3b56957b2755da9dae00a937e81 Mon Sep 17 00:00:00 2001 From: Doug Davis Date: Mon, 23 May 2016 11:20:41 -0700 Subject: [PATCH] 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 --- integration-cli/docker_api_stats_test.go | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/integration-cli/docker_api_stats_test.go b/integration-cli/docker_api_stats_test.go index c4a72597bf..18fb7d1102 100644 --- a/integration-cli/docker_api_stats_test.go +++ b/integration-cli/docker_api_stats_test.go @@ -107,9 +107,22 @@ func (s *DockerSuite) TestApiStatsNetworkStats(c *check.C) { if runtime.GOOS == "windows" { countParam = "-n" // Ping count parameter is -n on Windows } - pingout, err := exec.Command("ping", contIP, countParam, strconv.Itoa(numPings)).Output() - pingouts := string(pingout[:]) + pingout, err := exec.Command("ping", contIP, countParam, strconv.Itoa(numPings)).CombinedOutput() + if err != nil && runtime.GOOS == "linux" { + // If it fails then try a work-around, but just for linux. + // If this fails too then go back to the old error for reporting. + // + // The ping will sometimes fail due to an apparmor issue where it + // denies access to the libc.so.6 shared library - running it + // via /lib64/ld-linux-x86-64.so.2 seems to work around it. + pingout2, err2 := exec.Command("/lib64/ld-linux-x86-64.so.2", "/bin/ping", contIP, "-c", strconv.Itoa(numPings)).CombinedOutput() + if err2 == nil { + pingout = pingout2 + err = err2 + } + } c.Assert(err, checker.IsNil) + pingouts := string(pingout[:]) nwStatsPost := getNetworkStats(c, id) for _, v := range nwStatsPost { postRxPackets += v.RxPackets