Merge "Properly collect tasks with or conditional in step file." into stable/ussuri
This commit is contained in:
commit
fe15c10a7e
|
@ -1039,3 +1039,107 @@ class OvercloudConfigTest(base.TestCase):
|
||||||
'config-download-latest'))
|
'config-download-latest'))
|
||||||
mock_os_unlink.assert_called_once_with(
|
mock_os_unlink.assert_called_once_with(
|
||||||
'/var/lib/mistral/config-download-latest')
|
'/var/lib/mistral/config-download-latest')
|
||||||
|
|
||||||
|
@patch.object(ooo_config.Config, '_open_file')
|
||||||
|
def test_overcloud_config__write_tasks_per_step(self, mock_open_file):
|
||||||
|
heat = mock.MagicMock()
|
||||||
|
self.config = ooo_config.Config(heat)
|
||||||
|
|
||||||
|
# TODO: how can I share this tasks definition between to test
|
||||||
|
# as a fixture So that I do two several test cases instead of
|
||||||
|
# a big one.
|
||||||
|
tasks = [
|
||||||
|
{
|
||||||
|
"when": "step|int == 0",
|
||||||
|
"name": "Simple check"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"when": "(step|int == 0)",
|
||||||
|
"name": "Check within parenthesis"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"when": ["step|int == 0", "test1", False],
|
||||||
|
"name": "Check with list with boolean"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"when": ["test1", False, "step|int == 0"],
|
||||||
|
"name": "Check with list with boolean other order"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"when": "step|int == 0 or step|int == 3",
|
||||||
|
"name": "Check with boolean expression"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"when": "(step|int == 0 or step|int == 3) and other_cond",
|
||||||
|
"name": "Complex boolean expression"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Task with no conditional"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
||||||
|
# Everything should come back
|
||||||
|
tasks_per_step = self.config._write_tasks_per_step(
|
||||||
|
tasks,
|
||||||
|
'Compute/update_tasks_step0.yaml',
|
||||||
|
0
|
||||||
|
)
|
||||||
|
|
||||||
|
self.assertEqual(tasks, tasks_per_step)
|
||||||
|
|
||||||
|
# Using stict the tasks with no conditional will be dropped
|
||||||
|
tasks_per_step = self.config._write_tasks_per_step(
|
||||||
|
tasks,
|
||||||
|
'Compute/update_tasks_step0.yaml',
|
||||||
|
0,
|
||||||
|
strict=True,
|
||||||
|
)
|
||||||
|
|
||||||
|
expected_tasks = [task for task in tasks
|
||||||
|
if task != {"name": "Task with no conditional"}]
|
||||||
|
self.assertEqual(expected_tasks,
|
||||||
|
tasks_per_step)
|
||||||
|
|
||||||
|
# Some tasks will be filtered out for step 3.
|
||||||
|
tasks_per_step = self.config._write_tasks_per_step(
|
||||||
|
tasks,
|
||||||
|
'Compute/update_tasks_step3.yaml',
|
||||||
|
3
|
||||||
|
)
|
||||||
|
|
||||||
|
self.assertEqual(
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"when": "step|int == 0 or step|int == 3",
|
||||||
|
"name": "Check with boolean expression"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"when": "(step|int == 0 or step|int == 3) and other_cond",
|
||||||
|
"name": "Complex boolean expression"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Task with no conditional"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
tasks_per_step)
|
||||||
|
|
||||||
|
# Even more tasks will be filtered out for step 3 with strict.
|
||||||
|
tasks_per_step = self.config._write_tasks_per_step(
|
||||||
|
tasks,
|
||||||
|
'Compute/update_tasks_step3.yaml',
|
||||||
|
3,
|
||||||
|
strict=True,
|
||||||
|
)
|
||||||
|
|
||||||
|
self.assertEqual(
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"when": "step|int == 0 or step|int == 3",
|
||||||
|
"name": "Check with boolean expression"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"when": "(step|int == 0 or step|int == 3) and other_cond",
|
||||||
|
"name": "Complex boolean expression"
|
||||||
|
},
|
||||||
|
],
|
||||||
|
tasks_per_step)
|
||||||
|
|
|
@ -135,21 +135,22 @@ class Config(object):
|
||||||
return False
|
return False
|
||||||
if not isinstance(whenexpr, list):
|
if not isinstance(whenexpr, list):
|
||||||
whenexpr = [whenexpr]
|
whenexpr = [whenexpr]
|
||||||
for w in whenexpr:
|
|
||||||
# "when" accepts booleans and regex only work for strings
|
# Filter out boolean value and remove blanks
|
||||||
if not isinstance(w, six.string_types):
|
flatten_when = "".join([re.sub(r'\s+', '', x)
|
||||||
continue
|
for x in whenexpr
|
||||||
# remove all spaces to make the regex match easier
|
if isinstance(x, six.string_types)])
|
||||||
w = re.sub(r'\s+', '', w)
|
# make \|int optional incase forgotten; use only step digit:
|
||||||
# make \|int optional incase forgotten; use only step digit:
|
# ()'s around step|int are also optional
|
||||||
# ()'s around step|int are also optional
|
steps_found = re.findall(r'\(?step(?:\|int)?\)?==(\d+)',
|
||||||
match = re.search(r'\(?step(\|int)?\)?==([0-9]+)$', "%s" % w)
|
flatten_when)
|
||||||
if match:
|
if steps_found:
|
||||||
if match.group(2) == str(step):
|
if str(step) in steps_found:
|
||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
# No match
|
|
||||||
|
# No step found
|
||||||
if strict:
|
if strict:
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
Loading…
Reference in New Issue