|
@@ -87,8 +87,18 @@ func (s *DockerSuite) TestApiNetworkStats(c *check.C) {
|
|
contIP := findContainerIP(c, id)
|
|
contIP := findContainerIP(c, id)
|
|
numPings := 10
|
|
numPings := 10
|
|
|
|
|
|
|
|
+ var preRxPackets uint64
|
|
|
|
+ var preTxPackets uint64
|
|
|
|
+ var postRxPackets uint64
|
|
|
|
+ var postTxPackets uint64
|
|
|
|
+
|
|
// Get the container networking stats before and after pinging the container
|
|
// Get the container networking stats before and after pinging the container
|
|
nwStatsPre := getNetworkStats(c, id)
|
|
nwStatsPre := getNetworkStats(c, id)
|
|
|
|
+ for _, v := range nwStatsPre {
|
|
|
|
+ preRxPackets += v.RxPackets
|
|
|
|
+ preTxPackets += v.TxPackets
|
|
|
|
+ }
|
|
|
|
+
|
|
countParam := "-c"
|
|
countParam := "-c"
|
|
if runtime.GOOS == "windows" {
|
|
if runtime.GOOS == "windows" {
|
|
countParam = "-n" // Ping count parameter is -n on Windows
|
|
countParam = "-n" // Ping count parameter is -n on Windows
|
|
@@ -97,18 +107,22 @@ func (s *DockerSuite) TestApiNetworkStats(c *check.C) {
|
|
pingouts := string(pingout[:])
|
|
pingouts := string(pingout[:])
|
|
c.Assert(err, check.IsNil)
|
|
c.Assert(err, check.IsNil)
|
|
nwStatsPost := getNetworkStats(c, id)
|
|
nwStatsPost := getNetworkStats(c, id)
|
|
|
|
+ for _, v := range nwStatsPost {
|
|
|
|
+ postRxPackets += v.RxPackets
|
|
|
|
+ postTxPackets += v.TxPackets
|
|
|
|
+ }
|
|
|
|
|
|
// Verify the stats contain at least the expected number of packets (account for ARP)
|
|
// Verify the stats contain at least the expected number of packets (account for ARP)
|
|
- expRxPkts := 1 + nwStatsPre.RxPackets + uint64(numPings)
|
|
|
|
- expTxPkts := 1 + nwStatsPre.TxPackets + uint64(numPings)
|
|
|
|
- c.Assert(nwStatsPost.TxPackets >= expTxPkts, check.Equals, true,
|
|
|
|
- check.Commentf("Reported less TxPackets than expected. Expected >= %d. Found %d. %s", expTxPkts, nwStatsPost.TxPackets, pingouts))
|
|
|
|
- c.Assert(nwStatsPost.RxPackets >= expRxPkts, check.Equals, true,
|
|
|
|
- check.Commentf("Reported less Txbytes than expected. Expected >= %d. Found %d. %s", expRxPkts, nwStatsPost.RxPackets, pingouts))
|
|
|
|
|
|
+ expRxPkts := 1 + preRxPackets + uint64(numPings)
|
|
|
|
+ expTxPkts := 1 + preTxPackets + uint64(numPings)
|
|
|
|
+ c.Assert(postTxPackets >= expTxPkts, check.Equals, true,
|
|
|
|
+ check.Commentf("Reported less TxPackets than expected. Expected >= %d. Found %d. %s", expTxPkts, postTxPackets, pingouts))
|
|
|
|
+ c.Assert(postRxPackets >= expRxPkts, check.Equals, true,
|
|
|
|
+ check.Commentf("Reported less Txbytes than expected. Expected >= %d. Found %d. %s", expRxPkts, postRxPackets, pingouts))
|
|
}
|
|
}
|
|
|
|
|
|
-func getNetworkStats(c *check.C, id string) types.NetworkStats {
|
|
|
|
- var st *types.Stats
|
|
|
|
|
|
+func getNetworkStats(c *check.C, id string) map[string]types.NetworkStats {
|
|
|
|
+ var st *types.StatsJSON
|
|
|
|
|
|
_, body, err := sockRequestRaw("GET", fmt.Sprintf("/containers/%s/stats?stream=false", id), nil, "")
|
|
_, body, err := sockRequestRaw("GET", fmt.Sprintf("/containers/%s/stats?stream=false", id), nil, "")
|
|
c.Assert(err, check.IsNil)
|
|
c.Assert(err, check.IsNil)
|
|
@@ -117,5 +131,5 @@ func getNetworkStats(c *check.C, id string) types.NetworkStats {
|
|
c.Assert(err, check.IsNil)
|
|
c.Assert(err, check.IsNil)
|
|
body.Close()
|
|
body.Close()
|
|
|
|
|
|
- return st.Network
|
|
|
|
|
|
+ return st.Networks
|
|
}
|
|
}
|