Esempio n. 1
0
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
Esempio n. 2
0
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
Esempio n. 3
0
    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)
Esempio n. 4
0
 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)
Esempio n. 5
0
 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)
Esempio n. 6
0
    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)
Esempio n. 7
0
 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)
Esempio n. 8
0
 def testSpeedInvalidNic(self):
     nicName = '0' * 20  # devices can't have so long names
     self.assertEqual(netinfo.nicSpeed(nicName), 0)
Esempio n. 9
0
 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)
Esempio n. 10
0
 def testSpeedInvalidNic(self):
     nicName = '0' * 20  # devices can't have so long names
     self.assertEqual(netinfo.nicSpeed(nicName), 0)