Spec consistency

This commit is contained in:
Abin Shahab 2014-10-15 07:58:58 +00:00
parent 9264114895
commit f170df0a76
3 changed files with 21 additions and 10 deletions

View File

@ -22,6 +22,7 @@ import (
"flag"
"encoding/json"
"io/ioutil"
"os"
)
var argContainerHints = flag.String("container_hints", "/etc/cadvisor/container_hints.json", "container hints file")
type containerHints struct {
@ -36,12 +37,13 @@ type containerHint struct {
type networkInterface struct {
VethHost string `json:"veth_host,omitempty"`
VethChild string `json:"veth_child,omitempty"`
NsPath string `json:"ns_path,omitempty"`
}
func getContainerHintsFromFile(containerHintsFile string) (containerHints, error) {
dat, err := ioutil.ReadFile(containerHintsFile)
if os.IsNotExist(err) {
return containerHints{}, nil
}
var cHints containerHints
if err == nil {
err = json.Unmarshal(dat, &cHints)

View File

@ -4,7 +4,7 @@ import (
"testing"
)
func TestUnmarshal(t *testing.T) {
func TestGetContainerHintsFromFile(t *testing.T) {
cHints, err := getContainerHintsFromFile("test_resources/container_hints.json")
if err != nil {
@ -16,3 +16,10 @@ func TestUnmarshal(t *testing.T) {
t.Errorf("Cannot find network interface in %s", cHints)
}
}
func TestFileNotExist(t *testing.T) {
_, err := getContainerHintsFromFile("/file_does_not_exist.json")
if err != nil {
t.Fatalf("getContainerHintsFromFile must not error for blank file: %s", err)
}
}

View File

@ -167,25 +167,27 @@ func (self *rawContainerHandler) GetSpec() (info.ContainerSpec, error) {
if self.name == "/" {
spec.HasFilesystem = true
}
//Network
if self.networkInterface != nil {
spec.HasNetwork = true
}
return spec, nil
}
func (self *rawContainerHandler) GetStats() (*info.ContainerStats, error) {
var stats *info.ContainerStats
var err error
state := dockerlibcontainer.State{}
if self.networkInterface != nil {
state := dockerlibcontainer.State{
state = dockerlibcontainer.State{
NetworkState: network.NetworkState{
VethHost: self.networkInterface.VethHost,
VethChild: self.networkInterface.VethChild,
NsPath: "unknown",
},
}
stats, err = libcontainer.GetStats(self.cgroup, &state)
} else {
stats, err = libcontainer.GetStatsCgroupOnly(self.cgroup)
}
stats, err := libcontainer.GetStats(self.cgroup, &state)
if err != nil {
return nil, err
}