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
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
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
Hide 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
...
@@ -31,7 +31,7 @@ from flask import g, Flask, request, abort
import
xml_marshaller
import
xml_marshaller
from
lxml
import
etree
from
lxml
import
etree
from
slapos.slap.slap
import
Computer
,
ComputerPartition
,
\
from
slapos.slap.slap
import
Computer
,
ComputerPartition
,
\
SoftwareRelease
,
SoftwareInstance
SoftwareRelease
,
SoftwareInstance
,
NotFoundError
import
sqlite3
import
sqlite3
app
=
Flask
(
__name__
)
app
=
Flask
(
__name__
)
...
@@ -72,27 +72,30 @@ def dict2xml(dictionnary):
...
@@ -72,27 +72,30 @@ def dict2xml(dictionnary):
def
partitiondict2partition
(
partition
):
def
partitiondict2partition
(
partition
):
slap_partition
=
ComputerPartition
(
app
.
config
[
'computer_id'
],
slap_partition
=
ComputerPartition
(
app
.
config
[
'computer_id'
],
partition
[
'reference'
])
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'
]:
if
partition
[
'software_release'
]:
slap_partition
.
_need_modification
=
1
slap_partition
.
_need_modification
=
1
else
:
slap_partition
.
_requested_state
=
'started'
slap_partition
.
_need_modification
=
0
slap_partition
.
_parameter_dict
=
xml2dict
(
partition
[
'xml'
])
slap_partition
.
_parameter_dict
=
xml2dict
(
partition
[
'xml'
])
address_list
=
[]
address_list
=
[]
for
address
in
execute_db
(
'partition_network'
,
for
address
in
execute_db
(
'partition_network'
,
'SELECT * FROM %s WHERE partition_reference=?'
,
'SELECT * FROM %s WHERE partition_reference=?'
,
[
partition
[
'reference'
]]):
[
partition
[
'reference'
]]):
address_list
.
append
((
address
[
'reference'
],
address
[
'address'
]))
address_list
.
append
((
address
[
'reference'
],
address
[
'address'
]))
slap_partition
.
_parameter_dict
[
'ip_list'
]
=
address_list
if
not
partition
[
'slave_instance_list'
]
==
None
:
slap_partition
.
_parameter_dict
[
'slap_software_type'
]
=
\
slap_partition
.
_parameter_dict
[
'slave_instance_list'
]
=
\
partition
[
'software_type'
]
xml_marshaller
.
xml_marshaller
.
loads
(
partition
[
'slave_instance_list'
])
if
not
partition
[
'slave_instance_list'
]
==
None
:
slap_partition
.
_parameter_dict
[
'ip_list'
]
=
address_list
slap_partition
.
_parameter_dict
[
'slave_instance_list'
]
=
\
slap_partition
.
_parameter_dict
[
'slap_software_type'
]
=
\
xml_marshaller
.
xml_marshaller
.
loads
(
partition
[
'slave_instance_list'
])
partition
[
'software_type'
]
slap_partition
.
_connection_dict
=
xml2dict
(
partition
[
'connection_xml'
])
slap_partition
.
_connection_dict
=
xml2dict
(
partition
[
'connection_xml'
])
slap_partition
.
_software_release_document
=
SoftwareRelease
(
slap_partition
.
_software_release_document
=
SoftwareRelease
(
software_release
=
partition
[
'software_release'
],
software_release
=
partition
[
'software_release'
],
computer_guid
=
app
.
config
[
'computer_id'
])
computer_guid
=
app
.
config
[
'computer_id'
])
return
slap_partition
return
slap_partition
...
...
slapos/tests/slapproxy.py
View file @
dfc788b9
...
@@ -96,6 +96,27 @@ database_uri = %(tempdir)s/lib/proxy.db
...
@@ -96,6 +96,27 @@ database_uri = %(tempdir)s/lib/proxy.db
views
.
app
.
config
[
'port'
]
=
config
.
port
views
.
app
.
config
[
'port'
]
=
config
.
port
self
.
app
=
views
.
app
.
test_client
()
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
):
def
tearDown
(
self
):
"""
"""
Remove files generated for test
Remove files generated for test
...
@@ -137,36 +158,30 @@ class TestInformation(BasicMixin, unittest.TestCase):
...
@@ -137,36 +158,30 @@ class TestInformation(BasicMixin, unittest.TestCase):
Test that computer information won't be given to a requester different
Test that computer information won't be given to a requester different
from the one specified
from the one specified
"""
"""
with
self
.
assertRaises
(
views
.
Unauthorize
dError
):
with
self
.
assertRaises
(
slapos
.
slap
.
NotFoun
dError
):
self
.
app
.
get
(
'/getComputerInformation?computer_id='
self
.
app
.
get
(
'/getComputerInformation?computer_id='
+
self
.
computer_id
+
'42'
)
+
self
.
computer_id
+
'42'
)
def
test_partition_are_empty
(
self
):
"""
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
)
class
MasterMixin
(
BasicMixin
):
class
MasterMixin
(
BasicMixin
):
"""
"""
Define advanced tool for test proxy simulating behavior slap library tools
Define advanced tool for test proxy simulating behavior slap library tools
"""
"""
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
request
(
self
,
software_release
,
software_type
,
partition_reference
,
def
request
(
self
,
software_release
,
software_type
,
partition_reference
,
partition_id
,
partition_id
,
shared
=
False
,
partition_parameter_kw
=
None
,
filter_kw
=
None
,
shared
=
False
,
partition_parameter_kw
=
None
,
filter_kw
=
None
,
...
@@ -239,7 +254,6 @@ class TestRequest (MasterMixin, unittest.TestCase):
...
@@ -239,7 +254,6 @@ class TestRequest (MasterMixin, unittest.TestCase):
"""
"""
Set of tests for requests
Set of tests for requests
"""
"""
def
test_two_request_one_partition_free
(
self
):
def
test_two_request_one_partition_free
(
self
):
"""
"""
If only one partition is available and two different request are made
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