2012/11/8 Helga Velroyen <hel...@google.com>:
> --- a/lib/cmdlib.pyI don't think you need this. “recalculate_locks” is only used by one
> +++ b/lib/cmdlib.py
> @@ -12669,14 +12669,24 @@ class LUInstanceSetParams(LogicalUnit):
>
> def ExpandNames(self):
> self._ExpandAndLockInstance()
> + self.needed_locks[locking.LEVEL_NODEGROUP] = []
> # Can't even acquire node locks in shared mode as upcoming changes in
> # Ganeti 2.6 will start to modify the node object on disk conversion
> self.needed_locks[locking.LEVEL_NODE] = []
> self.needed_locks[locking.LEVEL_NODE_RES] = []
> self.recalculate_locks[locking.LEVEL_NODE] = constants.LOCKS_REPLACE
> + self.recalculate_locks[locking.LEVEL_NODEGROUP] = constants.LOCKS_REPLACE
or two functions and you don't seem to use them.
No need for the variable:
> + # Look node group to look up the ipolicy
> + self.share_locks[locking.LEVEL_NODEGROUP] = 1
>
> def DeclareLocks(self, level):
> - # TODO: Acquire group lock in shared mode (disk parameters)
> + if level == locking.LEVEL_NODEGROUP:
> + assert not self.needed_locks[locking.LEVEL_NODEGROUP]
> + # Acquire locks for the instance's nodegroups optimistically. Needs
> + # to be verified in CheckPrereq
> + instance_groups = self.cfg.GetInstanceNodeGroups(self.op.instance_name)
> + self.needed_locks[locking.LEVEL_NODEGROUP] = instance_groups
self.needed_locks[locking.LEVEL_NODEGROUP] = \
self.cfg.GetInstanceNodeGroups(self.op.instance_name)
This should be an “elif” now.
> +
> if level == locking.LEVEL_NODE:
> […]
> self._LockInstancesNodes()
> if self.op.disk_template and self.op.remote_node:
> + # dictionary with instance information after the modificationPlease don't use the “foo if x else bar” syntax yet. You should use
> + ispec = {}
> +
> # Prepare disk/NIC modifications
> self.diskmod = PrepareContainerMods(self.op.disks, None)
> self.nicmod = PrepareContainerMods(self.op.nics, _InstNicModPrivate)
> @@ -13039,6 +13058,12 @@ class LUInstanceSetParams(LogicalUnit):
> raise errors.OpPrereqError("Instance has too many disks (%d), cannot add"
> " more" % constants.MAX_DISKS,
> errors.ECODE_STATE)
> + ispec[constants.ISPEC_DISK_COUNT] = len(disks)
> + # Retrieve the disk size from the old disks given of type
> + # ganeti.objects.Disk and of the new ones specified as dict
> + disk_sizes = [disk["size"] if type(disk) is dict else
> + disk.size for disk in disks]
“isinstance” instead of directly comparing types. Also, why would you
expect two different forms here?
2012/11/9 Helga Velroyen <hel...@google.com>:
> On Thu, Nov 8, 2012 at 8:11 PM, Michael Hanselmann <han...@google.com>
> wrote:
>> 2012/11/8 Helga Velroyen <hel...@google.com>:
>> > --- a/lib/cmdlib.py
>> > +++ b/lib/cmdlib.py
>> > + self.recalculate_locks[locking.LEVEL_NODEGROUP] =Agreed for the nodes. Do you actually need it for groups (which you
>> > constants.LOCKS_REPLACE
>>
>> I don't think you need this. “recalculate_locks” is only used by one
>> or two functions and you don't seem to use them.
>
> I call the _LockInstancesNodes method in my DeclareLocks method and it
> checks if self.recalculate_locks is set for that particular level. I tried
> without setting the "recalculate_locks" and I actually get the error
> "_LockInstancesNodes helper function called with no nodes to recalculate".
now add), though?
2012/11/12 Helga Velroyen <hel...@google.com>:
> + res = list(set(res_max + res_min))You don't have to convert to list, CommaJoin can work with sets too.
Maybe you should use “sorted” instead?
Rest LGTM.
> + # FIXME: Improve error message by including information about whether the
> + # upper or lower limit of the parameter fails the ipolicy.
> + if not self.op.ignore_ipolicy and (res_max or res_min):
> + msg = ("Instance allocation to group %s (%s) violates policy: %s" %
> + (group_info, group_info.name, utils.CommaJoin(res)))
> + raise errors.OpPrereqError(msg, errors.ECODE_INVAL)
2012/11/13 Helga Velroyen <hel...@google.com>:
> + if not self.op.ignore_ipolicy and (res_max or res_min):Thinking about it now, do you actually have to do the whole
computation if the result is ignored anyway?
You're missing a recalculate_locks at level nodegroup here.
Thanks,
Guido