def _getLinkSpeed(dev): if dev.isNIC(): speed = netinfo.nicSpeed(dev.name) elif dev.isBOND(): speed = netinfo.bondSpeed(dev.name) elif dev.isVLAN(): speed = netinfo.vlanSpeed(dev.name) else: speed = 0 return speed
def testValidNicSpeed(self): values = ((0, OPERSTATE_UP, 0), (-10, OPERSTATE_UP, 0), (2**16 - 1, OPERSTATE_UP, 0), (2**32 - 1, OPERSTATE_UP, 0), (123, OPERSTATE_UP, 123), ('', OPERSTATE_UP, 0), ('', 'unknown', 0), (123, 'unknown', 0)) for passed, operstate, expected in values: with MonkeyPatchScope([ (__builtin__, 'open', lambda x: io.BytesIO(str(passed))), (netinfo, 'operstate', lambda x: operstate) ]): self.assertEqual(netinfo.nicSpeed('fake_nic'), expected)
def _updateIfidsIfrates(self): devices = getLinks() self._ifids = [dev.name for dev in devices] self._ifrates = [] for dev in devices: if dev.isNIC(): speed = netinfo.nicSpeed(dev.name) elif dev.isBOND(): speed = netinfo.bondSpeed(dev.name) else: speed = 0 self._ifrates.append(speed)
def _updateIfidsIfrates(self): devices = getLinks() self._ifids = [dev.name for dev in devices] self._ifrates = [] for dev in devices: if dev.isNIC(): speed = netinfo.nicSpeed(dev.name) elif dev.isBOND(): speed = netinfo.bondSpeed(dev.name) elif dev.isVLAN(): speed = netinfo.vlanSpeed(dev.name) else: speed = 0 self._ifrates.append(speed)
def testValidNicSpeed(self): values = ((0, OPERSTATE_UP, 0), (-10, OPERSTATE_UP, 0), (2 ** 16 - 1, OPERSTATE_UP, 0), (2 ** 32 - 1, OPERSTATE_UP, 0), (123, OPERSTATE_UP, 123), ('', OPERSTATE_UP, 0), ('', 'unknown', 0), (123, 'unknown', 0)) for passed, operstate, expected in values: with MonkeyPatchScope([(__builtin__, 'open', lambda x: io.BytesIO(str(passed))), (netinfo, 'operstate', lambda x: operstate)]): self.assertEqual(netinfo.nicSpeed('fake_nic'), expected)
def testSpeedInRange(self): for d in netinfo.nics(): s = netinfo.nicSpeed(d) self.assertFalse(s < 0) self.assertTrue(s in ETHTOOL_SPEEDS or s == 0)
def testSpeedInvalidNic(self): nicName = '0' * 20 # devices can't have so long names self.assertEqual(netinfo.nicSpeed(nicName), 0)