def test_fake_nics(self): with veth_pair() as (v1a, v1b): with dummy_device() as d1: fakes = set([d1, v1a, v1b]) _nics = nics.nics() self.assertTrue(fakes.issubset(_nics), 'Fake devices %s are not listed in nics ' '%s' % (fakes, _nics)) with veth_pair(prefix='mehv_') as (v2a, v2b): with dummy_device(prefix='mehd_') as d2: hiddens = set([d2, v2a, v2b]) _nics = nics.nics() self.assertFalse(hiddens.intersection(_nics), 'Some of ' 'hidden devices %s is shown in nics %s' % (hiddens, _nics))
def removeNic(self, nic, remove_even_if_used=False): if not self.owned_device(nic.name): IfcfgAcquire.acquire_device(nic.name) # If the nic is top device we should ifdown it even if it is # used by a VLAN. Otherwise we would keep its IP address. remove_even_if_used |= nic.master is None to_be_removed = self._ifaceDownAndCleanup(nic, remove_even_if_used) if to_be_removed: self.configApplier.removeNic(nic.name) if nic.name in nics.nics(): _exec_ifup(nic) else: logging.warning('host interface %s missing', nic.name) else: vlans = link_vlan.get_vlans_on_base_device(nic.name) set_mtu = self._setNewMtu(nic, vlans) # Since we are not taking the device up again, ifcfg will not be # read at this point and we need to set the live mtu value if set_mtu is not None: ipwrapper.linkSet(nic.name, ['mtu', str(set_mtu)]) # If the nic was bridged, we must remove BRIDGE parameter from its # ifcfg configuration file. if nic.bridge: self.configApplier.dropBridgeParameter(nic.name)
def validate_network_setup(networks, bondings): for network, networkAttrs in six.iteritems(networks): if networkAttrs.get('remove', False): _validate_network_remove(networkAttrs) elif 'vlan' in networkAttrs: Vlan.validateTag(networkAttrs['vlan']) _validate_nic_not_dpdk(networkAttrs.get('nic', None)) currentNicsSet = set(netinfo_nics.nics()) for bonding, bondingAttrs in six.iteritems(bondings): if 'options' in bondingAttrs: Bond.validateOptions(bondingAttrs['options']) if bondingAttrs.get('remove', False): continue nics = bondingAttrs.get('nics', None) if not nics: raise ConfigNetworkError(ne.ERR_BAD_PARAMS, 'Must specify nics for bonding') if not set(nics).issubset(currentNicsSet): raise ConfigNetworkError(ne.ERR_BAD_NIC, 'Unknown nics in: %r' % list(nics)) for nic in nics: if dpdk.is_dpdk(nic): raise ConfigNetworkError( ne.ERR_BAD_NIC, '%s is a dpdk device and not supported as ' 'a slave of bond' % nic)
def validate_network_setup(nets, bonds, net_info): kernel_nics = nics() kernel_bonds = Bond.bonds() for net, attrs in six.iteritems(nets): validate_net_configuration( net, attrs, bonds, kernel_bonds, kernel_nics) for bond, attrs in six.iteritems(bonds): validate_bond_configuration( bond, attrs, nets, net_info['networks'], kernel_nics)
def test_nics(self, mock_getLinks): """ managed by vdsm: em, me, fake0, fake1 not managed due to hidden bond (jbond) enslavement: me0, me1 not managed due to being hidden nics: hid0, hideous """ mock_getLinks.return_value = self._LINKS_REPORT self.assertEqual(set(nics.nics()), set(['em', 'me', 'fake', 'fake0']))
def testFakeNics(self): with MonkeyPatchScope([(ipwrapper.Link, '_fakeNics', ['veth_*', 'dummy_*'])]): with veth_pair() as (v1a, v1b): with dummy_device() as d1: fakes = set([d1, v1a, v1b]) _nics = nics.nics() self.assertTrue(fakes.issubset(_nics), 'Fake devices %s are not listed in nics ' '%s' % (fakes, _nics)) with veth_pair(prefix='mehv_') as (v2a, v2b): with dummy_device(prefix='mehd_') as d2: hiddens = set([d2, v2a, v2b]) _nics = nics.nics() self.assertFalse(hiddens.intersection(_nics), 'Some of ' 'hidden devices %s is shown in nics %s' % (hiddens, _nics))
def validate_network_setup(nets, bonds): _netinfo = info.create_netinfo(info.OvsInfo()) kernel_nics = nics() for net, attrs in six.iteritems(nets): validator.validate_net_configuration( net, attrs, bonds, _netinfo['bondings'], kernel_nics) for bond, attrs in six.iteritems(bonds): validator.validate_bond_configuration( bond, attrs, nets, _netinfo['networks'], kernel_nics)
def validate_network_setup(nets, bonds): ovs_networks = info.create_netinfo(info.OvsInfo())['networks'] kernel_nics = nics() kernel_bonds = Bond.bonds() for net, attrs in six.iteritems(nets): validator.validate_net_configuration( net, attrs, bonds, kernel_bonds, kernel_nics) for bond, attrs in six.iteritems(bonds): validator.validate_bond_configuration( bond, attrs, nets, ovs_networks, kernel_nics)
def removeNic(self, nic, remove_even_if_used=False): to_be_removed = self._ifaceDownAndCleanup(nic, remove_even_if_used) if to_be_removed: self.configApplier.removeNic(nic.name) if nic.name in nics.nics(): _exec_ifup(nic) else: logging.warning('host interface %s missing', nic.name) else: set_mtu = self._setNewMtu(nic, vlans.vlan_devs_for_iface(nic.name)) # Since we are not taking the device up again, ifcfg will not be # read at this point and we need to set the live mtu value if set_mtu is not None: ipwrapper.linkSet(nic.name, ['mtu', str(set_mtu)])
def _filter_available(persistent_config): """Returns only nets and bonds that can be configured with the devices present in the system""" available_nics = nics.nics() available_bonds = _find_bonds_with_available_nics(available_nics, persistent_config.bonds) available_nets = _find_nets_with_available_devices( available_bonds, available_nics, persistent_config.bonds, persistent_config.networks) return BaseConfig(available_nets, available_bonds, {})
def testNics(self): """ managed by vdsm: em, me, fake0, fake1 not managed due to hidden bond (jbond) enslavement: me0, me1 not managed due to being hidden nics: hid0, hideous """ with MonkeyPatchScope([(netinfo.misc, 'getLinks', self._testNics), (ipwrapper, '_bondExists', lambda x: x == 'jbond'), (ipwrapper.Link, '_detectType', partial(_fakeTypeDetection, ipwrapper.Link)), (ipwrapper.Link, '_fakeNics', ['fake*']), (ipwrapper.Link, '_hiddenBonds', ['jb*']), (ipwrapper.Link, '_hiddenNics', ['hid*']) ]): self.assertEqual(set(nics.nics()), set(['em', 'me', 'fake', 'fake0']))
def removeNic(self, nic, remove_even_if_used=False): if not self.owned_device(nic.name): IfcfgAcquire.acquire_device(nic.name) to_be_removed = self._ifaceDownAndCleanup(nic, remove_even_if_used) if to_be_removed: self.configApplier.removeNic(nic.name) if nic.name in nics.nics(): _exec_ifup(nic) else: logging.warning("host interface %s missing", nic.name) else: set_mtu = self._setNewMtu(nic, vlans.vlan_devs_for_iface(nic.name)) # Since we are not taking the device up again, ifcfg will not be # read at this point and we need to set the live mtu value if set_mtu is not None: ipwrapper.linkSet(nic.name, ["mtu", str(set_mtu)]) # If the nic was bridged, we must remove BRIDGE parameter from its # ifcfg configuration file. if nic.bridge: self.configApplier.dropBridgeParameter(nic.name)
def test_speed_in_range(self): for d in nics.nics(): s = nic.speed(d) self.assertFalse(s < 0) self.assertTrue(s in ETHTOOL_SPEEDS or s == 0)
def test_speed_in_range(self): for d in nics.nics(): s = nic.speed(d) assert not s < 0 assert s in ETHTOOL_SPEEDS or s == 0