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
Hardik Juneja
slapos.core
Commits
08446fba
Commit
08446fba
authored
Sep 20, 2012
by
Cédric de Saint Martin
Browse files
Options
Browse Files
Download
Plain Diff
Merge remote-tracking branch 'origin/proxy_slave_raise'
Conflicts: slapos/grid/slapgrid.py
parents
042adedf
4d0a5ab7
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
297 additions
and
68 deletions
+297
-68
slapos/grid/slapgrid.py
slapos/grid/slapgrid.py
+31
-2
slapos/proxy/views.py
slapos/proxy/views.py
+24
-8
slapos/tests/slapgrid.py
slapos/tests/slapgrid.py
+144
-18
slapos/tests/slapproxy.py
slapos/tests/slapproxy.py
+98
-40
No files found.
slapos/grid/slapgrid.py
View file @
08446fba
...
@@ -107,6 +107,8 @@ def parseArgumentTupleAndReturnSlapgridObject(*argument_tuple):
...
@@ -107,6 +107,8 @@ def parseArgumentTupleAndReturnSlapgridObject(*argument_tuple):
help
=
"Enables console output and live output from subcommands."
)
help
=
"Enables console output and live output from subcommands."
)
parser
.
add_argument
(
"-v"
,
"--verbose"
,
action
=
"store_true"
,
default
=
False
,
parser
.
add_argument
(
"-v"
,
"--verbose"
,
action
=
"store_true"
,
default
=
False
,
help
=
"Be verbose."
)
help
=
"Be verbose."
)
parser
.
add_argument
(
"--maximum-periodicity"
,
type
=
int
,
default
=
None
,
help
=
"Periodicity at which buildout should be run in instance."
)
parser
.
add_argument
(
"--promise-timeout"
,
type
=
int
,
default
=
3
,
parser
.
add_argument
(
"--promise-timeout"
,
type
=
int
,
default
=
3
,
help
=
"Promise timeout in seconds."
)
help
=
"Promise timeout in seconds."
)
parser
.
add_argument
(
"configuration_file"
,
nargs
=
1
,
type
=
argparse
.
FileType
(),
parser
.
add_argument
(
"configuration_file"
,
nargs
=
1
,
type
=
argparse
.
FileType
(),
...
@@ -170,6 +172,9 @@ def parseArgumentTupleAndReturnSlapgridObject(*argument_tuple):
...
@@ -170,6 +172,9 @@ def parseArgumentTupleAndReturnSlapgridObject(*argument_tuple):
if
option_dict
.
get
(
'all'
)
is
True
:
if
option_dict
.
get
(
'all'
)
is
True
:
option_dict
[
'develop'
]
=
True
option_dict
[
'develop'
]
=
True
if
option_dict
.
get
(
'maximum_periodicity'
)
is
not
None
:
option_dict
[
'force_periodicity'
]
=
True
repository_required
=
False
repository_required
=
False
if
'key_file'
in
option_dict
:
if
'key_file'
in
option_dict
:
repository_required
=
True
repository_required
=
True
...
@@ -232,6 +237,7 @@ def parseArgumentTupleAndReturnSlapgridObject(*argument_tuple):
...
@@ -232,6 +237,7 @@ def parseArgumentTupleAndReturnSlapgridObject(*argument_tuple):
else
:
else
:
signature_certificate_list
=
None
signature_certificate_list
=
None
# Parse cache / binary options
# Parse cache / binary options
option_dict
[
"binary-cache-url-blacklist"
]
=
[
option_dict
[
"binary-cache-url-blacklist"
]
=
[
url
.
strip
()
for
url
in
option_dict
.
get
(
"binary-cache-url-blacklist"
,
""
url
.
strip
()
for
url
in
option_dict
.
get
(
"binary-cache-url-blacklist"
,
""
...
@@ -285,6 +291,8 @@ def parseArgumentTupleAndReturnSlapgridObject(*argument_tuple):
...
@@ -285,6 +291,8 @@ def parseArgumentTupleAndReturnSlapgridObject(*argument_tuple):
develop
=
option_dict
.
get
(
'develop'
,
False
),
develop
=
option_dict
.
get
(
'develop'
,
False
),
software_release_filter_list
=
option_dict
.
get
(
'only_sr'
,
None
),
software_release_filter_list
=
option_dict
.
get
(
'only_sr'
,
None
),
computer_partition_filter_list
=
option_dict
.
get
(
'only_cp'
,
None
),
computer_partition_filter_list
=
option_dict
.
get
(
'only_cp'
,
None
),
force_periodicity
=
option_dict
.
get
(
'force_periodicity'
,
False
),
maximum_periodicity
=
option_dict
.
get
(
'maximum_periodicity'
,
86400
),
),
),
option_dict
])
option_dict
])
...
@@ -353,6 +361,8 @@ class Slapgrid(object):
...
@@ -353,6 +361,8 @@ class Slapgrid(object):
supervisord_socket
,
supervisord_socket
,
supervisord_configuration_path
,
supervisord_configuration_path
,
buildout
,
buildout
,
force_periodicity
=
False
,
maximum_periodicity
=
86400
,
key_file
=
None
,
key_file
=
None
,
cert_file
=
None
,
cert_file
=
None
,
signature_private_key_file
=
None
,
signature_private_key_file
=
None
,
...
@@ -374,7 +384,8 @@ class Slapgrid(object):
...
@@ -374,7 +384,8 @@ class Slapgrid(object):
shadir_key_file
=
None
,
shadir_key_file
=
None
,
develop
=
False
,
develop
=
False
,
software_release_filter_list
=
None
,
software_release_filter_list
=
None
,
computer_partition_filter_list
=
None
):
computer_partition_filter_list
=
None
,
):
"""Makes easy initialisation of class parameters"""
"""Makes easy initialisation of class parameters"""
# Parses arguments
# Parses arguments
self
.
software_root
=
os
.
path
.
abspath
(
software_root
)
self
.
software_root
=
os
.
path
.
abspath
(
software_root
)
...
@@ -424,6 +435,8 @@ class Slapgrid(object):
...
@@ -424,6 +435,8 @@ class Slapgrid(object):
if
computer_partition_filter_list
is
not
None
:
if
computer_partition_filter_list
is
not
None
:
self
.
computer_partition_filter_list
=
\
self
.
computer_partition_filter_list
=
\
computer_partition_filter_list
.
split
(
","
)
computer_partition_filter_list
.
split
(
","
)
self
.
maximum_periodicity
=
maximum_periodicity
self
.
force_periodicity
=
force_periodicity
def
checkEnvironmentAndCreateStructure
(
self
):
def
checkEnvironmentAndCreateStructure
(
self
):
"""Checks for software_root and instance_root existence, then creates
"""Checks for software_root and instance_root existence, then creates
...
@@ -638,15 +651,31 @@ class Slapgrid(object):
...
@@ -638,15 +651,31 @@ class Slapgrid(object):
else
:
else
:
timestamp
=
None
timestamp
=
None
software_path
=
os
.
path
.
join
(
self
.
software_root
,
getSoftwareUrlHash
(
software_url
))
# Get periodicity from periodicity file if not forced
if
not
self
.
force_periodicity
:
periodicity_path
=
os
.
path
.
join
(
software_path
,
'periodicity'
)
if
os
.
path
.
exists
(
periodicity_path
):
try
:
self
.
maximum_periodicity
=
int
(
open
(
periodicity_path
).
read
())
except
ValueError
:
os
.
remove
(
periodicity_path
)
exception
=
traceback
.
format_exc
()
logger
.
error
(
exception
)
# Check if timestamp from server is more recent than local one.
# Check if timestamp from server is more recent than local one.
# If not: it's not worth processing this partition (nothing has changed).
# If not: it's not worth processing this partition (nothing has changed).
if
computer_partition_id
not
in
self
.
computer_partition_filter_list
and
\
if
computer_partition_id
not
in
self
.
computer_partition_filter_list
and
\
(
not
self
.
develop
)
and
os
.
path
.
exists
(
timestamp_path
):
(
not
self
.
develop
)
and
os
.
path
.
exists
(
timestamp_path
):
old_timestamp
=
open
(
timestamp_path
).
read
()
old_timestamp
=
open
(
timestamp_path
).
read
()
last_runtime
=
int
(
os
.
path
.
getmtime
(
timestamp_path
))
if
timestamp
:
if
timestamp
:
try
:
try
:
if
int
(
timestamp
)
<=
int
(
old_timestamp
):
if
int
(
timestamp
)
<=
int
(
old_timestamp
):
continue
if
int
(
time
.
time
())
<=
(
last_runtime
+
self
.
maximum_periodicity
)
:
continue
except
ValueError
:
except
ValueError
:
os
.
remove
(
timestamp_path
)
os
.
remove
(
timestamp_path
)
exception
=
traceback
.
format_exc
()
exception
=
traceback
.
format_exc
()
...
...
slapos/proxy/views.py
View file @
08446fba
...
@@ -354,13 +354,21 @@ def request_not_shared():
...
@@ -354,13 +354,21 @@ def request_not_shared():
def
request_slave
():
def
request_slave
():
"""
"""
Function to organise link between slave and master
Function to organise link between slave and master.
Slave information are stored in places:
1. slave table having information such as slave reference,
connection information to slave (given by slave master),
hosted_by and asked_by reference.
2. A dictionnary in slave_instance_list of selected slave master
in which are stored slave_reference, software_type, slave_title and
partition_parameter_kw stored as individual keys.
"""
"""
software_release
=
request
.
form
[
'software_release'
].
encode
()
software_release
=
request
.
form
[
'software_release'
].
encode
()
# some supported parameters
# some supported parameters
software_type
=
request
.
form
.
get
(
'software_type'
).
encode
()
software_type
=
request
.
form
.
get
(
'software_type'
).
encode
()
partition_reference
=
request
.
form
.
get
(
'partition_reference'
,
''
).
encode
()
partition_reference
=
request
.
form
.
get
(
'partition_reference'
,
''
).
encode
()
partition_id
=
request
.
form
.
get
(
'computer_partition_id'
,
''
).
encode
()
partition_id
=
request
.
form
.
get
(
'computer_partition_id'
,
''
).
encode
()
# Contain slave parameters to be given to slave master
partition_parameter_kw
=
request
.
form
.
get
(
'partition_parameter_xml'
,
None
)
partition_parameter_kw
=
request
.
form
.
get
(
'partition_parameter_xml'
,
None
)
if
partition_parameter_kw
:
if
partition_parameter_kw
:
partition_parameter_kw
=
xml_marshaller
.
xml_marshaller
.
loads
(
partition_parameter_kw
=
xml_marshaller
.
xml_marshaller
.
loads
(
...
@@ -368,6 +376,7 @@ def request_slave():
...
@@ -368,6 +376,7 @@ def request_slave():
else
:
else
:
partition_parameter_kw
=
{}
partition_parameter_kw
=
{}
instance_xml
=
dict2xml
(
partition_parameter_kw
)
instance_xml
=
dict2xml
(
partition_parameter_kw
)
# We will search for a master corresponding to request
args
=
[]
args
=
[]
a
=
args
.
append
a
=
args
.
append
q
=
'SELECT * FROM %s WHERE software_release=?'
q
=
'SELECT * FROM %s WHERE software_release=?'
...
@@ -379,24 +388,31 @@ def request_slave():
...
@@ -379,24 +388,31 @@ def request_slave():
if
partition
is
None
:
if
partition
is
None
:
app
.
logger
.
warning
(
'No partition corresponding to slave request'
)
app
.
logger
.
warning
(
'No partition corresponding to slave request'
)
abort
(
408
)
abort
(
408
)
# Define Slave
# We set slave dictionnary as described in docstring
new_slave
=
{}
new_slave
=
{}
slave_reference
=
partition_id
+
'_'
+
partition_reference
slave_reference
=
partition_id
+
'_'
+
partition_reference
new_slave
[
'slave_title'
]
=
slave_reference
new_slave
[
'slave_title'
]
=
slave_reference
new_slave
[
'slap_software_type'
]
=
software_type
new_slave
[
'slap_software_type'
]
=
software_type
new_slave
[
'slave_reference'
]
=
slave_reference
new_slave
[
'slave_reference'
]
=
slave_reference
for
key
in
partition_parameter_kw
:
for
key
in
partition_parameter_kw
:
new_slave
[
key
]
=
partition_parameter_kw
[
key
]
if
partition_parameter_kw
[
key
]
is
not
None
:
new_slave
[
key
]
=
partition_parameter_kw
[
key
]
# Add slave to partition slave_list if not present
# Add slave to partition slave_list if not present
else replace information
slave_instance_list
=
partition
[
'slave_instance_list'
]
slave_instance_list
=
partition
[
'slave_instance_list'
]
if
slave_instance_list
==
None
:
if
slave_instance_list
==
None
:
slave_instance_list
=
[]
slave_instance_list
=
[]
else
:
else
:
slave_instance_list
=
xml_marshaller
.
xml_marshaller
.
loads
(
slave_instance_list
)
slave_instance_list
=
xml_marshaller
.
xml_marshaller
.
loads
(
slave_instance_list
)
if
not
slave_reference
in
(
x
[
'slave_reference'
]
for
x
in
slave_instance_list
):
for
x
in
slave_instance_list
:
slave_instance_list
.
append
(
new_slave
)
if
x
[
'slave_reference'
]
==
slave_reference
:
slave_instance_list
.
remove
(
x
)
slave_instance_list
.
append
(
new_slave
)
# Update slave_instance_list in database
args
=
[]
args
=
[]
a
=
args
.
append
a
=
args
.
append
q
=
'UPDATE %s SET slave_instance_list=?'
q
=
'UPDATE %s SET slave_instance_list=?'
...
@@ -413,8 +429,8 @@ def request_slave():
...
@@ -413,8 +429,8 @@ def request_slave():
[
slave_reference
],
one
=
True
)
[
slave_reference
],
one
=
True
)
if
slave
is
None
:
if
slave
is
None
:
execute_db
(
'slave'
,
execute_db
(
'slave'
,
'INSERT OR IGNORE INTO %s (reference,asked_by
) values(:reference,:ask
ed_by)'
,
'INSERT OR IGNORE INTO %s (reference,asked_by
,hosted_by) values(:reference,:asked_by,:host
ed_by)'
,
[
slave_reference
,
partition_id
])
[
slave_reference
,
partition_id
,
partition
[
'reference'
]
])
slave
=
execute_db
(
'slave'
,
'SELECT * FROM %s WHERE reference=?'
,
slave
=
execute_db
(
'slave'
,
'SELECT * FROM %s WHERE reference=?'
,
[
slave_reference
],
one
=
True
)
[
slave_reference
],
one
=
True
)
...
...
slapos/tests/slapgrid.py
View file @
08446fba
...
@@ -864,6 +864,132 @@ class TestSlapgridUsageReport(MasterMixin, unittest.TestCase):
...
@@ -864,6 +864,132 @@ class TestSlapgridUsageReport(MasterMixin, unittest.TestCase):
[
'getFullComputerInformation'
])
[
'getFullComputerInformation'
])
self
.
assertTrue
(
self
.
started
)
self
.
assertTrue
(
self
.
started
)
def
test_partition_periodicity_is_not_overloaded_if_forced
(
self
):
"""
If periodicity file in software directory but periodicity is forced
periodicity will be the one given by parameter
1. We set force_periodicity parameter to True
2. We put a periodicity file in the software release directory
with an unwanted periodicity
3. We process partition list and check that maximum periodicity
is not the one given in file
"""
self
.
sequence
=
[]
self
.
timestamp
=
str
(
int
(
time
.
time
()))
self
.
started
=
False
unwanted_periodicity
=
40
self
.
grid
.
force_periodicity
=
True
httplib
.
HTTPConnection
.
_callback
=
_server_response
(
self
,
'stopped'
,
self
.
timestamp
)
os
.
mkdir
(
self
.
software_root
)
os
.
mkdir
(
self
.
instance_root
)
partition_path
=
os
.
path
.
join
(
self
.
instance_root
,
'0'
)
os
.
mkdir
(
partition_path
,
0750
)
software_hash
=
slapos
.
grid
.
utils
.
getSoftwareUrlHash
(
'http://sr/'
)
srdir
=
os
.
path
.
join
(
self
.
software_root
,
software_hash
)
os
.
mkdir
(
srdir
)
open
(
os
.
path
.
join
(
srdir
,
'template.cfg'
),
'w'
).
write
(
"""[buildout]"""
)
open
(
os
.
path
.
join
(
srdir
,
'periodicity'
),
'w'
).
write
(
"""%s"""
%
(
unwanted_periodicity
))
srbindir
=
os
.
path
.
join
(
srdir
,
'bin'
)
os
.
mkdir
(
srbindir
)
open
(
os
.
path
.
join
(
srbindir
,
'buildout'
),
'w'
).
write
(
"""#!/bin/sh
touch worked"""
)
os
.
chmod
(
os
.
path
.
join
(
srbindir
,
'buildout'
),
0755
)
self
.
assertTrue
(
self
.
grid
.
processComputerPartitionList
())
self
.
assertNotEqual
(
unwanted_periodicity
,
self
.
grid
.
maximum_periodicity
)
def
test_partition_periodicity_in_software_overload_if_not_forced
(
self
):
"""
If periodicity file in software directory and it is not forced
periodicity will be the one given by file
1. We put a periodicity file in the software release directory
with wanted periodicity
2. We process partition list and check periodicity is the one given in
file
"""
self
.
sequence
=
[]
self
.
timestamp
=
str
(
int
(
time
.
time
()))
self
.
started
=
False
wanted_periodicity
=
40
httplib
.
HTTPConnection
.
_callback
=
_server_response
(
self
,
'stopped'
,
self
.
timestamp
)
os
.
mkdir
(
self
.
software_root
)
os
.
mkdir
(
self
.
instance_root
)
partition_path
=
os
.
path
.
join
(
self
.
instance_root
,
'0'
)
os
.
mkdir
(
partition_path
,
0750
)
software_hash
=
slapos
.
grid
.
utils
.
getSoftwareUrlHash
(
'http://sr/'
)
srdir
=
os
.
path
.
join
(
self
.
software_root
,
software_hash
)
os
.
mkdir
(
srdir
)
open
(
os
.
path
.
join
(
srdir
,
'template.cfg'
),
'w'
).
write
(
"""[buildout]"""
)
open
(
os
.
path
.
join
(
srdir
,
'periodicity'
),
'w'
).
write
(
"""%s"""
%
wanted_periodicity
)
srbindir
=
os
.
path
.
join
(
srdir
,
'bin'
)
os
.
mkdir
(
srbindir
)
open
(
os
.
path
.
join
(
srbindir
,
'buildout'
),
'w'
).
write
(
"""#!/bin/sh
touch worked"""
)
os
.
chmod
(
os
.
path
.
join
(
srbindir
,
'buildout'
),
0755
)
self
.
assertTrue
(
self
.
grid
.
processComputerPartitionList
())
self
.
assertEqual
(
wanted_periodicity
,
self
.
grid
.
maximum_periodicity
)
def
test_partition_periodicity_trigger_processing
(
self
):
"""
If time between last processing of instance and now is superior
to periodicity then instance should be proceed
1. We set a wanted maximum_periodicity in periodicity file in
in software release directory
2. We process computer partition and check if wanted_periodicity was
used as maximum_periodicty
3. We wait for a time superior to wanted_periodicty
4. We launch processComputerPartition and check that partition is
processed one more time
5. We check that modification time of .timestamp was modified
"""
self
.
sequence
=
[]
self
.
timestamp
=
str
(
int
(
time
.
time
()
-
5
))
self
.
started
=
False
wanted_periodicity
=
3
httplib
.
HTTPConnection
.
_callback
=
_server_response
(
self
,
'stopped'
,
self
.
timestamp
)
os
.
mkdir
(
self
.
software_root
)
os
.
mkdir
(
self
.
instance_root
)
partition_path
=
os
.
path
.
join
(
self
.
instance_root
,
'0'
)
os
.
mkdir
(
partition_path
,
0750
)
software_hash
=
slapos
.
grid
.
utils
.
getSoftwareUrlHash
(
'http://sr/'
)
srdir
=
os
.
path
.
join
(
self
.
software_root
,
software_hash
)
os
.
mkdir
(
srdir
)
open
(
os
.
path
.
join
(
srdir
,
'template.cfg'
),
'w'
).
write
(
"""[buildout]"""
)
open
(
os
.
path
.
join
(
srdir
,
'periodicity'
),
'w'
).
write
(
"""%s"""
%
wanted_periodicity
)
srbindir
=
os
.
path
.
join
(
srdir
,
'bin'
)
os
.
mkdir
(
srbindir
)
open
(
os
.
path
.
join
(
srbindir
,
'buildout'
),
'w'
).
write
(
"""#!/bin/sh
touch worked"""
)
os
.
chmod
(
os
.
path
.
join
(
srbindir
,
'buildout'
),
0755
)
self
.
assertTrue
(
self
.
grid
.
processComputerPartitionList
())
self
.
assertEqual
(
wanted_periodicity
,
self
.
grid
.
maximum_periodicity
)
self
.
setSlapgrid
()
last_runtime
=
os
.
path
.
getmtime
(
os
.
path
.
join
(
partition_path
,
'.timestamp'
))
time
.
sleep
(
wanted_periodicity
+
1
)
self
.
assertTrue
(
self
.
grid
.
processComputerPartitionList
())
self
.
assertEqual
(
self
.
sequence
,
[
'getFullComputerInformation'
,
'availableComputerPartition'
,
'stoppedComputerPartition'
,
'getFullComputerInformation'
,
'availableComputerPartition'
,
'stoppedComputerPartition'
,
])
self
.
assertGreater
(
os
.
path
.
getmtime
(
os
.
path
.
join
(
partition_path
,
'.timestamp'
)),
last_runtime
)
class
TestSlapgridArgumentTuple
(
unittest
.
TestCase
):
class
TestSlapgridArgumentTuple
(
unittest
.
TestCase
):
"""
"""
...
@@ -965,6 +1091,24 @@ buildout = /path/to/buildout/binary
...
@@ -965,6 +1091,24 @@ buildout = /path/to/buildout/binary
slapgrid_object
=
parser
(
*
argument_tuple
)[
0
]
slapgrid_object
=
parser
(
*
argument_tuple
)[
0
]
self
.
assertFalse
(
slapgrid_object
.
develop
)
self
.
assertFalse
(
slapgrid_object
.
develop
)
def
test_force_periodicity_if_periodicity_not_given
(
self
):
"""
Check if not giving --maximum-periodicity triggers "force_periodicity"
option to be false.
"""
parser
=
slapgrid
.
parseArgumentTupleAndReturnSlapgridObject
argument_tuple
=
self
.
default_arg_tuple
slapgrid_object
=
parser
(
*
argument_tuple
)[
0
]
self
.
assertFalse
(
slapgrid_object
.
force_periodicity
)
def
test_force_periodicity_if_periodicity_given
(
self
):
"""
Check if giving --maximum-periodicity triggers "force_periodicity" option.
"""
parser
=
slapgrid
.
parseArgumentTupleAndReturnSlapgridObject
argument_tuple
=
(
"--maximum-periodicity"
,
"40"
)
+
self
.
default_arg_tuple
slapgrid_object
=
parser
(
*
argument_tuple
)[
0
]
self
.
assertTrue
(
slapgrid_object
.
force_periodicity
)
class
TestSlapgridCPWithMasterPromise
(
MasterMixin
,
unittest
.
TestCase
):
class
TestSlapgridCPWithMasterPromise
(
MasterMixin
,
unittest
.
TestCase
):
def
test_one_failing_promise
(
self
):
def
test_one_failing_promise
(
self
):
...
@@ -1441,21 +1585,3 @@ exit 0""" % {'worked_file': worked_file, 'lockfile': lockfile})
...
@@ -1441,21 +1585,3 @@ exit 0""" % {'worked_file': worked_file, 'lockfile': lockfile})
self
.
assertEquals
(
self
.
error
,
1
)
self
.
assertEquals
(
self
.
error
,
1
)
self
.
assertFalse
(
self
.
started
)
self
.
assertFalse
(
self
.
started
)
@
unittest
.
skip
(
"Not implemented"
)
def
test_slapgrid_processes_partition_after_global_timeout
(
self
):
"""
Test that slapgrid processes again partition after delay defined by
slapgrid even if .timestamp is up-to-date.
"""
# XXX Not implemented
pass
@
unittest
.
skip
(
"Not implemented"
)
def
test_slapgrid_processes_partition_after_timeout_defined_by_software_release
(
self
):
"""
Test that if SR of instance defines a "buildotu delay", slapgrid processes
again partition after that delay and NOT after delay defined by slapgrid.
"""
# XXX Not implemented
pass
slapos/tests/slapproxy.py
View file @
08446fba
...
@@ -214,30 +214,25 @@ class MasterMixin(BasicMixin):
...
@@ -214,30 +214,25 @@ class MasterMixin(BasicMixin):
'_parameter_dict'
,
None
)
'_parameter_dict'
,
None
)
return
computer_partition
return
computer_partition
def
setComputerPartitionConnectionXml
(
self
,
instance
):
"""
def
setConnectionDict
(
self
,
partition_id
,
Will send instance connection information to server
connection_dict
,
slave_reference
=
None
):
including from slaves in this partition
self
.
app
.
post
(
'/setComputerPartitionConnectionXml'
,
data
=
{
"""
'computer_id'
:
self
.
computer_id
,
# Will post information about slaves
'computer_partition_id'
:
partition_id
,
for
slave
in
instance
.
_parameter_dict
[
'slave_instance_list'
]:
'connection_xml'
:
xml_marshaller
.
xml_marshaller
.
dumps
(
connection_dict
),
request_dict
=
{
'slave_reference'
:
slave_reference
})
'slave_reference'
:
slave
[
'slave_reference'
],
'computer_partition_id'
:
instance
.
_partition_id
,
def
getPartitionInformation
(
self
,
computer_partition_id
):
'connection_xml'
:
xml_marshaller
.
xml_marshaller
.
dumps
(
"""
instance
.
_connection_dict
),
Return computer information as stored in proxy for corresponding id
}
"""
self
.
app
.
post
(
'/setComputerPartitionConnectionXml'
,
rv
=
self
.
app
.
get
(
'/getFullComputerInformation?computer_id='
data
=
request_dict
)
+
self
.
computer_id
)
# Will post information about instance
computer
=
xml_marshaller
.
xml_marshaller
.
loads
(
rv
.
data
)
request_dict
=
{
for
instance
in
computer
.
_computer_partition_list
:
'slave_reference'
:
None
,
if
instance
.
_partition_id
==
computer_partition_id
:
'computer_partition_id'
:
instance
.
_partition_id
,
return
instance
'connection_xml'
:
xml_marshaller
.
xml_marshaller
.
dumps
(
instance
.
_connection_dict
),
}
self
.
app
.
post
(
'/setComputerPartitionConnectionXml'
,
data
=
request_dict
)
class
TestRequest
(
MasterMixin
,
unittest
.
TestCase
):
class
TestRequest
(
MasterMixin
,
unittest
.
TestCase
):
...
@@ -307,33 +302,96 @@ class TestRequest (MasterMixin, unittest.TestCase):
...
@@ -307,33 +302,96 @@ 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:
1. Provide one corresponding partition
1. Provide one corresponding partition
2. Ask for Slave instance.
Error is raise because it is not ready
2. Ask for Slave instance.
But no connection parameters
But slave is added to Master Instance slave list
But slave is added to Master Instance slave list
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
s and itself
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
master_partition_id
=
self
.
request
(
'http://sr//'
,
None
,
master_partition_id
=
self
.
request
(
'http://sr//'
,
None
,
'Maria'
,
'slappart4'
).
_partition_id
'Maria'
,
'slappart4'
).
_partition_id
# Failed request of slave instance
# First request of slave instance
with
self
.
assertRaises
(
TypeError
):
name
=
'Maria'
self
.
request
(
'http://sr//'
,
None
,
'Maria'
,
'slappart2'
,
shared
=
True
)
requester
=
'slappart2'
our_slave
=
self
.
request
(
'http://sr//'
,
None
,
name
,
requester
,
shared
=
True
)
self
.
assertIsInstance
(
our_slave
,
slapos
.
slap
.
ComputerPartition
)
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
self
.
setComputerPartitionConnectionXml
(
master_partition
)
slave_address
=
{
'url'
:
'%s.master.com'
}
# Successfull slave request
self
.
setConnectionDict
(
partition_id
=
master_partition
.
_partition_id
,
self
.
assertIsInstance
(
connection_dict
=
slave_address
,
self
.
request
(
'http://sr//'
,
None
,
'Maria'
,
'slappart2'
,
shared
=
True
),
slave_reference
=
slave_for_master
[
'slave_reference'
])
slapos
.
slap
.
ComputerPartition
)
# Successfull slave request with connection parameters
our_slave
=
self
.
request
(
'http://sr//'
,
None
,
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