Commit b0c5e369 by Őry Máté

vm: extract Instance._do_renew

Fixes unit tests.
parent 9f93161b
...@@ -302,7 +302,7 @@ class Instance(AclBase, VirtualMachineDescModel, TimeStampedModel): ...@@ -302,7 +302,7 @@ class Instance(AclBase, VirtualMachineDescModel, TimeStampedModel):
def clean(self, *args, **kwargs): def clean(self, *args, **kwargs):
if self.time_of_delete is None: if self.time_of_delete is None:
self.renew(which='delete') self._do_renew(which='delete')
super(Instance, self).clean(*args, **kwargs) super(Instance, self).clean(*args, **kwargs)
@classmethod @classmethod
...@@ -632,6 +632,15 @@ class Instance(AclBase, VirtualMachineDescModel, TimeStampedModel): ...@@ -632,6 +632,15 @@ class Instance(AclBase, VirtualMachineDescModel, TimeStampedModel):
timezone.now() + self.lease.suspend_interval, timezone.now() + self.lease.suspend_interval,
timezone.now() + self.lease.delete_interval) timezone.now() + self.lease.delete_interval)
def _do_renew(self, which='both'):
"""Set expiration times to renewed values.
"""
time_of_suspend, time_of_delete = self.get_renew_times()
if which in ('suspend', 'both'):
self.time_of_suspend = time_of_suspend
if which in ('delete', 'both'):
self.time_of_delete = time_of_delete
def renew(self, which='both', base_activity=None, user=None): def renew(self, which='both', base_activity=None, user=None):
"""Renew virtual machine instance leases. """Renew virtual machine instance leases.
""" """
...@@ -643,11 +652,7 @@ class Instance(AclBase, VirtualMachineDescModel, TimeStampedModel): ...@@ -643,11 +652,7 @@ class Instance(AclBase, VirtualMachineDescModel, TimeStampedModel):
with act: with act:
if which not in ('suspend', 'delete', 'both'): if which not in ('suspend', 'delete', 'both'):
raise ValueError('No such expiration type.') raise ValueError('No such expiration type.')
time_of_suspend, time_of_delete = self.get_renew_times() self._do_renew(which)
if which in ('suspend', 'both'):
self.time_of_suspend = time_of_suspend
if which in ('delete', 'both'):
self.time_of_delete = time_of_delete
self.save() self.save()
def change_password(self, user=None): def change_password(self, user=None):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment