Commit 4fdd40d9 authored by Romain Courteaud's avatar Romain Courteaud

recipe/request: do not propagate the request destroyed state

Prevent unexpected instance deletion.
parent ef5585ab
Pipeline #18706 failed with stage
......@@ -88,7 +88,9 @@ class Recipe(object):
Possible names depend on requested partition's software type.
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:
See "return" input key.
......@@ -120,8 +122,13 @@ class Recipe(object):
slave = options.get('slave', 'false').lower() in \
librecipe.GenericBaseRecipe.TRUE_VALUES
# By default XXXX Way of doing it is ugly and dangerous
requested_state = options.get('state', buildout['slap-connection'].get('requested','started'))
# By default, propagate the state of the parent instance
# 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
slap = slapmodule.slap()
......
......@@ -89,6 +89,35 @@ class RecipeTestMixin(object):
partition_parameter_kw=self.called_partition_parameter_kw,
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):
recipe = request.Recipe
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment