def _validateNetworkSetup(networks, bondings): for network, networkAttrs in networks.iteritems(): if networkAttrs.get('remove', False): if set(networkAttrs) - set(['remove']): raise ConfigNetworkError(ne.ERR_BAD_PARAMS, 'Cannot specify ' 'any attribute when removing') currentBondings = netinfo.bondings() currentNicsSet = set(netinfo.nics()) for bonding, bondingAttrs in bondings.iteritems(): Bond.validateName(bonding) if 'options' in bondingAttrs: Bond.validateOptions(bonding, bondingAttrs['options']) if bondingAttrs.get('remove', False): if bonding not in currentBondings: raise ConfigNetworkError(ne.ERR_BAD_BONDING, "Cannot remove " "bonding %s: Doesn't exist" % bonding) 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))
def _validateNetworkSetup(networks, bondings): for network, networkAttrs in networks.iteritems(): if networkAttrs.get('remove', False): net_attr_keys = set(networkAttrs) if 'remove' in net_attr_keys and net_attr_keys - set( ['remove', 'custom']): raise ConfigNetworkError( ne.ERR_BAD_PARAMS, "Cannot specify any attribute when removing (other " "than custom properties). specified attributes: %s" % ( networkAttrs,)) currentNicsSet = set(netinfo.nics()) for bonding, bondingAttrs in bondings.iteritems(): Bond.validateName(bonding) if 'options' in bondingAttrs: Bond.validateOptions(bonding, 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))
def _validateNetworkSetup(networks, bondings): for network, networkAttrs in networks.iteritems(): if networkAttrs.get('remove', False): net_attr_keys = set(networkAttrs) if 'remove' in net_attr_keys and net_attr_keys - set( ['remove', 'custom']): raise ConfigNetworkError( ne.ERR_BAD_PARAMS, "Cannot specify any attribute when removing (other " "than custom properties). specified attributes: %s" % (networkAttrs, )) currentNicsSet = set(netinfo.nics()) for bonding, bondingAttrs in bondings.iteritems(): Bond.validateName(bonding) 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))
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 = netinfo.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 = netinfo.nics() self.assertFalse(hiddens.intersection(nics), 'Some of ' 'hidden devices %s is shown in nics %s' % (hiddens, nics))
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 = netinfo.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 = netinfo.nics() self.assertFalse( hiddens.intersection(nics), 'Some of ' 'hidden devices %s is shown in nics %s' % (hiddens, nics))
def testNics(self): temp_dir = tempfile.mkdtemp() with MonkeyPatchScope([(netinfo, 'NET_FN_MATCH', self._dev_dirs_setup(temp_dir)), (netinfo, 'config', self._config_setup())]): try: self.assertEqual(set(netinfo.nics()), set(['em', 'me', 'fake0', 'fake'])) finally: rmtree(temp_dir)
def testNics(self): temp_dir = tempfile.mkdtemp() with MonkeyPatchScope([(netinfo, 'BONDING_SLAVES', temp_dir + '/%s/bonding/slaves'), (netinfo, 'NET_PATH', self._dev_dirs_setup(temp_dir)), (netinfo, 'config', self._config_setup())]): try: self.assertEqual(set(netinfo.nics()), set(['em', 'me', 'fake', 'fake0'])) finally: rmtree(temp_dir)
def testNics(self): temp_dir = tempfile.mkdtemp() with MonkeyPatchScope([ (netinfo, 'BONDING_SLAVES', temp_dir + '/%s/bonding/slaves'), (netinfo, 'NET_PATH', self._dev_dirs_setup(temp_dir)), (netinfo, 'config', self._config_setup()) ]): try: self.assertEqual(set(netinfo.nics()), set(['em', 'me', 'fake', 'fake0'])) finally: rmtree(temp_dir)
def removeNic(self, nic): to_be_removed = self._ifaceDownAndCleanup(nic) if to_be_removed: self.configApplier.removeNic(nic.name) if nic.name in netinfo.nics(): _exec_ifup(nic.name) else: logging.warning('host interface %s missing', nic.name) else: set_mtu = self._setNewMtu(nic, netinfo.vlanDevsForIface(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 __init__(self, log): """ Initialize the (single) clientIF instance :param log: a log object to be used for this object's logging. :type log: :class:`logging.Logger` """ self.vmContainerLock = threading.Lock() self._networkSemaphore = threading.Semaphore() self._shutdownSemaphore = threading.Semaphore() self.log = log self._recovery = True self.channelListener = Listener(self.log) self._generationID = str(uuid.uuid4()) self._initIRS() self.mom = None if _glusterEnabled: self.gluster = gapi.GlusterApi(self, log) else: self.gluster = None try: self.vmContainer = {} ifids = netinfo.nics() + netinfo.bondings() ifrates = map(netinfo.speed, ifids) self._hostStats = sampling.HostStatsThread(cif=self, log=log, ifids=ifids, ifrates=ifrates) self._hostStats.start() self.lastRemoteAccess = 0 self._memLock = threading.Lock() self._enabled = True self._netConfigDirty = False self._prepareMOM() threading.Thread(target=self._recoverExistingVms, name='clientIFinit').start() self.channelListener.settimeout( config.getint('vars', 'guest_agent_timeout')) self.channelListener.start() self.threadLocal = threading.local() self.threadLocal.client = '' except: self.log.error('failed to init clientIF, ' 'shutting down storage dispatcher') if self.irs: self.irs.prepareForShutdown() if self.mom: self.mom.stop() raise self._prepareBindings()
def removeNic(self, nic): to_be_removed = self._ifaceDownAndCleanup(nic) if to_be_removed: self.configApplier.removeNic(nic.name) if nic.name in netinfo.nics(): ifup(nic.name) else: logging.warning('host interface %s missing', nic.name) else: set_mtu = self._setNewMtu(nic, netinfo.vlanDevsForIface(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 __init__(self, log): """ Initialize the (single) clientIF instance :param log: a log object to be used for this object's logging. :type log: :class:`logging.Logger` """ self.vmContainerLock = threading.Lock() self._networkSemaphore = threading.Semaphore() self._shutdownSemaphore = threading.Semaphore() self.log = log self._recovery = True self.channelListener = Listener(self.log) self._generationID = str(uuid.uuid4()) self._initIRS() self.mom = None if _glusterEnabled: self.gluster = gapi.GlusterApi(self, log) else: self.gluster = None try: self.vmContainer = {} ifids = netinfo.nics() + netinfo.bondings() ifrates = map(netinfo.speed, ifids) self._hostStats = sampling.HostStatsThread( cif=self, log=log, ifids=ifids, ifrates=ifrates) self._hostStats.start() self.lastRemoteAccess = 0 self._memLock = threading.Lock() self._enabled = True self._netConfigDirty = False self._prepareMOM() threading.Thread(target=self._recoverExistingVms, name='clientIFinit').start() self.channelListener.settimeout( config.getint('vars', 'guest_agent_timeout')) self.channelListener.start() self.threadLocal = threading.local() self.threadLocal.client = '' except: self.log.error('failed to init clientIF, ' 'shutting down storage dispatcher') if self.irs: self.irs.prepareForShutdown() if self.mom: self.mom.stop() raise self._prepareBindings()
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, '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(netinfo.nics()), set(['em', 'me', 'fake', 'fake0']))
def __init__ (self, log): """ Initialize the (single) clientIF instance :param log: a log object to be used for this object's logging. :type log: :class:`logging.Logger` """ self.vmContainerLock = threading.Lock() self._networkSemaphore = threading.Semaphore() self._shutdownSemaphore = threading.Semaphore() self.log = log self._recovery = True self._libvirt = libvirtconnection.get() self._syncLibvirtNetworks() self.channelListener = Listener(self.log) self._generationID = str(uuid.uuid4()) self._initIRS() try: self.vmContainer = {} ifids = netinfo.nics() + netinfo.bondings() ifrates = map(netinfo.speed, ifids) self._hostStats = utils.HostStatsThread(cif=self, log=log, ifids=ifids, ifrates=ifrates) self._hostStats.start() mog = min(config.getint('vars', 'max_outgoing_migrations'), caps.CpuInfo().cores()) vm.MigrationSourceThread.setMaxOutgoingMigrations(mog) self.lastRemoteAccess = 0 self._memLock = threading.Lock() self._enabled = True self.ksmMonitor = ksm.KsmMonitorThread(self) self._netConfigDirty = False threading.Thread(target=self._recoverExistingVms, name='clientIFinit').start() self.channelListener.settimeout(config.getint('vars', 'guest_agent_timeout')) self.channelListener.start() self.threadLocal = threading.local() self.threadLocal.client = '' except: self.log.error('failed to init clientIF, shutting down storage dispatcher') if self.irs: self.irs.prepareForShutdown() raise self._prepareBindings()
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, '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(netinfo.nics()), set(['em', 'me', 'fake', 'fake0']))
def testFakeNics(self): with MonkeyPatchScope([(ipwrapper.Link, '_fakeNics', ['veth_*', 'dummy_*'])]): d1 = dummy.create() d2 = dummy.create(prefix='mehd_') v1a, v1b = veth.create() v2a, v2b = veth.create(prefix='mehv_') fakes = set([d1, v1a, v1b]) hiddens = set([d2, v2a, v2b]) nics = netinfo.nics() dummy.remove(d1) dummy.remove(d2) veth.remove(v1a) veth.remove(v2a) self.assertTrue(fakes.issubset(nics), 'Fake devices %s are not ' 'listed in nics %s' % (fakes, nics)) self.assertFalse(hiddens.intersection(nics), 'Some of hidden ' 'devices %s is shown in nics %s' % (hiddens, nics))
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)
def testSpeedInvalidNic(self): nicName = 'DUMMYNICDEVNAME' self.assertTrue(nicName not in netinfo.nics()) s = netinfo.speed(nicName) self.assertEqual(s, 0)