Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
slapos.core
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Ivan Tyagov
slapos.core
Commits
dfc788b9
Commit
dfc788b9
authored
Sep 21, 2012
by
Cédric Le Ninivin
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'proxy_slave_raise'
parents
47bd2ede
a6cc5765
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
57 additions
and
40 deletions
+57
-40
slapos/proxy/views.py
slapos/proxy/views.py
+21
-18
slapos/tests/slapproxy.py
slapos/tests/slapproxy.py
+36
-22
No files found.
slapos/proxy/views.py
View file @
dfc788b9
...
...
@@ -31,7 +31,7 @@ from flask import g, Flask, request, abort
import
xml_marshaller
from
lxml
import
etree
from
slapos.slap.slap
import
Computer
,
ComputerPartition
,
\
SoftwareRelease
,
SoftwareInstance
SoftwareRelease
,
SoftwareInstance
,
NotFoundError
import
sqlite3
app
=
Flask
(
__name__
)
...
...
@@ -72,27 +72,30 @@ def dict2xml(dictionnary):
def
partitiondict2partition
(
partition
):
slap_partition
=
ComputerPartition
(
app
.
config
[
'computer_id'
],
partition
[
'reference'
])
slap_partition
.
_requested_state
=
'started'
slap_partition
.
_software_release_document
=
None
slap_partition
.
_requested_state
=
'destroyed'
slap_partition
.
_need_modification
=
0
if
partition
[
'software_release'
]:
slap_partition
.
_need_modification
=
1
else
:
slap_partition
.
_need_modification
=
0
slap_partition
.
_requested_state
=
'started'
slap_partition
.
_parameter_dict
=
xml2dict
(
partition
[
'xml'
])
address_list
=
[]
for
address
in
execute_db
(
'partition_network'
,
'SELECT * FROM %s WHERE partition_reference=?'
,
[
partition
[
'reference'
]]):
address_list
.
append
((
address
[
'reference'
],
address
[
'address'
]))
if
not
partition
[
'slave_instance_list'
]
==
None
:
slap_partition
.
_parameter_dict
[
'slave_instance_list'
]
=
\
xml_marshaller
.
xml_marshaller
.
loads
(
partition
[
'slave_instance_list'
])
slap_partition
.
_parameter_dict
[
'ip_list'
]
=
address_list
slap_partition
.
_parameter_dict
[
'slap_software_type'
]
=
\
partition
[
'software_type'
]
if
not
partition
[
'slave_instance_list'
]
==
None
:
slap_partition
.
_parameter_dict
[
'slave_instance_list'
]
=
\
xml_marshaller
.
xml_marshaller
.
loads
(
partition
[
'slave_instance_list'
])
slap_partition
.
_connection_dict
=
xml2dict
(
partition
[
'connection_xml'
])
slap_partition
.
_software_release_document
=
SoftwareRelease
(
software_release
=
partition
[
'software_release'
],
computer_guid
=
app
.
config
[
'computer_id'
])
return
slap_partition
...
...
slapos/tests/slapproxy.py
View file @
dfc788b9
...
...
@@ -96,6 +96,27 @@ database_uri = %(tempdir)s/lib/proxy.db
views
.
app
.
config
[
'port'
]
=
config
.
port
self
.
app
=
views
.
app
.
test_client
()
def
add_free_partition
(
self
,
partition_amount
):
"""
Will simulate a slapformat first run
and create "partition_amount" partitions
"""
computer_dict
=
{
'reference'
:
self
.
computer_id
,
'address'
:
'123.456.789'
,
'netmask'
:
'fffffffff'
,
'partition_list'
:[]}
for
i
in
range
(
0
,
partition_amount
):
partition_example
=
{
'reference'
:
'slappart%s'
%
i
,
'address_list'
:[]}
computer_dict
[
'partition_list'
].
append
(
partition_example
)
request_dict
=
{
'computer_id'
:
self
.
computer_id
,
'xml'
:
xml_marshaller
.
xml_marshaller
.
dumps
(
computer_dict
),
}
self
.
app
.
post
(
'/loadComputerConfigurationFromXML'
,
data
=
request_dict
)
def
tearDown
(
self
):
"""
Remove files generated for test
...
...
@@ -137,35 +158,29 @@ class TestInformation(BasicMixin, unittest.TestCase):
Test that computer information won't be given to a requester different
from the one specified
"""
with
self
.
assertRaises
(
views
.
Unauthorize
dError
):
with
self
.
assertRaises
(
slapos
.
slap
.
NotFoun
dError
):
self
.
app
.
get
(
'/getComputerInformation?computer_id='
+
self
.
computer_id
+
'42'
)
class
MasterMixin
(
BasicMixin
):
def
test_partition_are_empty
(
self
):
"""
Define advanced tool for test proxy simulating behavior slap library tools
Test that empty partition are empty :)
"""
self
.
add_free_partition
(
10
)
rv
=
self
.
app
.
get
(
'/getFullComputerInformation?computer_id='
+
self
.
computer_id
)
computer
=
xml_marshaller
.
xml_marshaller
.
loads
(
rv
.
data
)
for
slap_partition
in
computer
.
_computer_partition_list
:
self
.
assertIsNone
(
slap_partition
.
_software_release_document
)
self
.
assertEqual
(
slap_partition
.
_requested_state
,
'destroyed'
)
self
.
assertEqual
(
slap_partition
.
_need_modification
,
0
)
def
add_free_partition
(
self
,
partition_amount
):
class
MasterMixin
(
BasicMixin
):
"""
Will simulate a slapformat first run
and create "partition_amount" partitions
Define advanced tool for test proxy simulating behavior slap library tools
"""
computer_dict
=
{
'reference'
:
self
.
computer_id
,
'address'
:
'123.456.789'
,
'netmask'
:
'fffffffff'
,
'partition_list'
:[]}
for
i
in
range
(
0
,
partition_amount
):
partition_example
=
{
'reference'
:
'slappart%s'
%
i
,
'address_list'
:[]}
computer_dict
[
'partition_list'
].
append
(
partition_example
)
request_dict
=
{
'computer_id'
:
self
.
computer_id
,
'xml'
:
xml_marshaller
.
xml_marshaller
.
dumps
(
computer_dict
),
}
self
.
app
.
post
(
'/loadComputerConfigurationFromXML'
,
data
=
request_dict
)
def
request
(
self
,
software_release
,
software_type
,
partition_reference
,
partition_id
,
...
...
@@ -239,7 +254,6 @@ class TestRequest (MasterMixin, unittest.TestCase):
"""
Set of tests for requests
"""
def
test_two_request_one_partition_free
(
self
):
"""
If only one partition is available and two different request are made
...
...
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