Merge pull request #439 from rjnagal/docs

Handle root network device names other than eth.
This commit is contained in:
Victor Marmol 2015-01-14 14:43:42 -08:00
commit ffa108f148
3 changed files with 30 additions and 3 deletions

View File

@ -69,7 +69,6 @@ func (self *FakeSysFs) GetBlockDeviceNumbers(name string) (string, error) {
}
func (self *FakeSysFs) GetNetworkDevices() ([]os.FileInfo, error) {
self.info.EntryName = "eth0"
return []os.FileInfo{&self.info}, nil
}
@ -101,3 +100,7 @@ func (self *FakeSysFs) GetCacheInfo(cpu int, cache string) (sysfs.CacheInfo, err
func (self *FakeSysFs) SetCacheInfo(cache sysfs.CacheInfo) {
self.cache = cache
}
func (self *FakeSysFs) SetEntryName(name string) {
self.info.EntryName = name
}

View File

@ -77,8 +77,16 @@ func GetNetworkDevices(sysfs sysfs.SysFs) ([]info.NetInfo, error) {
netDevices := []info.NetInfo{}
for _, dev := range devs {
name := dev.Name()
// Only consider ethernet devices for now.
if !strings.HasPrefix(name, "eth") {
// Ignore docker, loopback, and veth devices.
ignoredDevices := []string{"lo", "veth", "docker"}
ignored := false
for _, prefix := range ignoredDevices {
if strings.HasPrefix(name, prefix) {
ignored = true
break
}
}
if ignored {
continue
}
address, err := sysfs.GetNetworkAddress(name)

View File

@ -47,6 +47,7 @@ func TestGetBlockDeviceInfo(t *testing.T) {
func TestGetNetworkDevices(t *testing.T) {
fakeSys := fakesysfs.FakeSysFs{}
fakeSys.SetEntryName("eth0")
devs, err := GetNetworkDevices(&fakeSys)
if err != nil {
t.Errorf("expected call to GetNetworkDevices() to succeed. Failed with %s", err)
@ -69,6 +70,21 @@ func TestGetNetworkDevices(t *testing.T) {
}
}
func TestIgnoredNetworkDevices(t *testing.T) {
fakeSys := fakesysfs.FakeSysFs{}
ignoredDevices := []string{"veth1234", "lo", "docker0"}
for _, name := range ignoredDevices {
fakeSys.SetEntryName(name)
devs, err := GetNetworkDevices(&fakeSys)
if err != nil {
t.Errorf("expected call to GetNetworkDevices() to succeed. Failed with %s", err)
}
if len(devs) != 0 {
t.Errorf("expected dev %s to be ignored, but got info %+v", name, devs)
}
}
}
func TestGetCacheInfo(t *testing.T) {
fakeSys := &fakesysfs.FakeSysFs{}
cacheInfo := sysfs.CacheInfo{