Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Fukász Rómeó Ervin
/
cloud
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
8d77978d
authored
Jul 19, 2014
by
Őry Máté
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
*: add missing readable_names
parent
5432a550
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
82 additions
and
32 deletions
+82
-32
circle/dashboard/views.py
+4
-3
circle/vm/models/activity.py
+12
-4
circle/vm/models/instance.py
+8
-2
circle/vm/models/network.py
+6
-2
circle/vm/models/node.py
+6
-3
circle/vm/operations.py
+31
-11
circle/vm/tests/test_models.py
+15
-7
No files found.
circle/dashboard/views.py
View file @
8d77978d
...
...
@@ -264,9 +264,10 @@ class VmDetailVncTokenView(CheckedDetailView):
if
not
request
.
user
.
has_perm
(
'vm.access_console'
):
raise
PermissionDenied
()
if
self
.
object
.
node
:
with
instance_activity
(
code_suffix
=
'console-accessed'
,
instance
=
self
.
object
,
user
=
request
.
user
,
concurrency_check
=
False
):
with
instance_activity
(
code_suffix
=
'console-accessed'
,
instance
=
self
.
object
,
user
=
request
.
user
,
readable_name
=
ugettext_noop
(
"console access"
),
concurrency_check
=
False
):
port
=
self
.
object
.
vnc_port
host
=
str
(
self
.
object
.
node
.
host
.
ipv4
)
value
=
signing
.
dumps
({
'host'
:
host
,
'port'
:
port
},
...
...
circle/vm/models/activity.py
View file @
8d77978d
...
...
@@ -183,6 +183,8 @@ class InstanceActivity(ActivityModel):
concurrency_check
=
True
):
"""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
,
readable_name
=
readable_name
)
return
activitycontextimpl
(
act
,
on_abort
=
on_abort
,
on_commit
=
on_commit
)
...
...
@@ -190,11 +192,15 @@ class InstanceActivity(ActivityModel):
@contextmanager
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.
"""
if
not
readable_name
:
warn
(
"Set readable_name"
,
stacklevel
=
3
)
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
)
...
...
@@ -248,8 +254,10 @@ class NodeActivity(ActivityModel):
@contextmanager
def
node_activity
(
code_suffix
,
node
,
task_uuid
=
None
,
user
=
None
):
act
=
NodeActivity
.
create
(
code_suffix
,
node
,
task_uuid
,
user
)
def
node_activity
(
code_suffix
,
node
,
task_uuid
=
None
,
user
=
None
,
readable_name
=
None
):
act
=
NodeActivity
.
create
(
code_suffix
,
node
,
task_uuid
,
user
,
readable_name
=
readable_name
)
return
activitycontextimpl
(
act
)
...
...
circle/vm/models/instance.py
View file @
8d77978d
...
...
@@ -365,6 +365,7 @@ class Instance(AclBase, VirtualMachineDescModel, StatusModel, OperatedMixin,
activity
.
resultant_state
=
'PENDING'
with
instance_activity
(
code_suffix
=
'create'
,
instance
=
inst
,
readable_name
=
ugettext_noop
(
"create instance"
),
on_commit
=
__on_commit
,
user
=
inst
.
owner
)
as
act
:
# create related entities
inst
.
disks
.
add
(
*
[
disk
.
get_exclusive
()
for
disk
in
disks
])
...
...
@@ -449,8 +450,10 @@ class Instance(AclBase, VirtualMachineDescModel, StatusModel, OperatedMixin,
Can be used to recover VM after administrator fixed problems.
"""
# TODO cancel concurrent activity (if exists)
act
=
InstanceActivity
.
create
(
code_suffix
=
'manual_state_change'
,
instance
=
self
,
user
=
user
)
act
=
InstanceActivity
.
create
(
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
.
result
=
reason
act
.
resultant_state
=
new_state
...
...
@@ -681,6 +684,8 @@ class Instance(AclBase, VirtualMachineDescModel, StatusModel, OperatedMixin,
success
=
len
(
success
),
successes
=
success
)
with
instance_activity
(
'notification_about_expiration'
,
instance
=
self
,
readable_name
=
ugettext_noop
(
"notify owner about expiration"
),
on_commit
=
on_commit
):
from
dashboard.views
import
VmRenewView
level
=
self
.
get_level_object
(
"owner"
)
...
...
@@ -745,6 +750,7 @@ class Instance(AclBase, VirtualMachineDescModel, StatusModel, OperatedMixin,
self
.
pw
=
pwgen
()
with
instance_activity
(
code_suffix
=
'change_password'
,
instance
=
self
,
readable_name
=
ugettext_noop
(
"change password"
),
user
=
user
):
queue
=
self
.
get_remote_queue_name
(
"agent"
)
agent_tasks
.
change_password
.
apply_async
(
queue
=
queue
,
...
...
circle/vm/models/network.py
View file @
8d77978d
...
...
@@ -120,10 +120,14 @@ class Interface(Model):
host
.
hostname
=
instance
.
vm_name
# Get addresses from firewall
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
)
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
:
addresses
=
vlan
.
get_new_address
()
host
.
ipv4
=
addresses
[
'ipv4'
]
...
...
circle/vm/models/node.py
View file @
8d77978d
...
...
@@ -26,7 +26,7 @@ from django.db.models import (
FloatField
,
permalink
,
)
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
model_utils.models
import
TimeStampedModel
...
...
@@ -141,9 +141,12 @@ class Node(OperatedMixin, TimeStampedModel):
''' Disable the node.'''
if
self
.
enabled
:
if
base_activity
:
act_ctx
=
base_activity
.
sub_activity
(
'disable'
)
act_ctx
=
base_activity
.
sub_activity
(
'disable'
,
readable_name
=
ugettext_noop
(
"disable node"
))
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
:
self
.
enabled
=
False
self
.
save
()
...
...
circle/vm/operations.py
View file @
8d77978d
...
...
@@ -242,18 +242,24 @@ class DestroyOperation(InstanceOperation):
def
_operation
(
self
,
activity
):
# Destroy networks
with
activity
.
sub_activity
(
'destroying_net'
):
with
activity
.
sub_activity
(
'destroying_net'
,
readable_name
=
ugettext_noop
(
"destroy network"
)):
if
self
.
instance
.
node
:
self
.
instance
.
shutdown_net
()
self
.
instance
.
destroy_net
()
if
self
.
instance
.
node
:
# 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
()
# Destroy disks
with
activity
.
sub_activity
(
'destroying_disks'
):
with
activity
.
sub_activity
(
'destroying_disks'
,
readable_name
=
ugettext_noop
(
"destroy disks"
)):
self
.
instance
.
destroy_disks
()
# Delete mem. dump if exists
...
...
@@ -281,7 +287,9 @@ class MigrateOperation(InstanceOperation):
required_perms
=
()
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
()
def
check_precond
(
self
):
...
...
@@ -297,7 +305,9 @@ class MigrateOperation(InstanceOperation):
def
_operation
(
self
,
activity
,
to_node
=
None
,
timeout
=
120
):
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
()
sa
.
result
=
to_node
...
...
@@ -312,7 +322,9 @@ class MigrateOperation(InstanceOperation):
raise
# Shutdown networks
with
activity
.
sub_activity
(
'shutdown_net'
):
with
activity
.
sub_activity
(
'shutdown_net'
,
readable_name
=
ugettext_noop
(
"shutdown network"
)):
self
.
instance
.
shutdown_net
()
# Refresh node information
...
...
@@ -478,7 +490,8 @@ class SaveAsTemplateOperation(InstanceOperation):
return
disk
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
():
self
.
disks
.
append
(
__try_save_disk
(
disk
))
...
...
@@ -588,11 +601,14 @@ class SleepOperation(InstanceOperation):
def
_operation
(
self
,
activity
,
timeout
=
240
):
# Destroy networks
with
activity
.
sub_activity
(
'shutdown_net'
):
with
activity
.
sub_activity
(
'shutdown_net'
,
readable_name
=
ugettext_noop
(
"shutdown network"
)):
self
.
instance
.
shutdown_net
()
# 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
.
yield_node
()
...
...
@@ -633,11 +649,15 @@ class WakeUpOperation(InstanceOperation):
self
.
instance
.
allocate_node
()
# 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
)
# 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
()
# Renew vm
...
...
circle/vm/tests/test_models.py
View file @
8d77978d
...
...
@@ -112,7 +112,8 @@ class InstanceTestCase(TestCase):
migrate_op
(
system
=
True
)
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
()
def
test_migrate_wo_scheduling
(
self
):
...
...
@@ -147,8 +148,11 @@ class InstanceTestCase(TestCase):
self
.
assertRaises
(
Exception
,
migrate_op
,
system
=
True
)
migr
.
apply_async
.
assert_called
()
self
.
assertIn
(
call
.
sub_activity
(
u'scheduling'
),
act
.
mock_calls
)
self
.
assertIn
(
call
.
sub_activity
(
u'rollback_net'
),
act
.
mock_calls
)
self
.
assertIn
(
call
.
sub_activity
(
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
()
def
test_status_icon
(
self
):
...
...
@@ -216,7 +220,8 @@ class InstanceActivityTestCase(TestCase):
instance
.
activity_log
.
filter
.
return_value
.
exists
.
return_value
=
True
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
):
instance
=
MagicMock
(
spec
=
Instance
)
...
...
@@ -229,7 +234,8 @@ class InstanceActivityTestCase(TestCase):
mock_instance_activity_cls
,
original_create
.
im_class
)
try
:
mocked_create
(
'test'
,
instance
,
concurrency_check
=
False
)
mocked_create
(
'test'
,
instance
,
readable_name
=
"test"
,
concurrency_check
=
False
)
except
ActivityInProgressError
:
raise
AssertionError
(
"'create' method checked for concurrent "
"activities."
)
...
...
@@ -239,7 +245,8 @@ class InstanceActivityTestCase(TestCase):
iaobj
.
children
.
filter
.
return_value
.
exists
.
return_value
=
True
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
):
iaobj
=
MagicMock
(
spec
=
InstanceActivity
)
...
...
@@ -249,7 +256,8 @@ class InstanceActivityTestCase(TestCase):
create_sub_func
=
InstanceActivity
.
create_sub
with
patch
(
'vm.models.activity.InstanceActivity'
):
try
:
create_sub_func
(
iaobj
,
'test'
,
concurrency_check
=
False
)
create_sub_func
(
iaobj
,
'test'
,
readable_name
=
"test"
,
concurrency_check
=
False
)
except
ActivityInProgressError
:
raise
AssertionError
(
"'create_sub' method checked for "
"concurrent activities."
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment