Commit 8d77978d by Őry Máté

*: add missing readable_names

parent 5432a550
...@@ -264,9 +264,10 @@ class VmDetailVncTokenView(CheckedDetailView): ...@@ -264,9 +264,10 @@ class VmDetailVncTokenView(CheckedDetailView):
if not request.user.has_perm('vm.access_console'): if not request.user.has_perm('vm.access_console'):
raise PermissionDenied() raise PermissionDenied()
if self.object.node: if self.object.node:
with instance_activity(code_suffix='console-accessed', with instance_activity(
instance=self.object, user=request.user, code_suffix='console-accessed', instance=self.object,
concurrency_check=False): user=request.user, readable_name=ugettext_noop(
"console access"), concurrency_check=False):
port = self.object.vnc_port port = self.object.vnc_port
host = str(self.object.node.host.ipv4) host = str(self.object.node.host.ipv4)
value = signing.dumps({'host': host, 'port': port}, value = signing.dumps({'host': host, 'port': port},
......
...@@ -183,6 +183,8 @@ class InstanceActivity(ActivityModel): ...@@ -183,6 +183,8 @@ class InstanceActivity(ActivityModel):
concurrency_check=True): concurrency_check=True):
"""Create a transactional context for a nested instance activity. """Create a transactional context for a nested instance activity.
""" """
if not readable_name:
warn("Set readable_name", stacklevel=3)
act = self.create_sub(code_suffix, task_uuid, concurrency_check, act = self.create_sub(code_suffix, task_uuid, concurrency_check,
readable_name=readable_name) readable_name=readable_name)
return activitycontextimpl(act, on_abort=on_abort, on_commit=on_commit) return activitycontextimpl(act, on_abort=on_abort, on_commit=on_commit)
...@@ -190,11 +192,15 @@ class InstanceActivity(ActivityModel): ...@@ -190,11 +192,15 @@ class InstanceActivity(ActivityModel):
@contextmanager @contextmanager
def instance_activity(code_suffix, instance, on_abort=None, on_commit=None, def instance_activity(code_suffix, instance, on_abort=None, on_commit=None,
task_uuid=None, user=None, concurrency_check=True): task_uuid=None, user=None, concurrency_check=True,
readable_name=None):
"""Create a transactional context for an instance activity. """Create a transactional context for an instance activity.
""" """
if not readable_name:
warn("Set readable_name", stacklevel=3)
act = InstanceActivity.create(code_suffix, instance, task_uuid, user, act = InstanceActivity.create(code_suffix, instance, task_uuid, user,
concurrency_check) concurrency_check,
readable_name=readable_name)
return activitycontextimpl(act, on_abort=on_abort, on_commit=on_commit) return activitycontextimpl(act, on_abort=on_abort, on_commit=on_commit)
...@@ -248,8 +254,10 @@ class NodeActivity(ActivityModel): ...@@ -248,8 +254,10 @@ class NodeActivity(ActivityModel):
@contextmanager @contextmanager
def node_activity(code_suffix, node, task_uuid=None, user=None): def node_activity(code_suffix, node, task_uuid=None, user=None,
act = NodeActivity.create(code_suffix, node, task_uuid, user) readable_name=None):
act = NodeActivity.create(code_suffix, node, task_uuid, user,
readable_name=readable_name)
return activitycontextimpl(act) return activitycontextimpl(act)
......
...@@ -365,6 +365,7 @@ class Instance(AclBase, VirtualMachineDescModel, StatusModel, OperatedMixin, ...@@ -365,6 +365,7 @@ class Instance(AclBase, VirtualMachineDescModel, StatusModel, OperatedMixin,
activity.resultant_state = 'PENDING' activity.resultant_state = 'PENDING'
with instance_activity(code_suffix='create', instance=inst, with instance_activity(code_suffix='create', instance=inst,
readable_name=ugettext_noop("create instance"),
on_commit=__on_commit, user=inst.owner) as act: on_commit=__on_commit, user=inst.owner) as act:
# create related entities # create related entities
inst.disks.add(*[disk.get_exclusive() for disk in disks]) inst.disks.add(*[disk.get_exclusive() for disk in disks])
...@@ -449,8 +450,10 @@ class Instance(AclBase, VirtualMachineDescModel, StatusModel, OperatedMixin, ...@@ -449,8 +450,10 @@ class Instance(AclBase, VirtualMachineDescModel, StatusModel, OperatedMixin,
Can be used to recover VM after administrator fixed problems. Can be used to recover VM after administrator fixed problems.
""" """
# TODO cancel concurrent activity (if exists) # TODO cancel concurrent activity (if exists)
act = InstanceActivity.create(code_suffix='manual_state_change', act = InstanceActivity.create(
instance=self, user=user) code_suffix='manual_state_change', instance=self, user=user,
readable_name=create_readable(ugettext_noop(
"force %(state)s state"), state=new_state))
act.finished = act.started act.finished = act.started
act.result = reason act.result = reason
act.resultant_state = new_state act.resultant_state = new_state
...@@ -681,6 +684,8 @@ class Instance(AclBase, VirtualMachineDescModel, StatusModel, OperatedMixin, ...@@ -681,6 +684,8 @@ class Instance(AclBase, VirtualMachineDescModel, StatusModel, OperatedMixin,
success=len(success), successes=success) success=len(success), successes=success)
with instance_activity('notification_about_expiration', instance=self, with instance_activity('notification_about_expiration', instance=self,
readable_name=ugettext_noop(
"notify owner about expiration"),
on_commit=on_commit): on_commit=on_commit):
from dashboard.views import VmRenewView from dashboard.views import VmRenewView
level = self.get_level_object("owner") level = self.get_level_object("owner")
...@@ -745,6 +750,7 @@ class Instance(AclBase, VirtualMachineDescModel, StatusModel, OperatedMixin, ...@@ -745,6 +750,7 @@ class Instance(AclBase, VirtualMachineDescModel, StatusModel, OperatedMixin,
self.pw = pwgen() self.pw = pwgen()
with instance_activity(code_suffix='change_password', instance=self, with instance_activity(code_suffix='change_password', instance=self,
readable_name=ugettext_noop("change password"),
user=user): user=user):
queue = self.get_remote_queue_name("agent") queue = self.get_remote_queue_name("agent")
agent_tasks.change_password.apply_async(queue=queue, agent_tasks.change_password.apply_async(queue=queue,
......
...@@ -120,10 +120,14 @@ class Interface(Model): ...@@ -120,10 +120,14 @@ class Interface(Model):
host.hostname = instance.vm_name host.hostname = instance.vm_name
# Get addresses from firewall # Get addresses from firewall
if base_activity is None: if base_activity is None:
act_ctx = instance_activity(code_suffix='allocating_ip', act_ctx = instance_activity(
code_suffix='allocating_ip',
readable_name=ugettext_noop("allocate IP address"),
instance=instance, user=owner) instance=instance, user=owner)
else: else:
act_ctx = base_activity.sub_activity('allocating_ip') act_ctx = base_activity.sub_activity(
'allocating_ip',
readable_name=ugettext_noop("allocate IP address"))
with act_ctx as act: with act_ctx as act:
addresses = vlan.get_new_address() addresses = vlan.get_new_address()
host.ipv4 = addresses['ipv4'] host.ipv4 = addresses['ipv4']
......
...@@ -26,7 +26,7 @@ from django.db.models import ( ...@@ -26,7 +26,7 @@ from django.db.models import (
FloatField, permalink, FloatField, permalink,
) )
from django.utils import timezone from django.utils import timezone
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _, ugettext_noop
from celery.exceptions import TimeoutError from celery.exceptions import TimeoutError
from model_utils.models import TimeStampedModel from model_utils.models import TimeStampedModel
...@@ -141,9 +141,12 @@ class Node(OperatedMixin, TimeStampedModel): ...@@ -141,9 +141,12 @@ class Node(OperatedMixin, TimeStampedModel):
''' Disable the node.''' ''' Disable the node.'''
if self.enabled: if self.enabled:
if base_activity: if base_activity:
act_ctx = base_activity.sub_activity('disable') act_ctx = base_activity.sub_activity(
'disable', readable_name=ugettext_noop("disable node"))
else: else:
act_ctx = node_activity('disable', node=self, user=user) act_ctx = node_activity(
'disable', node=self, user=user,
readable_name=ugettext_noop("disable node"))
with act_ctx: with act_ctx:
self.enabled = False self.enabled = False
self.save() self.save()
......
...@@ -242,18 +242,24 @@ class DestroyOperation(InstanceOperation): ...@@ -242,18 +242,24 @@ class DestroyOperation(InstanceOperation):
def _operation(self, activity): def _operation(self, activity):
# Destroy networks # Destroy networks
with activity.sub_activity('destroying_net'): with activity.sub_activity(
'destroying_net',
readable_name=ugettext_noop("destroy network")):
if self.instance.node: if self.instance.node:
self.instance.shutdown_net() self.instance.shutdown_net()
self.instance.destroy_net() self.instance.destroy_net()
if self.instance.node: if self.instance.node:
# Delete virtual machine # Delete virtual machine
with activity.sub_activity('destroying_vm'): with activity.sub_activity(
'destroying_vm',
readable_name=ugettext_noop("destroy virtual machine")):
self.instance.delete_vm() self.instance.delete_vm()
# Destroy disks # Destroy disks
with activity.sub_activity('destroying_disks'): with activity.sub_activity(
'destroying_disks',
readable_name=ugettext_noop("destroy disks")):
self.instance.destroy_disks() self.instance.destroy_disks()
# Delete mem. dump if exists # Delete mem. dump if exists
...@@ -281,7 +287,9 @@ class MigrateOperation(InstanceOperation): ...@@ -281,7 +287,9 @@ class MigrateOperation(InstanceOperation):
required_perms = () required_perms = ()
def rollback(self, activity): def rollback(self, activity):
with activity.sub_activity('rollback_net'): with activity.sub_activity(
'rollback_net', readable_name=ugettext_noop(
"redeploy network (rollback)")):
self.instance.deploy_net() self.instance.deploy_net()
def check_precond(self): def check_precond(self):
...@@ -297,7 +305,9 @@ class MigrateOperation(InstanceOperation): ...@@ -297,7 +305,9 @@ class MigrateOperation(InstanceOperation):
def _operation(self, activity, to_node=None, timeout=120): def _operation(self, activity, to_node=None, timeout=120):
if not to_node: if not to_node:
with activity.sub_activity('scheduling') as sa: with activity.sub_activity('scheduling',
readable_name=ugettext_noop(
"schedule")) as sa:
to_node = self.instance.select_node() to_node = self.instance.select_node()
sa.result = to_node sa.result = to_node
...@@ -312,7 +322,9 @@ class MigrateOperation(InstanceOperation): ...@@ -312,7 +322,9 @@ class MigrateOperation(InstanceOperation):
raise raise
# Shutdown networks # Shutdown networks
with activity.sub_activity('shutdown_net'): with activity.sub_activity(
'shutdown_net', readable_name=ugettext_noop(
"shutdown network")):
self.instance.shutdown_net() self.instance.shutdown_net()
# Refresh node information # Refresh node information
...@@ -478,7 +490,8 @@ class SaveAsTemplateOperation(InstanceOperation): ...@@ -478,7 +490,8 @@ class SaveAsTemplateOperation(InstanceOperation):
return disk return disk
self.disks = [] self.disks = []
with activity.sub_activity('saving_disks'): with activity.sub_activity('saving_disks',
readable_name=ugettext_noop("save disks")):
for disk in self.instance.disks.all(): for disk in self.instance.disks.all():
self.disks.append(__try_save_disk(disk)) self.disks.append(__try_save_disk(disk))
...@@ -588,11 +601,14 @@ class SleepOperation(InstanceOperation): ...@@ -588,11 +601,14 @@ class SleepOperation(InstanceOperation):
def _operation(self, activity, timeout=240): def _operation(self, activity, timeout=240):
# Destroy networks # Destroy networks
with activity.sub_activity('shutdown_net'): with activity.sub_activity('shutdown_net', readable_name=ugettext_noop(
"shutdown network")):
self.instance.shutdown_net() self.instance.shutdown_net()
# Suspend vm # Suspend vm
with activity.sub_activity('suspending'): with activity.sub_activity('suspending',
readable_name=ugettext_noop(
"suspend virtual machine")):
self.instance.suspend_vm(timeout=timeout) self.instance.suspend_vm(timeout=timeout)
self.instance.yield_node() self.instance.yield_node()
...@@ -633,11 +649,15 @@ class WakeUpOperation(InstanceOperation): ...@@ -633,11 +649,15 @@ class WakeUpOperation(InstanceOperation):
self.instance.allocate_node() self.instance.allocate_node()
# Resume vm # Resume vm
with activity.sub_activity('resuming'): with activity.sub_activity(
'resuming', readable_name=ugettext_noop(
"resume virtual machine")):
self.instance.wake_up_vm(timeout=timeout) self.instance.wake_up_vm(timeout=timeout)
# Estabilish network connection (vmdriver) # Estabilish network connection (vmdriver)
with activity.sub_activity('deploying_net'): with activity.sub_activity(
'deploying_net', readable_name=ugettext_noop(
"deploy network")):
self.instance.deploy_net() self.instance.deploy_net()
# Renew vm # Renew vm
......
...@@ -112,7 +112,8 @@ class InstanceTestCase(TestCase): ...@@ -112,7 +112,8 @@ class InstanceTestCase(TestCase):
migrate_op(system=True) migrate_op(system=True)
migr.apply_async.assert_called() migr.apply_async.assert_called()
self.assertIn(call.sub_activity(u'scheduling'), act.mock_calls) self.assertIn(call.sub_activity(
u'scheduling', readable_name=u'schedule'), act.mock_calls)
inst.select_node.assert_called() inst.select_node.assert_called()
def test_migrate_wo_scheduling(self): def test_migrate_wo_scheduling(self):
...@@ -147,8 +148,11 @@ class InstanceTestCase(TestCase): ...@@ -147,8 +148,11 @@ class InstanceTestCase(TestCase):
self.assertRaises(Exception, migrate_op, system=True) self.assertRaises(Exception, migrate_op, system=True)
migr.apply_async.assert_called() migr.apply_async.assert_called()
self.assertIn(call.sub_activity(u'scheduling'), act.mock_calls) self.assertIn(call.sub_activity(
self.assertIn(call.sub_activity(u'rollback_net'), act.mock_calls) u'scheduling', readable_name=u'schedule'), act.mock_calls)
self.assertIn(call.sub_activity(
u'rollback_net', readable_name=u'redeploy network (rollback)'),
act.mock_calls)
inst.select_node.assert_called() inst.select_node.assert_called()
def test_status_icon(self): def test_status_icon(self):
...@@ -216,7 +220,8 @@ class InstanceActivityTestCase(TestCase): ...@@ -216,7 +220,8 @@ class InstanceActivityTestCase(TestCase):
instance.activity_log.filter.return_value.exists.return_value = True instance.activity_log.filter.return_value.exists.return_value = True
with self.assertRaises(ActivityInProgressError): with self.assertRaises(ActivityInProgressError):
InstanceActivity.create('test', instance, concurrency_check=True) InstanceActivity.create('test', instance, readable_name="test",
concurrency_check=True)
def test_create_no_concurrency_check(self): def test_create_no_concurrency_check(self):
instance = MagicMock(spec=Instance) instance = MagicMock(spec=Instance)
...@@ -229,7 +234,8 @@ class InstanceActivityTestCase(TestCase): ...@@ -229,7 +234,8 @@ class InstanceActivityTestCase(TestCase):
mock_instance_activity_cls, mock_instance_activity_cls,
original_create.im_class) original_create.im_class)
try: try:
mocked_create('test', instance, concurrency_check=False) mocked_create('test', instance, readable_name="test",
concurrency_check=False)
except ActivityInProgressError: except ActivityInProgressError:
raise AssertionError("'create' method checked for concurrent " raise AssertionError("'create' method checked for concurrent "
"activities.") "activities.")
...@@ -239,7 +245,8 @@ class InstanceActivityTestCase(TestCase): ...@@ -239,7 +245,8 @@ class InstanceActivityTestCase(TestCase):
iaobj.children.filter.return_value.exists.return_value = True iaobj.children.filter.return_value.exists.return_value = True
with self.assertRaises(ActivityInProgressError): with self.assertRaises(ActivityInProgressError):
InstanceActivity.create_sub(iaobj, "test", concurrency_check=True) InstanceActivity.create_sub(iaobj, "test", readable_name="test",
concurrency_check=True)
def test_create_sub_no_concurrency_check(self): def test_create_sub_no_concurrency_check(self):
iaobj = MagicMock(spec=InstanceActivity) iaobj = MagicMock(spec=InstanceActivity)
...@@ -249,7 +256,8 @@ class InstanceActivityTestCase(TestCase): ...@@ -249,7 +256,8 @@ class InstanceActivityTestCase(TestCase):
create_sub_func = InstanceActivity.create_sub create_sub_func = InstanceActivity.create_sub
with patch('vm.models.activity.InstanceActivity'): with patch('vm.models.activity.InstanceActivity'):
try: try:
create_sub_func(iaobj, 'test', concurrency_check=False) create_sub_func(iaobj, 'test', readable_name="test",
concurrency_check=False)
except ActivityInProgressError: except ActivityInProgressError:
raise AssertionError("'create_sub' method checked for " raise AssertionError("'create_sub' method checked for "
"concurrent activities.") "concurrent activities.")
......
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