From eb34860069c7379beea90028c951f6c036c0fd5d Mon Sep 17 00:00:00 2001 From: Mark Goddard Date: Fri, 13 Mar 2020 17:40:59 +0000 Subject: [PATCH] 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 --- ansible/filter_plugins/tenks.py | 14 +++++++++++--- .../fix-veth-uniqueness-05bf5ebfcd5d4929.yaml | 6 ++++++ 2 files changed, 17 insertions(+), 3 deletions(-) create mode 100644 releasenotes/notes/fix-veth-uniqueness-05bf5ebfcd5d4929.yaml diff --git a/ansible/filter_plugins/tenks.py b/ansible/filter_plugins/tenks.py index c7fb921..2418ac4 100644 --- a/ansible/filter_plugins/tenks.py +++ b/ansible/filter_plugins/tenks.py @@ -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))) diff --git a/releasenotes/notes/fix-veth-uniqueness-05bf5ebfcd5d4929.yaml b/releasenotes/notes/fix-veth-uniqueness-05bf5ebfcd5d4929.yaml new file mode 100644 index 0000000..7943998 --- /dev/null +++ b/releasenotes/notes/fix-veth-uniqueness-05bf5ebfcd5d4929.yaml @@ -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 + `__ for details.