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
6b4499cc
authored
Jul 03, 2014
by
Bach Dániel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
vm: add precondition checks
parent
9c872372
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
33 additions
and
0 deletions
+33
-0
circle/vm/operations.py
+30
-0
circle/vm/tests/test_models.py
+3
-0
No files found.
circle/vm/operations.py
View file @
6b4499cc
...
@@ -157,6 +157,11 @@ class DeployOperation(InstanceOperation):
...
@@ -157,6 +157,11 @@ class DeployOperation(InstanceOperation):
name
=
_
(
"deploy"
)
name
=
_
(
"deploy"
)
description
=
_
(
"Deploy new virtual machine with network."
)
description
=
_
(
"Deploy new virtual machine with network."
)
def
check_precond
(
self
):
super
(
DeployOperation
,
self
)
.
check_precond
()
if
self
.
instance
.
status
in
[
'RUNNING'
,
'SUSPENDED'
]:
raise
self
.
instance
.
WrongStateError
(
self
.
instance
)
def
on_commit
(
self
,
activity
):
def
on_commit
(
self
,
activity
):
activity
.
resultant_state
=
'RUNNING'
activity
.
resultant_state
=
'RUNNING'
...
@@ -238,6 +243,11 @@ class MigrateOperation(InstanceOperation):
...
@@ -238,6 +243,11 @@ class MigrateOperation(InstanceOperation):
with
activity
.
sub_activity
(
'rollback_net'
):
with
activity
.
sub_activity
(
'rollback_net'
):
self
.
instance
.
deploy_net
()
self
.
instance
.
deploy_net
()
def
check_precond
(
self
):
super
(
MigrateOperation
,
self
)
.
check_precond
()
if
self
.
instance
.
status
not
in
[
'RUNNING'
]:
raise
self
.
instance
.
WrongStateError
(
self
.
instance
)
def
check_auth
(
self
,
user
):
def
check_auth
(
self
,
user
):
if
not
user
.
is_superuser
:
if
not
user
.
is_superuser
:
raise
PermissionDenied
()
raise
PermissionDenied
()
...
@@ -279,6 +289,11 @@ class RebootOperation(InstanceOperation):
...
@@ -279,6 +289,11 @@ class RebootOperation(InstanceOperation):
name
=
_
(
"reboot"
)
name
=
_
(
"reboot"
)
description
=
_
(
"Reboot virtual machine with Ctrl+Alt+Del signal."
)
description
=
_
(
"Reboot virtual machine with Ctrl+Alt+Del signal."
)
def
check_precond
(
self
):
super
(
RebootOperation
,
self
)
.
check_precond
()
if
self
.
instance
.
status
not
in
[
'RUNNING'
]:
raise
self
.
instance
.
WrongStateError
(
self
.
instance
)
def
_operation
(
self
,
timeout
=
5
):
def
_operation
(
self
,
timeout
=
5
):
self
.
instance
.
reboot_vm
(
timeout
=
timeout
)
self
.
instance
.
reboot_vm
(
timeout
=
timeout
)
...
@@ -329,6 +344,11 @@ class ResetOperation(InstanceOperation):
...
@@ -329,6 +344,11 @@ class ResetOperation(InstanceOperation):
name
=
_
(
"reset"
)
name
=
_
(
"reset"
)
description
=
_
(
"Reset virtual machine (reset button)."
)
description
=
_
(
"Reset virtual machine (reset button)."
)
def
check_precond
(
self
):
super
(
ResetOperation
,
self
)
.
check_precond
()
if
self
.
instance
.
status
not
in
[
'RUNNING'
]:
raise
self
.
instance
.
WrongStateError
(
self
.
instance
)
def
_operation
(
self
,
timeout
=
5
):
def
_operation
(
self
,
timeout
=
5
):
self
.
instance
.
reset_vm
(
timeout
=
timeout
)
self
.
instance
.
reset_vm
(
timeout
=
timeout
)
...
@@ -362,6 +382,11 @@ class SaveAsTemplateOperation(InstanceOperation):
...
@@ -362,6 +382,11 @@ class SaveAsTemplateOperation(InstanceOperation):
for
disk
in
self
.
disks
:
for
disk
in
self
.
disks
:
disk
.
destroy
()
disk
.
destroy
()
def
check_precond
(
self
):
super
(
SaveAsTemplateOperation
,
self
)
.
check_precond
()
if
self
.
instance
.
status
not
in
[
'RUNNING'
,
'PENDING'
,
'STOPPED'
]:
raise
self
.
instance
.
WrongStateError
(
self
.
instance
)
def
_operation
(
self
,
activity
,
user
,
system
,
timeout
=
300
,
name
=
None
,
def
_operation
(
self
,
activity
,
user
,
system
,
timeout
=
300
,
name
=
None
,
with_shutdown
=
True
,
task
=
None
,
**
kwargs
):
with_shutdown
=
True
,
task
=
None
,
**
kwargs
):
if
with_shutdown
:
if
with_shutdown
:
...
@@ -456,6 +481,11 @@ class ShutOffOperation(InstanceOperation):
...
@@ -456,6 +481,11 @@ class ShutOffOperation(InstanceOperation):
name
=
_
(
"shut off"
)
name
=
_
(
"shut off"
)
description
=
_
(
"Shut off VM (plug-out)."
)
description
=
_
(
"Shut off VM (plug-out)."
)
def
check_precond
(
self
):
super
(
ShutOffOperation
,
self
)
.
check_precond
()
if
self
.
instance
.
status
not
in
[
'RUNNING'
]:
raise
self
.
instance
.
WrongStateError
(
self
.
instance
)
def
on_commit
(
self
,
activity
):
def
on_commit
(
self
,
activity
):
activity
.
resultant_state
=
'STOPPED'
activity
.
resultant_state
=
'STOPPED'
...
...
circle/vm/tests/test_models.py
View file @
6b4499cc
...
@@ -103,6 +103,7 @@ class InstanceTestCase(TestCase):
...
@@ -103,6 +103,7 @@ class InstanceTestCase(TestCase):
inst
=
Mock
(
destroyed_at
=
None
,
spec
=
Instance
)
inst
=
Mock
(
destroyed_at
=
None
,
spec
=
Instance
)
inst
.
interface_set
.
all
.
return_value
=
[]
inst
.
interface_set
.
all
.
return_value
=
[]
inst
.
node
=
MagicMock
(
spec
=
Node
)
inst
.
node
=
MagicMock
(
spec
=
Node
)
inst
.
status
=
'RUNNING'
migrate_op
=
MigrateOperation
(
inst
)
migrate_op
=
MigrateOperation
(
inst
)
with
patch
(
'vm.models.instance.vm_tasks.migrate'
)
as
migr
:
with
patch
(
'vm.models.instance.vm_tasks.migrate'
)
as
migr
:
act
=
MagicMock
()
act
=
MagicMock
()
...
@@ -118,6 +119,7 @@ class InstanceTestCase(TestCase):
...
@@ -118,6 +119,7 @@ class InstanceTestCase(TestCase):
inst
=
MagicMock
(
destroyed_at
=
None
,
spec
=
Instance
)
inst
=
MagicMock
(
destroyed_at
=
None
,
spec
=
Instance
)
inst
.
interface_set
.
all
.
return_value
=
[]
inst
.
interface_set
.
all
.
return_value
=
[]
inst
.
node
=
MagicMock
(
spec
=
Node
)
inst
.
node
=
MagicMock
(
spec
=
Node
)
inst
.
status
=
'RUNNING'
migrate_op
=
MigrateOperation
(
inst
)
migrate_op
=
MigrateOperation
(
inst
)
with
patch
(
'vm.models.instance.vm_tasks.migrate'
)
as
migr
:
with
patch
(
'vm.models.instance.vm_tasks.migrate'
)
as
migr
:
inst
.
select_node
.
side_effect
=
AssertionError
inst
.
select_node
.
side_effect
=
AssertionError
...
@@ -133,6 +135,7 @@ class InstanceTestCase(TestCase):
...
@@ -133,6 +135,7 @@ class InstanceTestCase(TestCase):
inst
=
Mock
(
destroyed_at
=
None
,
spec
=
Instance
)
inst
=
Mock
(
destroyed_at
=
None
,
spec
=
Instance
)
inst
.
interface_set
.
all
.
return_value
=
[]
inst
.
interface_set
.
all
.
return_value
=
[]
inst
.
node
=
MagicMock
(
spec
=
Node
)
inst
.
node
=
MagicMock
(
spec
=
Node
)
inst
.
status
=
'RUNNING'
e
=
Exception
(
'abc'
)
e
=
Exception
(
'abc'
)
setattr
(
e
,
'libvirtError'
,
''
)
setattr
(
e
,
'libvirtError'
,
''
)
inst
.
migrate_vm
.
side_effect
=
e
inst
.
migrate_vm
.
side_effect
=
e
...
...
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