#!/usr/bin/python
#
-# Copyright (C) 2008, 2011 Google Inc.
+# Copyright (C) 2008, 2011, 2012 Google Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
import shutil
import operator
import itertools
+import copy
from ganeti import constants
from ganeti import mcpu
}
def testNoneValue(self):
- self.assertTrue(cmdlib._ComputeMinMaxSpec(constants.ISPEC_MEM_SIZE,
+ self.assertTrue(cmdlib._ComputeMinMaxSpec(constants.ISPEC_MEM_SIZE, None,
self.ipolicy, None) is None)
def testAutoValue(self):
- self.assertTrue(cmdlib._ComputeMinMaxSpec(constants.ISPEC_MEM_SIZE,
+ self.assertTrue(cmdlib._ComputeMinMaxSpec(constants.ISPEC_MEM_SIZE, None,
self.ipolicy,
constants.VALUE_AUTO) is None)
def testNotDefined(self):
- self.assertTrue(cmdlib._ComputeMinMaxSpec(constants.ISPEC_NIC_COUNT,
+ self.assertTrue(cmdlib._ComputeMinMaxSpec(constants.ISPEC_NIC_COUNT, None,
self.ipolicy, 3) is None)
def testNoMinDefined(self):
- self.assertTrue(cmdlib._ComputeMinMaxSpec(constants.ISPEC_DISK_SIZE,
+ self.assertTrue(cmdlib._ComputeMinMaxSpec(constants.ISPEC_DISK_SIZE, None,
self.ipolicy, 128) is None)
def testNoMaxDefined(self):
- self.assertTrue(cmdlib._ComputeMinMaxSpec(constants.ISPEC_DISK_COUNT,
+ self.assertTrue(cmdlib._ComputeMinMaxSpec(constants.ISPEC_DISK_COUNT, None,
self.ipolicy, 16) is None)
def testOutOfRange(self):
(constants.ISPEC_DISK_COUNT, 0)):
min_v = self.ipolicy[constants.ISPECS_MIN].get(name, val)
max_v = self.ipolicy[constants.ISPECS_MAX].get(name, val)
- self.assertEqual(cmdlib._ComputeMinMaxSpec(name, self.ipolicy, val),
+ self.assertEqual(cmdlib._ComputeMinMaxSpec(name, None,
+ self.ipolicy, val),
"%s value %s is not in range [%s, %s]" %
(name, val,min_v, max_v))
+ self.assertEqual(cmdlib._ComputeMinMaxSpec(name, "1",
+ self.ipolicy, val),
+ "%s/1 value %s is not in range [%s, %s]" %
+ (name, val,min_v, max_v))
def test(self):
for (name, val) in ((constants.ISPEC_MEM_SIZE, 256),
(constants.ISPEC_DISK_SIZE, 0),
(constants.ISPEC_DISK_COUNT, 1),
(constants.ISPEC_DISK_COUNT, 5)):
- self.assertTrue(cmdlib._ComputeMinMaxSpec(name, self.ipolicy, val)
+ self.assertTrue(cmdlib._ComputeMinMaxSpec(name, None, self.ipolicy, val)
is None)
def test(self):
compute_fn = _ValidateComputeMinMaxSpec
ret = cmdlib._ComputeIPolicySpecViolation(NotImplemented, 1024, 1, 1, 1,
- [1024], _compute_fn=compute_fn)
+ [1024], 1, _compute_fn=compute_fn)
self.assertEqual(ret, [])
def testInvalidArguments(self):
self.assertRaises(AssertionError, cmdlib._ComputeIPolicySpecViolation,
- NotImplemented, 1024, 1, 1, 1, [])
+ NotImplemented, 1024, 1, 1, 1, [], 1)
def testInvalidSpec(self):
- spec = _SpecWrapper([None, False, "foo", None, "bar"])
+ spec = _SpecWrapper([None, False, "foo", None, "bar", None])
compute_fn = spec.ComputeMinMaxSpec
ret = cmdlib._ComputeIPolicySpecViolation(NotImplemented, 1024, 1, 1, 1,
- [1024], _compute_fn=compute_fn)
+ [1024], 1, _compute_fn=compute_fn)
self.assertEqual(ret, ["foo", "bar"])
self.assertFalse(spec.spec)
class _StubComputeIPolicySpecViolation:
- def __init__(self, mem_size, cpu_count, disk_count, nic_count, disk_sizes):
+ def __init__(self, mem_size, cpu_count, disk_count, nic_count, disk_sizes,
+ spindle_use):
self.mem_size = mem_size
self.cpu_count = cpu_count
self.disk_count = disk_count
self.nic_count = nic_count
self.disk_sizes = disk_sizes
+ self.spindle_use = spindle_use
- def __call__(self, _, mem_size, cpu_count, disk_count, nic_count, disk_sizes):
+ def __call__(self, _, mem_size, cpu_count, disk_count, nic_count, disk_sizes,
+ spindle_use):
assert self.mem_size == mem_size
assert self.cpu_count == cpu_count
assert self.disk_count == disk_count
assert self.nic_count == nic_count
assert self.disk_sizes == disk_sizes
+ assert self.spindle_use == spindle_use
return []
beparams = {
constants.BE_MAXMEM: 2048,
constants.BE_VCPUS: 2,
+ constants.BE_SPINDLE_USE: 4,
}
disks = [objects.Disk(size=512)]
instance = objects.Instance(beparams=beparams, disks=disks, nics=[])
- stub = _StubComputeIPolicySpecViolation(2048, 2, 1, 0, [512])
+ stub = _StubComputeIPolicySpecViolation(2048, 2, 1, 0, [512], 4)
ret = cmdlib._ComputeIPolicyInstanceViolation(NotImplemented, instance,
_compute_fn=stub)
self.assertEqual(ret, [])
constants.ISPEC_DISK_COUNT: 1,
constants.ISPEC_DISK_SIZE: [512],
constants.ISPEC_NIC_COUNT: 0,
+ constants.ISPEC_SPINDLE_USE: 1,
}
- stub = _StubComputeIPolicySpecViolation(2048, 2, 1, 0, [512])
+ stub = _StubComputeIPolicySpecViolation(2048, 2, 1, 0, [512], 1)
ret = cmdlib._ComputeIPolicyInstanceSpecViolation(NotImplemented, ispec,
_compute_fn=stub)
self.assertEqual(ret, [])
def GenerateDRBDSecret(self, ec_id):
return "ec%s-secret%s" % (ec_id, self._secret.next())
+ def GetInstanceInfo(self, _):
+ return "foobar"
+
class _FakeProcForGenDiskTemplate:
def GetECId(self):
self.lu = _FakeLU(cfg=cfg, proc=proc)
self.nodegroup = nodegroup
+ @staticmethod
+ def GetDiskParams():
+ return copy.deepcopy(constants.DISK_DT_DEFAULTS)
+
def testWrongDiskTemplate(self):
gdt = cmdlib._GenerateDiskTemplate
disk_template = "##unknown##"
self.assertRaises(errors.ProgrammerError, gdt, self.lu, disk_template,
"inst26831.example.com", "node30113.example.com", [], [],
NotImplemented, NotImplemented, 0, self.lu.LogInfo,
- self.nodegroup.diskparams)
+ self.GetDiskParams())
def testDiskless(self):
gdt = cmdlib._GenerateDiskTemplate
result = gdt(self.lu, constants.DT_DISKLESS, "inst27734.example.com",
"node30113.example.com", [], [],
NotImplemented, NotImplemented, 0, self.lu.LogInfo,
- self.nodegroup.diskparams)
+ self.GetDiskParams())
self.assertEqual(result, [])
def _TestTrivialDisk(self, template, disk_info, base_index, exp_dev_type,
template, "inst25088.example.com",
"node185.example.com", ["node323.example.com"], [],
NotImplemented, NotImplemented, base_index,
- self.lu.LogInfo, self.nodegroup.diskparams,
+ self.lu.LogInfo, self.GetDiskParams(),
_req_file_storage=req_file_storage,
_req_shr_file_storage=req_shr_file_storage)
result = gdt(self.lu, template, "inst21662.example.com",
"node21741.example.com", [],
disk_info, file_storage_dir, file_driver, base_index,
- self.lu.LogInfo, self.nodegroup.diskparams,
+ self.lu.LogInfo, self.GetDiskParams(),
_req_file_storage=req_file_storage,
_req_shr_file_storage=req_shr_file_storage)
self.assertEqual(disk.mode, disk_info[idx][constants.IDISK_MODE])
self.assertTrue(disk.children is None)
- self.assertEqual(map(operator.attrgetter("iv_name"), result),
- ["disk/%s" % i for i in range(base_index, base_index + len(disk_info))])
+ self._CheckIvNames(result, base_index, base_index + len(disk_info))
+ cmdlib._UpdateIvNames(base_index, result)
+ self._CheckIvNames(result, base_index, base_index + len(disk_info))
return result
+ def _CheckIvNames(self, disks, base_index, end_index):
+ self.assertEqual(map(operator.attrgetter("iv_name"), disks),
+ ["disk/%s" % i for i in range(base_index, end_index)])
+
def testPlain(self):
disk_info = [{
constants.IDISK_SIZE: 1024,
self.assertRaises(errors.ProgrammerError, gdt, self.lu, constants.DT_DRBD8,
"inst827.example.com", "node1334.example.com", [],
disk_info, NotImplemented, NotImplemented, 0,
- self.lu.LogInfo, self.nodegroup.diskparams)
+ self.lu.LogInfo, self.GetDiskParams())
result = gdt(self.lu, constants.DT_DRBD8, "inst827.example.com",
"node1334.example.com", ["node12272.example.com"],
disk_info, NotImplemented, NotImplemented, 0, self.lu.LogInfo,
- self.nodegroup.diskparams)
+ self.GetDiskParams())
for (idx, disk) in enumerate(result):
self.assertTrue(isinstance(disk, objects.Disk))
self.assertEqual(disk.children[0].size, disk.size)
self.assertEqual(disk.children[1].size, cmdlib.DRBD_META_SIZE)
- self.assertEqual(map(operator.attrgetter("iv_name"), result),
- ["disk/0", "disk/1", "disk/2"])
+ self._CheckIvNames(result, 0, len(disk_info))
+ cmdlib._UpdateIvNames(0, result)
+ self._CheckIvNames(result, 0, len(disk_info))
self.assertEqual(map(operator.attrgetter("logical_id"), result), [
("node1334.example.com", "node12272.example.com",