def _validateNetworkSetup(networks, bondings): _netinfo = netinfo.NetInfo() 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') 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 _netinfo.bondings: 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(set(_netinfo.nics)): 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): 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 testValidateBondingOptions(self): if not os.path.exists(netinfo.BONDING_MASTERS): raise SkipTest("bonding kernel module could not be found.") opts = 'mode=802.3ad miimon=150' badOpts = 'foo=bar badopt=one' with self.assertRaises(neterrors.ConfigNetworkError) as cne: Bond.validateOptions('bond0', badOpts) self.assertEqual(cne.exception.errCode, neterrors.ERR_BAD_BONDING) self.assertEqual(Bond.validateOptions('bond0', opts), None)
def testValidateBondingOptions(self): if not os.path.exists(netinfo.BONDING_MASTERS): raise SkipTest("bonding kernel module could not be found.") opts = 'mode=802.3ad miimon=150' badOpts = 'foo=bar badopt=one' with self.assertRaises(neterrors.ConfigNetworkError) as cne: Bond.validateOptions('bond0', badOpts) self.assertEqual(cne.exception.errCode, neterrors.ERR_BAD_BONDING) self.assertEqual(Bond.validateOptions('bond0', opts), None)