Revision 255e19d4

b/lib/objects.py
312 312
  """Config object representing a network card."""
313 313
  __slots__ = ["mac", "ip", "bridge"]
314 314

  
315
  @classmethod
316
  def CheckParameterSyntax(cls, nicparams):
317
    """Check the given parameters for validity.
318

  
319
    @type nicparams:  dict
320
    @param nicparams: dictionary with parameter names/value
321
    @raise errors.ConfigurationError: when a parameter is not valid
322

  
323
    """
324
    if nicparams[constants.NIC_MODE] not in constants.NIC_VALID_MODES:
325
      err = "Invalid nic mode: %s" % nicparams[constants.NIC_MODE]
326
      raise errors.ConfigurationError(err)
327

  
328
    if (nicparams[constants.NIC_MODE] is constants.NIC_MODE_BRIDGED and
329
        not nicparams[constants.NIC_LINK]):
330
      err = "Missing bridged nic link"
331
      raise errors.ConfigurationError(err)
332

  
315 333

  
316 334
class Disk(ConfigObject):
317 335
  """Config object representing a block device."""
b/test/ganeti.config_unittest.py
152 152
    # but the fake_instance update should still fail
153 153
    self.failUnlessRaises(errors.ConfigurationError, cfg.Update, fake_instance)
154 154

  
155
  def testNICParameterSyntaxCheck(self):
156
    """Test the NIC's CheckParameterSyntax function"""
157
    mode = constants.NIC_MODE
158
    link = constants.NIC_LINK
159
    m_bridged = constants.NIC_MODE_BRIDGED
160
    m_routed = constants.NIC_MODE_ROUTED
161
    CheckSyntax = objects.NIC.CheckParameterSyntax
162

  
163
    CheckSyntax(constants.NICC_DEFAULTS)
164
    CheckSyntax({mode: m_bridged, link: 'br1'})
165
    CheckSyntax({mode: m_routed, link: 'default'})
166
    self.assertRaises(errors.ConfigurationError,
167
                      CheckSyntax, {mode: '000invalid', link: 'any'})
168
    self.assertRaises(errors.ConfigurationError,
169
                      CheckSyntax, {mode: m_bridged, link: None})
170
    self.assertRaises(errors.ConfigurationError,
171
                      CheckSyntax, {mode: m_bridged, link: ''})
172

  
155 173

  
156 174
if __name__ == '__main__':
157 175
  unittest.main()

Also available in: Unified diff