Skip to content

Commit 3b229c2

Browse files
almusildceara
authored andcommitted
ci: Add back removed lflow defines in base branch.
Add back removed lflow defines to make sure the base branch compiles. The number doesn't matter for the test, add it at the end and assign some unused number. Fixes: 9b26455 ("ci: Run system tests in upgrade scenario.") Assisted-by: Claude Opus 4.6, OpenCode Signed-off-by: Ales Musil <amusil@redhat.com> Signed-off-by: Dumitru Ceara <dceara@redhat.com>
1 parent 92c7ab5 commit 3b229c2

1 file changed

Lines changed: 71 additions & 8 deletions

File tree

.ci/ovn_upgrade_utils.py

Lines changed: 71 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -393,11 +393,51 @@ def ovn_upgrade_checkout_base(config):
393393
return True
394394

395395

396+
def _append_removed_defines(src_file, old_defines, new_defines, fmt_func):
397+
"""Append compat defines to src_file for symbols removed in new code.
398+
399+
Any OFTABLE_* (or m4) define present in old_defines but absent from
400+
new_defines gets a non-conflicting ID above the highest new value and
401+
is appended to src_file so that the subsequent replace_block_in_file()
402+
includes it in one shot.
403+
"""
404+
removed = set(old_defines.keys()) - set(new_defines.keys())
405+
if not removed:
406+
return
407+
408+
max_new = max(new_defines.values())
409+
410+
with open(src_file, 'a', encoding='utf-8') as f:
411+
for i, name in enumerate(sorted(removed), start=1):
412+
table_id = max_new + i
413+
f.write(fmt_func(name, table_id))
414+
log(f" Compat define: {name} = {table_id} "
415+
f"(was {old_defines[name]})")
416+
417+
log(f" Added {len(removed)} compat define(s) for removed tables")
418+
419+
396420
def ovn_upgrade_patch_for_ovn_debug(config):
397-
return replace_block_in_file(
398-
Path('controller/lflow.h'),
399-
config.file.ofctl_defines,
400-
'#define OFTABLE_')
421+
lflow_h = Path('controller/lflow.h')
422+
423+
if not lflow_h.exists() or not config.file.ofctl_defines.exists():
424+
return False
425+
426+
# Parse old defines from the base lflow.h before overwriting.
427+
with open(lflow_h, encoding='utf-8') as f:
428+
old_defines = _parse_oftable_defines(f.readlines())
429+
430+
# Parse new defines and append compat entries for any that were
431+
# removed, so old source files (e.g. lib/actions.c) still compile.
432+
with open(config.file.ofctl_defines, encoding='utf-8') as f:
433+
new_defines = _parse_oftable_defines(f.readlines())
434+
435+
_append_removed_defines(
436+
config.file.ofctl_defines, old_defines, new_defines,
437+
lambda name, tid: f'#define {name:<40s}{tid}\n')
438+
439+
return replace_block_in_file(lflow_h, config.file.ofctl_defines,
440+
'#define OFTABLE_')
401441

402442

403443
def ovn_upgrade_save_ovn_debug(binaries_dir):
@@ -553,11 +593,34 @@ def ovn_upgrade_schema_in_macros_patch():
553593
return True
554594

555595

596+
def _parse_m4_oftable_defines(lines):
597+
"""Return {name: int_value} for all m4_define([OFTABLE_*] lines."""
598+
result = {}
599+
for line in lines:
600+
m = re.match(r"m4_define\(\[(OFTABLE_\w+)\],\s*\[(\d+)\]\)", line)
601+
if m:
602+
result[m.group(1)] = int(m.group(2))
603+
return result
604+
605+
556606
def ovn_upgrade_oftable_ovn_macro_patch(config):
557-
return replace_block_in_file(
558-
Path('tests/ovn-macros.at'),
559-
config.file.m4_defines,
560-
'm4_define([OFTABLE_')
607+
macros_at = Path('tests/ovn-macros.at')
608+
609+
if not macros_at.exists() or not config.file.m4_defines.exists():
610+
return False
611+
612+
with open(macros_at, encoding='utf-8') as f:
613+
old_m4 = _parse_m4_oftable_defines(f.readlines())
614+
615+
with open(config.file.m4_defines, encoding='utf-8') as f:
616+
new_m4 = _parse_m4_oftable_defines(f.readlines())
617+
618+
_append_removed_defines(
619+
config.file.m4_defines, old_m4, new_m4,
620+
lambda name, tid: f'm4_define([{name}], [{tid}])\n')
621+
622+
return replace_block_in_file(macros_at, config.file.m4_defines,
623+
'm4_define([OFTABLE_')
561624

562625

563626
def ovn_upgrade_apply_tests_patches(config):

0 commit comments

Comments
 (0)