From 4a018c44d6e90ee5972bdfa6ab44d6e12513bb12 Mon Sep 17 00:00:00 2001 From: Ravi Minnikanti Date: Wed, 4 Feb 2026 12:10:12 +0530 Subject: [PATCH] vrf: Fix ifupdown2_vrf_map.conf creation failure Older versions of iproute2 package created /etc/iproute2/rt_tables.d directory because of which ifupdown2_vrf_map.conf generation succeeded. New version of iproute2 (6.15.0-1) in debian trixie doesn't create /etc/iproute2, because of this vrf map conf generation failing, inturn resulting in mgmt VRF creation failure Fix is to ensure /etc/iproute2/rt_tables.d directory present before generating ifupdown2_vrf_map.conf Signed-off-by: Ravi Minnikanti --- ifupdown2/addons/vrf.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/ifupdown2/addons/vrf.py b/ifupdown2/addons/vrf.py index 712c5fd0..c88e5a59 100644 --- a/ifupdown2/addons/vrf.py +++ b/ifupdown2/addons/vrf.py @@ -265,6 +265,13 @@ def _iproute2_map_warn(self, errstr): 'map (%s)' %errstr) self.warn_on_vrf_map_write_err = False + def _ensure_iproute2_vrf_dir(self): + """Ensure the iproute2 VRF map directory exists""" + vrf_dir = os.path.dirname(self.iproute2_vrf_filename) + if not os.path.exists(vrf_dir): + os.makedirs(vrf_dir, exist_ok=True) + self.logger.info('vrf: created directory %s' % vrf_dir) + def _iproute2_vrf_map_sync_to_disk(self): if (ifupdownflags.flags.DRYRUN or not self.iproute2_vrf_map_sync_to_disk): @@ -272,6 +279,7 @@ def _iproute2_vrf_map_sync_to_disk(self): self.logger.info('vrf: syncing table map to %s' %self.iproute2_vrf_filename) try: + self._ensure_iproute2_vrf_dir() with open(self.iproute2_vrf_filename, 'w') as f: f.write(self.iproute2_vrf_filehdr %(self.vrf_table_id_start, self.vrf_table_id_end)) @@ -286,6 +294,7 @@ def _iproute2_vrf_map_open(self, sync_vrfs=False, append=False): %self.iproute2_vrf_filename) if ifupdownflags.flags.DRYRUN: return + self._ensure_iproute2_vrf_dir() fmode = 'a+' if append else 'w' if not append: # write file header @@ -357,6 +366,7 @@ def _iproute2_vrf_table_entry_add(self, vrfifaceobj, table_id): old_vrf_name = self.iproute2_vrf_map.get(int(table_id)) if not old_vrf_name: self.iproute2_vrf_map[int(table_id)] = vrfifaceobj.name + self._ensure_iproute2_vrf_dir() with open(self.iproute2_vrf_filename, "a+") as vrf_map_fd: vrf_map_fd.write('%s %s\n' % (table_id, vrfifaceobj.name))