Per server deployments instead of per role

The ansible variables containing the list of deployment names that apply
to each server are now written as individual host_vars instead of
group_vars. This change handles the case where a deployment only applies
to a single server (or subset of servers) within a role instead of
applying to all servers in that role.

Change-Id: I06e8de7a81d06445768b729bf9a8e8b58455415f
Closes-Bug: #1798895
This commit is contained in:
James Slagle 2018-10-23 08:57:05 -04:00
parent 85e99cc444
commit 6d74a843b5
12 changed files with 84 additions and 43 deletions

View File

@ -0,0 +1,7 @@
---
fixes:
- The list of pre and post deployment names generated with config-download
are now written per server instead of per role. This change handles the
case where a deployment may apply to only an individual or set of servers
within a role, and not all servers in that role. host_vars are used to set
the variable of deployment names per server instead of group_vars.

View File

@ -1,14 +1,3 @@
{{ role }}_pre_deployments:
{% for deployment in pre_deployments %}
- {{ deployment }}
{% endfor %}
{{ role }}_post_deployments: {% if not post_deployments %} [] {% endif %}
{% for deployment in post_deployments %}
- {{ deployment }}
{% endfor %}
{% for k,v in role_group_vars.items() %} {% for k,v in role_group_vars.items() %}
{{ k }}: {{ v }} {{ k }}: {{ v }}
{% endfor %} {% endfor %}

View File

@ -0,0 +1,10 @@
{{ role }}_pre_deployments:
{% for deployment in pre_deployments %}
- {{ deployment }}
{% endfor %}
{{ role }}_post_deployments: {% if not post_deployments %} [] {% endif %}
{% for deployment in post_deployments %}
- {{ deployment }}
{% endfor %}

View File

@ -1,10 +1,2 @@
Compute_pre_deployments:
- ComputeHostEntryDeployment
- NetworkDeployment
- MyExtraConfigPost
- AnsibleDeployment
Compute_post_deployments: []
max_fail_percentage: 15 max_fail_percentage: 15
any_errors_fatal: yes any_errors_fatal: yes

View File

@ -1,10 +1,2 @@
Controller_pre_deployments:
- ControllerHostEntryDeployment
- NetworkDeployment
- MyPostConfig
- MyExtraConfigPost
Controller_post_deployments: []
max_fail_percentage: 15 max_fail_percentage: 15
any_errors_fatal: yes any_errors_fatal: yes

View File

@ -52,6 +52,8 @@ deployments:
deployment: 5096a321-64f9-4f07-a74c-53f2b029e62e deployment: 5096a321-64f9-4f07-a74c-53f2b029e62e
config: 9ccb2f66-7cd8-4e3e-a034-4c1cfafd037e config: 9ccb2f66-7cd8-4e3e-a034-4c1cfafd037e
name: MyExtraConfigPost name: MyExtraConfigPost
# Only applies to overcloud-novacompute-2
- server: 169b46f8-1965-4d90-a7de-f36fb4a830fe - server: 169b46f8-1965-4d90-a7de-f36fb4a830fe
deployment: 05c94b5d-59ad-484e-b120-e271c2e100ed deployment: 05c94b5d-59ad-484e-b120-e271c2e100ed
config: 391263ba-3d06-43b6-a47e-481808aaff20 config: 391263ba-3d06-43b6-a47e-481808aaff20

View File

@ -0,0 +1,7 @@
Controller_pre_deployments:
- ControllerHostEntryDeployment
- NetworkDeployment
- MyPostConfig
- MyExtraConfigPost
Controller_post_deployments: []

View File

@ -0,0 +1,6 @@
Compute_pre_deployments:
- ComputeHostEntryDeployment
- NetworkDeployment
- MyExtraConfigPost
Compute_post_deployments: []

View File

@ -0,0 +1,6 @@
Compute_pre_deployments:
- ComputeHostEntryDeployment
- NetworkDeployment
- MyExtraConfigPost
Compute_post_deployments: []

View File

@ -0,0 +1,7 @@
Compute_pre_deployments:
- ComputeHostEntryDeployment
- NetworkDeployment
- MyExtraConfigPost
- AnsibleDeployment
Compute_post_deployments: []

View File

@ -300,9 +300,19 @@ class TestConfig(base.TestCase):
'Compute', ]: 'Compute', ]:
self.assertEqual( self.assertEqual(
self._get_yaml_file(f),
yaml.safe_load( yaml.safe_load(
open(os.path.join(tmp_path, 'group_vars', f)).read()), open(os.path.join(tmp_path, 'group_vars', f)).read()))
self._get_yaml_file(f))
for f in ['overcloud-controller-0',
'overcloud-novacompute-0',
'overcloud-novacompute-1',
'overcloud-novacompute-2']:
self.assertEqual(
self._get_yaml_file(os.path.join('host_vars', f)),
yaml.safe_load(
open(os.path.join(tmp_path, 'host_vars', f)).read()))
for d in ['ControllerHostEntryDeployment', for d in ['ControllerHostEntryDeployment',
'NetworkDeployment', 'NetworkDeployment',

View File

@ -245,10 +245,10 @@ class Config(object):
# server_names is a dict of server id to server_name for easier lookup # server_names is a dict of server id to server_name for easier lookup
server_names = self.get_server_names() server_names = self.get_server_names()
server_ids = dict([(v, k) for (k, v) in server_names.items()]) server_ids = dict([(v, k) for (k, v) in server_names.items()])
# role_deployment_names is a dict of role names to deployment names for # server_deployment_names is a dict of server names to deployment names
# that role. The deployment names are further separated in their own # for that role. The deployment names are further separated in their
# dict with keys of pre_deployment/post_deployment. # own dict with keys of pre_deployment/post_deployment.
role_deployment_names = {} server_deployment_names = {}
# server_roles is a dict of server name to server role for easier # server_roles is a dict of server name to server role for easier
# lookup # lookup
server_roles = {} server_roles = {}
@ -325,10 +325,11 @@ class Config(object):
raise Exception(err_msg) raise Exception(err_msg)
role = self.get_role_from_server_id(stack, server_id) role = self.get_role_from_server_id(stack, server_id)
role_deployments = role_deployment_names.setdefault(role, {}) server_pre_deployments = server_deployment_names.setdefault(
role_pre_deployments = role_deployments.setdefault( server_names[server_id], {}).setdefault(
'pre_deployments', []) 'pre_deployments', [])
role_post_deployments = role_deployments.setdefault( server_post_deployments = server_deployment_names.setdefault(
server_names[server_id], {}).setdefault(
'post_deployments', []) 'post_deployments', [])
server_roles[server_names[server_id]] = role server_roles[server_names[server_id]] = role
@ -339,11 +340,11 @@ class Config(object):
# they are consistent interfaces in our templates. # they are consistent interfaces in our templates.
if 'ExtraConfigPost' in deployment.physical_resource_id or \ if 'ExtraConfigPost' in deployment.physical_resource_id or \
'PostConfig' in deployment.physical_resource_id: 'PostConfig' in deployment.physical_resource_id:
if deployment_name not in role_post_deployments: if deployment_name not in server_post_deployments:
role_post_deployments.append(deployment_name) server_post_deployments.append(deployment_name)
else: else:
if deployment_name not in role_pre_deployments: if deployment_name not in server_pre_deployments:
role_pre_deployments.append(deployment_name) server_pre_deployments.append(deployment_name)
env, templates_path = self.get_jinja_env(config_dir) env, templates_path = self.get_jinja_env(config_dir)
@ -412,19 +413,31 @@ class Config(object):
self.validate_config(template_data, deployment_path) self.validate_config(template_data, deployment_path)
f.write(template_data) f.write(template_data)
for role, deployments in role_deployment_names.items(): # Render group_vars
for role in set(server_roles.values()):
group_var_role_path = os.path.join(group_vars_dir, role) group_var_role_path = os.path.join(group_vars_dir, role)
group_var_role_template = env.get_template('group_var_role.j2') group_var_role_template = env.get_template('group_var_role.j2')
with open(group_var_role_path, 'w') as f: with open(group_var_role_path, 'w') as f:
template_data = group_var_role_template.render( template_data = group_var_role_template.render(
role=role, role=role,
pre_deployments=deployments['pre_deployments'],
post_deployments=deployments['post_deployments'],
role_group_vars=role_group_vars[role]) role_group_vars=role_group_vars[role])
self.validate_config(template_data, group_var_role_path) self.validate_config(template_data, group_var_role_path)
f.write(template_data) f.write(template_data)
# Render host_vars
for server, deployments in server_deployment_names.items():
host_var_server_path = os.path.join(host_vars_dir, server)
host_var_server_template = env.get_template('host_var_server.j2')
with open(host_var_server_path, 'w') as f:
template_data = host_var_server_template.render(
role=server_roles[server],
pre_deployments=deployments['pre_deployments'],
post_deployments=deployments['post_deployments'])
self.validate_config(template_data, host_var_server_path)
f.write(template_data)
shutil.copyfile( shutil.copyfile(
os.path.join(templates_path, 'deployments.yaml'), os.path.join(templates_path, 'deployments.yaml'),
os.path.join(config_dir, 'deployments.yaml')) os.path.join(config_dir, 'deployments.yaml'))