Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Gyuricska Milán
/
cloud
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
95055e89
authored
9 years ago
by
Kálmán Viktor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
requests: tests
parent
8a3dbb79
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
159 additions
and
13 deletions
+159
-13
circle/circle/settings/test.py
+10
-0
circle/dashboard/fixtures/test-vm-fixture.json
+1
-0
circle/dashboard/tests/test_views.py
+1
-2
circle/request/forms.py
+2
-0
circle/request/tests.py
+144
-2
circle/vm/operations.py
+1
-9
No files found.
circle/circle/settings/test.py
View file @
95055e89
...
...
@@ -56,6 +56,16 @@ LOGGING['handlers']['console'] = {'level': level,
'formatter'
:
'simple'
}
for
i
in
LOCAL_APPS
:
LOGGING
[
'loggers'
][
i
]
=
{
'handlers'
:
[
'console'
],
'level'
:
level
}
# don't print SQL queries
LOGGING
[
'handlers'
][
'null'
]
=
{
'level'
:
"DEBUG"
,
'class'
:
"django.utils.log.NullHandler"
}
LOGGING
[
'loggers'
][
'django.db.backends'
]
=
{
'handlers'
:
[
'null'
],
'propagate'
:
False
,
'level'
:
'DEBUG'
,
}
# Forbid store usage
STORE_URL
=
""
...
...
This diff is collapsed.
Click to expand it.
circle/dashboard/fixtures/test-vm-fixture.json
View file @
95055e89
...
...
@@ -1395,6 +1395,7 @@
"vnc_port"
:
1234
,
"num_cores"
:
2
,
"status"
:
"RUNNING"
,
"system"
:
"system pls"
,
"modified"
:
"2013-10-14T07:27:38.192Z"
}
},
...
...
This diff is collapsed.
Click to expand it.
circle/dashboard/tests/test_views.py
View file @
95055e89
...
...
@@ -20,8 +20,7 @@ import json
# from unittest import skip
from
django.test
import
TestCase
from
django.test.client
import
Client
from
django.contrib.auth.models
import
User
,
Group
from
django.contrib.auth.models
import
Permission
from
django.contrib.auth.models
import
User
,
Group
,
Permission
from
django.contrib.auth
import
authenticate
from
common.tests.celery_mock
import
MockCeleryMixin
...
...
This diff is collapsed.
Click to expand it.
circle/request/forms.py
View file @
95055e89
...
...
@@ -41,6 +41,7 @@ class LeaseTypeForm(ModelForm):
class
Meta
:
model
=
LeaseType
fields
=
[
"name"
,
"lease"
,
]
class
TemplateAccessTypeForm
(
ModelForm
):
...
...
@@ -56,6 +57,7 @@ class TemplateAccessTypeForm(ModelForm):
class
Meta
:
model
=
TemplateAccessType
fields
=
[
"name"
,
"templates"
,
]
class
InitialFromFileMixin
(
object
):
...
...
This diff is collapsed.
Click to expand it.
circle/request/tests.py
View file @
95055e89
# from django.test import TestCase
# Copyright 2014 Budapest University of Technology and Economics (BME IK)
#
# This file is part of CIRCLE Cloud.
#
# CIRCLE is free software: you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free
# Software Foundation, either version 3 of the License, or (at your option)
# any later version.
#
# CIRCLE is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
# details.
#
# You should have received a copy of the GNU General Public License along
# with CIRCLE. If not, see <http://www.gnu.org/licenses/>.
# Create your tests here.
from
django.test
import
TestCase
from
django.test.client
import
Client
from
django.contrib.auth.models
import
User
,
Permission
from
mock
import
Mock
,
patch
from
common.tests.celery_mock
import
MockCeleryMixin
from
vm.models
import
Instance
,
InstanceTemplate
,
Lease
from
dashboard.models
import
Profile
from
request.models
import
Request
,
LeaseType
,
TemplateAccessType
from
dashboard.tests.test_views
import
LoginMixin
from
vm.operations
import
ResourcesRequestOperation
class
RequestTest
(
LoginMixin
,
MockCeleryMixin
,
TestCase
):
fixtures
=
[
'test-vm-fixture.json'
,
'node.json'
]
def
setUp
(
self
):
Instance
.
get_remote_queue_name
=
Mock
(
return_value
=
'test'
)
self
.
u1
=
User
.
objects
.
create
(
username
=
'user1'
)
self
.
u1
.
set_password
(
'password'
)
self
.
u1
.
save
()
self
.
us
=
User
.
objects
.
create
(
username
=
'superuser'
,
is_superuser
=
True
)
self
.
us
.
set_password
(
'password'
)
self
.
us
.
save
()
self
.
u1
.
user_permissions
.
add
(
Permission
.
objects
.
get
(
codename
=
'create_vm'
))
# superusers are notified uppon
for
u
in
User
.
objects
.
filter
(
is_superuser
=
True
):
p
=
Profile
(
user
=
u
)
p
.
save
()
self
.
lease
=
Lease
(
name
=
"new lease"
,
suspend_interval_seconds
=
1
,
delete_interval_seconds
=
1
)
self
.
lease
.
save
()
LeaseType
(
name
=
"lease type #1"
,
lease
=
self
.
lease
)
.
save
()
tat
=
TemplateAccessType
(
name
=
"a"
)
tat
.
save
()
tat
.
templates
.
add
(
InstanceTemplate
.
objects
.
get
(
pk
=
1
))
def
tearDown
(
self
):
super
(
RequestTest
,
self
)
.
tearDown
()
self
.
u1
.
delete
()
self
.
us
.
delete
()
def
test_resources_request
(
self
):
c
=
Client
()
self
.
login
(
c
,
"user1"
)
inst
=
Instance
.
objects
.
get
(
pk
=
1
)
inst
.
set_level
(
self
.
u1
,
'owner'
)
req_count
=
Request
.
objects
.
count
()
resp
=
c
.
post
(
"/request/resource/1/"
,
{
'num_cores'
:
5
,
'ram_size'
:
512
,
'priority'
:
30
,
'message'
:
"szia"
,
})
self
.
assertEqual
(
resp
.
status_code
,
302
)
self
.
assertEqual
(
req_count
+
1
,
Request
.
objects
.
count
())
new_request
=
Request
.
objects
.
latest
(
"pk"
)
self
.
assertEqual
(
new_request
.
status
,
"PENDING"
)
self
.
assertEqual
(
inst
.
num_cores
,
2
)
self
.
assertEqual
(
inst
.
ram_size
,
200
)
self
.
assertEqual
(
inst
.
priority
,
10
)
# workaround for NOSTATE
inst
.
emergency_change_state
(
new_state
=
"STOPPED"
,
system
=
True
)
with
patch
.
object
(
ResourcesRequestOperation
,
'async'
)
as
mock_method
:
mock_method
.
side_effect
=
(
new_request
.
action
.
instance
.
resources_request
)
new_request
.
accept
(
self
.
us
)
inst
=
Instance
.
objects
.
get
(
pk
=
1
)
self
.
assertEqual
(
inst
.
num_cores
,
5
)
self
.
assertEqual
(
inst
.
ram_size
,
512
)
self
.
assertEqual
(
inst
.
priority
,
30
)
new_request
=
Request
.
objects
.
latest
(
"pk"
)
self
.
assertEqual
(
new_request
.
status
,
"ACCEPTED"
)
def
test_template_access_request
(
self
):
c
=
Client
()
self
.
login
(
c
,
"user1"
)
template
=
InstanceTemplate
.
objects
.
get
(
pk
=
1
)
self
.
assertFalse
(
template
.
has_level
(
self
.
u1
,
"user"
))
req_count
=
Request
.
objects
.
count
()
resp
=
c
.
post
(
"/request/template/"
,
{
'template'
:
1
,
'level'
:
"user"
,
'message'
:
"szia"
,
})
self
.
assertEqual
(
resp
.
status_code
,
302
)
self
.
assertEqual
(
req_count
+
1
,
Request
.
objects
.
count
())
new_request
=
Request
.
objects
.
latest
(
"pk"
)
self
.
assertEqual
(
new_request
.
status
,
"PENDING"
)
new_request
.
accept
(
self
.
us
)
new_request
=
Request
.
objects
.
latest
(
"pk"
)
self
.
assertEqual
(
new_request
.
status
,
"ACCEPTED"
)
self
.
assertTrue
(
template
.
has_level
(
self
.
u1
,
"user"
))
def
test_lease_request
(
self
):
c
=
Client
()
self
.
login
(
c
,
"user1"
)
inst
=
Instance
.
objects
.
get
(
pk
=
1
)
inst
.
set_level
(
self
.
u1
,
'owner'
)
req_count
=
Request
.
objects
.
count
()
resp
=
c
.
post
(
"/request/lease/1/"
,
{
'lease'
:
1
,
'message'
:
"szia"
,
})
self
.
assertEqual
(
resp
.
status_code
,
302
)
self
.
assertEqual
(
req_count
+
1
,
Request
.
objects
.
count
())
new_request
=
Request
.
objects
.
latest
(
"pk"
)
self
.
assertEqual
(
new_request
.
status
,
"PENDING"
)
new_request
.
accept
(
self
.
us
)
inst
=
Instance
.
objects
.
get
(
pk
=
1
)
new_request
=
Request
.
objects
.
latest
(
"pk"
)
self
.
assertEqual
(
new_request
.
status
,
"ACCEPTED"
)
self
.
assertEqual
(
inst
.
lease
,
self
.
lease
)
This diff is collapsed.
Click to expand it.
circle/vm/operations.py
View file @
95055e89
...
...
@@ -1337,15 +1337,7 @@ class ResourcesOperation(InstanceOperation):
accept_states
=
(
'STOPPED'
,
'PENDING'
,
)
def
_operation
(
self
,
user
,
activity
,
num_cores
,
ram_size
,
max_ram_size
,
priority
,
with_shutdown
=
True
):
if
with_shutdown
:
try
:
self
.
instance
.
shutdown
(
parent_activity
=
activity
,
user
=
user
)
except
Instance
.
WrongStateError
:
pass
num_cores
,
ram_size
,
max_ram_size
,
priority
):
self
.
instance
.
num_cores
=
num_cores
self
.
instance
.
ram_size
=
ram_size
self
.
instance
.
max_ram_size
=
max_ram_size
...
...
This diff is collapsed.
Click to expand it.
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