Merge "Add a strict option to per role tasks file generation." into stable/ussuri
This commit is contained in:
commit
9af8337c4c
|
@ -220,4 +220,9 @@ EXCLUSIVE_NEUTRON_DRIVERS = ['ovn', 'openvswitch']
|
||||||
|
|
||||||
DEFAULT_STEPS_MAX = 6
|
DEFAULT_STEPS_MAX = 6
|
||||||
|
|
||||||
PER_STEP_TASKS = ['upgrade_tasks', 'deploy_steps_tasks']
|
_PER_STEP_TASK_STRICTNESS = [False for i in range(DEFAULT_STEPS_MAX)]
|
||||||
|
|
||||||
|
PER_STEP_TASKS = {
|
||||||
|
'upgrade_tasks': _PER_STEP_TASK_STRICTNESS,
|
||||||
|
'deploy_steps_tasks': _PER_STEP_TASK_STRICTNESS
|
||||||
|
}
|
||||||
|
|
|
@ -121,14 +121,18 @@ class Config(object):
|
||||||
return os.fdopen(
|
return os.fdopen(
|
||||||
os.open(path, os.O_WRONLY | os.O_CREAT | os.O_TRUNC, 0o600), 'w')
|
os.open(path, os.O_WRONLY | os.O_CREAT | os.O_TRUNC, 0o600), 'w')
|
||||||
|
|
||||||
def _write_tasks_per_step(self, tasks, filepath, step):
|
def _write_tasks_per_step(self, tasks, filepath, step, strict=False):
|
||||||
|
|
||||||
def step_in_task(task, step):
|
def step_in_task(task, step, strict):
|
||||||
whenexpr = task.get('when', None)
|
whenexpr = task.get('when', None)
|
||||||
if whenexpr is None:
|
if whenexpr is None:
|
||||||
# If no step is defined, it will be executed for all
|
if not strict:
|
||||||
# steps.
|
# If no step is defined, it will be executed for all
|
||||||
return True
|
# steps if strict is false
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
# We only want the task with the step defined.
|
||||||
|
return False
|
||||||
if not isinstance(whenexpr, list):
|
if not isinstance(whenexpr, list):
|
||||||
whenexpr = [whenexpr]
|
whenexpr = [whenexpr]
|
||||||
for w in whenexpr:
|
for w in whenexpr:
|
||||||
|
@ -145,9 +149,14 @@ class Config(object):
|
||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
|
# No match
|
||||||
|
if strict:
|
||||||
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
tasks_per_step = [task for task in tasks if step_in_task(task, step)]
|
tasks_per_step = [task for task in tasks if step_in_task(task,
|
||||||
|
step,
|
||||||
|
strict)]
|
||||||
with self._open_file(filepath) as conf_file:
|
with self._open_file(filepath) as conf_file:
|
||||||
yaml.safe_dump(tasks_per_step, conf_file, default_flow_style=False)
|
yaml.safe_dump(tasks_per_step, conf_file, default_flow_style=False)
|
||||||
return tasks_per_step
|
return tasks_per_step
|
||||||
|
@ -264,12 +273,14 @@ class Config(object):
|
||||||
# run per step.
|
# run per step.
|
||||||
# We include it here to allow the CI to pass until THT
|
# We include it here to allow the CI to pass until THT
|
||||||
# changed is not merged.
|
# changed is not merged.
|
||||||
if config in constants.PER_STEP_TASKS:
|
if config in constants.PER_STEP_TASKS.keys():
|
||||||
for i in range(constants.DEFAULT_STEPS_MAX):
|
for i in range(len(constants.PER_STEP_TASKS[config])):
|
||||||
filepath = os.path.join(role_path, '%s_step%s.yaml'
|
filepath = os.path.join(role_path, '%s_step%s.yaml'
|
||||||
% (config, i))
|
% (config, i))
|
||||||
self._write_tasks_per_step(role[config],
|
self._write_tasks_per_step(
|
||||||
filepath, i)
|
role[config],
|
||||||
|
filepath,
|
||||||
|
i, constants.PER_STEP_TASKS[config][i])
|
||||||
|
|
||||||
try:
|
try:
|
||||||
data = role[config]
|
data = role[config]
|
||||||
|
|
Loading…
Reference in New Issue