Revision ec3a7362
b/lib/cmdlib/instance.py | ||
---|---|---|
294 | 294 |
disk_sizes, spindle_use, disk_template) |
295 | 295 |
|
296 | 296 |
|
297 |
def _CheckOSVariant(os_obj, name): |
|
298 |
"""Check whether an OS name conforms to the os variants specification. |
|
299 |
|
|
300 |
@type os_obj: L{objects.OS} |
|
301 |
@param os_obj: OS object to check |
|
302 |
@type name: string |
|
303 |
@param name: OS name passed by the user, to check for validity |
|
304 |
|
|
305 |
""" |
|
306 |
variant = objects.OS.GetVariant(name) |
|
307 |
if not os_obj.supported_variants: |
|
308 |
if variant: |
|
309 |
raise errors.OpPrereqError("OS '%s' doesn't support variants ('%s'" |
|
310 |
" passed)" % (os_obj.name, variant), |
|
311 |
errors.ECODE_INVAL) |
|
312 |
return |
|
313 |
if not variant: |
|
314 |
raise errors.OpPrereqError("OS name must include a variant", |
|
315 |
errors.ECODE_INVAL) |
|
316 |
|
|
317 |
if variant not in os_obj.supported_variants: |
|
318 |
raise errors.OpPrereqError("Unsupported OS variant", errors.ECODE_INVAL) |
|
319 |
|
|
320 |
|
|
321 | 297 |
def _ComputeInstanceCommunicationNIC(instance_name): |
322 | 298 |
"""Compute the name of the instance NIC used by instance |
323 | 299 |
communication. |
b/test/py/cmdlib/instance_unittest.py | ||
---|---|---|
39 | 39 |
from ganeti.rpc import node as rpc |
40 | 40 |
from ganeti import utils |
41 | 41 |
from ganeti.cmdlib import instance |
42 |
from ganeti.cmdlib import instance_utils |
|
42 | 43 |
|
43 | 44 |
from cmdlib.cmdlib_unittest import _StubComputeIPolicySpecViolation, _FakeLU |
44 | 45 |
|
... | ... | |
743 | 744 |
class TestCheckOSVariant(CmdlibTestCase): |
744 | 745 |
def testNoVariantsSupported(self): |
745 | 746 |
os = self.cfg.CreateOs(supported_variants=[]) |
746 |
self.assertRaises(errors.OpPrereqError, instance._CheckOSVariant, |
|
747 |
self.assertRaises(errors.OpPrereqError, instance_utils._CheckOSVariant,
|
|
747 | 748 |
os, "os+variant") |
748 | 749 |
|
749 | 750 |
def testNoVariantGiven(self): |
750 | 751 |
os = self.cfg.CreateOs(supported_variants=["default"]) |
751 |
self.assertRaises(errors.OpPrereqError, instance._CheckOSVariant, |
|
752 |
self.assertRaises(errors.OpPrereqError, instance_utils._CheckOSVariant,
|
|
752 | 753 |
os, "os") |
753 | 754 |
|
754 | 755 |
def testWrongVariantGiven(self): |
755 | 756 |
os = self.cfg.CreateOs(supported_variants=["default"]) |
756 |
self.assertRaises(errors.OpPrereqError, instance._CheckOSVariant, |
|
757 |
self.assertRaises(errors.OpPrereqError, instance_utils._CheckOSVariant,
|
|
757 | 758 |
os, "os+wrong_variant") |
758 | 759 |
|
759 | 760 |
def testOkWithVariant(self): |
760 | 761 |
os = self.cfg.CreateOs(supported_variants=["default"]) |
761 |
instance._CheckOSVariant(os, "os+default") |
|
762 |
instance_utils._CheckOSVariant(os, "os+default")
|
|
762 | 763 |
|
763 | 764 |
def testOkWithoutVariant(self): |
764 | 765 |
os = self.cfg.CreateOs(supported_variants=[]) |
765 |
instance._CheckOSVariant(os, "os") |
|
766 |
instance_utils._CheckOSVariant(os, "os")
|
|
766 | 767 |
|
767 | 768 |
|
768 | 769 |
class TestCheckTargetNodeIPolicy(TestLUInstanceCreate): |
Also available in: Unified diff