def _getLinkSpeed(dev): if dev.isNIC(): speed = nics.speed(dev.name) elif dev.isBOND(): speed = bonding.speed(dev.name) elif dev.isVLAN(): speed = vlans.speed(dev.name) else: speed = 0 return speed
def testValidNicSpeed(self): values = ((0, nics.OPERSTATE_UP, 0), (-10, nics.OPERSTATE_UP, 0), (2**16 - 1, nics.OPERSTATE_UP, 0), (2**32 - 1, nics.OPERSTATE_UP, 0), (123, nics.OPERSTATE_UP, 123), ('', nics.OPERSTATE_UP, 0), ('', 'unknown', 0), (123, 'unknown', 0)) for passed, operstate, expected in values: with MonkeyPatchScope([(__builtin__, 'open', lambda x: io.BytesIO(str(passed))), (nics, 'operstate', lambda x: operstate)]): self.assertEqual(nics.speed('fake_nic'), expected)
def testValidNicSpeed(self): values = ((0, nics.OPERSTATE_UP, 0), (-10, nics.OPERSTATE_UP, 0), (2 ** 16 - 1, nics.OPERSTATE_UP, 0), (2 ** 32 - 1, nics.OPERSTATE_UP, 0), (123, nics.OPERSTATE_UP, 123), ('', nics.OPERSTATE_UP, 0), ('', 'unknown', 0), (123, 'unknown', 0)) for passed, operstate, expected in values: with MonkeyPatchScope([(io, 'open', lambda x: io.BytesIO(str(passed))), (nics, 'operstate', lambda x: operstate)]): self.assertEqual(nics.speed('fake_nic'), expected)
def testSpeedInRange(self): for d in nics.nics(): s = nics.speed(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(nics.speed(nicName), 0)