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
This commit is contained in:
Eduardo Olivares 2024-12-11 09:26:06 +01:00
parent 8466581e52
commit 7d2eef5654
5 changed files with 20 additions and 22 deletions

View File

@ -268,6 +268,17 @@ subparsers:
Timeout error is raised if an ubuntu instance is not reachable Timeout error is raised if an ubuntu instance is not reachable
before it expires before it expires
ansible_variable: ubuntu_is_reachable_timeout 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: cleanup-containerlist-file:
type: Bool type: Bool
help: | help: |

View File

@ -72,5 +72,5 @@ download_images:
--run-command 'systemctl enable iperf3-server@5201' --run-command 'systemctl enable iperf3-server@5201'
--run-command 'echo "8021q" >> /etc/modules' --run-command 'echo "8021q" >> /etc/modules'
--run-command --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' > /etc/netplan/75-tobiko-vlan.yaml'

View File

@ -31,6 +31,12 @@
value: True value: True
{% endif %} {% endif %}
{% endfor %} {% endfor %}
{% if ubuntu_nic_name is defined %}
- section: ubuntu
option: interface_name
value: "{{ ubuntu_nic_name }}"
{% endif %}
vars: vars:
sections: "{{ test_default_conf | combine(test_conf, recursive=True) }}" sections: "{{ test_default_conf | combine(test_conf, recursive=True) }}"

View File

@ -59,7 +59,7 @@ def get_images_options():
cfg.StrOpt('password', cfg.StrOpt('password',
help="Default " + name + " password"), help="Default " + name + " password"),
cfg.StrOpt('interface_name', cfg.StrOpt('interface_name',
default=None, default=None if name != 'ubuntu' else 'ens3',
help="Default " + name + " interface name"), help="Default " + name + " interface name"),
cfg.FloatOpt('connection_timeout', cfg.FloatOpt('connection_timeout',
default=None, default=None,

View File

@ -114,26 +114,7 @@ class UbuntuImageFixture(glance.CustomizedGlanceImageFixture):
run_commands.append('echo "8021q" >> /etc/modules') run_commands.append('echo "8021q" >> /etc/modules')
return run_commands return run_commands
@property ethernet_device = CONF.tobiko.ubuntu.interface_name
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'
def _get_customized_suffix(self) -> str: def _get_customized_suffix(self) -> str:
return f'{super()._get_customized_suffix()}-{self.ethernet_device}' return f'{super()._get_customized_suffix()}-{self.ethernet_device}'