Example #1
0
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
Example #2
0
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
Example #3
0
    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)
Example #4
0
    def testValidNicSpeed(self, mock_io_open, mock_operstate):
        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:
            mock_io_open.return_value = io.BytesIO(str(passed))
            mock_operstate.return_value = operstate

            self.assertEqual(nics.speed('fake_nic'), expected)
Example #5
0
    def test_valid_nic_speed(self, mock_io_open, mock_operstate):
        values = ((b'0', nics.OPERSTATE_UP, 0), (b'-10', nics.OPERSTATE_UP, 0),
                  (six.b(str(2**16 - 1)), nics.OPERSTATE_UP,
                   0), (six.b(str(2**32 - 1)), nics.OPERSTATE_UP,
                        0), (b'123', nics.OPERSTATE_UP, 123),
                  (b'', nics.OPERSTATE_UP, 0), (b'', 'unknown',
                                                0), (b'123', 'unknown', 0))

        for passed, operstate, expected in values:
            mock_io_open.return_value = io.BytesIO(passed)
            mock_operstate.return_value = operstate

            self.assertEqual(nics.speed('fake_nic'), expected)
Example #6
0
    def test_valid_nic_speed(self, mock_io_open, mock_operstate):
        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:
            mock_io_open.return_value = io.BytesIO(str(passed))
            mock_operstate.return_value = operstate

            self.assertEqual(nics.speed('fake_nic'), expected)
Example #7
0
    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)
Example #8
0
 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)
Example #9
0
 def testSpeedInvalidNic(self):
     nicName = '0' * 20  # devices can't have so long names
     self.assertEqual(nics.speed(nicName), 0)
Example #10
0
 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)
Example #11
0
 def testSpeedInvalidNic(self):
     nicName = '0' * 20  # devices can't have so long names
     self.assertEqual(nics.speed(nicName), 0)
Example #12
0
 def test_dpdk_device_speed(self):
     self.assertEqual(nics.speed('dpdk0'), 0)
Example #13
0
 def test_dpdk_device_speed(self):
     self.assertEqual(nics.speed('dpdk0'), 0)