Ensure veth pairs are uniquely named

We name veth pairs using up to the first 6 characters from the nodes names. If
the node name prefixes are longer than this then the node index will not be
included, and the interface names will not be unique.

e.g. prefix compute, 2 nodes: compute0 & compute1

Link names are all p-comput-0-tap

Note that the 0 here is the index of the physnet, node the node.

This patch includes any trailing digits to keep link names unique, e.g.
p-compu0-0-tap.

Change-Id: I35c3da1d00030d8a270ac1a09e88e22098594f20
Story: 2007431
Task: 39058
This commit is contained in:
Mark Goddard 2020-03-13 17:40:59 +00:00
parent f2560ae00f
commit eb34860069
2 changed files with 17 additions and 3 deletions

View File

@ -201,9 +201,17 @@ def _parse_size_string(size):
def _link_name(context, node, physnet, inventory_hostname=None):
prefix = _get_hostvar(context, 'veth_prefix',
inventory_hostname=inventory_hostname)
# Use up to the first 6 characters of the node name to avoid hitting the
# maximum link name length limit (15).
name = node['name'][:6]
# Use up to 6 characters of the node name to avoid hitting the maximum link
# name length limit (15). Node names consist of a prefix and an index.
# Ensure we include the index to keep link names unique.
m = re.search(r'\d+$', node['name'])
trailing_digits = m.group()
if len(trailing_digits) > 6:
msg = ("Cannot ensure uniqueness of link names for node %s" %
node['name'])
raise AnsibleFilterError(to_text(msg))
name_prefix = node['name'][:6 - len(trailing_digits)]
name = name_prefix + trailing_digits
return (prefix + name + '-' +
str(physnet_name_to_index(context, physnet,
inventory_hostname=inventory_hostname)))

View File

@ -0,0 +1,6 @@
---
fixes:
- |
Fixes an issue where virtual Ethernet link names might not be unique. This
would cause nodes to fail to start. See `story 2007431
<https://storyboard.openstack.org/#!/story/2007431>`__ for details.