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
Łukasz Nowak
slapos.core
Commits
b28e7c9c
Commit
b28e7c9c
authored
Aug 05, 2014
by
Cédric de Saint Martin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
slapproxy: add correct support for slaves, instance_guid, state.
parent
686cbd17
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
60 additions
and
13 deletions
+60
-13
slapos/proxy/views.py
slapos/proxy/views.py
+8
-6
slapos/tests/slapproxy.py
slapos/tests/slapproxy.py
+52
-7
No files found.
slapos/proxy/views.py
View file @
b28e7c9c
...
...
@@ -98,6 +98,8 @@ def partitiondict2partition(partition):
if
partition
[
'slave_instance_list'
]
is
not
None
:
slap_partition
.
_parameter_dict
[
'slave_instance_list'
]
=
\
xml_marshaller
.
xml_marshaller
.
loads
(
partition
[
'slave_instance_list'
])
else
:
slap_partition
.
_parameter_dict
[
'slave_instance_list'
]
=
[]
slap_partition
.
_connection_dict
=
xml2dict
(
partition
[
'connection_xml'
])
slap_partition
.
_software_release_document
=
SoftwareRelease
(
software_release
=
partition
[
'software_release'
],
...
...
@@ -289,7 +291,6 @@ def softwareInstanceRename():
execute_db
(
'partition'
,
q
,
[
new_name
,
computer_partition_id
])
return
'done'
def
request_not_shared
():
software_release
=
request
.
form
[
'software_release'
].
encode
()
# some supported parameters
...
...
@@ -359,9 +360,10 @@ def request_not_shared():
for
address
in
execute_db
(
'partition_network'
,
'SELECT * FROM %s WHERE partition_reference=?'
,
[
partition
[
'reference'
]]):
address_list
.
append
((
address
[
'reference'
],
address
[
'address'
]))
if
not
requested_state
:
requested_state
=
'started'
# XXX it should be ComputerPartition, not a SoftwareInstance
software_instance
=
SoftwareInstance
(
xml
=
partition
[
'xml'
],
_connection_dict
=
xml2dict
(
partition
[
'connection_xml'
]),
software_instance
=
SoftwareInstance
(
_connection_dict
=
xml2dict
(
partition
[
'connection_xml'
]),
_parameter_dict
=
xml2dict
(
partition
[
'xml'
]),
connection_xml
=
partition
[
'connection_xml'
],
slap_computer_id
=
app
.
config
[
'computer_id'
],
...
...
@@ -369,8 +371,8 @@ def request_not_shared():
slap_software_release_url
=
partition
[
'software_release'
],
slap_server_url
=
'slap_server_url'
,
slap_software_type
=
partition
[
'software_type'
],
slave_instance_list
=
partition
[
'slave_instance_list
'
],
instance_guid
=
partition
[
'reference'
]
,
_instance_guid
=
partition
[
'reference
'
],
_requested_state
=
requested_state
,
ip_list
=
address_list
)
return
xml_marshaller
.
xml_marshaller
.
dumps
(
software_instance
)
...
...
@@ -473,7 +475,7 @@ def request_slave():
# XXX it should be ComputerPartition, not a SoftwareInstance
software_instance
=
SoftwareInstance
(
_connection_dict
=
xml2dict
(
slave
[
'connection_xml'
]),
xml
=
instance_xml
,
_parameter_dict
=
xml2dict
(
instance_xml
)
,
slap_computer_id
=
app
.
config
[
'computer_id'
],
slap_computer_partition_id
=
slave
[
'hosted_by'
],
slap_software_release_url
=
partition
[
'software_release'
],
...
...
slapos/tests/slapproxy.py
View file @
b28e7c9c
...
...
@@ -287,12 +287,8 @@ class MasterMixin(BasicMixin):
computer_partition
=
slapos
.
slap
.
ComputerPartition
(
software_instance
.
slap_computer_id
,
software_instance
.
slap_computer_partition_id
)
if
shared
:
computer_partition
.
_synced
=
True
computer_partition
.
_connection_dict
=
getattr
(
software_instance
,
'_connection_dict'
,
None
)
computer_partition
.
_parameter_dict
=
getattr
(
software_instance
,
'_parameter_dict'
,
None
)
computer_partition
.
__dict__
.
update
(
software_instance
.
__dict__
)
return
computer_partition
def
setConnectionDict
(
self
,
partition_id
,
...
...
@@ -318,6 +314,16 @@ class TestRequest(MasterMixin, unittest.TestCase):
"""
Set of tests for requests
"""
def
test_request_consistent_parameters
(
self
):
"""
Check that all different parameters related to requests (like instance_guid, state) are set and consistent
"""
self
.
add_free_partition
(
1
)
partition
=
self
.
request
(
'http://sr//'
,
None
,
'Maria'
,
'slappart0'
)
self
.
assertEqual
(
partition
.
getState
(),
'started'
)
self
.
assertEqual
(
partition
.
getInstanceGuid
(),
'slappart0'
)
# XXX define me
def
test_two_request_one_partition_free
(
self
):
"""
Since slapproxy does not implement scope, providing two partition_id
...
...
@@ -373,7 +379,7 @@ class TestRequest(MasterMixin, unittest.TestCase):
requested_result2
=
self
.
getPartitionInformation
(
request2_dict
[
'_partition_id'
])
# Test we received same partition
for
key
in
request1_dict
:
for
key
in
[
'_partition_id'
,
'_computer_id'
]
:
self
.
assertEqual
(
request1_dict
[
key
],
request2_dict
[
key
])
# Test that only parameters changed
for
key
in
requested_result2
.
__dict__
:
...
...
@@ -410,6 +416,11 @@ class TestRequest(MasterMixin, unittest.TestCase):
self
.
request
(
'http://sr//'
,
None
,
'Maria'
,
'slappart2'
).
__dict__
,
self
.
request
(
'http://sr//'
,
None
,
'frontend'
,
'slappart2'
).
__dict__
)
class
TestSlaveRequest
(
TestRequest
):
"""
Test requests related to slave instances.
"""
def
test_slave_request_no_corresponding_partition
(
self
):
"""
Slave instance request will fail if no corresponding are found
...
...
@@ -440,6 +451,17 @@ class TestRequest(MasterMixin, unittest.TestCase):
our_slave
=
master_partition
.
_parameter_dict
[
'slave_instance_list'
][
0
]
self
.
assertEqual
(
our_slave
.
get
(
'domain'
),
wanted_domain
)
def
test_master_instance_with_no_slave
(
self
):
"""
Test that a master instance with no requested slave
has an empty slave_instance_list parameter.
"""
self
.
add_free_partition
(
6
)
# Provide partition
master_partition_id
=
self
.
request
(
'http://sr//'
,
None
,
'MyMasterInstance'
,
'slappart4'
).
_partition_id
master_partition
=
self
.
getPartitionInformation
(
master_partition_id
)
self
.
assertEqual
(
len
(
master_partition
.
_parameter_dict
[
'slave_instance_list'
]),
0
)
def
test_slave_request_set_parameters_are_updated
(
self
):
"""
Parameters sent in slave request must be put in slave master
...
...
@@ -475,6 +497,28 @@ class TestRequest(MasterMixin, unittest.TestCase):
self
.
assertNotEqual
(
our_slave
.
get
(
'domain'
),
wanted_domain_1
)
self
.
assertEqual
(
our_slave
.
get
(
'domain'
),
wanted_domain_2
)
def
test_slave_request_set_connection_parameters
(
self
):
"""
Parameters set in slave instance by master instance must be put in slave instance connection parameters.
1. We request a slave instance
2. We set connection parameters for this slave instance
2. We check parameter is present when we do request() for the slave.
"""
self
.
add_free_partition
(
6
)
# Provide partition
master_partition_id
=
self
.
request
(
'http://sr//'
,
None
,
'MyMasterInstance'
,
'slappart4'
).
_partition_id
# First request of slave instance
self
.
request
(
'http://sr//'
,
None
,
'MySlaveInstance'
,
'slappart2'
,
shared
=
True
)
# Set connection parameter
master_partition
=
self
.
getPartitionInformation
(
master_partition_id
)
self
.
setConnectionDict
(
partition_id
=
master_partition
.
_partition_id
,
connection_dict
=
{
'foo'
:
'bar'
},
slave_reference
=
master_partition
.
_parameter_dict
[
'slave_instance_list'
][
0
][
'slave_reference'
])
# Get updated information for slave partition
slave_partition
=
self
.
request
(
'http://sr//'
,
None
,
'MySlaveInstance'
,
'slappart2'
,
shared
=
True
)
self
.
assertEqual
(
slave_partition
.
getConnectionParameter
(
'foo'
),
'bar'
)
def
test_slave_request_one_corresponding_partition
(
self
):
"""
Successfull request slave instance follow these steps:
...
...
@@ -510,3 +554,4 @@ class TestRequest(MasterMixin, unittest.TestCase):
name
,
requester
,
shared
=
True
)
self
.
assertIsInstance
(
our_slave
,
slapos
.
slap
.
ComputerPartition
)
self
.
assertEqual
(
slave_address
,
our_slave
.
_connection_dict
)
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