mirror of
https://github.com/opencontainers/runc.git
synced 2026-07-11 06:03:57 +08:00
Ignore stats that are not available
Closes #13 Docker-DCO-1.1-Signed-off-by: Victor Marmol <vmarmol@google.com> (github: vmarmol)
This commit is contained in:
@@ -7,6 +7,7 @@ import (
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"strings"
|
||||
"syscall"
|
||||
|
||||
"github.com/docker/libcontainer/cgroups"
|
||||
)
|
||||
@@ -65,6 +66,9 @@ func getBlkioStat(path string) ([]cgroups.BlkioStatEntry, error) {
|
||||
var blkioStats []cgroups.BlkioStatEntry
|
||||
f, err := os.Open(path)
|
||||
if err != nil {
|
||||
if pathErr, ok := err.(*os.PathError); ok && pathErr.Err == syscall.ENOENT {
|
||||
return blkioStats, nil
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
@@ -86,8 +86,8 @@ func TestBlkioStatsNoSectorsFile(t *testing.T) {
|
||||
|
||||
blkio := &blkioGroup{}
|
||||
err := blkio.GetStats(helper.CgroupData, &actualStats)
|
||||
if err == nil {
|
||||
t.Fatal("Expected to fail, but did not")
|
||||
if err != nil {
|
||||
t.Fatalf("Failed unexpectedly: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -102,8 +102,8 @@ func TestBlkioStatsNoServiceBytesFile(t *testing.T) {
|
||||
|
||||
blkio := &blkioGroup{}
|
||||
err := blkio.GetStats(helper.CgroupData, &actualStats)
|
||||
if err == nil {
|
||||
t.Fatal("Expected to fail, but did not")
|
||||
if err != nil {
|
||||
t.Fatalf("Failed unexpectedly: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -118,8 +118,8 @@ func TestBlkioStatsNoServicedFile(t *testing.T) {
|
||||
|
||||
blkio := &blkioGroup{}
|
||||
err := blkio.GetStats(helper.CgroupData, &actualStats)
|
||||
if err == nil {
|
||||
t.Fatal("Expected to fail, but did not")
|
||||
if err != nil {
|
||||
t.Fatalf("Failed unexpectedly: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -134,8 +134,8 @@ func TestBlkioStatsNoQueuedFile(t *testing.T) {
|
||||
|
||||
blkio := &blkioGroup{}
|
||||
err := blkio.GetStats(helper.CgroupData, &actualStats)
|
||||
if err == nil {
|
||||
t.Fatal("Expected to fail, but did not")
|
||||
if err != nil {
|
||||
t.Fatalf("Failed unexpectedly: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"syscall"
|
||||
|
||||
"github.com/docker/libcontainer/cgroups"
|
||||
)
|
||||
@@ -60,6 +61,9 @@ func (s *memoryGroup) GetStats(d *data, stats *cgroups.Stats) error {
|
||||
// Set stats from memory.stat.
|
||||
statsFile, err := os.Open(filepath.Join(path, "memory.stat"))
|
||||
if err != nil {
|
||||
if pathErr, ok := err.(*os.PathError); ok && pathErr.Err == syscall.ENOENT {
|
||||
return nil
|
||||
}
|
||||
return err
|
||||
}
|
||||
defer statsFile.Close()
|
||||
|
||||
@@ -43,8 +43,8 @@ func TestMemoryStatsNoStatFile(t *testing.T) {
|
||||
|
||||
memory := &memoryGroup{}
|
||||
err := memory.GetStats(helper.CgroupData, &actualStats)
|
||||
if err == nil {
|
||||
t.Fatal("Expected failure")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user