summaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
authorChristian Breunig <christian@breunig.cc>2024-12-21 23:29:21 +0100
committerChristian Breunig <christian@breunig.cc>2024-12-22 11:19:49 +0100
commit1c53bf748375482dfa1630f2ed98a435b9aaf4ea (patch)
treeae617d27bc13792de48c9a88361bb2cff3f872d1 /python
parent961440be7e9af7fad3dc2e1ecad4684a183f7997 (diff)
downloadvyos-1x-1c53bf748375482dfa1630f2ed98a435b9aaf4ea.tar.gz
vyos-1x-1c53bf748375482dfa1630f2ed98a435b9aaf4ea.zip
ifconfig: T6972: smoketests fail as IP address is not removed in time
From time to time integration tests fail as the DHCP assigned IP address is not removed in time then dhclient stops. Add an explicit code path cleaning dynamic assigned addresses from interface when disabling DHCP - if such a dynamic address is remaining. ====================================================================== FAIL: test_dhcp_vrf (__main__.EthernetInterfaceTest.test_dhcp_vrf) ---------------------------------------------------------------------- Traceback (most recent call last): File "/usr/libexec/vyos/tests/smoke/cli/test_interfaces_ethernet.py", line 72, in tearDown self.assertNotIn(AF_INET, ifaddresses(interface)) AssertionError: 2 unexpectedly found in {17: [{'addr': '52:54:00:00:00:00', 'broadcast': 'ff:ff:ff:ff:ff:ff'}], 2: [{'addr': '192.0.2.103', 'netmask': '255.255.255.0', 'broadcast': '192.0.2.255'}], 10: [{'addr': 'fe80::5054:ff:fe00:0%eth0', 'netmask': 'ffff:ffff:ffff:ffff::/64'}]}
Diffstat (limited to 'python')
-rw-r--r--python/vyos/ifconfig/interface.py27
1 files changed, 21 insertions, 6 deletions
diff --git a/python/vyos/ifconfig/interface.py b/python/vyos/ifconfig/interface.py
index eac9f61f5..cad1685a9 100644
--- a/python/vyos/ifconfig/interface.py
+++ b/python/vyos/ifconfig/interface.py
@@ -29,6 +29,7 @@ from netifaces import AF_INET6
from netaddr import EUI
from netaddr import mac_unix_expanded
+from vyos.base import ConfigError
from vyos.configdict import list_diff
from vyos.configdict import dict_merge
from vyos.configdict import get_vlan_ids
@@ -43,6 +44,7 @@ from vyos.template import render
from vyos.utils.network import mac2eui64
from vyos.utils.dict import dict_search
from vyos.utils.network import get_interface_config
+from vyos.utils.network import get_interface_address
from vyos.utils.network import get_interface_namespace
from vyos.utils.network import get_vrf_tableid
from vyos.utils.network import is_netns_interface
@@ -62,7 +64,6 @@ from vyos.ifconfig.control import Control
from vyos.ifconfig.vrrp import VRRP
from vyos.ifconfig.operational import Operational
from vyos.ifconfig import Section
-from vyos import ConfigError
link_local_prefix = 'fe80::/64'
@@ -1375,12 +1376,11 @@ class Interface(Control):
if enable not in [True, False]:
raise ValueError()
- ifname = self.ifname
config_base = directories['isc_dhclient_dir'] + '/dhclient'
- dhclient_config_file = f'{config_base}_{ifname}.conf'
- dhclient_lease_file = f'{config_base}_{ifname}.leases'
- systemd_override_file = f'/run/systemd/system/dhclient@{ifname}.service.d/10-override.conf'
- systemd_service = f'dhclient@{ifname}.service'
+ dhclient_config_file = f'{config_base}_{self.ifname}.conf'
+ dhclient_lease_file = f'{config_base}_{self.ifname}.leases'
+ systemd_override_file = f'/run/systemd/system/dhclient@{self.ifname}.service.d/10-override.conf'
+ systemd_service = f'dhclient@{self.ifname}.service'
# Rendered client configuration files require the apsolute config path
self.config['isc_dhclient_dir'] = directories['isc_dhclient_dir']
@@ -1414,6 +1414,21 @@ class Interface(Control):
else:
if is_systemd_service_active(systemd_service):
self._cmd(f'systemctl stop {systemd_service}')
+
+ # Smoketests occationally fail if the lease is not removed from the Kernel fast enough:
+ # AssertionError: 2 unexpectedly found in {17: [{'addr': '52:54:00:00:00:00',
+ # 'broadcast': 'ff:ff:ff:ff:ff:ff'}], 2: [{'addr': '192.0.2.103', 'netmask': '255.255.255.0',
+ #
+ # We will force removal of any dynamic IPv4 address from the interface
+ tmp = get_interface_address(self.ifname)
+ if tmp and 'addr_info' in tmp:
+ for address_dict in tmp['addr_info']:
+ # Only remove dynamic assigned addresses
+ if 'dynamic' not in address_dict:
+ continue
+ address = address_dict['local']
+ self.del_addr(address)
+
# cleanup old config files
for file in [dhclient_config_file, systemd_override_file, dhclient_lease_file]:
if os.path.isfile(file):