コード例 #1
0
ファイル: models.py プロジェクト: nirs/vdsm
    def objectivize(cls, name, configurator, options, nics, mtu, _netinfo,
                    hwaddr, on_removal_just_detach_from_network=False):

        if nics:  # New bonding or edit bonding.
            slaves = cls._objectivizeSlaves(name, configurator, _nicSort(nics),
                                            mtu, _netinfo)
            if name in _netinfo.bondings:
                if _netinfo.ifaceUsers(name):
                    mtu = max(mtu or 0, link_iface.iface(name).mtu())

                if not options:
                    options = _netinfo.bondings[name].get('opts')
                    options = Bond._dict2list(options)
        elif name in _netinfo.bondings:  # Implicit bonding.
            if _netinfo.ifaceUsers(name):
                mtu = max(mtu or 0, link_iface.iface(name).mtu())

            slaves = [Nic(nic, configurator, mtu=mtu, _netinfo=_netinfo)
                      for nic in _netinfo.getNicsForBonding(name)]
            options = _netinfo.bondings[name].get('opts')
            options = Bond._dict2list(options)
        else:
            raise ConfigNetworkError(ne.ERR_BAD_PARAMS,
                                     'Missing required nics on a bonding %s '
                                     'that is unknown to Vdsm ' % name)

        detach = on_removal_just_detach_from_network  # argument is too long
        return cls(name, configurator, slaves=slaves, options=options, mtu=mtu,
                   hwaddr=hwaddr, on_removal_just_detach_from_network=detach)
コード例 #2
0
ファイル: net_with_bond_test.py プロジェクト: emesika/vdsm
    def test_add_net_on_existing_external_bond_preserving_mac(
            self, adapter, switch, nic0, nic1):
        if switch == 'ovs':
            pytest.xfail('Preserving bond mac is not supported on OVS switch.')
        HWADDRESS = 'ce:0c:46:59:c9:d1'
        with Bond(BOND_NAME, slaves=(nic0, nic1)) as bond:
            bond.create()
            iface(BOND_NAME).set_address(HWADDRESS)

            NETBASE = {
                NETWORK1_NAME: {
                    'bonding': BOND_NAME,
                    'bridged': False,
                    'switch': switch,
                }
            }
            with adapter.setupNetworks(NETBASE, {}, NOCHK):
                adapter.assertNetwork(NETWORK1_NAME, NETBASE[NETWORK1_NAME])
                adapter.assertBond(
                    BOND_NAME,
                    {
                        'nics': [nic0, nic1],
                        'hwaddr': HWADDRESS,
                        'switch': switch,
                    },
                )
        adapter.setupNetworks({}, {BOND_NAME: {'remove': True}}, NOCHK)
コード例 #3
0
    def objectivize(cls, name, configurator, options, nics, mtu, _netinfo,
                    hwaddr, on_removal_just_detach_from_network=False):

        if nics:  # New bonding or edit bonding.
            slaves = cls._objectivizeSlaves(name, configurator, _nicSort(nics),
                                            mtu, _netinfo)
            if name in _netinfo.bondings:
                if _netinfo.ifaceUsers(name):
                    mtu = max(mtu, link_iface.iface(name).mtu())

                if not options:
                    options = _netinfo.bondings[name].get('opts')
                    options = Bond._dict2list(options)
        elif name in _netinfo.bondings:  # Implicit bonding.
            if _netinfo.ifaceUsers(name):
                mtu = max(mtu, link_iface.iface(name).mtu())

            slaves = [Nic(nic, configurator, mtu=mtu, _netinfo=_netinfo)
                      for nic in _netinfo.getNicsForBonding(name)]
            options = _netinfo.bondings[name].get('opts')
            options = Bond._dict2list(options)
        else:
            raise ConfigNetworkError(ne.ERR_BAD_PARAMS,
                                     'Missing required nics on a bonding %s '
                                     'that is unknown to Vdsm ' % name)

        detach = on_removal_just_detach_from_network  # argument is too long
        return cls(name, configurator, slaves=slaves, options=options, mtu=mtu,
                   hwaddr=hwaddr, on_removal_just_detach_from_network=detach)
コード例 #4
0
ファイル: net_basic_test.py プロジェクト: chaodongqu/vdsm
    def test_add_net_based_on_existing_vlan_bond_nm_setup(self):
        vlan_id = '101'
        NET = {
            NETWORK_NAME: {
                'bonding': self.iface,
                'vlan': int(vlan_id),
                'switch': self.switch,
            }
        }
        with dummy_devices(1) as nics:
            with nmnettestlib.nm_connections(self.iface,
                                             ipv4addr=None,
                                             vlan=vlan_id,
                                             slaves=nics):
                bond_hwaddress = link_iface.iface(self.iface).address()
                vlan_iface = '.'.join([self.iface, vlan_id])
                vlan_hwaddress = link_iface.iface(vlan_iface).address()
                assert vlan_hwaddress == bond_hwaddress

                with adapter.setupNetworks(NET, {}, NOCHK):
                    adapter.assertNetwork(NETWORK_NAME, NET[NETWORK_NAME])

                    # Check if the mac has been preserved.
                    bridge_hwaddress = link_iface.iface(NETWORK_NAME).address()
                    assert vlan_hwaddress == bridge_hwaddress
コード例 #5
0
ファイル: link_bond_test.py プロジェクト: nirs/vdsm
 def test_bond_devices_are_up(self):
     with dummy_devices(2) as (nic1, nic2):
         with bond_device() as bond:
             bond.add_slaves((nic1, nic2))
             bond.up()
             self.assertTrue(iface(nic1).is_up())
             self.assertTrue(iface(nic2).is_up())
             self.assertTrue(iface(bond.master).is_up())
コード例 #6
0
def dummy_device(prefix='dummy_', max_length=11):
    dummy_interface = Dummy(prefix, max_length)
    dummy_name = dummy_interface.create()
    try:
        linkiface.iface(dummy_name).up()
        yield dummy_name
    finally:
        dummy_interface.remove()
コード例 #7
0
ファイル: nettestlib.py プロジェクト: oVirt/vdsm
def dummy_device(prefix='dummy_', max_length=11):
    dummy_interface = Dummy(prefix, max_length)
    dummy_name = dummy_interface.create()
    try:
        linkiface.iface(dummy_name).up()
        yield dummy_name
    finally:
        dummy_interface.remove()
コード例 #8
0
ファイル: link_bond_test.py プロジェクト: xin49/vdsm
 def test_bond_devices_are_up(self):
     with dummy_devices(2) as (nic1, nic2):
         with bond_device() as bond:
             bond.add_slaves((nic1, nic2))
             bond.up()
             self.assertTrue(iface(nic1).is_up())
             self.assertTrue(iface(nic2).is_up())
             self.assertTrue(iface(bond.master).is_up())
コード例 #9
0
ファイル: bridge_test.py プロジェクト: oVirt/vdsm
def _create_tap():
    devname = '_tap99'
    rc, _, err = exec_sync(['ip', 'tuntap', 'add', devname, 'mode', 'tap'])
    if rc != 0:
        pytest.fail('Unable to create tap device. err: {}'.format(err))
    try:
        iface(devname).up()
        yield devname
    finally:
        exec_sync(['ip', 'tuntap', 'del', devname, 'mode', 'tap'])
コード例 #10
0
ファイル: bridge_test.py プロジェクト: kumarchandan786/vdsm
def _create_tap():
    devname = '_tap99'
    rc, _, err = exec_sync(['ip', 'tuntap', 'add', devname, 'mode', 'tap'])
    if rc != 0:
        pytest.fail('Unable to create tap device. err: {}'.format(err))
    try:
        iface(devname).up()
        yield devname
    finally:
        exec_sync(['ip', 'tuntap', 'del', devname, 'mode', 'tap'])
コード例 #11
0
ファイル: __init__.py プロジェクト: nirs/vdsm
 def _setlinks(self, up):
     master = iface(self._master)
     if up:
         master.up()
     else:
         master.down()
     for s in self._slaves:
         slave = iface(s)
         if up:
             slave.up()
         else:
             slave.down()
コード例 #12
0
 def _setlinks(self, up):
     master = iface(self._master)
     if up:
         master.up()
     else:
         master.down()
     for s in self._slaves:
         slave = iface(s)
         if up:
             slave.up()
         else:
             slave.down()
コード例 #13
0
ファイル: api.py プロジェクト: oVirt/vdsm
def change_numvfs(pci_path, numvfs, devname):
    """Change number of virtual functions of a device.

    The persistence is stored in the same place as other network persistence is
    stored. A call to setSafeNetworkConfig() will persist it across reboots.
    """
    logging.info('Changing number of vfs on device %s -> %s.',
                 pci_path, numvfs)
    sriov.update_numvfs(pci_path, numvfs)
    sriov.persist_numvfs(devname, numvfs)

    link_iface.iface(devname).up()
コード例 #14
0
ファイル: api.py プロジェクト: vjuranek/vdsm
def change_numvfs(pci_path, numvfs, devname):
    """Change number of virtual functions of a device.

    The persistence is stored in the same place as other network persistence is
    stored. A call to setSafeNetworkConfig() will persist it across reboots.
    """
    logging.info('Changing number of vfs on device %s -> %s.', pci_path,
                 numvfs)
    sriov.update_numvfs(pci_path, numvfs)
    sriov.persist_numvfs(devname, numvfs)

    link_iface.iface(devname).up()
コード例 #15
0
    def _ifup_vlan_with_slave_bond_hwaddr_sync(vlan):
        """
        When NM is active and the network includes a vlan on top of a bond, the
        following scenario may occur:
        - VLAN over a bond with slaves is already defined in the system and
          VDSM is about to acquire it to define on it a network.
        - The VLAN iface is re-created while the bond slaves are temporary
          detached, causing the vlan to be created with the bond temporary
          mac address, which is different from the original existing address.
        Therefore, following the VLAN ifup command, its mac address is compared
        with the first bond slave. In case they differ, the vlan device is
        recreated.
        Bond mode 5 & 6 is excluded from the mac sync check.
        """
        bond = vlan.device
        bond_mode = Ifcfg._get_bond_mode(bond)
        if not bond.slaves or bond_mode == '5' or bond_mode == '6':
            _ifup(vlan)
            return

        blocking = _blocking_action_required(vlan)
        for attempt in range(5):
            if blocking:
                _ifup(vlan, blocking=blocking)
            else:
                with waitfor.waitfor_link_exists(vlan.name):
                    _ifup(vlan, blocking=blocking)

            vlan_hwaddr = link_iface.iface(vlan.name).address()
            slaves_hwaddr = [
                link_iface.iface(slave.name).address() for slave in bond.slaves
            ]
            if slaves_hwaddr[0] == vlan_hwaddr:
                return

            bond_hwaddr = link_iface.iface(bond.name).address()
            logging.info(
                '%s. vlan@bond hwaddr is not in sync (v/b/[s]): %s/%s/%s',
                attempt,
                vlan_hwaddr,
                bond_hwaddr,
                slaves_hwaddr,
            )

            ifdown(vlan.name)

        raise ConfigNetworkError(
            ERR_BAD_BONDING,
            'While adding vlan {} over bond {}, '
            'the bond hwaddr was not in sync '
            'whith its slaves.'.format(vlan.name, vlan.device.name),
        )
コード例 #16
0
ファイル: vlan.py プロジェクト: nirs/vdsm
def speed(dev_name):
    """Return the vlan's underlying device speed."""
    dev_speed = 0
    dev_vlan = iface.iface(dev_name)
    dev_base_name = dev_vlan.properties()['device']
    dev_base = iface.iface(dev_base_name)
    dev_base_type = dev_base.type()
    if dev_base_type == iface.Type.NIC:
        dev_speed = nic.speed(dev_name)
    elif dev_base_type == iface.Type.BOND:
        dev_speed = bond.speed(dev_base_name)

    return dev_speed
コード例 #17
0
ファイル: netfunctestlib.py プロジェクト: vjuranek/vdsm
 def assertLinksUp(self, net, attrs, check_oper_state=True):
     switch = attrs.get('switch', 'legacy')
     if switch == 'legacy':
         expected_links = _gather_expected_legacy_links(
             net, attrs, self.netinfo)
     elif switch == 'ovs':
         expected_links = _gather_expected_ovs_links(
             net, attrs, self.netinfo)
     if expected_links:
         for dev in expected_links:
             check_is_up = (iface(dev).is_oper_up
                            if check_oper_state else iface(dev).is_admin_up)
             assert check_is_up(), 'Dev {} is DOWN'.format(dev)
コード例 #18
0
ファイル: vlan.py プロジェクト: guozhonghua216/vdsm
def speed(dev_name):
    """Return the vlan's underlying device speed."""
    dev_speed = 0
    dev_vlan = iface.iface(dev_name)
    dev_base_name = dev_vlan.properties()['device']
    dev_base = iface.iface(dev_base_name)
    dev_base_type = dev_base.type()
    if dev_base_type == iface.Type.NIC:
        dev_speed = nic.speed(dev_name)
    elif dev_base_type == iface.Type.BOND:
        dev_speed = bond.speed(dev_base_name)

    return dev_speed
コード例 #19
0
ファイル: api.py プロジェクト: asasuou/vdsm
def change_numvfs(pci_path, numvfs, net_name):
    """Change number of virtual functions of a device.

    The persistence is stored in the same place as other network persistence is
    stored. A call to setSafeNetworkConfig() will persist it across reboots.
    """
    # TODO: net_name is here only because it is hard to call pf_to_net_name
    # TODO: from here. once all our code will be under lib/vdsm this should be
    # TODO: removed.
    logging.info('Changing number of vfs on device %s -> %s.', pci_path,
                 numvfs)
    sriov.update_numvfs(pci_path, numvfs)
    sriov.persist_numvfs(pci_path, numvfs)

    link_iface.iface(net_name).up()
コード例 #20
0
ファイル: link_iface_test.py プロジェクト: nirs/vdsm
    def test_iface_hwaddr(self):
        MAC_ADDR = '02:00:00:00:00:01'

        with dummy_device() as nic:
            _iface = iface(nic)
            _iface.set_address(MAC_ADDR)
            self.assertEqual(MAC_ADDR, _iface.address())
コード例 #21
0
def _getNetInfo(iface, bridged, routes, ipaddrs):
    """Returns a dictionary of properties about the network's interface status.
    Raises a NetworkIsMissing if the iface does not exist."""
    data = {}
    try:
        if bridged:
            data.update({'ports': bridges.ports(iface),
                         'stp': bridges.stp_state(iface)})
        else:
            # ovirt-engine-3.1 expects to see the "interface" attribute iff the
            # network is bridgeless. Please remove the attribute and this
            # comment when the version is no longer supported.
            data['interface'] = iface

        gateway = get_gateway(routes, iface)
        ipv4addr, ipv4netmask, ipv4addrs, ipv6addrs = getIpInfo(
            iface, ipaddrs, gateway)

        data.update({'iface': iface, 'bridged': bridged,
                     'addr': ipv4addr, 'netmask': ipv4netmask,
                     'ipv4addrs': ipv4addrs,
                     'ipv6addrs': ipv6addrs,
                     'ipv6autoconf': is_ipv6_local_auto(iface),
                     'gateway': gateway,
                     'ipv6gateway': get_gateway(routes, iface, family=6),
                     'ipv4defaultroute': is_default_route(gateway, routes),
                     'mtu': link_iface.iface(iface).mtu()})
    except (IOError, OSError) as e:
        if e.errno == errno.ENOENT or e.errno == errno.ENODEV:
            logging.info('Obtaining info for net %s.', iface, exc_info=True)
            raise NetworkIsMissing('Network %s was not found' % iface)
        else:
            raise
    return data
コード例 #22
0
def _get_info(device):
    dev_info = {'enabled': False,
                'tlvs': []}
    if iface(device).is_oper_up() and Lldp.is_lldp_enabled_on_iface(device):
        dev_info['enabled'] = True
        dev_info['tlvs'] = Lldp.get_tlvs(device)
    return dev_info
コード例 #23
0
    def test_iface_hwaddr(self):
        MAC_ADDR = '02:00:00:00:00:01'

        with dummy_device() as nic:
            _iface = iface(nic)
            _iface.set_address(MAC_ADDR)
            self.assertEqual(MAC_ADDR, _iface.address())
コード例 #24
0
ファイル: sysfs_driver.py プロジェクト: nirs/vdsm
def _preserve_iface_state(dev):
    _iface = iface(dev)
    dev_was_up = _iface.is_up()
    try:
        yield _iface
    finally:
        if dev_was_up and not _iface.is_up():
            _iface.up()
コード例 #25
0
ファイル: models.py プロジェクト: vjuranek/vdsm
    def configure(self, **opts):
        # in a limited condition, we should not touch the nic config
        if (self.vlan and nics.operstate(self.name) == nics.OPERSTATE_UP
                and self.configurator.net_info.ifaceUsers(self.name)
                and self.mtu <= link_iface.iface(self.name).mtu()):
            return

        self.configurator.configureNic(self, **opts)
コード例 #26
0
ファイル: ifcfg.py プロジェクト: oVirt/vdsm
    def _ifup_vlan_with_slave_bond_hwaddr_sync(vlan):
        """
        When NM is active and the network includes a vlan on top of a bond, the
        following scenario may occur:
        - VLAN over a bond with slaves is already defined in the system and
          VDSM is about to acquire it to define on it a network.
        - The VLAN iface is re-created while the bond slaves are temporary
          detached, causing the vlan to be created with the bond temporary
          mac address, which is different from the original existing address.
        Therefore, following the VLAN ifup command, its mac address is compared
        with the first bond slave. In case they differ, the vlan device is
        recreated.
        Bond mode 5 & 6 is excluded from the mac sync check.
        """
        bond = vlan.device
        bond_mode = Ifcfg._get_bond_mode(bond)
        if not bond.slaves or bond_mode == '5' or bond_mode == '6':
            _ifup(vlan)
            return

        blocking = _blocking_action_required(vlan)
        for attempt in range(5):
            if blocking:
                _ifup(vlan, blocking=blocking)
            else:
                with waitfor.waitfor_link_exists(vlan.name):
                    _ifup(vlan, blocking=blocking)

            vlan_hwaddr = link_iface.iface(vlan.name).address()
            slaves_hwaddr = [link_iface.iface(slave.name).address()
                             for slave in bond.slaves]
            if slaves_hwaddr[0] == vlan_hwaddr:
                return

            bond_hwaddr = link_iface.iface(bond.name).address()
            logging.info(
                '%s. vlan@bond hwaddr is not in sync (v/b/[s]): %s/%s/%s',
                attempt, vlan_hwaddr, bond_hwaddr, slaves_hwaddr)

            ifdown(vlan.name)

        raise ConfigNetworkError(
            ERR_BAD_BONDING,
            'While adding vlan {} over bond {}, '
            'the bond hwaddr was not in sync '
            'whith its slaves.'.format(vlan.name, vlan.device.name))
コード例 #27
0
def _preserve_iface_state(dev):
    _iface = iface(dev)
    dev_was_up = _iface.is_up()
    try:
        yield _iface
    finally:
        if dev_was_up and not _iface.is_up():
            _iface.up()
コード例 #28
0
def speed(nic_name):
    """Return the nic speed if it is a legal value, 0 otherwise."""
    interface = iface(nic_name)
    if interface.is_oper_up():
        try:
            return read_speed_using_sysfs(nic_name)
        except Exception:
            logging.debug('cannot read %s speed', nic_name)
    return 0
コード例 #29
0
ファイル: models.py プロジェクト: nirs/vdsm
    def configure(self, **opts):
        # in a limited condition, we should not touch the nic config
        if (self.vlan and
                nics.operstate(self.name) == nics.OPERSTATE_UP and
                self.configurator.net_info.ifaceUsers(self.name) and
                self.mtu <= link_iface.iface(self.name).mtu()):
            return

        self.configurator.configureNic(self, **opts)
コード例 #30
0
ファイル: legacy_switch.py プロジェクト: oVirt/vdsm
def _update_mtu_for_an_existing_bridge(dev_name, configurator, mtu):
    # When the MTU changes to the default MTU, reading the existing MTU on the
    # bridge is misleading, as with the latest OS, when no ports are connected
    # to it, it will fall down to the default.
    # In such a scenario, the ifcfg file still needs to be updated.
    if mtu != link_iface.iface(dev_name).mtu():
        configurator.configApplier.setIfaceMtu(dev_name, mtu)
        _update_bridge_ports_mtu(dev_name, mtu)
    elif mtu == link_iface.DEFAULT_MTU:
        configurator.configApplier.setIfaceMtu(dev_name, mtu)
コード例 #31
0
 def configureBridge(self, bridge, **opts):
     if not self.owned_device(bridge.name):
         IfcfgAcquire.acquire_device(bridge.name)
     self.configApplier.addBridge(bridge, **opts)
     if link_iface.iface(bridge.name).exists():
         ifdown(bridge.name)
     if bridge.port:
         bridge.port.configure(**opts)
     self._addSourceRoute(bridge)
     _ifup(bridge)
コード例 #32
0
ファイル: stats.py プロジェクト: vjuranek/vdsm
def report():
    stats = {}
    for iface_properties in iface.list():
        try:
            interface = iface.iface(iface_properties['name'])
            stats[interface.device] = _generate_iface_stats(interface)
        except IOError as e:
            if e.errno != errno.ENODEV:
                raise
    return stats
コード例 #33
0
ファイル: legacy_switch.py プロジェクト: minqf/vdsm
def _update_mtu_for_an_existing_bridge(dev_name, configurator, mtu):
    # When the MTU changes to the default MTU, reading the existing MTU on the
    # bridge is misleading, as with the latest OS, when no ports are connected
    # to it, it will fall down to the default.
    # In such a scenario, the ifcfg file still needs to be updated.
    if mtu != link_iface.iface(dev_name).mtu():
        configurator.configApplier.setIfaceMtu(dev_name, mtu)
        _update_bridge_ports_mtu(dev_name, mtu)
    elif mtu == link_iface.DEFAULT_MTU:
        configurator.configApplier.setIfaceMtu(dev_name, mtu)
コード例 #34
0
ファイル: ifcfg.py プロジェクト: oVirt/vdsm
 def configureBridge(self, bridge, **opts):
     if not self.owned_device(bridge.name):
         IfcfgAcquire.acquire_device(bridge.name)
     self.configApplier.addBridge(bridge, **opts)
     if link_iface.iface(bridge.name).exists():
         ifdown(bridge.name)
     if bridge.port:
         bridge.port.configure(**opts)
     self._addSourceRoute(bridge)
     _ifup(bridge)
コード例 #35
0
    def test_get_lldp_tlvs(self):
        with veth_pair() as (nic1, nic2):
            iface(nic1).up()
            iface(nic2).up()
            with enable_lldp_on_ifaces((nic1, nic2), rx_only=False):
                self.assertTrue(lldptool.is_lldp_enabled_on_iface(nic1))
                self.assertTrue(lldptool.is_lldp_enabled_on_iface(nic2))
                tlvs = lldptool.get_tlvs(nic1)
                self.assertEqual(3, len(tlvs))
                expected_ttl_tlv = {
                    'type': 3,
                    'name': 'Time to Live',
                    'properties': {
                        'time to live': '120'
                    }
                }
                self.assertEqual(expected_ttl_tlv, tlvs[-1])

                tlvs = lldptool.get_tlvs(nic2)
                self.assertEqual(3, len(tlvs))
コード例 #36
0
ファイル: net_with_bond_test.py プロジェクト: nirs/vdsm
    def test_add_net_on_existing_external_bond_preserving_mac(self, switch):
        if switch == 'ovs':
            pytest.xfail('Preserving bond mac is not supported on OVS switch.')
        HWADDRESS = 'ce:0c:46:59:c9:d1'
        with dummy_devices(2) as (nic1, nic2):
            with Bond(BOND_NAME, slaves=(nic1, nic2)) as bond:
                bond.create()
                iface(BOND_NAME).set_address(HWADDRESS)

                NETBASE = {NETWORK1_NAME: {'bonding': BOND_NAME,
                                           'bridged': False,
                                           'switch': switch}}
                with adapter.setupNetworks(NETBASE, {}, NOCHK):
                    adapter.assertNetwork(NETWORK1_NAME,
                                          NETBASE[NETWORK1_NAME])
                    adapter.assertBond(
                        BOND_NAME, {'nics': [nic1, nic2],
                                    'hwaddr': HWADDRESS,
                                    'switch': switch})
            adapter.setupNetworks({}, {BOND_NAME: {'remove': True}}, NOCHK)
コード例 #37
0
ファイル: lldpad_test.py プロジェクト: minqf/vdsm
    def test_get_lldp_tlvs(self):
        with veth_pair() as (nic1, nic2):
            iface(nic1).up()
            iface(nic2).up()
            with enable_lldp_on_ifaces((nic1, nic2), rx_only=False):
                assert lldptool.is_lldp_enabled_on_iface(nic1)
                assert lldptool.is_lldp_enabled_on_iface(nic2)
                tlvs = lldptool.get_tlvs(nic1)
                assert 3 == len(tlvs)
                expected_ttl_tlv = {
                    'type': 3,
                    'name': 'Time to Live',
                    'properties': {
                        'time to live': '120'
                    },
                }
                assert expected_ttl_tlv == tlvs[-1]

                tlvs = lldptool.get_tlvs(nic2)
                assert 3 == len(tlvs)
コード例 #38
0
ファイル: nic.py プロジェクト: nirs/vdsm
def speed(nic_name):
    """Return the nic speed if it is a legal value, 0 otherwise."""
    interface = iface(nic_name)
    if interface.is_oper_up():
        if dpdk.is_dpdk(nic_name):
            return dpdk.speed(nic_name)
        try:
            return read_speed_using_sysfs(nic_name)
        except Exception:
            logging.debug('cannot read %s speed', nic_name)
    return 0
コード例 #39
0
ファイル: netfunctestlib.py プロジェクト: nirs/vdsm
 def assertLinksUp(self, net, attrs):
     switch = attrs.get('switch', 'legacy')
     if switch == 'legacy':
         expected_links = _gather_expected_legacy_links(
             net, attrs, self.netinfo)
     elif switch == 'ovs':
         expected_links = _gather_expected_ovs_links(
             net, attrs, self.netinfo)
     if expected_links:
         for dev in expected_links:
             assert iface(dev).is_oper_up(), 'Dev {} is DOWN'.format(dev)
コード例 #40
0
ファイル: lldpad_test.py プロジェクト: nirs/vdsm
    def test_get_lldp_tlvs(self):
        with veth_pair() as (nic1, nic2):
            iface(nic1).up()
            iface(nic2).up()
            with enable_lldp_on_ifaces((nic1, nic2), rx_only=False):
                self.assertTrue(lldptool.is_lldp_enabled_on_iface(nic1))
                self.assertTrue(lldptool.is_lldp_enabled_on_iface(nic2))
                tlvs = lldptool.get_tlvs(nic1)
                self.assertEqual(3, len(tlvs))
                expected_ttl_tlv = {
                    'type': 3,
                    'name': 'Time to Live',
                    'properties': {
                        'time to live': '120'
                    }
                }
                self.assertEqual(expected_ttl_tlv, tlvs[-1])

                tlvs = lldptool.get_tlvs(nic2)
                self.assertEqual(3, len(tlvs))
コード例 #41
0
ファイル: netfunctestlib.py プロジェクト: SanderSander/vdsm
 def assertLinksUp(self, net, attrs):
     switch = attrs.get('switch', 'legacy')
     if switch == 'legacy':
         expected_links = _gather_expected_legacy_links(
             net, attrs, self.netinfo)
     elif switch == 'ovs':
         expected_links = _gather_expected_ovs_links(
             net, attrs, self.netinfo)
     if expected_links:
         for dev in expected_links:
             assert iface(dev).is_oper_up(), 'Dev {} is DOWN'.format(dev)
コード例 #42
0
ファイル: models.py プロジェクト: nirs/vdsm
    def __init__(self, name, configurator, ipv4=None, ipv6=None,
                 blockingdhcp=False, mtu=None, _netinfo=None):
        if _netinfo is None:
            _netinfo = CachingNetInfo()
        if name not in _netinfo.nics:
            raise ConfigNetworkError(ne.ERR_BAD_NIC, 'unknown nic: %s' % name)

        if _netinfo.ifaceUsers(name):
            mtu = max(mtu or 0, link_iface.iface(name).mtu())

        super(Nic, self).__init__(name, configurator, ipv4, ipv6, blockingdhcp,
                                  mtu)
コード例 #43
0
    def __init__(self, name, configurator, ipv4=None, ipv6=None,
                 blockingdhcp=False, mtu=None, _netinfo=None):
        if _netinfo is None:
            _netinfo = CachingNetInfo()
        if name not in _netinfo.nics:
            raise ConfigNetworkError(ne.ERR_BAD_NIC, 'unknown nic: %s' % name)

        if _netinfo.ifaceUsers(name):
            mtu = max(mtu, link_iface.iface(name).mtu())

        super(Nic, self).__init__(name, configurator, ipv4, ipv6, blockingdhcp,
                                  mtu)
コード例 #44
0
def speed(dev_name):
    """Return the vlan's underlying device speed."""
    dev_speed = 0
    interface = iface.iface(dev_name)
    iface_type = interface.type()
    if iface_type == iface.Type.NIC:
        # vlans on a nics expose the speed through sysfs
        dev_speed = nic.read_speed_using_sysfs(dev_name)
    elif iface_type == iface.Type.BOND:
        dev_speed = bond.speed(dev_name)

    return dev_speed
コード例 #45
0
 def shutdown(self):
     try:
         pid = int(open(self.pidFile).readline().strip())
     except IOError as e:
         if e.errno == errno.ENOENT:
             pass
         else:
             raise
     else:
         logging.info('Stopping dhclient-%s on %s', self.family, self.iface)
         _kill_and_rm_pid(pid, self.pidFile)
         if linkiface.iface(self.iface).exists():
             address.flush(self.iface)
コード例 #46
0
ファイル: __init__.py プロジェクト: nirs/vdsm
    def _setNewMtu(self, iface, ifaceVlans):
        """
        Update an interface's MTU when one of its users is removed.

        :param iface: interface object (bond or nic device)
        :type iface: NetDevice instance

        :param ifaceVlans: vlan devices using the interface 'iface'
        :type ifaceVlans: iterable

        :return mtu value that was applied
        """
        ifaceMtu = link_iface.iface(iface.name).mtu()
        ifaces = tuple(ifaceVlans)
        maxMtu = (max(link_iface.iface(dev).mtu() for dev in ifaces)
                  if ifaces else None)
        if maxMtu and maxMtu < ifaceMtu:
            if isinstance(iface, Bond):
                self.configApplier.setBondingMtu(iface.name, maxMtu)
            else:
                self.configApplier.setIfaceMtu(iface.name, maxMtu)
        return maxMtu
コード例 #47
0
    def _setNewMtu(self, iface, ifaceVlans):
        """
        Update an interface's MTU when one of its users is removed.

        :param iface: interface object (bond or nic device)
        :type iface: NetDevice instance

        :param ifaceVlans: vlan devices using the interface 'iface'
        :type ifaceVlans: iterable

        :return mtu value that was applied
        """
        ifaceMtu = link_iface.iface(iface.name).mtu()
        ifaces = tuple(ifaceVlans)
        maxMtu = (max(link_iface.iface(dev).mtu()
                      for dev in ifaces) if ifaces else None)
        if maxMtu and maxMtu < ifaceMtu:
            if isinstance(iface, Bond):
                self.configApplier.setBondingMtu(iface.name, maxMtu)
            else:
                self.configApplier.setIfaceMtu(iface.name, maxMtu)
        return maxMtu
コード例 #48
0
ファイル: dhclient.py プロジェクト: oVirt/vdsm
 def shutdown(self):
     try:
         pid = int(open(self.pidFile).readline().strip())
     except IOError as e:
         if e.errno == errno.ENOENT:
             pass
         else:
             raise
     else:
         logging.info('Stopping dhclient-%s on %s', self.family, self.iface)
         _kill_and_rm_pid(pid, self.pidFile)
         if linkiface.iface(self.iface).exists():
             address.flush(self.iface)
コード例 #49
0
ファイル: dhclient.py プロジェクト: oVirt/vdsm
    def _dhclient(self):
        if linkiface.iface(self.iface).exists():
            kill(self.iface, self.family)
            address.flush(self.iface, family=self.family)

        cmds = [DHCLIENT_BINARY.cmd, '-%s' % self.family, '-1', '-pf',
                self.pidFile, '-lf', self.leaseFile]
        if not self.default_route:
            # Instruct Fedora/EL's dhclient-script not to set gateway on iface
            cmds += ['-e', 'DEFROUTE=no']
        if self.duid_source_file and supports_duid_file():
            cmds += ['-df', self.duid_source_file]
        cmds += [self.iface]
        return cmd.exec_systemd_new_unit(cmds, slice_name=self._cgroup)
コード例 #50
0
    def _dhclient(self):
        if linkiface.iface(self.iface).exists():
            kill(self.iface, self.family)
            address.flush(self.iface, family=self.family)

        cmds = [DHCLIENT_BINARY.cmd, '-%s' % self.family, '-1', '-pf',
                self.pidFile, '-lf', self.leaseFile]
        if not self.default_route:
            # Instruct Fedora/EL's dhclient-script not to set gateway on iface
            cmds += ['-e', 'DEFROUTE=no']
        if self.duid_source_file and supports_duid_file():
            cmds += ['-df', self.duid_source_file]
        cmds += [self.iface]
        return cmd.exec_systemd_new_unit(cmds, slice_name=self._cgroup)
コード例 #51
0
def monitor_stable_link_state(device, wait_for_linkup=True):
    """Raises an exception if it detects that the device link state changes."""
    if wait_for_linkup:
        with waitfor.waitfor_linkup(device):
            pass
    iface_properties = iface(device).properties()
    original_state = iface_properties['state']
    try:
        with monitor.Monitor(groups=('link', )) as mon:
            yield
    finally:
        state_changes = (e['state'] for e in mon if e['name'] == device)
        for state in state_changes:
            if state != original_state:
                raise pytest.fail('{} link state changed: {} -> {}'.format(
                    device, original_state, state))
コード例 #52
0
ファイル: models.py プロジェクト: nirs/vdsm
    def configure(self, **opts):
        # When the bond is up and we are not changing the configuration that
        # is already applied in any way, we can skip the configuring.
        if (self.vlan and
            self.name in bonding.bondings() and
            (not self.configurator.unifiedPersistence or
             self.name in self.configurator.runningConfig.bonds) and
            nics.operstate(self.name) == nics.OPERSTATE_UP and
            self.configurator.net_info.ifaceUsers(self.name) and
            self.mtu <= link_iface.iface(self.name).mtu() and
            not self._bond_hwaddr_changed() and
            self.areOptionsApplied() and
            frozenset(slave.name for slave in self.slaves) ==
                frozenset(link_bond.Bond(self.name).slaves)):
                return

        self.configurator.configureBond(self, **opts)
コード例 #53
0
ファイル: netfunctestlib.py プロジェクト: nirs/vdsm
def monitor_stable_link_state(device, wait_for_linkup=True):
    """Raises an exception if it detects that the device link state changes."""
    if wait_for_linkup:
        with waitfor.waitfor_linkup(device):
            pass
    iface_properties = iface(device).properties()
    original_state = iface_properties['state']
    try:
        with monitor.Monitor(groups=('link',)) as mon:
            yield
    finally:
        state_changes = (e['state'] for e in mon if e['name'] == device)
        for state in state_changes:
            if state != original_state:
                raise pytest.fail(
                    '{} link state changed: {} -> {}'.format(
                        device, original_state, state))
コード例 #54
0
ファイル: stats.py プロジェクト: nirs/vdsm
def report():
    stats = {}
    for iface_properties in iface.list():
        i = iface.iface(iface_properties['name'])
        stats[i.device] = i.statistics()

        speed = 0
        if i.type() == iface.Type.NIC:
            speed = nic.speed(i.device)
        elif i.type() == iface.Type.BOND:
            speed = bond.speed(i.device)
        elif i.type() == iface.Type.VLAN:
            speed = vlan.speed(i.device)
        elif i.type() == iface.Type.DPDK:
            speed = dpdk.speed(i.device)

        stats[i.device]['speed'] = speed
        stats[i.device]['duplex'] = nic.duplex(i.device)

    return stats
コード例 #55
0
ファイル: cache.py プロジェクト: nirs/vdsm
def networks_base_info(running_nets, routes=None, ipaddrs=None):
    if routes is None:
        routes = get_routes()
    if ipaddrs is None:
        ipaddrs = getIpAddrs()

    info = {}
    for net, attrs in six.viewitems(running_nets):
        if attrs.get('switch') != 'legacy':
            continue
        iface = get_net_iface_from_config(net, attrs)
        try:
            if not link_iface.iface(iface).exists():
                raise NetworkIsMissing('Iface %s was not found' % iface)
            info[net] = _getNetInfo(iface, attrs['bridged'], routes, ipaddrs)
        except NetworkIsMissing:
            # Missing networks are ignored, reporting only what exists.
            logging.warning('Missing network detected [%s]: %s', net, attrs)

    return info
コード例 #56
0
ファイル: canonicalize.py プロジェクト: nirs/vdsm
def _canonicalize_bond_hwaddress(bondname, bondattrs):
    if 'hwaddr' not in bondattrs:
        if _bond_hwaddr_should_be_enforced(bondname):
            bondattrs['hwaddr'] = iface.iface(bondname).address()
コード例 #57
0
ファイル: dhclient.py プロジェクト: oVirt/vdsm
def kill(device_name, family=4):
    if not linkiface.iface(device_name).exists():
        return
    for pid, pid_file in _pid_lookup(device_name, family):
        logging.info('Stopping dhclient-%s on %s', family, device_name)
        _kill_and_rm_pid(pid, pid_file)
コード例 #58
0
ファイル: link_iface_test.py プロジェクト: nirs/vdsm
 def test_iface_down(self):
     with dummy_device() as nic:
         _iface = iface(nic)
         _iface.up()
         _iface.down()
         self.assertFalse(_iface.is_up())
コード例 #59
0
ファイル: link_iface_test.py プロジェクト: nirs/vdsm
 def test_iface_notpromisc(self):
     with dummy_device() as nic:
         _iface = iface(nic)
         _iface.up()
         self.assertFalse(_iface.is_promisc())