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
Labels
Merge Requests
16
Merge Requests
16
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Jobs
Commits
Open sidebar
nexedi
slapos.core
Commits
4d0a5ab7
Commit
4d0a5ab7
authored
Sep 20, 2012
by
Cédric Le Ninivin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added test on parameters send and received
parent
cea99f88
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
77 additions
and
15 deletions
+77
-15
slapos/tests/slapproxy.py
slapos/tests/slapproxy.py
+77
-15
No files found.
slapos/tests/slapproxy.py
View file @
4d0a5ab7
...
@@ -214,6 +214,7 @@ class MasterMixin(BasicMixin):
...
@@ -214,6 +214,7 @@ class MasterMixin(BasicMixin):
'_parameter_dict'
,
None
)
'_parameter_dict'
,
None
)
return
computer_partition
return
computer_partition
def
setConnectionDict
(
self
,
partition_id
,
def
setConnectionDict
(
self
,
partition_id
,
connection_dict
,
slave_reference
=
None
):
connection_dict
,
slave_reference
=
None
):
self
.
app
.
post
(
'/setComputerPartitionConnectionXml'
,
data
=
{
self
.
app
.
post
(
'/setComputerPartitionConnectionXml'
,
data
=
{
...
@@ -222,6 +223,17 @@ class MasterMixin(BasicMixin):
...
@@ -222,6 +223,17 @@ class MasterMixin(BasicMixin):
'connection_xml'
:
xml_marshaller
.
xml_marshaller
.
dumps
(
connection_dict
),
'connection_xml'
:
xml_marshaller
.
xml_marshaller
.
dumps
(
connection_dict
),
'slave_reference'
:
slave_reference
})
'slave_reference'
:
slave_reference
})
def
getPartitionInformation
(
self
,
computer_partition_id
):
"""
Return computer information as stored in proxy for corresponding id
"""
rv
=
self
.
app
.
get
(
'/getFullComputerInformation?computer_id='
+
self
.
computer_id
)
computer
=
xml_marshaller
.
xml_marshaller
.
loads
(
rv
.
data
)
for
instance
in
computer
.
_computer_partition_list
:
if
instance
.
_partition_id
==
computer_partition_id
:
return
instance
class
TestRequest
(
MasterMixin
,
unittest
.
TestCase
):
class
TestRequest
(
MasterMixin
,
unittest
.
TestCase
):
"""
"""
...
@@ -290,6 +302,64 @@ class TestRequest (MasterMixin, unittest.TestCase):
...
@@ -290,6 +302,64 @@ class TestRequest (MasterMixin, unittest.TestCase):
with
self
.
assertRaises
(
WrongFormat
):
with
self
.
assertRaises
(
WrongFormat
):
self
.
request
(
'http://sr//'
,
None
,
'Maria'
,
'slappart2'
,
shared
=
True
)
self
.
request
(
'http://sr//'
,
None
,
'Maria'
,
'slappart2'
,
shared
=
True
)
def
test_slave_request_set_parameters
(
self
):
"""
Parameters sent in slave request must be put in slave master
slave instance list.
1. We request a slave instance we defined parameters
2. We check parameters are in the dictionnary defining slave in
slave master slave_instance_list
"""
self
.
add_free_partition
(
6
)
# Provide partition
master_partition_id
=
self
.
request
(
'http://sr//'
,
None
,
'Maria'
,
'slappart4'
).
_partition_id
# First request of slave instance
wanted_domain
=
'fou.org'
self
.
request
(
'http://sr//'
,
None
,
'Maria'
,
'slappart2'
,
shared
=
True
,
partition_parameter_kw
=
{
'domain'
:
wanted_domain
})
# Get updated information for master partition
master_partition
=
self
.
getPartitionInformation
(
master_partition_id
)
our_slave
=
master_partition
.
_parameter_dict
[
'slave_instance_list'
][
0
]
self
.
assertEqual
(
our_slave
.
get
(
'domain'
),
wanted_domain
)
def
test_slave_request_set_parameters_are_updated
(
self
):
"""
Parameters sent in slave request must be put in slave master
slave instance list and updated when they change.
1. We request a slave instance we defined parameters
2. We check parameters are in the dictionnary defining slave in
slave master slave_instance_list
3. We request same slave instance with changed parameters
4. We check parameters are in the dictionnary defining slave in
slave master slave_instance_list have changed
"""
self
.
add_free_partition
(
6
)
# Provide partition
master_partition_id
=
self
.
request
(
'http://sr//'
,
None
,
'Maria'
,
'slappart4'
).
_partition_id
# First request of slave instance
wanted_domain_1
=
'crazy.org'
self
.
request
(
'http://sr//'
,
None
,
'Maria'
,
'slappart2'
,
shared
=
True
,
partition_parameter_kw
=
{
'domain'
:
wanted_domain_1
})
# Get updated information for master partition
master_partition
=
self
.
getPartitionInformation
(
master_partition_id
)
our_slave
=
master_partition
.
_parameter_dict
[
'slave_instance_list'
][
0
]
self
.
assertEqual
(
our_slave
.
get
(
'domain'
),
wanted_domain_1
)
# Second request of slave instance
wanted_domain_2
=
'maluco.org'
self
.
request
(
'http://sr//'
,
None
,
'Maria'
,
'slappart2'
,
shared
=
True
,
partition_parameter_kw
=
{
'domain'
:
wanted_domain_2
})
# Get updated information for master partition
master_partition
=
self
.
getPartitionInformation
(
master_partition_id
)
our_slave
=
master_partition
.
_parameter_dict
[
'slave_instance_list'
][
0
]
self
.
assertNotEqual
(
our_slave
.
get
(
'domain'
),
wanted_domain_1
)
self
.
assertEqual
(
our_slave
.
get
(
'domain'
),
wanted_domain_2
)
def
test_slave_request_one_corresponding_partition
(
self
):
def
test_slave_request_one_corresponding_partition
(
self
):
"""
"""
Successfull request slave instance follow these steps:
Successfull request slave instance follow these steps:
...
@@ -299,6 +369,7 @@ class TestRequest (MasterMixin, unittest.TestCase):
...
@@ -299,6 +369,7 @@ class TestRequest (MasterMixin, unittest.TestCase):
3. Master Instance get updated information (including slave list)
3. Master Instance get updated information (including slave list)
4. Master instance post information about slave connection parameters
4. Master instance post information about slave connection parameters
5. Ask for slave instance is successfull and return a computer instance
5. Ask for slave instance is successfull and return a computer instance
with connection information
"""
"""
self
.
add_free_partition
(
6
)
self
.
add_free_partition
(
6
)
# Provide partition
# Provide partition
...
@@ -312,22 +383,13 @@ class TestRequest (MasterMixin, unittest.TestCase):
...
@@ -312,22 +383,13 @@ class TestRequest (MasterMixin, unittest.TestCase):
self
.
assertIsInstance
(
our_slave
,
slapos
.
slap
.
ComputerPartition
)
self
.
assertIsInstance
(
our_slave
,
slapos
.
slap
.
ComputerPartition
)
self
.
assertEqual
(
our_slave
.
_connection_dict
,{})
self
.
assertEqual
(
our_slave
.
_connection_dict
,{})
# Get updated information for master partition
# Get updated information for master partition
rv
=
self
.
app
.
get
(
'/getFullComputerInformation?computer_id='
master_partition
=
self
.
getPartitionInformation
(
master_partition_id
)
+
self
.
computer_id
)
slave_for_master
=
master_partition
.
_parameter_dict
[
'slave_instance_list'
][
0
]
computer
=
xml_marshaller
.
xml_marshaller
.
loads
(
rv
.
data
)
for
instance
in
computer
.
_computer_partition_list
:
if
instance
.
_partition_id
==
master_partition_id
:
master_partition
=
instance
# Send information about slave
# Send information about slave
for
slave
in
master_partition
.
_parameter_dict
.
get
(
'slave_instance_list'
):
slave_address
=
{
'url'
:
'%s.master.com'
}
print
slave
self
.
setConnectionDict
(
partition_id
=
master_partition
.
_partition_id
,
slave_reference
=
slave
.
get
(
'slave_reference'
)
connection_dict
=
slave_address
,
# Check we got the right slave
slave_reference
=
slave_for_master
[
'slave_reference'
])
if
requester
and
name
in
slave_reference
:
slave_address
=
{
'url'
:
'%s.master.com'
%
slave_reference
}
self
.
setConnectionDict
(
partition_id
=
master_partition
.
_partition_id
,
connection_dict
=
slave_address
,
slave_reference
=
slave_reference
)
# Successfull slave request with connection parameters
# Successfull slave request with connection parameters
our_slave
=
self
.
request
(
'http://sr//'
,
None
,
our_slave
=
self
.
request
(
'http://sr//'
,
None
,
name
,
requester
,
shared
=
True
)
name
,
requester
,
shared
=
True
)
...
...
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