Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
slapos
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
Justin
slapos
Commits
4fdd40d9
Commit
4fdd40d9
authored
Dec 02, 2021
by
Romain Courteaud
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
recipe/request: do not propagate the request destroyed state
Prevent unexpected instance deletion.
parent
ef5585ab
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
39 additions
and
3 deletions
+39
-3
slapos/recipe/request.py
slapos/recipe/request.py
+10
-3
slapos/test/recipe/test_request.py
slapos/test/recipe/test_request.py
+29
-0
No files found.
slapos/recipe/request.py
View file @
4fdd40d9
...
@@ -88,7 +88,9 @@ class Recipe(object):
...
@@ -88,7 +88,9 @@ class Recipe(object):
Possible names depend on requested partition's software type.
Possible names depend on requested partition's software type.
state (optional)
state (optional)
Requested state, default value is the state of the requester.
Requested state, default value is "started", except the state of
the requester is "stopped" (which changes the default value to
"stopped").
Output:
Output:
See "return" input key.
See "return" input key.
...
@@ -120,8 +122,13 @@ class Recipe(object):
...
@@ -120,8 +122,13 @@ class Recipe(object):
slave
=
options
.
get
(
'slave'
,
'false'
).
lower
()
in
\
slave
=
options
.
get
(
'slave'
,
'false'
).
lower
()
in
\
librecipe
.
GenericBaseRecipe
.
TRUE_VALUES
librecipe
.
GenericBaseRecipe
.
TRUE_VALUES
# By default XXXX Way of doing it is ugly and dangerous
# By default, propagate the state of the parent instance
requested_state
=
options
.
get
(
'state'
,
buildout
[
'slap-connection'
].
get
(
'requested'
,
'started'
))
# Except if parent is destroyed, as it may lead to the unexpected
# destruction of the full instance tree
default_state
=
buildout
[
'slap-connection'
].
get
(
'requested'
,
'started'
)
if
default_state
not
in
(
'started'
,
'stopped'
):
default_state
=
'started'
requested_state
=
options
.
get
(
'state'
,
default_state
)
options
[
'requested-state'
]
=
requested_state
options
[
'requested-state'
]
=
requested_state
slap
=
slapmodule
.
slap
()
slap
=
slapmodule
.
slap
()
...
...
slapos/test/recipe/test_request.py
View file @
4fdd40d9
...
@@ -89,6 +89,35 @@ class RecipeTestMixin(object):
...
@@ -89,6 +89,35 @@ class RecipeTestMixin(object):
partition_parameter_kw
=
self
.
called_partition_parameter_kw
,
partition_parameter_kw
=
self
.
called_partition_parameter_kw
,
shared
=
False
,
state
=
'started'
)
shared
=
False
,
state
=
'started'
)
def
test_requester_stopped_state_propagated
(
self
):
options
=
defaultdict
(
str
)
options
[
'return'
]
=
'anything'
self
.
buildout
[
'slap-connection'
][
'requested'
]
=
'stopped'
self
.
instance_getConnectionParameter
.
return_value
=
self
.
return_value_empty
with
LogCapture
()
as
log
:
self
.
recipe
(
self
.
buildout
,
"request"
,
options
)
log
.
check
()
self
.
request_instance
.
assert_called_with
(
''
,
'RootSoftwareInstance'
,
''
,
filter_kw
=
{},
partition_parameter_kw
=
self
.
called_partition_parameter_kw
,
shared
=
False
,
state
=
'stopped'
)
def
test_requester_destroyed_state_not_propagated
(
self
):
options
=
defaultdict
(
str
)
options
[
'return'
]
=
'anything'
self
.
buildout
[
'slap-connection'
][
'requested'
]
=
'destroyed'
self
.
instance_getConnectionParameter
.
return_value
=
self
.
return_value_empty
with
LogCapture
()
as
log
:
self
.
recipe
(
self
.
buildout
,
"request"
,
options
)
log
.
check
()
self
.
request_instance
.
assert_called_with
(
''
,
'RootSoftwareInstance'
,
''
,
filter_kw
=
{},
partition_parameter_kw
=
self
.
called_partition_parameter_kw
,
shared
=
False
,
state
=
'started'
)
class
RecipeTest
(
RecipeTestMixin
,
unittest
.
TestCase
):
class
RecipeTest
(
RecipeTestMixin
,
unittest
.
TestCase
):
recipe
=
request
.
Recipe
recipe
=
request
.
Recipe
...
...
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