From 7d2eef5654fc5e97ccf7c4ff21c3b00900f65ee1 Mon Sep 17 00:00:00 2001 From: Eduardo Olivares Date: Wed, 11 Dec 2024 09:26:06 +0100 Subject: [PATCH] Make ubuntu_interface configurable again With some recent changes, the virt-customize command that modifies the ubuntu guest image was broken: the interface name was hardcoded to "ens3" and in some cases it should be set to "enp3s0". This patch makes the value it configurable. Change-Id: If31d9d998931253cbea9ae5310e2c36b6b7e2ce9 --- infrared_plugin/plugin.spec | 11 +++++++++++ roles/tobiko-common/defaults/main.yaml | 2 +- roles/tobiko-configure/tasks/main.yaml | 6 ++++++ tobiko/openstack/glance/config.py | 2 +- tobiko/openstack/stacks/_ubuntu.py | 21 +-------------------- 5 files changed, 20 insertions(+), 22 deletions(-) diff --git a/infrared_plugin/plugin.spec b/infrared_plugin/plugin.spec index 234ab632c..73917a532 100644 --- a/infrared_plugin/plugin.spec +++ b/infrared_plugin/plugin.spec @@ -268,6 +268,17 @@ subparsers: Timeout error is raised if an ubuntu instance is not reachable before it expires ansible_variable: ubuntu_is_reachable_timeout + ubuntu-vm-nic-name: + type: Value + help: | + NIC name expected on Ubuntu VM instances. + When Openstack spawns these VMs, their NIC (usually they + only have one NIC and one VLAN on that NIC) name is usually + "ens3", but with some Openstack versions, it is "enp3s0". + Defaults to "enp3s0" because it is the value obtained with + Openstack versions that use infrared. + default: "enp3s0" + ansible_variable: ubuntu_nic_name cleanup-containerlist-file: type: Bool help: | diff --git a/roles/tobiko-common/defaults/main.yaml b/roles/tobiko-common/defaults/main.yaml index 1c39449e2..218fb3946 100644 --- a/roles/tobiko-common/defaults/main.yaml +++ b/roles/tobiko-common/defaults/main.yaml @@ -72,5 +72,5 @@ download_images: --run-command 'systemctl enable iperf3-server@5201' --run-command 'echo "8021q" >> /etc/modules' --run-command - 'echo "network:\n version: 2\n vlans:\n vlan101:\n dhcp4: true\n dhcp4-overrides:\n use-routes: false\n dhcp6: true\n dhcp6-overrides:\n use-routes: false\n id: 101\n link: ens3\n" + 'echo "network:\n version: 2\n vlans:\n vlan101:\n dhcp4: true\n dhcp4-overrides:\n use-routes: false\n dhcp6: true\n dhcp6-overrides:\n use-routes: false\n id: 101\n link: {{ ubuntu_nic_name | default('ens3') }}\n" > /etc/netplan/75-tobiko-vlan.yaml' diff --git a/roles/tobiko-configure/tasks/main.yaml b/roles/tobiko-configure/tasks/main.yaml index e67653ff4..290d7dc28 100644 --- a/roles/tobiko-configure/tasks/main.yaml +++ b/roles/tobiko-configure/tasks/main.yaml @@ -31,6 +31,12 @@ value: True {% endif %} {% endfor %} + {% if ubuntu_nic_name is defined %} + - section: ubuntu + option: interface_name + value: "{{ ubuntu_nic_name }}" + {% endif %} + vars: sections: "{{ test_default_conf | combine(test_conf, recursive=True) }}" diff --git a/tobiko/openstack/glance/config.py b/tobiko/openstack/glance/config.py index 65a066b7b..9d2397b9e 100644 --- a/tobiko/openstack/glance/config.py +++ b/tobiko/openstack/glance/config.py @@ -59,7 +59,7 @@ def get_images_options(): cfg.StrOpt('password', help="Default " + name + " password"), cfg.StrOpt('interface_name', - default=None, + default=None if name != 'ubuntu' else 'ens3', help="Default " + name + " interface name"), cfg.FloatOpt('connection_timeout', default=None, diff --git a/tobiko/openstack/stacks/_ubuntu.py b/tobiko/openstack/stacks/_ubuntu.py index 6ab920d52..500f56b6e 100644 --- a/tobiko/openstack/stacks/_ubuntu.py +++ b/tobiko/openstack/stacks/_ubuntu.py @@ -114,26 +114,7 @@ class UbuntuImageFixture(glance.CustomizedGlanceImageFixture): run_commands.append('echo "8021q" >> /etc/modules') return run_commands - @property - def ethernet_device(self) -> str: - if self._ethernet_device is None: - self._ethernet_device = self._get_ethernet_device() - return self._ethernet_device - - @staticmethod - def _get_ethernet_device() -> str: - """From OSP17 and above, Ubuntu stack should use a different interface - name. This method returns the interface name, depending on the OSP - version. - """ - if_name = CONF.tobiko.ubuntu.interface_name - if if_name is not None: - return if_name - from tobiko import tripleo - if tripleo.has_overcloud(min_version='17.0'): - return 'enp3s0' - else: - return 'ens3' + ethernet_device = CONF.tobiko.ubuntu.interface_name def _get_customized_suffix(self) -> str: return f'{super()._get_customized_suffix()}-{self.ethernet_device}'