Example #1
0
File: api.py Project: fancyKai/vdsm
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.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))
Example #2
0
    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))
Example #3
0
    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))
Example #4
0
File: ifcfg.py Project: mykaul/vdsm
 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.name)
         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)])
Example #5
0
 def removeNic(self, nic):
     to_be_removed = self._ifaceDownAndCleanup(nic)
     if to_be_removed:
         self.configApplier.removeNic(nic.name)
         if nic.name in nics.nics():
             _exec_ifup(nic.name)
         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)])
Example #6
0
 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']))
Example #7
0
 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']))
Example #8
0
def validateNetworkSetup(networks, bondings):
    for network, networkAttrs in networks.iteritems():
        if networkAttrs.get('remove', False):
            _validate_network_remove(networkAttrs)
        elif 'vlan' in networkAttrs:
            Vlan.validateTag(networkAttrs['vlan'])

    currentNicsSet = set(netinfo_nics.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))
Example #9
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 #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)