Add yaml validation for upgrade_tasks section.

In every ansible task defined within upgrade_tasks it is
necessary to specify the tag 'tags' which are used during
the ansible execution for the upgrade_tasks serialization.

Adding the 'tags' check per upgrade_tasks step into
the YAML validation will allow us to catch if any
service upgrade task is missing this flag.

Change-Id: I8f56a87cc2e9ffc0d827bbb729f6bc3f6ca7550b
This commit is contained in:
Jose Luis Franco Arza 2017-08-25 15:39:37 +02:00
parent 7897d38274
commit 0be3317f45
2 changed files with 31 additions and 2 deletions

View File

@ -72,11 +72,10 @@ outputs:
register: bootstrap_node
- block:
- name: Sync cinder DB
tags: step5
command: cinder-manage db sync
- name: Start cinder_volume service (pacemaker)
tags: step5
pacemaker_resource:
resource: openstack-cinder-volume
state: enable
tags: step5
when: bootstrap_node.stdout == ansible_hostname

View File

@ -356,6 +356,11 @@ def validate_docker_service(filename, tpl):
print('ERROR: bootstrap_host_exec needs to run as the root user.')
return 1
if 'upgrade_tasks' in role_data and role_data['upgrade_tasks'] and \
validate_upgrade_tasks(role_data['upgrade_tasks']):
print('ERROR: upgrade_tasks validation failed')
return 1
if 'parameters' in tpl:
for param in required_params:
if param not in tpl['parameters']:
@ -388,6 +393,10 @@ def validate_service(filename, tpl):
validate_mysql_connection(role_data['config_settings']):
print('ERROR: mysql connection uri should use option bind_address')
return 1
if 'upgrade_tasks' in role_data and role_data['upgrade_tasks'] and \
validate_upgrade_tasks(role_data['upgrade_tasks']):
print('ERROR: upgrade_tasks validation failed')
return 1
if 'parameters' in tpl:
for param in required_params:
if param not in tpl['parameters']:
@ -466,6 +475,27 @@ def validate(filename, param_map):
return retval
def validate_upgrade_tasks(upgrade_steps):
# some templates define its upgrade_tasks via list_concat
if isinstance(upgrade_steps, dict):
if upgrade_steps.get('list_concat'):
return validate_upgrade_tasks(upgrade_steps['list_concat'][1])
elif upgrade_steps.get('get_attr'):
return 0
for step in upgrade_steps:
if 'tags' not in step.keys():
if 'name' in step.keys():
print('ERROR: upgrade task named (%s) is missing its tags keyword.'
% step['name'])
else:
print('ERROR: upgrade task (%s) is missing its tags keyword.'
% step)
return 1
return 0
if len(sys.argv) < 2:
exit_usage()