Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Gutyán Gábor
/
circlestack
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
0b3c50f3
authored
Mar 31, 2014
by
Dudás Ádám
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
vm: fix tests
parent
1fd46fee
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
38 additions
and
23 deletions
+38
-23
circle/vm/tests/test_models.py
+38
-23
No files found.
circle/vm/tests/test_models.py
View file @
0b3c50f3
...
@@ -9,6 +9,9 @@ from ..models import (
...
@@ -9,6 +9,9 @@ from ..models import (
Lease
,
Node
,
Interface
,
Instance
,
InstanceTemplate
,
InstanceActivity
,
Lease
,
Node
,
Interface
,
Instance
,
InstanceTemplate
,
InstanceActivity
,
)
)
from
..models.instance
import
find_unused_port
,
ActivityInProgressError
from
..models.instance
import
find_unused_port
,
ActivityInProgressError
from
..models.operation
import
(
DeployOperation
,
DestroyOperation
,
MigrateOperation
)
class
PortFinderTestCase
(
TestCase
):
class
PortFinderTestCase
(
TestCase
):
...
@@ -52,50 +55,60 @@ class InstanceTestCase(TestCase):
...
@@ -52,50 +55,60 @@ class InstanceTestCase(TestCase):
def
test_deploy_destroyed
(
self
):
def
test_deploy_destroyed
(
self
):
inst
=
Mock
(
destroyed_at
=
datetime
.
now
(),
spec
=
Instance
,
inst
=
Mock
(
destroyed_at
=
datetime
.
now
(),
spec
=
Instance
,
InstanceDestroyedError
=
Instance
.
InstanceDestroyedError
)
InstanceDestroyedError
=
Instance
.
InstanceDestroyedError
)
with
self
.
assertRaises
(
Instance
.
InstanceDestroyedError
):
deploy_op
=
DeployOperation
(
inst
)
Instance
.
deploy
(
inst
)
with
patch
.
object
(
DeployOperation
,
'create_activity'
):
with
self
.
assertRaises
(
Instance
.
InstanceDestroyedError
):
deploy_op
(
system
=
True
)
def
test_destroy_destroyed
(
self
):
def
test_destroy_destroyed
(
self
):
inst
=
Mock
(
destroyed_at
=
datetime
.
now
(),
spec
=
Instance
)
inst
=
Mock
(
destroyed_at
=
datetime
.
now
(),
spec
=
Instance
,
Instance
.
destroy
(
inst
)
InstanceDestroyedError
=
Instance
.
InstanceDestroyedError
)
destroy_op
=
DestroyOperation
(
inst
)
with
patch
.
object
(
DestroyOperation
,
'create_activity'
):
with
self
.
assertRaises
(
Instance
.
InstanceDestroyedError
):
destroy_op
(
system
=
True
)
self
.
assertFalse
(
inst
.
save
.
called
)
self
.
assertFalse
(
inst
.
save
.
called
)
def
test_destroy_sets_destroyed
(
self
):
def
test_destroy_sets_destroyed
(
self
):
inst
=
MagicMock
(
destroyed_at
=
None
,
spec
=
Instance
)
inst
=
Mock
(
destroyed_at
=
None
,
spec
=
Instance
,
InstanceDestroyedError
=
Instance
.
InstanceDestroyedError
)
inst
.
node
=
MagicMock
(
spec
=
Node
)
inst
.
node
=
MagicMock
(
spec
=
Node
)
inst
.
disks
.
all
.
return_value
=
[]
inst
.
disks
.
all
.
return_value
=
[]
with
patch
(
'vm.models.instance.instance_activity'
)
as
ia
:
destroy_op
=
DestroyOperation
(
inst
)
ia
.
return_value
=
MagicMock
()
with
patch
.
object
(
DestroyOperation
,
'create_activity'
):
Instance
.
destroy
(
inst
)
destroy_op
(
system
=
True
)
self
.
assertTrue
(
inst
.
destroyed_at
)
self
.
assertTrue
(
inst
.
destroyed_at
)
inst
.
save
.
assert_called
()
inst
.
save
.
assert_called
()
def
test_migrate_with_scheduling
(
self
):
def
test_migrate_with_scheduling
(
self
):
inst
=
M
agicMock
(
spec
=
Instance
)
inst
=
M
ock
(
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
)
with
patch
(
'vm.models.instance.instance_activity'
)
as
ia
,
\
migrate_op
=
MigrateOperation
(
inst
)
patch
(
'vm.models.instance.vm_tasks.migrate'
)
as
migr
:
with
patch
(
'vm.models.instance.vm_tasks.migrate'
)
as
migr
:
Instance
.
migrate
(
inst
)
act
=
MagicMock
()
with
patch
.
object
(
MigrateOperation
,
'create_activity'
,
return_value
=
act
):
migrate_op
(
system
=
True
)
migr
.
apply_async
.
assert_called
()
migr
.
apply_async
.
assert_called
()
self
.
assertIn
(
call
()
.
__enter__
()
.
sub_activity
(
u'scheduling'
),
self
.
assertIn
(
call
.
sub_activity
(
u'scheduling'
),
act
.
mock_calls
)
ia
.
mock_calls
)
inst
.
select_node
.
assert_called
()
inst
.
select_node
.
assert_called
()
def
test_migrate_wo_scheduling
(
self
):
def
test_migrate_wo_scheduling
(
self
):
inst
=
MagicMock
(
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
)
with
patch
(
'vm.models.instance.instance_activity'
)
as
ia
,
\
migrate_op
=
MigrateOperation
(
inst
)
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
act
=
MagicMock
()
Instance
.
migrate
(
inst
,
inst
.
node
)
with
patch
.
object
(
MigrateOperation
,
'create_activity'
,
return_value
=
act
):
migrate_op
(
to_node
=
inst
.
node
,
system
=
True
)
migr
.
apply_async
.
assert_called
()
migr
.
apply_async
.
assert_called
()
self
.
assertNotIn
(
call
()
.
__enter__
()
.
sub_activity
(
u'scheduling'
),
self
.
assertNotIn
(
call
.
sub_activity
(
u'scheduling'
),
act
.
mock_calls
)
ia
.
mock_calls
)
def
test_status_icon
(
self
):
def
test_status_icon
(
self
):
inst
=
MagicMock
(
spec
=
Instance
)
inst
=
MagicMock
(
spec
=
Instance
)
...
@@ -233,7 +246,8 @@ class InstanceActivityTestCase(TestCase):
...
@@ -233,7 +246,8 @@ class InstanceActivityTestCase(TestCase):
def
test_flush
(
self
):
def
test_flush
(
self
):
node
=
MagicMock
(
spec
=
Node
,
enabled
=
True
)
node
=
MagicMock
(
spec
=
Node
,
enabled
=
True
)
user
=
MagicMock
(
spec
=
User
)
user
=
MagicMock
(
spec
=
User
)
insts
=
[
MagicMock
(
spec
=
Instance
),
MagicMock
(
spec
=
Instance
)]
insts
=
[
MagicMock
(
spec
=
Instance
,
migrate
=
MagicMock
()),
MagicMock
(
spec
=
Instance
,
migrate
=
MagicMock
())]
with
patch
(
'vm.models.node.node_activity'
)
as
na
:
with
patch
(
'vm.models.node.node_activity'
)
as
na
:
act
=
na
.
return_value
.
__enter__
.
return_value
=
MagicMock
()
act
=
na
.
return_value
.
__enter__
.
return_value
=
MagicMock
()
...
@@ -248,7 +262,8 @@ class InstanceActivityTestCase(TestCase):
...
@@ -248,7 +262,8 @@ class InstanceActivityTestCase(TestCase):
def
test_flush_disabled_wo_user
(
self
):
def
test_flush_disabled_wo_user
(
self
):
node
=
MagicMock
(
spec
=
Node
,
enabled
=
False
)
node
=
MagicMock
(
spec
=
Node
,
enabled
=
False
)
insts
=
[
MagicMock
(
spec
=
Instance
),
MagicMock
(
spec
=
Instance
)]
insts
=
[
MagicMock
(
spec
=
Instance
,
migrate
=
MagicMock
()),
MagicMock
(
spec
=
Instance
,
migrate
=
MagicMock
())]
with
patch
(
'vm.models.node.node_activity'
)
as
na
:
with
patch
(
'vm.models.node.node_activity'
)
as
na
:
act
=
na
.
return_value
.
__enter__
.
return_value
=
MagicMock
()
act
=
na
.
return_value
.
__enter__
.
return_value
=
MagicMock
()
...
...
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