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
a9b92d27
Commit
a9b92d27
authored
Oct 25, 2016
by
Alain Takoudjou
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
slapproxy: propagate parent partition state to children
parent
3ba5547c
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
66 additions
and
5 deletions
+66
-5
slapos/proxy/views.py
slapos/proxy/views.py
+23
-4
slapos/tests/slapproxy/__init__.py
slapos/tests/slapproxy/__init__.py
+43
-1
No files found.
slapos/proxy/views.py
View file @
a9b92d27
...
...
@@ -547,6 +547,19 @@ def getAllocatedSlaveInstance(slave_reference, requested_computer_id):
# XXX: check there is only one result
return
execute_db
(
table
,
q
,
args
,
one
=
True
)
def
getRootPartition
(
reference
):
p
=
'SELECT * FROM %s WHERE reference=?'
parent_partition
=
execute_db
(
'partition'
,
p
,
[
reference
],
one
=
True
)
while
parent_partition
is
not
None
:
parent_reference
=
parent_partition
[
'requested_by'
]
if
not
parent_reference
or
parent_reference
==
reference
:
break
reference
=
parent_reference
parent_partition
=
execute_db
(
'partition'
,
p
,
[
reference
],
one
=
True
)
return
parent_partition
def
requestNotSlave
(
software_release
,
software_type
,
partition_reference
,
partition_id
,
partition_parameter_kw
,
filter_kw
,
requested_state
):
instance_xml
=
dict2xml
(
partition_parameter_kw
)
requested_computer_id
=
filter_kw
[
'computer_guid'
]
...
...
@@ -563,10 +576,6 @@ def requestNotSlave(software_release, software_type, partition_reference, partit
a
=
args
.
append
q
=
'UPDATE %s SET slap_state="busy"'
if
requested_state
:
q
+=
', requested_state=?'
a
(
requested_state
)
if
partition
is
None
:
partition
=
execute_db
(
'partition'
,
'SELECT * FROM %s WHERE slap_state="free" and computer_reference=?'
,
...
...
@@ -589,6 +598,16 @@ def requestNotSlave(software_release, software_type, partition_reference, partit
if
partition
[
'software_release'
].
encode
()
!=
software_release
:
q
+=
' ,software_release=?'
a
(
software_release
)
if
partition
[
'requested_by'
]:
root_partition
=
getRootPartition
(
partition
[
'requested_by'
])
if
root_partition
and
root_partition
[
'requested_state'
]
!=
"started"
:
# propagate parent state to child
# child can be stopped or destroyed while parent is started
requested_state
=
root_partition
[
'requested_state'
]
if
requested_state
:
q
+=
', requested_state=?'
a
(
requested_state
)
#
# XXX change software_type when requested
...
...
slapos/tests/slapproxy/__init__.py
View file @
a9b92d27
...
...
@@ -285,7 +285,7 @@ class MasterMixin(BasicMixin, unittest.TestCase):
Define advanced tool for test proxy simulating behavior slap library tools
"""
def
_requestComputerPartition
(
self
,
software_release
,
software_type
,
partition_reference
,
partition_id
,
partition_id
=
None
,
shared
=
False
,
partition_parameter_kw
=
None
,
filter_kw
=
None
,
state
=
None
):
"""
...
...
@@ -406,6 +406,48 @@ class TestRequest(MasterMixin):
self
.
request
(
'http://sr//'
,
None
,
'MyFirstInstance'
,
'slappart2'
).
__dict__
,
self
.
request
(
'http://sr//'
,
None
,
'MyFirstInstance'
,
'slappart2'
).
__dict__
)
def
test_request_propagate_partition_state
(
self
):
"""
Request will return same partition for two equal requests
"""
self
.
add_free_partition
(
2
)
partition_parent
=
self
.
request
(
'http://sr//'
,
None
,
'MyFirstInstance'
)
parent_dict
=
partition_parent
.
__dict__
partition_child
=
self
.
request
(
'http://sr//'
,
None
,
'MySubInstance'
,
parent_dict
[
'_partition_id'
])
self
.
assertEqual
(
partition_parent
.
getState
(),
'started'
)
self
.
assertEqual
(
partition_child
.
getState
(),
'started'
)
partition_parent
=
self
.
request
(
'http://sr//'
,
None
,
'MyFirstInstance'
,
state
=
'stopped'
)
partition_child
=
self
.
request
(
'http://sr//'
,
None
,
'MySubInstance'
,
parent_dict
[
'_partition_id'
])
self
.
assertEqual
(
partition_parent
.
getState
(),
'stopped'
)
self
.
assertEqual
(
partition_child
.
getState
(),
'stopped'
)
partition_parent
=
self
.
request
(
'http://sr//'
,
None
,
'MyFirstInstance'
,
state
=
'started'
)
partition_child
=
self
.
request
(
'http://sr//'
,
None
,
'MySubInstance'
,
parent_dict
[
'_partition_id'
])
self
.
assertEqual
(
partition_parent
.
getState
(),
'started'
)
self
.
assertEqual
(
partition_child
.
getState
(),
'started'
)
def
test_request_parent_started_children_stopped
(
self
):
"""
Request will return same partition for two equal requests
"""
self
.
add_free_partition
(
2
)
partition_parent
=
self
.
request
(
'http://sr//'
,
None
,
'MyFirstInstance'
)
parent_dict
=
partition_parent
.
__dict__
partition_child
=
self
.
request
(
'http://sr//'
,
None
,
'MySubInstance'
,
parent_dict
[
'_partition_id'
])
self
.
assertEqual
(
partition_parent
.
getState
(),
'started'
)
self
.
assertEqual
(
partition_child
.
getState
(),
'started'
)
partition_parent
=
self
.
request
(
'http://sr//'
,
None
,
'MyFirstInstance'
)
partition_child
=
self
.
request
(
'http://sr//'
,
None
,
'MySubInstance'
,
parent_dict
[
'_partition_id'
],
state
=
'stopped'
)
self
.
assertEqual
(
partition_parent
.
getState
(),
'started'
)
self
.
assertEqual
(
partition_child
.
getState
(),
'stopped'
)
def
test_two_requests_with_different_parameters_but_same_reference
(
self
):
"""
Request will return same partition for two different requests but will
...
...
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